@naturalcycles/nodejs-lib 15.81.0 → 15.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exec2/exec2.js +13 -7
- package/dist/slack/slack.service.model.d.ts +3 -1
- package/dist/validation/ajv/ajvSchema.d.ts +5 -0
- package/dist/validation/ajv/ajvSchema.js +45 -1
- package/package.json +1 -1
- package/src/exec2/exec2.ts +13 -7
- package/src/slack/slack.service.model.ts +3 -1
- package/src/validation/ajv/ajvSchema.ts +66 -1
package/dist/exec2/exec2.js
CHANGED
|
@@ -146,10 +146,13 @@ class Exec2 {
|
|
|
146
146
|
...env,
|
|
147
147
|
},
|
|
148
148
|
});
|
|
149
|
-
p.on('close', code => {
|
|
150
|
-
const isSuccessful =
|
|
149
|
+
p.on('close', (code, signal) => {
|
|
150
|
+
const isSuccessful = code === 0;
|
|
151
151
|
this.logFinish(cmd, opt, started, isSuccessful);
|
|
152
|
-
if (
|
|
152
|
+
if (signal) {
|
|
153
|
+
return reject(new Error(`spawnAsync killed by signal ${signal}: ${cmd}`));
|
|
154
|
+
}
|
|
155
|
+
if (!isSuccessful) {
|
|
153
156
|
return reject(new Error(`spawnAsync exited with code ${code}: ${cmd}`));
|
|
154
157
|
}
|
|
155
158
|
resolve();
|
|
@@ -217,16 +220,19 @@ class Exec2 {
|
|
|
217
220
|
process.stderr.write(data);
|
|
218
221
|
}
|
|
219
222
|
});
|
|
220
|
-
p.on('close', code => {
|
|
221
|
-
const isSuccessful =
|
|
223
|
+
p.on('close', (code, signal) => {
|
|
224
|
+
const isSuccessful = code === 0;
|
|
222
225
|
this.logFinish(cmd, opt, started, isSuccessful);
|
|
223
|
-
const exitCode = code
|
|
226
|
+
const exitCode = code ?? -1;
|
|
224
227
|
const o = {
|
|
225
228
|
exitCode,
|
|
226
229
|
stdout: stdout.trim(),
|
|
227
230
|
stderr: stderr.trim(),
|
|
228
231
|
};
|
|
229
|
-
if (
|
|
232
|
+
if (signal) {
|
|
233
|
+
return reject(new SpawnError(`spawnAsyncAndReturn killed by signal ${signal}: ${cmd}`, o));
|
|
234
|
+
}
|
|
235
|
+
if (throwOnNonZeroCode && !isSuccessful) {
|
|
230
236
|
return reject(new SpawnError(`spawnAsyncAndReturn exited with code ${code}: ${cmd}`, o));
|
|
231
237
|
}
|
|
232
238
|
resolve(o);
|
|
@@ -42,7 +42,9 @@ export interface SlackMessage<CTX = any> extends SlackMessageProps {
|
|
|
42
42
|
*/
|
|
43
43
|
kv?: AnyObject;
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Slack Member IDs to mention at the end of the message.
|
|
46
|
+
* Use Member IDs (e.g., 'U1234567890'), not usernames.
|
|
47
|
+
* To find a Member ID: click on their profile in Slack → "..." → "Copy member ID".
|
|
46
48
|
*/
|
|
47
49
|
mentions?: string[];
|
|
48
50
|
/**
|
|
@@ -49,6 +49,11 @@ export declare class AjvSchema<IN = unknown, OUT = IN> {
|
|
|
49
49
|
private getAJVValidateFunction;
|
|
50
50
|
private static requireValidJsonSchema;
|
|
51
51
|
private applyImprovementsOnErrorMessages;
|
|
52
|
+
private getErrorMessageForInstancePath;
|
|
53
|
+
private traverseSchemaPath;
|
|
54
|
+
private getChildSchema;
|
|
55
|
+
private getArrayItemSchema;
|
|
56
|
+
private getObjectPropertySchema;
|
|
52
57
|
}
|
|
53
58
|
export declare const HIDDEN_AJV_SCHEMA: unique symbol;
|
|
54
59
|
export type WithCachedAjvSchema<Base, IN, OUT> = Base & {
|
|
@@ -162,12 +162,56 @@ export class AjvSchema {
|
|
|
162
162
|
return;
|
|
163
163
|
const { errorMessages } = this.schema;
|
|
164
164
|
for (const error of errors) {
|
|
165
|
-
|
|
165
|
+
const errorMessage = this.getErrorMessageForInstancePath(this.schema, error.instancePath, error.keyword);
|
|
166
|
+
if (errorMessage) {
|
|
167
|
+
error.message = errorMessage;
|
|
168
|
+
}
|
|
169
|
+
else if (errorMessages?.[error.keyword]) {
|
|
166
170
|
error.message = errorMessages[error.keyword];
|
|
167
171
|
}
|
|
168
172
|
error.instancePath = error.instancePath.replaceAll(/\/(\d+)/g, `[$1]`).replaceAll('/', '.');
|
|
169
173
|
}
|
|
170
174
|
}
|
|
175
|
+
getErrorMessageForInstancePath(schema, instancePath, keyword) {
|
|
176
|
+
if (!schema || !instancePath)
|
|
177
|
+
return undefined;
|
|
178
|
+
const segments = instancePath.split('/').filter(Boolean);
|
|
179
|
+
return this.traverseSchemaPath(schema, segments, keyword);
|
|
180
|
+
}
|
|
181
|
+
traverseSchemaPath(schema, segments, keyword) {
|
|
182
|
+
if (!segments.length)
|
|
183
|
+
return undefined;
|
|
184
|
+
const [currentSegment, ...remainingSegments] = segments;
|
|
185
|
+
const nextSchema = this.getChildSchema(schema, currentSegment);
|
|
186
|
+
if (!nextSchema)
|
|
187
|
+
return undefined;
|
|
188
|
+
if (nextSchema.errorMessages?.[keyword]) {
|
|
189
|
+
return nextSchema.errorMessages[keyword];
|
|
190
|
+
}
|
|
191
|
+
if (remainingSegments.length) {
|
|
192
|
+
return this.traverseSchemaPath(nextSchema, remainingSegments, keyword);
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
getChildSchema(schema, segment) {
|
|
197
|
+
if (!segment)
|
|
198
|
+
return undefined;
|
|
199
|
+
if (/^\d+$/.test(segment) && schema.items) {
|
|
200
|
+
return this.getArrayItemSchema(schema, segment);
|
|
201
|
+
}
|
|
202
|
+
return this.getObjectPropertySchema(schema, segment);
|
|
203
|
+
}
|
|
204
|
+
getArrayItemSchema(schema, indexSegment) {
|
|
205
|
+
if (!schema.items)
|
|
206
|
+
return undefined;
|
|
207
|
+
if (Array.isArray(schema.items)) {
|
|
208
|
+
return schema.items[Number(indexSegment)];
|
|
209
|
+
}
|
|
210
|
+
return schema.items;
|
|
211
|
+
}
|
|
212
|
+
getObjectPropertySchema(schema, segment) {
|
|
213
|
+
return schema.properties?.[segment];
|
|
214
|
+
}
|
|
171
215
|
}
|
|
172
216
|
const separator = '\n';
|
|
173
217
|
export const HIDDEN_AJV_SCHEMA = Symbol('HIDDEN_AJV_SCHEMA');
|
package/package.json
CHANGED
package/src/exec2/exec2.ts
CHANGED
|
@@ -174,10 +174,13 @@ class Exec2 {
|
|
|
174
174
|
},
|
|
175
175
|
})
|
|
176
176
|
|
|
177
|
-
p.on('close', code => {
|
|
178
|
-
const isSuccessful =
|
|
177
|
+
p.on('close', (code, signal) => {
|
|
178
|
+
const isSuccessful = code === 0
|
|
179
179
|
this.logFinish(cmd, opt, started, isSuccessful)
|
|
180
|
-
if (
|
|
180
|
+
if (signal) {
|
|
181
|
+
return reject(new Error(`spawnAsync killed by signal ${signal}: ${cmd}`))
|
|
182
|
+
}
|
|
183
|
+
if (!isSuccessful) {
|
|
181
184
|
return reject(new Error(`spawnAsync exited with code ${code}: ${cmd}`))
|
|
182
185
|
}
|
|
183
186
|
resolve()
|
|
@@ -259,16 +262,19 @@ class Exec2 {
|
|
|
259
262
|
}
|
|
260
263
|
})
|
|
261
264
|
|
|
262
|
-
p.on('close', code => {
|
|
263
|
-
const isSuccessful =
|
|
265
|
+
p.on('close', (code, signal) => {
|
|
266
|
+
const isSuccessful = code === 0
|
|
264
267
|
this.logFinish(cmd, opt, started, isSuccessful)
|
|
265
|
-
const exitCode = code
|
|
268
|
+
const exitCode = code ?? -1
|
|
266
269
|
const o: SpawnOutput = {
|
|
267
270
|
exitCode,
|
|
268
271
|
stdout: stdout.trim(),
|
|
269
272
|
stderr: stderr.trim(),
|
|
270
273
|
}
|
|
271
|
-
if (
|
|
274
|
+
if (signal) {
|
|
275
|
+
return reject(new SpawnError(`spawnAsyncAndReturn killed by signal ${signal}: ${cmd}`, o))
|
|
276
|
+
}
|
|
277
|
+
if (throwOnNonZeroCode && !isSuccessful) {
|
|
272
278
|
return reject(new SpawnError(`spawnAsyncAndReturn exited with code ${code}: ${cmd}`, o))
|
|
273
279
|
}
|
|
274
280
|
resolve(o)
|
|
@@ -51,7 +51,9 @@ export interface SlackMessage<CTX = any> extends SlackMessageProps {
|
|
|
51
51
|
kv?: AnyObject
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Slack Member IDs to mention at the end of the message.
|
|
55
|
+
* Use Member IDs (e.g., 'U1234567890'), not usernames.
|
|
56
|
+
* To find a Member ID: click on their profile in Slack → "..." → "Copy member ID".
|
|
55
57
|
*/
|
|
56
58
|
mentions?: string[]
|
|
57
59
|
|
|
@@ -229,13 +229,78 @@ export class AjvSchema<IN = unknown, OUT = IN> {
|
|
|
229
229
|
const { errorMessages } = this.schema
|
|
230
230
|
|
|
231
231
|
for (const error of errors) {
|
|
232
|
-
|
|
232
|
+
const errorMessage = this.getErrorMessageForInstancePath(
|
|
233
|
+
this.schema,
|
|
234
|
+
error.instancePath,
|
|
235
|
+
error.keyword,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
if (errorMessage) {
|
|
239
|
+
error.message = errorMessage
|
|
240
|
+
} else if (errorMessages?.[error.keyword]) {
|
|
233
241
|
error.message = errorMessages[error.keyword]
|
|
234
242
|
}
|
|
235
243
|
|
|
236
244
|
error.instancePath = error.instancePath.replaceAll(/\/(\d+)/g, `[$1]`).replaceAll('/', '.')
|
|
237
245
|
}
|
|
238
246
|
}
|
|
247
|
+
|
|
248
|
+
private getErrorMessageForInstancePath(
|
|
249
|
+
schema: JsonSchema<IN, OUT> | undefined,
|
|
250
|
+
instancePath: string,
|
|
251
|
+
keyword: string,
|
|
252
|
+
): string | undefined {
|
|
253
|
+
if (!schema || !instancePath) return undefined
|
|
254
|
+
|
|
255
|
+
const segments = instancePath.split('/').filter(Boolean)
|
|
256
|
+
return this.traverseSchemaPath(schema, segments, keyword)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private traverseSchemaPath<IN = unknown, OUT = IN>(
|
|
260
|
+
schema: JsonSchema<IN, OUT>,
|
|
261
|
+
segments: string[],
|
|
262
|
+
keyword: string,
|
|
263
|
+
): string | undefined {
|
|
264
|
+
if (!segments.length) return undefined
|
|
265
|
+
|
|
266
|
+
const [currentSegment, ...remainingSegments] = segments
|
|
267
|
+
|
|
268
|
+
const nextSchema = this.getChildSchema(schema, currentSegment)
|
|
269
|
+
if (!nextSchema) return undefined
|
|
270
|
+
|
|
271
|
+
if (nextSchema.errorMessages?.[keyword]) {
|
|
272
|
+
return nextSchema.errorMessages[keyword]
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (remainingSegments.length) {
|
|
276
|
+
return this.traverseSchemaPath(nextSchema, remainingSegments, keyword)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return undefined
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private getChildSchema(schema: JsonSchema, segment: string | undefined): JsonSchema | undefined {
|
|
283
|
+
if (!segment) return undefined
|
|
284
|
+
if (/^\d+$/.test(segment) && schema.items) {
|
|
285
|
+
return this.getArrayItemSchema(schema, segment)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return this.getObjectPropertySchema(schema, segment)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private getArrayItemSchema(schema: JsonSchema, indexSegment: string): JsonSchema | undefined {
|
|
292
|
+
if (!schema.items) return undefined
|
|
293
|
+
|
|
294
|
+
if (Array.isArray(schema.items)) {
|
|
295
|
+
return schema.items[Number(indexSegment)]
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return schema.items
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
private getObjectPropertySchema(schema: JsonSchema, segment: string): JsonSchema | undefined {
|
|
302
|
+
return schema.properties?.[segment as keyof typeof schema.properties]
|
|
303
|
+
}
|
|
239
304
|
}
|
|
240
305
|
|
|
241
306
|
const separator = '\n'
|