@rxap/plugin-gpt 20.0.1-dev.8 → 20.1.0-dev.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/CHANGELOG.md +10 -0
- package/package.json +6 -6
- package/src/generators/documentation/compose-context.d.ts +2 -0
- package/src/generators/documentation/compose-context.js +33 -0
- package/src/generators/documentation/compose-context.js.map +1 -0
- package/src/generators/documentation/generator.js +32 -16
- package/src/generators/documentation/generator.js.map +1 -1
- package/src/generators/documentation/process-source-file.js +3 -4
- package/src/generators/documentation/process-source-file.js.map +1 -1
- package/src/generators/documentation/prompt.d.ts +2 -1
- package/src/generators/documentation/prompt.js +4 -1
- package/src/generators/documentation/prompt.js.map +1 -1
- package/src/generators/documentation/schema.json +1 -1
- package/src/generators/documentation/simple-prompt.d.ts +16 -2
- package/src/generators/documentation/simple-prompt.js +45 -40
- package/src/generators/documentation/simple-prompt.js.map +1 -1
- package/src/generators/documentation/system-prompts/block-tags.txt +132 -0
- package/src/generators/documentation/system-prompts/context.xsd +35 -0
- package/src/generators/documentation/system-prompts/generic.txt +375 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [20.1.0-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@20.1.0-dev.0...@rxap/plugin-gpt@20.1.0-dev.1) (2025-02-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rxap/plugin-gpt
|
|
9
|
+
|
|
10
|
+
# [20.1.0-dev.0](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@20.0.1-dev.8...@rxap/plugin-gpt@20.1.0-dev.0) (2025-02-07)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- support new ai models ([a43ffc6](https://gitlab.com/rxap/packages/commit/a43ffc6b77b949c6521f0a6a4d7557734d062e42))
|
|
15
|
+
|
|
6
16
|
## [20.0.1-dev.8](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@20.0.1-dev.7...@rxap/plugin-gpt@20.0.1-dev.8) (2025-01-30)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rxap/plugin-gpt
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "20.0
|
|
2
|
+
"version": "20.1.0-dev.1",
|
|
3
3
|
"name": "@rxap/plugin-gpt",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@nx/devkit": "20.4.
|
|
7
|
-
"@rxap/ts-morph": "^1.5.3-dev.
|
|
8
|
-
"@rxap/workspace-ts-morph": "^19.1.9-dev.
|
|
9
|
-
"@rxap/workspace-utilities": "^19.6.1-dev.
|
|
6
|
+
"@nx/devkit": "20.4.2",
|
|
7
|
+
"@rxap/ts-morph": "^1.5.3-dev.5",
|
|
8
|
+
"@rxap/workspace-ts-morph": "^19.1.9-dev.10",
|
|
9
|
+
"@rxap/workspace-utilities": "^19.6.1-dev.9",
|
|
10
10
|
"gpt-3-encoder": "^1.1.4",
|
|
11
11
|
"openai": "^4.52.0",
|
|
12
12
|
"ts-morph": "18.0.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"schematics": "./generators.json",
|
|
45
45
|
"type": "commonjs",
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "3c5aef907af80a815e7c9a404878c2eda2596cf4",
|
|
47
47
|
"types": "./src/index.d.ts",
|
|
48
48
|
"main": "./src/index.js"
|
|
49
49
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.composeContext = composeContext;
|
|
4
|
+
const xml2js_1 = require("xml2js");
|
|
5
|
+
function sourceFileToContextSourceFile(sourceFile) {
|
|
6
|
+
return {
|
|
7
|
+
$: {
|
|
8
|
+
path: sourceFile.getFilePath(),
|
|
9
|
+
},
|
|
10
|
+
_: '\n' + sourceFile.getText({ trimLeadingIndentation: true, includeJsDocComments: false })
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function getReferenced(sourceFile) {
|
|
14
|
+
return [
|
|
15
|
+
...sourceFile.getReferencedSourceFiles(),
|
|
16
|
+
...sourceFile.getReferencedSourceFiles().map(sf => getReferenced(sf)).flat()
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
function composeContext(sourceFile) {
|
|
20
|
+
const builder = new xml2js_1.Builder();
|
|
21
|
+
const context = {
|
|
22
|
+
referenced: { sourceFile: [] },
|
|
23
|
+
used: { sourceFile: [] },
|
|
24
|
+
};
|
|
25
|
+
sourceFile.getReferencingSourceFiles().forEach(sf => {
|
|
26
|
+
context.used.sourceFile.push(sourceFileToContextSourceFile(sf));
|
|
27
|
+
});
|
|
28
|
+
getReferenced(sourceFile).forEach(sf => {
|
|
29
|
+
context.referenced.sourceFile.push(sourceFileToContextSourceFile(sf));
|
|
30
|
+
});
|
|
31
|
+
return builder.buildObject(context).replace(/root>/g, 'context>') + '\n';
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=compose-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-context.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/compose-context.ts"],"names":[],"mappings":";;AAmCA,wCAmBC;AArDD,mCAAiC;AAkBjC,SAAS,6BAA6B,CAAC,UAAsB;IAC3D,OAAO;QACL,CAAC,EAAE;YACD,IAAI,EAAE,UAAU,CAAC,WAAW,EAAE;SAC/B;QACD,CAAC,EAAE,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,sBAAsB,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;KAC5F,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,UAAsB;IAC3C,OAAO;QACL,GAAG,UAAU,CAAC,wBAAwB,EAAE;QACxC,GAAG,UAAU,CAAC,wBAAwB,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;KAC7E,CAAC;AACJ,CAAC;AAED,SAAgB,cAAc,CAAC,UAAsB;IAEnD,MAAM,OAAO,GAAG,IAAI,gBAAO,EAAE,CAAC;IAE9B,MAAM,OAAO,GAAY;QACvB,UAAU,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;QAC9B,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;KACzB,CAAC;IAEF,UAAU,CAAC,yBAAyB,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QAClD,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,6BAA6B,CAAC,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,aAAa,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACrC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,6BAA6B,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,IAAI,CAAC;AAE3E,CAAC"}
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.documentationGenerator = documentationGenerator;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const workspace_ts_morph_1 = require("@rxap/workspace-ts-morph");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = require("path");
|
|
6
8
|
const process = require("process");
|
|
9
|
+
const add_js_doc_1 = require("./add-js-doc");
|
|
10
|
+
const compose_context_1 = require("./compose-context");
|
|
7
11
|
const open_ai_instance_1 = require("./open-ai-instance");
|
|
8
|
-
const
|
|
12
|
+
const prompt_1 = require("./prompt");
|
|
9
13
|
function skipProject(project, projectName, options) {
|
|
10
14
|
var _a;
|
|
11
15
|
if (options.project === projectName) {
|
|
@@ -18,30 +22,42 @@ function skipProject(project, projectName, options) {
|
|
|
18
22
|
}
|
|
19
23
|
function documentationGenerator(tree, options) {
|
|
20
24
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
var _a, _b, _c;
|
|
25
|
+
var _a, _b, _c, _d;
|
|
22
26
|
const openaiApiKey = (_a = options.openaiApiKey) !== null && _a !== void 0 ? _a : process.env.OPENAI_API_KEY;
|
|
23
|
-
const openaiOrganization = (_b = options.openaiOrgId) !== null && _b !== void 0 ? _b : process.env.OPENAI_ORG_ID;
|
|
24
|
-
const openaiProjectId = (
|
|
27
|
+
const openaiOrganization = (_c = (_b = options.openaiOrgId) !== null && _b !== void 0 ? _b : process.env.OPENAI_ORG_ID) !== null && _c !== void 0 ? _c : process.env.OPENAI_ORGANIZATION;
|
|
28
|
+
const openaiProjectId = (_d = options.openaiProjectId) !== null && _d !== void 0 ? _d : process.env.OPENAI_PROJECT_ID;
|
|
25
29
|
if (!openaiApiKey) {
|
|
26
30
|
throw new Error('Can not find OPENAI_API_KEY environment variable');
|
|
27
31
|
}
|
|
28
|
-
if (!openaiOrganization) {
|
|
29
|
-
throw new Error('Can not find OPENAI_ORGANIZATION environment variable');
|
|
30
|
-
}
|
|
31
|
-
if (!openaiProjectId) {
|
|
32
|
-
throw new Error('Can not find OPENAI_PROJECT_ID environment variable');
|
|
33
|
-
}
|
|
34
32
|
yield (0, open_ai_instance_1.createOpenApi)({
|
|
35
33
|
apiKey: openaiApiKey,
|
|
36
34
|
organization: openaiOrganization,
|
|
37
35
|
project: openaiProjectId,
|
|
38
36
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
// relative path form the workspace root
|
|
38
|
+
const path = (0, path_1.relative)(tree.root, process.cwd());
|
|
39
|
+
const systemPrompt = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, 'system-prompts', 'generic.txt'), 'utf-8');
|
|
40
|
+
yield (0, workspace_ts_morph_1.TsMorphTransform)(tree, path, (project) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
42
|
+
const context = (0, compose_context_1.composeContext)(sourceFile);
|
|
43
|
+
let target = `<sourceFile path="${sourceFile.getFilePath()}">\n`;
|
|
44
|
+
target += sourceFile.getText({ trimLeadingIndentation: true, includeJsDocComments: false });
|
|
45
|
+
target += '</sourceFile>\n';
|
|
46
|
+
for (const functionDeclaration of sourceFile.getFunctions()) {
|
|
47
|
+
const question = `TASK: create the JsDoc documentation for the function \`${functionDeclaration.getName()}\` from the file \`${sourceFile.getFilePath()}\``;
|
|
48
|
+
console.log(question);
|
|
49
|
+
try {
|
|
50
|
+
const jsDoc = yield (0, prompt_1.prompt)(options, systemPrompt, [context, target, question].join('\n\n'));
|
|
51
|
+
console.log('jsDoc', jsDoc);
|
|
52
|
+
(0, add_js_doc_1.addJsDoc)(options, functionDeclaration, jsDoc);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.log(`jsDoc prompt error: ${e.message}`.red);
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
42
59
|
}
|
|
43
|
-
|
|
44
|
-
}
|
|
60
|
+
}));
|
|
45
61
|
});
|
|
46
62
|
}
|
|
47
63
|
exports.default = documentationGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/generator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources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AC,CAAC;oBACtD,CAAC;oBAED,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC,CAAA,CAAC,CAAC;IAEL,CAAC;CAAA;AAED,kBAAe,sBAAsB,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processSourceFile = processSourceFile;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const process_class_1 = require("./process-class");
|
|
6
5
|
const process_function_1 = require("./process-function");
|
|
7
6
|
function processSourceFile(options, sourceFile) {
|
|
8
7
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -10,9 +9,9 @@ function processSourceFile(options, sourceFile) {
|
|
|
10
9
|
for (const functionDeclaration of sourceFile.getFunctions()) {
|
|
11
10
|
yield (0, process_function_1.processFunction)(options, functionDeclaration);
|
|
12
11
|
}
|
|
13
|
-
for (const classDeclaration of sourceFile.getClasses()) {
|
|
14
|
-
|
|
15
|
-
}
|
|
12
|
+
// for (const classDeclaration of sourceFile.getClasses()) {
|
|
13
|
+
// await processClass(options, classDeclaration);
|
|
14
|
+
// }
|
|
16
15
|
});
|
|
17
16
|
}
|
|
18
17
|
//# sourceMappingURL=process-source-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-source-file.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/process-source-file.ts"],"names":[],"mappings":";;AAQA,8CAgBC;;
|
|
1
|
+
{"version":3,"file":"process-source-file.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/process-source-file.ts"],"names":[],"mappings":";;AAQA,8CAgBC;;AAnBD,yDAAqD;AAGrD,SAAsB,iBAAiB,CACrC,OAAqC,EACrC,UAAsB;;QAGtB,OAAO,CAAC,GAAG,CAAC,uCAAwC,UAAU,CAAC,WAAW,EAAG,SAAS,CAAC,CAAC;QAExF,KAAK,MAAM,mBAAmB,IAAI,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC;YAC5D,MAAM,IAAA,kCAAe,EAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QACtD,CAAC;QAED,4DAA4D;QAC5D,mDAAmD;QACnD,IAAI;IAGN,CAAC;CAAA"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { DocumentationGeneratorSchema } from './schema';
|
|
2
|
+
export declare function prompt(options: DocumentationGeneratorSchema, systemPrompt: string, prompt: string): Promise<string>;
|
|
@@ -7,9 +7,12 @@ const simple_prompt_1 = require("./simple-prompt");
|
|
|
7
7
|
function prompt(options, systemPrompt, prompt) {
|
|
8
8
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
9
|
if (options.offline) {
|
|
10
|
+
console.log('Prompt:', prompt);
|
|
10
11
|
return '';
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
else {
|
|
14
|
+
return (0, simple_prompt_1.SimplePrompt)(systemPrompt, prompt, (0, open_ai_instance_1.getOpenAi)());
|
|
15
|
+
}
|
|
13
16
|
});
|
|
14
17
|
}
|
|
15
18
|
//# sourceMappingURL=prompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/prompt.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/prompt.ts"],"names":[],"mappings":";;AAIA,wBAYC;;AAhBD,yDAA+C;AAE/C,mDAA+C;AAE/C,SAAsB,MAAM,CAAC,OAAqC,EAAE,YAAoB,EAAE,MAAc;;QAEtG,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/B,OAAO,EAAE,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,OAAO,IAAA,4BAAY,EACjB,YAAY,EACZ,MAAM,EACN,IAAA,4BAAS,GAAE,CACZ,CAAC;QACJ,CAAC;IACH,CAAC;CAAA"}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { OpenAI } from 'openai';
|
|
2
2
|
import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions';
|
|
3
|
-
|
|
3
|
+
import 'colors';
|
|
4
|
+
/**
|
|
5
|
+
* Model Context size https://platform.openai.com/docs/models
|
|
6
|
+
*/
|
|
7
|
+
declare const tokenLimits: {
|
|
8
|
+
'gpt-4o': number;
|
|
9
|
+
'gpt-4o-mini': number;
|
|
10
|
+
o1: number;
|
|
11
|
+
'o1-mini': number;
|
|
12
|
+
'o3-mini': number;
|
|
13
|
+
};
|
|
14
|
+
export type Model = keyof typeof tokenLimits;
|
|
4
15
|
export interface SimplePromptOptions {
|
|
5
16
|
max_tokens?: number;
|
|
6
17
|
model?: Model;
|
|
7
18
|
}
|
|
8
19
|
export declare function IsAllDefined(options: SimplePromptOptions): options is Required<SimplePromptOptions>;
|
|
9
20
|
export declare function AssertAllDefined(options: SimplePromptOptions): asserts options is Required<SimplePromptOptions>;
|
|
10
|
-
export declare function SimplePrompt(systemPrompt: string, prompt: string, openai: OpenAI, options?: Partial<ChatCompletionCreateParamsBase>
|
|
21
|
+
export declare function SimplePrompt(systemPrompt: string, prompt: string, openai: OpenAI, options?: Partial<ChatCompletionCreateParamsBase> & {
|
|
22
|
+
model: Model;
|
|
23
|
+
}): Promise<string>;
|
|
24
|
+
export {};
|
|
@@ -4,13 +4,17 @@ exports.IsAllDefined = IsAllDefined;
|
|
|
4
4
|
exports.AssertAllDefined = AssertAllDefined;
|
|
5
5
|
exports.SimplePrompt = SimplePrompt;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
|
-
const
|
|
7
|
+
const tiktoken_1 = require("tiktoken");
|
|
8
|
+
require("colors");
|
|
9
|
+
/**
|
|
10
|
+
* Model Context size https://platform.openai.com/docs/models
|
|
11
|
+
*/
|
|
8
12
|
const tokenLimits = {
|
|
9
|
-
'gpt-
|
|
10
|
-
'gpt-
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
13
|
+
'gpt-4o': 128000, // $2.50
|
|
14
|
+
'gpt-4o-mini': 128000, // $0.15
|
|
15
|
+
'o1': 200000, // $15.00
|
|
16
|
+
'o1-mini': 128000, // $1.10
|
|
17
|
+
'o3-mini': 200000, // $1.10
|
|
14
18
|
};
|
|
15
19
|
function IsAllDefined(options) {
|
|
16
20
|
return options.max_tokens !== undefined && options.model !== undefined;
|
|
@@ -22,15 +26,16 @@ function AssertAllDefined(options) {
|
|
|
22
26
|
}
|
|
23
27
|
function SimplePrompt(systemPrompt_1, prompt_1, openai_1) {
|
|
24
28
|
return tslib_1.__awaiter(this, arguments, void 0, function* (systemPrompt, prompt, openai, options = {
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
model: 'o3-mini',
|
|
30
|
+
max_tokens: 10000
|
|
27
31
|
}) {
|
|
28
|
-
var _a, _b
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const enc = (0, tiktoken_1.encoding_for_model)(options.model);
|
|
34
|
+
const systemPromptLength = enc.encode(systemPrompt).length;
|
|
35
|
+
const promptLength = enc.encode(prompt).length;
|
|
36
|
+
enc.free();
|
|
37
|
+
const inputLength = systemPromptLength + promptLength;
|
|
38
|
+
(_a = options.model) !== null && _a !== void 0 ? _a : (options.model = 'o3-mini');
|
|
34
39
|
if (!tokenLimits[options.model]) {
|
|
35
40
|
throw new Error(`\x1b[31mModel '${options.model}' is not supported.\x1b[0m`);
|
|
36
41
|
}
|
|
@@ -46,34 +51,34 @@ function SimplePrompt(systemPrompt_1, prompt_1, openai_1) {
|
|
|
46
51
|
options.max_tokens = tokenLimit - inputLength;
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
|
-
let content;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
catch (e) {
|
|
72
|
-
console.log((_d = e.response) === null || _d === void 0 ? void 0 : _d.data);
|
|
73
|
-
throw new Error('OpenAI API error: ' + e.message);
|
|
54
|
+
let content = undefined;
|
|
55
|
+
console.log(`send with '${promptLength}' prompt tokens and '${systemPromptLength}' system prompt tokens with '${options.max_tokens}' max tokens`.grey);
|
|
56
|
+
const input = {
|
|
57
|
+
model: options.model,
|
|
58
|
+
messages: [
|
|
59
|
+
{
|
|
60
|
+
'role': 'system',
|
|
61
|
+
'content': systemPrompt,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
'role': 'user',
|
|
65
|
+
'content': prompt,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
if (options.max_tokens) {
|
|
70
|
+
if (options.model.startsWith('o')) {
|
|
71
|
+
input.max_completion_tokens = options.max_tokens;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
input.max_tokens = options.max_tokens;
|
|
75
|
+
}
|
|
74
76
|
}
|
|
77
|
+
const response = yield openai.chat.completions.create(input);
|
|
78
|
+
content = (_b = response.choices[0].message) === null || _b === void 0 ? void 0 : _b.content;
|
|
75
79
|
if (!content) {
|
|
76
|
-
|
|
80
|
+
console.log('No content in response'.red);
|
|
81
|
+
throw new Error(`No content in response`);
|
|
77
82
|
}
|
|
78
83
|
return content;
|
|
79
84
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/simple-prompt.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"simple-prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/simple-prompt.ts"],"names":[],"mappings":";;AAwBA,oCAEC;AAED,4CAIC;AAED,oCA0EC;;AAzGD,uCAA8C;AAC9C,kBAAgB;AAEhB;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,QAAQ,EAAE,MAAO,EAAE,QAAQ;IAC3B,aAAa,EAAE,MAAO,EAAE,QAAQ;IAChC,IAAI,EAAE,MAAO,EAAE,SAAS;IACxB,SAAS,EAAE,MAAO,EAAE,QAAQ;IAC5B,SAAS,EAAE,MAAO,EAAE,QAAQ;CAC7B,CAAC;AASF,SAAgB,YAAY,CAAC,OAA4B;IACvD,OAAO,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC;AACzE,CAAC;AAED,SAAgB,gBAAgB,CAAC,OAA4B;IAC3D,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED,SAAsB,YAAY;iEAChC,YAAoB,EACpB,MAAc,EACd,MAAc,EACd,UAAsE;QACpE,KAAK,EAAE,SAAS;QAChB,UAAU,EAAE,KAAM;KACnB;;QAGD,MAAM,GAAG,GAAG,IAAA,6BAAkB,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAE9C,MAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC;QAC3D,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;QAE/C,GAAG,CAAC,IAAI,EAAE,CAAC;QAEX,MAAM,WAAW,GAAG,kBAAkB,GAAG,YAAY,CAAC;QAEtD,MAAA,OAAO,CAAC,KAAK,oCAAb,OAAO,CAAC,KAAK,GAAK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,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACxC,CAAC;QACH,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE7D,OAAO,GAAG,MAAA,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,0CAAE,OAAO,CAAC;QAE/C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,OAAO,CAAC;IAEjB,CAAC;CAAA"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
@abstract (synonyms: @virtual)
|
|
2
|
+
This member must be implemented (or overridden) by the inheritor.
|
|
3
|
+
@access
|
|
4
|
+
Specify the access level of this member (private, package-private, public, or protected).
|
|
5
|
+
@alias
|
|
6
|
+
Treat a member as if it had a different name.
|
|
7
|
+
@async
|
|
8
|
+
Indicate that a function is asynchronous.
|
|
9
|
+
@augments (synonyms: @extends)
|
|
10
|
+
Indicate that a symbol inherits from, and adds to, a parent symbol.
|
|
11
|
+
@author
|
|
12
|
+
Identify the author of an item.
|
|
13
|
+
@borrows
|
|
14
|
+
This object uses something from another object.
|
|
15
|
+
@class (synonyms: @constructor)
|
|
16
|
+
This function is intended to be called with the "new" keyword.
|
|
17
|
+
@classdesc
|
|
18
|
+
Use the following text to describe the entire class.
|
|
19
|
+
@constant (synonyms: @const)
|
|
20
|
+
Document an object as a constant.
|
|
21
|
+
@constructs
|
|
22
|
+
This function member will be the constructor for the previous class.
|
|
23
|
+
@copyright
|
|
24
|
+
Document some copyright information.
|
|
25
|
+
@default (synonyms: @defaultvalue)
|
|
26
|
+
Document the default value.
|
|
27
|
+
@deprecated
|
|
28
|
+
Document that this is no longer the preferred way.
|
|
29
|
+
@description (synonyms: @desc)
|
|
30
|
+
Describe a symbol.
|
|
31
|
+
@enum
|
|
32
|
+
Document a collection of related properties.
|
|
33
|
+
@event
|
|
34
|
+
Document an event.
|
|
35
|
+
@example
|
|
36
|
+
Provide an example of how to use a documented item.
|
|
37
|
+
@exports
|
|
38
|
+
Identify the member that is exported by a JavaScript module.
|
|
39
|
+
@external (synonyms: @host)
|
|
40
|
+
Identifies an external class, namespace, or module.
|
|
41
|
+
@file (synonyms: @fileoverview, @overview)
|
|
42
|
+
Describe a file.
|
|
43
|
+
@fires (synonyms: @emits)
|
|
44
|
+
Describe the events this method may fire.
|
|
45
|
+
@function (synonyms: @func, @method)
|
|
46
|
+
Describe a function or method.
|
|
47
|
+
@generator
|
|
48
|
+
Indicate that a function is a generator function.
|
|
49
|
+
@global
|
|
50
|
+
Document a global object.
|
|
51
|
+
@hideconstructor
|
|
52
|
+
Indicate that the constructor should not be displayed.
|
|
53
|
+
@ignore
|
|
54
|
+
Omit a symbol from the documentation.
|
|
55
|
+
@implements
|
|
56
|
+
This symbol implements an interface.
|
|
57
|
+
@inheritdoc
|
|
58
|
+
Indicate that a symbol should inherit its parent's documentation.
|
|
59
|
+
@inner
|
|
60
|
+
Document an inner object.
|
|
61
|
+
@instance
|
|
62
|
+
Document an instance member.
|
|
63
|
+
@interface
|
|
64
|
+
This symbol is an interface that others can implement.
|
|
65
|
+
@kind
|
|
66
|
+
What kind of symbol is this?
|
|
67
|
+
@lends
|
|
68
|
+
Document properties on an object literal as if they belonged to a symbol with a given name.
|
|
69
|
+
@license
|
|
70
|
+
Identify the license that applies to this code.
|
|
71
|
+
@listens
|
|
72
|
+
List the events that a symbol listens for.
|
|
73
|
+
@member (synonyms: @var)
|
|
74
|
+
Document a member.
|
|
75
|
+
@memberof
|
|
76
|
+
This symbol belongs to a parent symbol.
|
|
77
|
+
@mixes
|
|
78
|
+
This object mixes in all the members from another object.
|
|
79
|
+
@mixin
|
|
80
|
+
Document a mixin object.
|
|
81
|
+
@module
|
|
82
|
+
Document a JavaScript module.
|
|
83
|
+
@name
|
|
84
|
+
Document the name of an object.
|
|
85
|
+
@namespace
|
|
86
|
+
Document a namespace object.
|
|
87
|
+
@override
|
|
88
|
+
Indicate that a symbol overrides its parent.
|
|
89
|
+
@package
|
|
90
|
+
This symbol is meant to be package-private.
|
|
91
|
+
@param (synonyms: @arg, @argument)
|
|
92
|
+
Document the parameter to a function.
|
|
93
|
+
@private
|
|
94
|
+
This symbol is meant to be private.
|
|
95
|
+
@property (synonyms: @prop)
|
|
96
|
+
Document a property of an object.
|
|
97
|
+
@protected
|
|
98
|
+
This symbol is meant to be protected.
|
|
99
|
+
@public
|
|
100
|
+
This symbol is meant to be public.
|
|
101
|
+
@readonly
|
|
102
|
+
This symbol is meant to be read-only.
|
|
103
|
+
@requires
|
|
104
|
+
This file requires a JavaScript module.
|
|
105
|
+
@returns (synonyms: @return)
|
|
106
|
+
Document the return value of a function.
|
|
107
|
+
@see
|
|
108
|
+
Refer to some other documentation for more information.
|
|
109
|
+
@since
|
|
110
|
+
When was this feature added?
|
|
111
|
+
@static
|
|
112
|
+
Document a static member.
|
|
113
|
+
@summary
|
|
114
|
+
A shorter version of the full description.
|
|
115
|
+
@this
|
|
116
|
+
What does the 'this' keyword refer to here?
|
|
117
|
+
@throws (synonyms: @exception)
|
|
118
|
+
Describe what errors could be thrown.
|
|
119
|
+
@todo
|
|
120
|
+
Document tasks to be completed.
|
|
121
|
+
@tutorial
|
|
122
|
+
Insert a link to an included tutorial file.
|
|
123
|
+
@type
|
|
124
|
+
Document the type of an object.
|
|
125
|
+
@typedef
|
|
126
|
+
Document a custom type.
|
|
127
|
+
@variation
|
|
128
|
+
Distinguish different objects with the same name.
|
|
129
|
+
@version
|
|
130
|
+
Documents the version number of an item.
|
|
131
|
+
@yields (synonyms: @yield)
|
|
132
|
+
Document the value yielded by a generator function.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
3
|
+
elementFormDefault="qualified">
|
|
4
|
+
|
|
5
|
+
<!-- Definition of the sourceFileType to capture the 'path' attribute -->
|
|
6
|
+
<xsd:complexType name="sourceFileType">
|
|
7
|
+
<xsd:attribute name="path" type="xsd:string" use="required"/>
|
|
8
|
+
</xsd:complexType>
|
|
9
|
+
|
|
10
|
+
<!-- Root element 'context' -->
|
|
11
|
+
<xsd:element name="context">
|
|
12
|
+
<xsd:complexType>
|
|
13
|
+
<xsd:sequence>
|
|
14
|
+
<!-- 'referenced' element with multiple 'source-file' elements -->
|
|
15
|
+
<xsd:element name="referenced" minOccurs="0" maxOccurs="1">
|
|
16
|
+
<xsd:complexType>
|
|
17
|
+
<xsd:sequence>
|
|
18
|
+
<xsd:element name="source-file" type="sourceFileType" minOccurs="0" maxOccurs="unbounded"/>
|
|
19
|
+
</xsd:sequence>
|
|
20
|
+
</xsd:complexType>
|
|
21
|
+
</xsd:element>
|
|
22
|
+
|
|
23
|
+
<!-- 'used' element with multiple 'source-file' elements -->
|
|
24
|
+
<xsd:element name="used" minOccurs="0" maxOccurs="1">
|
|
25
|
+
<xsd:complexType>
|
|
26
|
+
<xsd:sequence>
|
|
27
|
+
<xsd:element name="source-file" type="sourceFileType" minOccurs="0" maxOccurs="unbounded"/>
|
|
28
|
+
</xsd:sequence>
|
|
29
|
+
</xsd:complexType>
|
|
30
|
+
</xsd:element>
|
|
31
|
+
</xsd:sequence>
|
|
32
|
+
</xsd:complexType>
|
|
33
|
+
</xsd:element>
|
|
34
|
+
|
|
35
|
+
</xsd:schema>
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
Your task is to generate complete JSDoc documentation for the provided TypeScript source code. The context supplied consists of two parts:
|
|
2
|
+
|
|
3
|
+
1. The source code and all related files (both files referenced by the source code and files that use the source code) are provided as context formatted according to the schema in the context.xsd file below.
|
|
4
|
+
|
|
5
|
+
2. An overview of the available JSDoc block tags is provided in the block-tags.txt file below. You must use these tags in your documentation.
|
|
6
|
+
|
|
7
|
+
Use the following file contents as reference:
|
|
8
|
+
|
|
9
|
+
-------------------- block-tags.txt --------------------
|
|
10
|
+
@deprecated
|
|
11
|
+
Document that this is no longer the preferred way.
|
|
12
|
+
|
|
13
|
+
@description (synonyms: @desc)
|
|
14
|
+
Describe a symbol.
|
|
15
|
+
|
|
16
|
+
@enum
|
|
17
|
+
Document a collection of related properties.
|
|
18
|
+
|
|
19
|
+
@event
|
|
20
|
+
Document an event.
|
|
21
|
+
|
|
22
|
+
@example
|
|
23
|
+
Provide an example of how to use a documented item.
|
|
24
|
+
|
|
25
|
+
@exports
|
|
26
|
+
Identify the member that is exported by a JavaScript module.
|
|
27
|
+
|
|
28
|
+
@external (synonyms: @host)
|
|
29
|
+
Identifies an external class, namespace, or module.
|
|
30
|
+
|
|
31
|
+
@file (synonyms: @fileoverview, @overview)
|
|
32
|
+
Describe a file.
|
|
33
|
+
|
|
34
|
+
@fires (synonyms: @emits)
|
|
35
|
+
Describe the events this method may fire.
|
|
36
|
+
|
|
37
|
+
@function (synonyms: @func, @method)
|
|
38
|
+
Describe a function or method.
|
|
39
|
+
|
|
40
|
+
@generator
|
|
41
|
+
Indicate that a function is a generator function.
|
|
42
|
+
|
|
43
|
+
@global
|
|
44
|
+
Document a global object.
|
|
45
|
+
|
|
46
|
+
@hideconstructor
|
|
47
|
+
Indicate that the constructor should not be displayed.
|
|
48
|
+
|
|
49
|
+
@ignore
|
|
50
|
+
Omit a symbol from the documentation.
|
|
51
|
+
|
|
52
|
+
@implements
|
|
53
|
+
This symbol implements an interface.
|
|
54
|
+
|
|
55
|
+
@inheritdoc
|
|
56
|
+
Indicate that a symbol should inherit its parent's documentation.
|
|
57
|
+
|
|
58
|
+
@inner
|
|
59
|
+
Document an inner object.
|
|
60
|
+
|
|
61
|
+
@instance
|
|
62
|
+
Document an instance member.
|
|
63
|
+
|
|
64
|
+
@interface
|
|
65
|
+
This symbol is an interface that others can implement.
|
|
66
|
+
|
|
67
|
+
@kind
|
|
68
|
+
What kind of symbol is this?
|
|
69
|
+
|
|
70
|
+
@lends
|
|
71
|
+
Document properties on an object literal as if they belonged to a symbol with a given name.
|
|
72
|
+
|
|
73
|
+
@license
|
|
74
|
+
Identify the license that applies to this code.
|
|
75
|
+
|
|
76
|
+
@listens
|
|
77
|
+
List the events that a symbol listens for.
|
|
78
|
+
|
|
79
|
+
@member (synonyms: @var)
|
|
80
|
+
Document a member.
|
|
81
|
+
|
|
82
|
+
@memberof
|
|
83
|
+
This symbol belongs to a parent symbol.
|
|
84
|
+
|
|
85
|
+
@mixes
|
|
86
|
+
This object mixes in all the members from another object.
|
|
87
|
+
|
|
88
|
+
@mixin
|
|
89
|
+
Document a mixin object.
|
|
90
|
+
|
|
91
|
+
@module
|
|
92
|
+
Document a JavaScript module.
|
|
93
|
+
|
|
94
|
+
@name
|
|
95
|
+
Document the name of an object.
|
|
96
|
+
|
|
97
|
+
@namespace
|
|
98
|
+
Document a namespace object.
|
|
99
|
+
|
|
100
|
+
@override
|
|
101
|
+
Indicate that a symbol overrides its parent.
|
|
102
|
+
|
|
103
|
+
@package
|
|
104
|
+
This symbol is meant to be package-private.
|
|
105
|
+
|
|
106
|
+
@param (synonyms: @arg, @argument)
|
|
107
|
+
Document the parameter to a function.
|
|
108
|
+
|
|
109
|
+
@private
|
|
110
|
+
This symbol is meant to be private.
|
|
111
|
+
|
|
112
|
+
@property (synonyms: @prop)
|
|
113
|
+
Document a property of an object.
|
|
114
|
+
|
|
115
|
+
@protected
|
|
116
|
+
This symbol is meant to be protected.
|
|
117
|
+
|
|
118
|
+
@public
|
|
119
|
+
This symbol is meant to be public.
|
|
120
|
+
|
|
121
|
+
@readonly
|
|
122
|
+
This symbol is meant to be read-only.
|
|
123
|
+
|
|
124
|
+
@requires
|
|
125
|
+
This file requires a JavaScript module.
|
|
126
|
+
|
|
127
|
+
@returns (synonyms: @return)
|
|
128
|
+
Document the return value of a function.
|
|
129
|
+
|
|
130
|
+
@see
|
|
131
|
+
Refer to some other documentation for more information.
|
|
132
|
+
|
|
133
|
+
@since
|
|
134
|
+
When was this feature added?
|
|
135
|
+
|
|
136
|
+
@static
|
|
137
|
+
Document a static member.
|
|
138
|
+
|
|
139
|
+
@summary
|
|
140
|
+
A shorter version of the full description.
|
|
141
|
+
|
|
142
|
+
@this
|
|
143
|
+
What does the 'this' keyword refer to here?
|
|
144
|
+
|
|
145
|
+
@throws (synonyms: @exception)
|
|
146
|
+
Describe what errors could be thrown.
|
|
147
|
+
|
|
148
|
+
@todo
|
|
149
|
+
Document tasks to be completed.
|
|
150
|
+
|
|
151
|
+
@tutorial
|
|
152
|
+
Insert a link to an included tutorial file.
|
|
153
|
+
|
|
154
|
+
@type
|
|
155
|
+
Document the type of an object.
|
|
156
|
+
|
|
157
|
+
@typedef
|
|
158
|
+
Document a custom type.
|
|
159
|
+
|
|
160
|
+
@variation
|
|
161
|
+
Distinguish different objects with the same name.
|
|
162
|
+
|
|
163
|
+
@version
|
|
164
|
+
Documents the version number of an item.
|
|
165
|
+
|
|
166
|
+
@yields (synonyms: @yield)
|
|
167
|
+
Document the value yielded by a generator function.
|
|
168
|
+
------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
-------------------- context.xsd --------------------
|
|
171
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
172
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
173
|
+
elementFormDefault="qualified">
|
|
174
|
+
|
|
175
|
+
<!-- Definition of the sourceFileType to capture the 'path' attribute -->
|
|
176
|
+
<xsd:complexType name="sourceFileType">
|
|
177
|
+
<xsd:attribute name="path" type="xsd:string" use="required"/>
|
|
178
|
+
</xsd:complexType>
|
|
179
|
+
|
|
180
|
+
<!-- Root element 'context' -->
|
|
181
|
+
<xsd:element name="context">
|
|
182
|
+
<xsd:complexType>
|
|
183
|
+
<xsd:sequence>
|
|
184
|
+
<!-- 'referenced' element with multiple 'source-file' elements -->
|
|
185
|
+
<xsd:element name="referenced" minOccurs="0" maxOccurs="1">
|
|
186
|
+
<xsd:complexType>
|
|
187
|
+
<xsd:sequence>
|
|
188
|
+
<xsd:element name="source-file" type="sourceFileType" minOccurs="0" maxOccurs="unbounded"/>
|
|
189
|
+
</xsd:sequence>
|
|
190
|
+
</xsd:complexType>
|
|
191
|
+
</xsd:element>
|
|
192
|
+
|
|
193
|
+
<!-- 'used' element with multiple 'source-file' elements -->
|
|
194
|
+
<xsd:element name="used" minOccurs="0" maxOccurs="1">
|
|
195
|
+
<xsd:complexType>
|
|
196
|
+
<xsd:sequence>
|
|
197
|
+
<xsd:element name="source-file" type="sourceFileType" minOccurs="0" maxOccurs="unbounded"/>
|
|
198
|
+
</xsd:sequence>
|
|
199
|
+
</xsd:complexType>
|
|
200
|
+
</xsd:element>
|
|
201
|
+
|
|
202
|
+
</xsd:sequence>
|
|
203
|
+
</xsd:complexType>
|
|
204
|
+
</xsd:element>
|
|
205
|
+
|
|
206
|
+
</xsd:schema>
|
|
207
|
+
------------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
Instructions:
|
|
210
|
+
- Read the provided source code along with its related files (referenced and using) as structured by the context.xsd.
|
|
211
|
+
- Create the complete JSDoc documentation using only the JSDoc block tags listed above.
|
|
212
|
+
- Output ONLY the JSDoc content, without any additional text or any TypeScript comment syntax (omit /*, */, etc.).
|
|
213
|
+
|
|
214
|
+
Example Input:
|
|
215
|
+
------------------------------------------------------------
|
|
216
|
+
<context>
|
|
217
|
+
<referenced>
|
|
218
|
+
<sourceFile path="/delete-undefined-properties.ts">
|
|
219
|
+
export function DeleteUndefinedProperties<T extends {}>(obj: T, recursive?: boolean): Exclude<T, undefined> {
|
|
220
|
+
if (!obj || typeof obj !== 'object') {
|
|
221
|
+
return obj as any;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const keys = Object.keys(obj);
|
|
225
|
+
const cloneObj: any = {};
|
|
226
|
+
|
|
227
|
+
for (const key of keys) {
|
|
228
|
+
if ((obj as any)[key] !== undefined) {
|
|
229
|
+
const value = (obj as any)[key];
|
|
230
|
+
cloneObj[key] = value;
|
|
231
|
+
if (recursive && value) {
|
|
232
|
+
if (Array.isArray(value)) {
|
|
233
|
+
cloneObj[key] = value.map((item) => DeleteUndefinedProperties(item, true));
|
|
234
|
+
} else if (typeof value === 'object') {
|
|
235
|
+
cloneObj[key] = DeleteUndefinedProperties(value, true);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return cloneObj;
|
|
242
|
+
}
|
|
243
|
+
</sourceFile>
|
|
244
|
+
<sourceFile path="/delete-null-properties.ts">
|
|
245
|
+
export function DeleteNullProperties<T extends {}>(obj: T, recursive?: boolean): Exclude<T, null> {
|
|
246
|
+
if (!obj || typeof obj !== 'object') {
|
|
247
|
+
return obj as any;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const keys = Object.keys(obj);
|
|
251
|
+
const cloneObj: any = {};
|
|
252
|
+
|
|
253
|
+
for (const key of keys) {
|
|
254
|
+
if ((obj as any)[key] !== null) {
|
|
255
|
+
const value = (obj as any)[key];
|
|
256
|
+
cloneObj[key] = value;
|
|
257
|
+
if (recursive && value) {
|
|
258
|
+
if (Array.isArray(value)) {
|
|
259
|
+
cloneObj[key] = value.map((item) => DeleteNullProperties(item, true));
|
|
260
|
+
} else if (typeof value === 'object') {
|
|
261
|
+
cloneObj[key] = DeleteNullProperties(value, true);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return cloneObj;
|
|
268
|
+
}
|
|
269
|
+
</sourceFile>
|
|
270
|
+
</referenced>
|
|
271
|
+
<used>
|
|
272
|
+
<sourceFile path="/delete-empty-properties.spec.ts">
|
|
273
|
+
import { DeleteEmptyProperties } from './delete-empty-properties';
|
|
274
|
+
|
|
275
|
+
describe('DeleteEmptyProperties function', () => {
|
|
276
|
+
test('should remove null properties from an object', () => {
|
|
277
|
+
const inputObj = {
|
|
278
|
+
a: 1,
|
|
279
|
+
b: null,
|
|
280
|
+
c: 'test',
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const expectedOutput = {
|
|
284
|
+
a: 1,
|
|
285
|
+
c: 'test',
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
expect(DeleteEmptyProperties(inputObj)).toEqual(expectedOutput);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('should not remove null properties from nested objects if recursive flag is not set', () => {
|
|
292
|
+
const inputObj = {
|
|
293
|
+
a: 1,
|
|
294
|
+
b: null,
|
|
295
|
+
c: {
|
|
296
|
+
d: 3,
|
|
297
|
+
e: null,
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const expectedOutput = {
|
|
302
|
+
a: 1,
|
|
303
|
+
c: {
|
|
304
|
+
d: 3,
|
|
305
|
+
e: null,
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
expect(DeleteEmptyProperties(inputObj)).toEqual(expectedOutput);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('should remove null properties from nested objects if recursive flag is set', () => {
|
|
313
|
+
const inputObj = {
|
|
314
|
+
a: 1,
|
|
315
|
+
b: null,
|
|
316
|
+
c: {
|
|
317
|
+
d: 3,
|
|
318
|
+
e: null,
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const expectedOutput = {
|
|
323
|
+
a: 1,
|
|
324
|
+
c: {
|
|
325
|
+
d: 3,
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
expect(DeleteEmptyProperties(inputObj, true)).toEqual(expectedOutput);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
</sourceFile>
|
|
333
|
+
</used>
|
|
334
|
+
</context>
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
<sourceFile path="/delete-empty-properties.ts">
|
|
338
|
+
import { DeleteUndefinedProperties } from './delete-undefined-properties';
|
|
339
|
+
import { DeleteNullProperties } from './delete-null-properties';
|
|
340
|
+
|
|
341
|
+
export function DeleteEmptyProperties<T extends {}>(obj: T, recursive?: boolean): Exclude<Exclude<T, null>, undefined> {
|
|
342
|
+
return DeleteUndefinedProperties(DeleteNullProperties(obj, recursive), recursive);
|
|
343
|
+
}
|
|
344
|
+
</sourceFile>
|
|
345
|
+
|
|
346
|
+
TASK: create the JsDoc documentation for the function DeleteEmptyProperties from the file `delete-empty-properties.ts`
|
|
347
|
+
------------------------------------------------------------
|
|
348
|
+
|
|
349
|
+
Example Output:
|
|
350
|
+
------------------------------------------------------------
|
|
351
|
+
Deletes all properties from an object that are either null or undefined.
|
|
352
|
+
|
|
353
|
+
@template T - The type of the object. It must be an object type.
|
|
354
|
+
|
|
355
|
+
@param {T} obj - The object from which to delete the properties. This object is not modified.
|
|
356
|
+
|
|
357
|
+
@param {boolean} [recursive=false] - Optional. If true, the function will recursively delete null and undefined properties from all nested objects and arrays within the object. If false or omitted, the function will only delete null and undefined properties from the top level of the object.
|
|
358
|
+
|
|
359
|
+
@returns {Exclude<Exclude<T, null>, undefined>} - A new object of the same type as the input object, but with all null and undefined properties removed. If the recursive option is true, all nested objects and arrays within the object will also have their null and undefined properties removed.
|
|
360
|
+
|
|
361
|
+
@example
|
|
362
|
+
```typescript
|
|
363
|
+
// returns { a: 1, c: { d: 4 } }
|
|
364
|
+
DeleteEmptyProperties({ a: 1, b: null, c: { d: 4, e: undefined } }, true);
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
@example
|
|
368
|
+
```typescript
|
|
369
|
+
// returns { a: 1, c: { d: 4, e: undefined } }
|
|
370
|
+
DeleteEmptyProperties({ a: 1, b: null, c: { d: 4, e: undefined } });
|
|
371
|
+
```
|
|
372
|
+
------------------------------------------------------------
|
|
373
|
+
Remember:
|
|
374
|
+
- Your output must include only the JSDoc documentation content as shown in the example output, with no surrounding comment syntax.
|
|
375
|
+
- Ensure if an example is given the code is inclosed in "```typescript" and "```"
|