@sap-ux/fe-mockserver-admin 0.0.2

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @sap-ux/fe-mockserver-admin
2
+
3
+ Admin service package for the SAP Fiori mockserver that provides an OData service to list currently running services.
4
+
5
+ ## Overview
6
+
7
+ This package provides an admin OData service that exposes information about currently registered services in a running mockserver instance. It allows you to query which services are active, their configuration, and status.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @sap-ux/fe-mockserver-admin
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ You need to define the admin in the `plugins` section of the mockerver
18
+
19
+ ```yaml
20
+ configuration:
21
+ plugins:
22
+ - "@sap-ux/fe-mockserver-admin"
23
+ ```
24
+
25
+
26
+ ## Example
27
+
28
+ Access the admin service at `http://localhost:3000/admin/Services` to get a list of all registered services in OData JSON format.
29
+
30
+ ## Binary for Mock Data Generation
31
+
32
+ This package also provides a CLI binary `fe-mockserver-admin` to generate TypeScript mock data files from OData metadata:
33
+
34
+ ### Generate Entity Files
35
+
36
+ ```bash
37
+ # Generate entity files from metadata.xml
38
+ fe-mockserver-admin generate-entity-files -m path/to/metadata.xml
39
+
40
+ # Generate entity files with custom output directory
41
+ fe-mockserver-admin generate-entity-files -m path/to/metadata.xml -o path/to/output/directory
42
+ ```
43
+
44
+ This command will:
45
+ - Parse the OData metadata file
46
+ - Generate TypeScript entity files for each entity set
47
+ - Create an EntityContainer file for action handling
48
+ - Generate proper TypeScript interfaces and types
49
+
50
+ The generated files can be used as mock data contributors in your SAP Fiori mockserver setup.
51
+
52
+ ## License
53
+
54
+ Apache-2.0
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ const commander_1 = require("commander");
28
+ const fs = __importStar(require("fs"));
29
+ const path = __importStar(require("path"));
30
+ const generate_entity_files_1 = require("./generate-entity-files");
31
+ const program = new commander_1.Command();
32
+ program.name('fe-mockserver-admin').description('CLI for FE Mockserver administration tasks').version('0.0.1');
33
+ program
34
+ .command('generate-entity-files')
35
+ .description('Generate entity files from OData metadata')
36
+ .requiredOption('-m, --metadata <path>', 'Path to the metadata.xml file')
37
+ .option('-o, --output <path>', 'Output directory for generated files (defaults to metadata directory)')
38
+ .action(async (options) => {
39
+ try {
40
+ const metadataPath = path.resolve(options.metadata);
41
+ const outputDir = options.output ? path.resolve(options.output) : path.dirname(metadataPath);
42
+ // Validate metadata file exists
43
+ if (!fs.existsSync(metadataPath)) {
44
+ console.error(`Error: Metadata file not found at: ${metadataPath}`);
45
+ process.exit(1);
46
+ }
47
+ // Ensure output directory exists
48
+ if (!fs.existsSync(outputDir)) {
49
+ fs.mkdirSync(outputDir, { recursive: true });
50
+ }
51
+ console.log(`Loading metadata from: ${metadataPath}`);
52
+ console.log(`Output directory: ${outputDir}`);
53
+ await (0, generate_entity_files_1.generateEntityFiles)(metadataPath, outputDir);
54
+ console.log('All entity files generated successfully!');
55
+ }
56
+ catch (error) {
57
+ console.error('Error generating entity files:', error);
58
+ process.exit(1);
59
+ }
60
+ });
61
+ // Parse arguments and execute
62
+ program.parse();
63
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,uCAAyB;AACzB,2CAA6B;AAC7B,mEAA8D;AAE9D,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,WAAW,CAAC,4CAA4C,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/G,OAAO;KACF,OAAO,CAAC,uBAAuB,CAAC;KAChC,WAAW,CAAC,2CAA2C,CAAC;KACxD,cAAc,CAAC,uBAAuB,EAAE,+BAA+B,CAAC;KACxE,MAAM,CAAC,qBAAqB,EAAE,uEAAuE,CAAC;KACtG,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACtB,IAAI;QACA,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACpD,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAE7F,gCAAgC;QAChC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;YAC9B,OAAO,CAAC,KAAK,CAAC,sCAAsC,YAAY,EAAE,CAAC,CAAC;YACpE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACnB;QAED,iCAAiC;QACjC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;YAC3B,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;SAChD;QAED,OAAO,CAAC,GAAG,CAAC,0BAA0B,YAAY,EAAE,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,qBAAqB,SAAS,EAAE,CAAC,CAAC;QAE9C,MAAM,IAAA,2CAAmB,EAAC,YAAY,EAAE,SAAS,CAAC,CAAC;QAEnD,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;KAC3D;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;AACL,CAAC,CAAC,CAAC;AAEP,8BAA8B;AAC9B,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function generateEntityFiles(METADATA_PATH: string, OUTPUT_DIR: string): Promise<void>;
2
+ //# sourceMappingURL=generate-entity-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-entity-files.d.ts","sourceRoot":"","sources":["../src/generate-entity-files.ts"],"names":[],"mappings":"AAaA,wBAAsB,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAwBlF"}
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateEntityFiles = void 0;
27
+ const annotation_converter_1 = require("@sap-ux/annotation-converter");
28
+ const edmx_parser_1 = require("@sap-ux/edmx-parser");
29
+ const fs = __importStar(require("fs"));
30
+ const path = __importStar(require("path"));
31
+ async function generateEntityFiles(METADATA_PATH, OUTPUT_DIR) {
32
+ try {
33
+ console.log('Loading metadata.xml...');
34
+ const metadataContent = fs.readFileSync(METADATA_PATH, 'utf8');
35
+ console.log('Parsing EDMX...');
36
+ const parsedMetadata = (0, edmx_parser_1.parse)(metadataContent);
37
+ console.log('Converting metadata with annotation converter...');
38
+ const convertedMetadata = (0, annotation_converter_1.convert)(parsedMetadata);
39
+ // Generate TS files for each entity set
40
+ for (const entitySet of convertedMetadata.entitySets) {
41
+ console.log(`Generating TS file for ${entitySet.name}...`);
42
+ await generateEntityFile(entitySet, convertedMetadata, OUTPUT_DIR);
43
+ }
44
+ await generateEntityContainerFile(convertedMetadata, OUTPUT_DIR);
45
+ console.log('All entity files generated successfully!');
46
+ }
47
+ catch (error) {
48
+ console.error('Error generating entity files:', error);
49
+ process.exit(1);
50
+ }
51
+ }
52
+ exports.generateEntityFiles = generateEntityFiles;
53
+ async function generateEntityContainerFile(convertedMetadata, OUTPUT_DIR) {
54
+ const actions = convertedMetadata.actionImports;
55
+ if (actions.length > 0) {
56
+ const actionSwitchCase = actions
57
+ .map((action) => {
58
+ return `case '${action.name}':
59
+ break; // TODO: Implement ${action.name} action`;
60
+ })
61
+ .join('\n');
62
+ const mockEntityContainer = `import type {MockEntityContainerContributor, ODataRequest, Action} from "@sap-ux/ui5-middleware-fe-mockserver";
63
+
64
+
65
+ const EntityContainer: MockEntityContainerContributor = {
66
+ async executeAction(actionDefinition: Action, _actionData: any, _keys: Record<string, unknown>, _odataRequest: ODataRequest): Promise<unknown> {
67
+ switch(actionDefinition.name) {
68
+ ${actionSwitchCase}
69
+ // Implement action handlers here
70
+ default:
71
+ return undefined; // No custom action handler, proceed with default handling
72
+ }
73
+ }
74
+ }
75
+ export default EntityContainer;`;
76
+ const outputPath = path.join(OUTPUT_DIR, `EntityContainer.ts`);
77
+ fs.writeFileSync(outputPath, mockEntityContainer);
78
+ }
79
+ }
80
+ async function generateEntityFile(entitySet, metadata, OUTPUT_DIR) {
81
+ const entityType = entitySet.entityType;
82
+ const keyName = entityType.name.split('.').pop() + 'Keys';
83
+ const actionDataName = entityType.name.split('.').pop() + 'ActionData';
84
+ // Get actions for this entity set
85
+ const actions = entitySet.entityType.actions;
86
+ // Get navigation properties without constraints for this entity set
87
+ const entityNavPropsWithoutConstraints = entityType.navigationProperties.filter((prop) => {
88
+ var _a;
89
+ return prop.name !== 'DraftAdministrativeData' &&
90
+ prop.name !== 'SiblingEntity' && // Exclude DraftAdministrativeData and SiblingEntity
91
+ prop.referentialConstraint.length === 0 &&
92
+ (!prop.partner ||
93
+ ((_a = prop.targetType.navigationProperties.by_name(prop.partner)) === null || _a === void 0 ? void 0 : _a.referentialConstraint.length) === 0);
94
+ });
95
+ // Generate TypeScript interface for the entity
96
+ const entityInterface = generateEntityInterface(entityType);
97
+ const entityNavPropNamesInterface = generateEntityNavPropNamesInterface(entityType);
98
+ const entityNavPropTypesInterface = generateEntityNavPropTypesInterface(entityType);
99
+ const entityActionParams = generateEntityActionParams(entitySet, actions);
100
+ // Generate action switch cases
101
+ const actionSwitchCases = generateActionSwitchCases(actions);
102
+ let executeActionMethod = '';
103
+ if (Object.keys(actions).length > 0) {
104
+ executeActionMethod = `async executeAction(actionDefinition: Action, actionData: ${actionDataName}, _keys: ${keyName}, _odataRequest: ODataRequest): Promise<object | undefined> {
105
+ switch(actionData._type) {
106
+ ${actionSwitchCases}
107
+ default:
108
+ console.warn(\`Unhandled action: \${actionDefinition.name}\`);
109
+ return undefined;
110
+ }
111
+ }`;
112
+ }
113
+ // Generate getReferentialConstraints method
114
+ const getReferentialConstraintsMethod = generateGetReferentialConstraintsMethod(entityNavPropsWithoutConstraints);
115
+ const allMethods = [];
116
+ if (executeActionMethod.length) {
117
+ allMethods.push(executeActionMethod);
118
+ }
119
+ if (getReferentialConstraintsMethod.length) {
120
+ allMethods.push(getReferentialConstraintsMethod);
121
+ }
122
+ const fileContent = `import type { MockDataContributor, ODataRequest, Action, NavigationProperty, PartialReferentialConstraint } from "@sap-ux/ui5-middleware-fe-mockserver"
123
+ ${entityNavPropTypesInterface}
124
+ ${entityNavPropNamesInterface}
125
+ ${entityInterface}
126
+ ${entityActionParams}
127
+
128
+
129
+ const ${entitySet.name}: MockDataContributor<${entitySet.entityTypeName.split('.').pop()}Type> = {
130
+ ${allMethods.join(',')}
131
+ }
132
+
133
+ export default ${entitySet.name};
134
+ `;
135
+ //if(allMethods.length > 0) {
136
+ const outputPath = path.join(OUTPUT_DIR, `${entitySet.name}.ts`);
137
+ fs.writeFileSync(outputPath, fileContent);
138
+ console.log(`Generated: ${outputPath}`);
139
+ //} else {
140
+ // console.log(`No method to generate for ${entitySet.name}, skipping file creation.`);
141
+ //}
142
+ }
143
+ function generateEntityNavPropNamesInterface(entityType) {
144
+ const typeName = entityType.name.split('.').pop() + 'NavPropNames';
145
+ const properties = [];
146
+ for (const prop of entityType.navigationProperties) {
147
+ if (prop.name !== 'DraftAdministrativeData') {
148
+ properties.push(`"${prop.name}"`);
149
+ }
150
+ }
151
+ if (!entityType || !entityType.navigationProperties || properties.length === 0) {
152
+ return `export type ${typeName} = {
153
+ // Navigation properties not available in metadata
154
+ }`;
155
+ }
156
+ return `export type ${typeName} = ${properties.join(' | ')};`;
157
+ }
158
+ function generateEntityNavPropTypesInterface(entityType) {
159
+ const currentType = entityType.name.split('.').pop() + 'Type';
160
+ const typeName = entityType.name.split('.').pop() + 'NavPropTypes';
161
+ const importStatements = new Set();
162
+ if (!entityType || !entityType.navigationProperties) {
163
+ return `export type ${typeName} = {
164
+ // Navigation properties not available in metadata
165
+ }`;
166
+ }
167
+ const properties = [];
168
+ for (const prop of entityType.navigationProperties) {
169
+ const targetTypeName = prop.targetType.name.split('.').pop() + 'Type';
170
+ if (targetTypeName !== 'DraftAdministrativeDataType' && targetTypeName !== currentType) {
171
+ importStatements.add(`import type { ${targetTypeName} } from "./${prop.targetType.name.split('.').pop()}";`);
172
+ }
173
+ if (targetTypeName !== 'DraftAdministrativeDataType') {
174
+ if (prop.isCollection) {
175
+ properties.push(`${prop.name}: ${targetTypeName}[];`);
176
+ }
177
+ else {
178
+ properties.push(`${prop.name}: ${targetTypeName};`);
179
+ }
180
+ }
181
+ }
182
+ return `${Array.from(importStatements).join('\n')}
183
+ export type ${typeName} = {
184
+ ${properties.join('\n')}
185
+ }`;
186
+ }
187
+ function generateEntityInterface(entityType) {
188
+ var _a;
189
+ const typeName = entityType.name.split('.').pop() + 'Type';
190
+ const keyName = entityType.name.split('.').pop() + 'Keys';
191
+ if (!entityType || !entityType.keys) {
192
+ return `export type ${typeName} = {
193
+ // Entity type definition not available in metadata
194
+ };
195
+ export type ${keyName} = {
196
+ // Entity type definition not available in metadata
197
+ };`;
198
+ }
199
+ const keys = [];
200
+ const properties = [];
201
+ // Add key properties
202
+ if (entityType.keys) {
203
+ for (const key of entityType.keys) {
204
+ const prop = entityType.entityProperties.by_name(key.name);
205
+ if (prop) {
206
+ const tsType = mapODataTypeToTypeScript(prop.type);
207
+ const nullable = prop.nullable ? '?' : '';
208
+ properties.push(` ${key.name}${nullable}: ${tsType};`);
209
+ keys.push(` ${key.name}${nullable}: ${tsType};`);
210
+ }
211
+ }
212
+ }
213
+ // Add other entity properties
214
+ if (entityType.entityProperties) {
215
+ for (const prop of entityType.entityProperties) {
216
+ if (!((_a = entityType.keys) === null || _a === void 0 ? void 0 : _a.some((k) => k.name === prop.name))) {
217
+ const tsType = mapODataTypeToTypeScript(prop.type);
218
+ const nullable = prop.nullable ? '?' : '';
219
+ properties.push(` ${prop.name}${nullable}: ${tsType};`);
220
+ }
221
+ }
222
+ }
223
+ return `export type ${typeName} = {
224
+ ${properties.join('\n')}
225
+ };
226
+
227
+ export type ${keyName} = {
228
+ ${keys.join('\n')}
229
+ };`;
230
+ }
231
+ function mapODataTypeToTypeScript(odataType) {
232
+ const typeMap = {
233
+ 'Edm.String': 'string',
234
+ 'Edm.Int32': 'number',
235
+ 'Edm.Int64': 'number',
236
+ 'Edm.Double': 'number',
237
+ 'Edm.Decimal': 'number',
238
+ 'Edm.Boolean': 'boolean',
239
+ 'Edm.DateTime': 'Date',
240
+ 'Edm.DateTimeOffset': 'Date',
241
+ 'Edm.Date': 'Date',
242
+ 'Edm.Time': 'Date',
243
+ 'Edm.Guid': 'string',
244
+ 'Edm.Binary': 'string'
245
+ };
246
+ return typeMap[odataType] || 'any';
247
+ }
248
+ function generateEntityActionParams(entitySet, actions) {
249
+ if (Object.keys(actions).length === 0) {
250
+ return '';
251
+ }
252
+ const actionParams = Object.keys(actions)
253
+ .filter((actionName) => {
254
+ return (!actionName.endsWith('draftEdit') &&
255
+ !actionName.endsWith('draftActivate') &&
256
+ !actionName.endsWith('draftPrepare') &&
257
+ !actionName.endsWith('draftDiscard'));
258
+ })
259
+ .map((actionName) => {
260
+ const action = actions[actionName];
261
+ if (action.parameters && action.parameters.length > 0) {
262
+ const params = action.parameters
263
+ .map((param) => {
264
+ let tsType = mapODataTypeToTypeScript(param.type);
265
+ if (tsType === 'any' && param.type === entitySet.entityTypeName) {
266
+ tsType = entitySet.entityTypeName.split('.').pop() + 'Type';
267
+ }
268
+ const optional = param.nullable ? '?' : '';
269
+ return ` ${param.name}${optional}: ${tsType};`;
270
+ })
271
+ .join('\n');
272
+ return ` | {\n _type: '${action.name}';\n${params}\n}`;
273
+ }
274
+ })
275
+ .join('\n');
276
+ return `export type ${entitySet.entityType.name}ActionData =\n${actionParams};`;
277
+ }
278
+ function generateActionSwitchCases(actions) {
279
+ return Object.keys(actions)
280
+ .filter((actionName) => !actionName.endsWith('draftEdit') &&
281
+ !actionName.endsWith('draftActivate') &&
282
+ !actionName.endsWith('draftPrepare') &&
283
+ !actionName.endsWith('draftDiscard'))
284
+ .map((actionName) => ` case '${actions[actionName].name}':
285
+ // TODO: Implement ${actions[actionName].name} action
286
+ console.log('Executing action: ${actions[actionName].name}');
287
+ return {};`)
288
+ .join('\n');
289
+ }
290
+ function generateGetReferentialConstraintsMethod(navPropsWithoutConstraints) {
291
+ if (navPropsWithoutConstraints.length === 0) {
292
+ return '';
293
+ }
294
+ const allPotentialCases = navPropsWithoutConstraints
295
+ .map((prop) => `
296
+ case '${prop.name}': // Navigation to ${prop.targetTypeName}
297
+ return []; // TODO add the missing referential constraints
298
+ break;`)
299
+ .join('\n');
300
+ return `
301
+ getReferentialConstraints: (navigationProperty: NavigationProperty):PartialReferentialConstraint[] | undefined => {
302
+ // Navigation properties without referential constraints:
303
+ switch(navigationProperty.name) {
304
+ ${allPotentialCases}
305
+ default:
306
+ return navigationProperty.referentialConstraint;
307
+ }
308
+ }`;
309
+ }
310
+ //# sourceMappingURL=generate-entity-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gener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AC,UAAU,CAAC,CAAC,IAAI;qCACpC,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI;iDACZ,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI;2BAC9C,CAClB;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,uCAAuC,CAAC,0BAAgD;IAC7F,IAAI,0BAA0B,CAAC,MAAM,KAAK,CAAC,EAAE;QACzC,OAAO,EAAE,CAAC;KACb;IAED,MAAM,iBAAiB,GAAG,0BAA0B;SAC/C,GAAG,CACA,CAAC,IAAI,EAAE,EAAE,CACL;oBACI,IAAI,CAAC,IAAI,wBAAwB,IAAI,CAAC,cAAc;;mBAErD,CACV;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;IAEhB,OAAO;;;;eAII,iBAAiB;;;;MAI1B,CAAC;AACP,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { IMockserverPlugin } from '@sap-ux/fe-mockserver-core';
2
+ declare const mockServerAdminConfig: IMockserverPlugin;
3
+ export = mockServerAdminConfig;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,QAAA,MAAM,qBAAqB,EAAE,iBAW5B,CAAC;AAEF,SAAS,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ const path = __importStar(require("node:path"));
26
+ const mockServerAdminConfig = {
27
+ name: 'mockserver-admin',
28
+ services: [
29
+ {
30
+ alias: 'AdminService',
31
+ urlPath: '/admin',
32
+ metadataPath: path.join(__dirname, 'metadata.xml'),
33
+ mockdataPath: path.join(__dirname, 'mockdata'),
34
+ generateMockData: false
35
+ }
36
+ ]
37
+ };
38
+ module.exports = mockServerAdminConfig;
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,gDAAkC;AAElC,MAAM,qBAAqB,GAAsB;IAC7C,IAAI,EAAE,kBAAkB;IACxB,QAAQ,EAAE;QACN;YACI,KAAK,EAAE,cAAc;YACrB,OAAO,EAAE,QAAQ;YACjB,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC;YAClD,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;YAC9C,gBAAgB,EAAE,KAAK;SAC1B;KACJ;CACJ,CAAC;AAEF,iBAAS,qBAAqB,CAAC"}
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
3
+ <edmx:DataServices>
4
+ <Schema Namespace="MockServerAdmin" xmlns="http://docs.oasis-open.org/odata/ns/edm">
5
+ <EntityType Name="Service">
6
+ <Key>
7
+ <PropertyRef Name="UrlPath"/>
8
+ </Key>
9
+ <Property Name="UrlPath" Type="Edm.String" Nullable="false" MaxLength="255"/>
10
+ <Property Name="InternalName" Type="Edm.String" Nullable="true" MaxLength="100"/>
11
+ <Property Name="EncodedPath" Type="Edm.String" Nullable="true" MaxLength="255"/>
12
+ <Property Name="ContextIsolation" Type="Edm.Boolean" Nullable="false"/>
13
+ <Property Name="Debug" Type="Edm.Boolean" Nullable="false"/>
14
+ <Property Name="Watch" Type="Edm.Boolean" Nullable="false"/>
15
+ <Property Name="HasETag" Type="Edm.Boolean" Nullable="false"/>
16
+ <Property Name="RegisteredAt" Type="Edm.DateTimeOffset" Nullable="false"/>
17
+ </EntityType>
18
+ <EntityContainer Name="AdminContainer">
19
+ <EntitySet Name="Services" EntityType="MockServerAdmin.Service"/>
20
+ </EntityContainer>
21
+ </Schema>
22
+ </edmx:DataServices>
23
+ </edmx:Edmx>
@@ -0,0 +1,4 @@
1
+ import type { MockEntityContainerContributor } from '@sap-ux/fe-mockserver-core';
2
+ declare const MockEntityContainer: MockEntityContainerContributor;
3
+ export default MockEntityContainer;
4
+ //# sourceMappingURL=EntityContainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityContainer.d.ts","sourceRoot":"","sources":["../../src/mockdata/EntityContainer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAgB,MAAM,4BAA4B,CAAC;AAE/F,QAAA,MAAM,mBAAmB,EAAE,8BAK1B,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const MockEntityContainer = {
4
+ async handleRequest(odataRequest) {
5
+ odataRequest.addResponseHeader('content-type', 'text/html ;charset=utf-8');
6
+ return `<html><body><h1>Hello</h1></body></html>`;
7
+ }
8
+ };
9
+ exports.default = MockEntityContainer;
10
+ //# sourceMappingURL=EntityContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityContainer.js","sourceRoot":"","sources":["../../src/mockdata/EntityContainer.ts"],"names":[],"mappings":";;AAEA,MAAM,mBAAmB,GAAmC;IACxD,KAAK,CAAC,aAAa,CAAC,YAA0B;QAC1C,YAAY,CAAC,iBAAiB,CAAC,cAAc,EAAE,0BAA0B,CAAC,CAAC;QAC3E,OAAO,0CAA0C,CAAC;IACtD,CAAC;CACJ,CAAC;AAEF,kBAAe,mBAAmB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { MockDataContributor } from '@sap-ux/fe-mockserver-core';
2
+ type ServiceDefinition = {
3
+ url: string;
4
+ alias?: string;
5
+ };
6
+ /**
7
+ * Mock data contributor for services.
8
+ */
9
+ declare const Services: MockDataContributor<ServiceDefinition>;
10
+ export default Services;
11
+ //# sourceMappingURL=Services.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Services.d.ts","sourceRoot":"","sources":["../../src/mockdata/Services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAiB,MAAM,4BAA4B,CAAC;AAIrF,KAAK,iBAAiB,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AACF;;GAEG;AACH,QAAA,MAAM,QAAQ,EAAE,mBAAmB,CAAC,iBAAiB,CA2BpD,CAAC;AACF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_path_1 = __importDefault(require("node:path"));
7
+ /**
8
+ * Mock data contributor for services.
9
+ */
10
+ const Services = {
11
+ /**
12
+ * Return all the service definitions.
13
+ * @param __odataRequest
14
+ * @returns A promise that resolves to an array of service definitions.
15
+ */
16
+ async getAllEntries(__odataRequest) {
17
+ var _a, _b, _c;
18
+ const configs = (_b = (_a = this.base) === null || _a === void 0 ? void 0 : _a.getServiceRegistry().getServices()) !== null && _b !== void 0 ? _b : [];
19
+ (_c = this.base) === null || _c === void 0 ? void 0 : _c.getServiceRegistry().loadServices([
20
+ {
21
+ alias: `AdminService${configs.length}`,
22
+ urlPath: `/admin-${configs.length}`,
23
+ metadataPath: node_path_1.default.join(__dirname, '../metadata.xml'),
24
+ mockdataPath: node_path_1.default.join(__dirname),
25
+ generateMockData: false
26
+ }
27
+ ]);
28
+ return configs.map((config) => {
29
+ return {
30
+ url: config.urlPath,
31
+ alias: config.alias
32
+ };
33
+ });
34
+ }
35
+ };
36
+ exports.default = Services;
37
+ //# sourceMappingURL=Services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Services.js","sourceRoot":"","sources":["../../src/mockdata/Services.ts"],"names":[],"mappings":";;;;;AAEA,0DAA6B;AAM7B;;GAEG;AACH,MAAM,QAAQ,GAA2C;IACrD;;;;OAIG;IACH,KAAK,CAAC,aAAa,CAEf,cAA4B;;QAE5B,MAAM,OAAO,GAAoB,MAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,kBAAkB,GAAG,WAAW,EAAE,mCAAI,EAAE,CAAC;QACrF,MAAA,IAAI,CAAC,IAAI,0CAAE,kBAAkB,GAAG,YAAY,CAAC;YACzC;gBACI,KAAK,EAAE,eAAe,OAAO,CAAC,MAAM,EAAE;gBACtC,OAAO,EAAE,UAAU,OAAO,CAAC,MAAM,EAAE;gBACnC,YAAY,EAAE,mBAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC;gBACrD,YAAY,EAAE,mBAAI,CAAC,IAAI,CAAC,SAAS,CAAC;gBAClC,gBAAgB,EAAE,KAAK;aAC1B;SACJ,CAAC,CAAC;QACH,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1B,OAAO;gBACH,GAAG,EAAE,MAAM,CAAC,OAAO;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;aACtB,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAC;AACF,kBAAe,QAAQ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@sap-ux/fe-mockserver-admin",
3
+ "version": "0.0.2",
4
+ "description": "SAP Fiori OData - Mockserver admin service to list running services",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/SAP/open-ux-odata.git",
8
+ "directory": "packages/fe-mockserver-admin"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/SAP/open-ux-odata/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Afe-mockserver"
12
+ },
13
+ "bin": {
14
+ "fe-mockserver-admin": "dist/cli.js"
15
+ },
16
+ "main": "dist/index.js",
17
+ "typings": "dist/index.d.ts",
18
+ "license": "Apache-2.0",
19
+ "dependencies": {
20
+ "commander": "^11.1.0",
21
+ "router": "2.0.0",
22
+ "@sap-ux/fe-mockserver-core": "1.6.6",
23
+ "@sap-ux/edmx-parser": "0.9.6",
24
+ "@sap-ux/annotation-converter": "0.10.5",
25
+ "@sap-ux/vocabularies-types": "0.13.0"
26
+ },
27
+ "devDependencies": {
28
+ "@ui5/logger": "^4.0.1",
29
+ "copyfiles": "2.4.1",
30
+ "@types/node": "^18.15.0"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "build": "pnpm clean && tsc && copyfiles -u 1 src/*.xml dist/",
38
+ "clean": "rimraf dist build",
39
+ "dev": "pnpm clean && tsc -project ./tsconfig.dev.json --watch",
40
+ "format": "prettier **/* --write --ignore-unknown --ignore-path ../../.prettierignore",
41
+ "lint": "eslint . --ext .ts --quiet",
42
+ "lint:fix": "eslint . --ext .ts --fix",
43
+ "watch": "tsc --watch",
44
+ "link": "pnpm link --global",
45
+ "unlink": "pnpm unlink --global",
46
+ "test": "jest --ci --forceExit --detectOpenHandles --colors --passWithNoTests",
47
+ "test-u": "jest --ci --forceExit --detectOpenHandles --colors -u --passWithNoTests"
48
+ }
49
+ }