@skyramp/skyramp 1.3.17 → 1.3.19
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/package.json +1 -1
- package/src/classes/SkyrampClient.d.ts +5 -0
- package/src/classes/SkyrampClient.js +6 -2
- package/src/lib.js +57 -0
package/package.json
CHANGED
|
@@ -146,6 +146,9 @@ interface GenerateRestTestOptions {
|
|
|
146
146
|
consumerMode?: boolean;
|
|
147
147
|
providerOutput?: string;
|
|
148
148
|
consumerOutput?: string;
|
|
149
|
+
skipProvisionParents?: boolean;
|
|
150
|
+
mockPort?: number;
|
|
151
|
+
optionalFields?: boolean;
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
interface GenerateRestMockOptions {
|
|
@@ -172,6 +175,8 @@ interface GenerateRestMockOptions {
|
|
|
172
175
|
apiSchema?: string[];
|
|
173
176
|
traceFilePath?: string;
|
|
174
177
|
entrypoint?: string;
|
|
178
|
+
mockPort?: number;
|
|
179
|
+
optionalFields?: boolean;
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
interface SendScenarioOptions {
|
|
@@ -111,7 +111,8 @@ const generateRestTestWrapper = lib.func('generateRestTestWrapper', 'string', [
|
|
|
111
111
|
'string', // providerOutput (contract test)
|
|
112
112
|
'string', // consumerOutput (contract test)
|
|
113
113
|
'bool', // skipProvisionParents
|
|
114
|
-
'int'
|
|
114
|
+
'int', // mockPort
|
|
115
|
+
'bool' // optionalFields
|
|
115
116
|
]);
|
|
116
117
|
const generateRestMockWrapper = lib.func('generateRestMockWrapper', 'string', [
|
|
117
118
|
'string', // uri
|
|
@@ -136,7 +137,8 @@ const generateRestMockWrapper = lib.func('generateRestMockWrapper', 'string', [
|
|
|
136
137
|
'string', // apiSchema
|
|
137
138
|
'string', // traceFilePath
|
|
138
139
|
'string', // entryPoint
|
|
139
|
-
'int'
|
|
140
|
+
'int', // mockPort
|
|
141
|
+
'bool' // optionalFields
|
|
140
142
|
]);
|
|
141
143
|
const traceCollectWrapper = lib.func('traceCollectWrapper', 'string', ['string', 'string', 'bool', 'string', 'string']);
|
|
142
144
|
const analyzeOpenapiWrapper = lib.func('analyzeOpenapiWrapper', 'string', ['string', 'string']);
|
|
@@ -960,6 +962,7 @@ class SkyrampClient {
|
|
|
960
962
|
options.consumerOutput || "",
|
|
961
963
|
options.skipProvisionParents || false,
|
|
962
964
|
options.mockPort || 0,
|
|
965
|
+
options.optionalFields || false,
|
|
963
966
|
(err, res) => {
|
|
964
967
|
if (err) {
|
|
965
968
|
reject(err);
|
|
@@ -997,6 +1000,7 @@ class SkyrampClient {
|
|
|
997
1000
|
options.traceFilePath || "",
|
|
998
1001
|
options.entrypoint || "",
|
|
999
1002
|
options.mockPort || 0,
|
|
1003
|
+
options.optionalFields || false,
|
|
1000
1004
|
(err, res) => {
|
|
1001
1005
|
if (err) {
|
|
1002
1006
|
reject(err);
|
package/src/lib.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const koffi = require('koffi');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
3
4
|
|
|
4
5
|
const platform = process.platform;
|
|
5
6
|
const arch = process.arch;
|
|
@@ -26,7 +27,63 @@ if (platform === 'linux') {
|
|
|
26
27
|
if (!libPath) {
|
|
27
28
|
throw new Error(`Unsupported platform or architecture: ${platform}-${arch}`);
|
|
28
29
|
}
|
|
30
|
+
|
|
29
31
|
const libFullPath = path.join(__dirname, '..', 'lib', libPath);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Wait for library file to be available (handles case where npm module is used
|
|
35
|
+
* before library file is fully downloaded during installation).
|
|
36
|
+
* Uses synchronous polling since Node.js module loading is synchronous.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} filePath - Path to the library file
|
|
39
|
+
* @param {number} timeoutMs - Maximum time to wait in milliseconds
|
|
40
|
+
* @param {number} intervalMs - Check interval in milliseconds
|
|
41
|
+
*/
|
|
42
|
+
function waitForFileSync(filePath, timeoutMs = 180000, intervalMs = 500) {
|
|
43
|
+
const startTime = Date.now();
|
|
44
|
+
let warningShown = false;
|
|
45
|
+
const { execSync } = require('child_process');
|
|
46
|
+
|
|
47
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
48
|
+
if (fs.existsSync(filePath)) {
|
|
49
|
+
if (warningShown) {
|
|
50
|
+
console.log(`Library file is now available: ${filePath}`);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Show warning on first check if file is missing
|
|
56
|
+
if (!warningShown) {
|
|
57
|
+
console.warn(
|
|
58
|
+
`Warning: Library file not yet available: ${filePath}\n` +
|
|
59
|
+
`Waiting for up to ${timeoutMs / 1000} seconds for the file to become available...\n` +
|
|
60
|
+
`This may happen if the module is used before installation is fully complete.`
|
|
61
|
+
);
|
|
62
|
+
warningShown = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Synchronous sleep using platform-specific commands
|
|
66
|
+
try {
|
|
67
|
+
if (platform === 'win32') {
|
|
68
|
+
execSync(`timeout /t ${Math.ceil(intervalMs / 1000)} /nobreak >nul 2>&1`, { stdio: 'ignore' });
|
|
69
|
+
} else {
|
|
70
|
+
execSync(`sleep ${intervalMs / 1000}`, { stdio: 'ignore' });
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
// If sleep command fails, fall back to a simple check without delay
|
|
74
|
+
// This prevents the loop from running too fast
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Library file not found after waiting ${timeoutMs / 1000} seconds: ${filePath}\n` +
|
|
80
|
+
`This may happen if the npm module is used before the native library is fully downloaded.\n` +
|
|
81
|
+
`Please ensure the installation completed successfully.`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Wait for the library file to be available before loading
|
|
86
|
+
waitForFileSync(libFullPath, 180000); // Wait up to 3 minutes
|
|
30
87
|
const lib = koffi.load(libFullPath);
|
|
31
88
|
|
|
32
89
|
module.exports = lib;
|