@platformatic/foundation 3.14.0 → 3.16.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/index.d.ts +7 -0
- package/lib/cli.js +1 -0
- package/lib/configuration.js +27 -23
- package/lib/schema.js +8 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -101,6 +101,13 @@ export declare function replaceEnv (
|
|
|
101
101
|
onMissingEnv?: (key: string) => string | undefined,
|
|
102
102
|
ignore?: string[]
|
|
103
103
|
): RawConfiguration
|
|
104
|
+
export declare function validate (
|
|
105
|
+
schema: JSONSchemaType<any>,
|
|
106
|
+
config: RawConfiguration,
|
|
107
|
+
validationOptions?: object,
|
|
108
|
+
fixPaths?: boolean,
|
|
109
|
+
root?: string
|
|
110
|
+
): void
|
|
104
111
|
export declare function loadConfiguration (
|
|
105
112
|
source: string | RawConfiguration,
|
|
106
113
|
schema?: any,
|
package/lib/cli.js
CHANGED
package/lib/configuration.js
CHANGED
|
@@ -316,6 +316,30 @@ export function createValidator (schema, validationOptions, context = {}) {
|
|
|
316
316
|
return ajv.compile(schema)
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
+
export function validate (schema, config, validationOptions = {}, fixPaths = true, root = '') {
|
|
320
|
+
const validator = createValidator(schema, validationOptions, { root, fixPaths })
|
|
321
|
+
const valid = validator(config)
|
|
322
|
+
|
|
323
|
+
if (!valid) {
|
|
324
|
+
const validationErrors = []
|
|
325
|
+
let errors = ':'
|
|
326
|
+
|
|
327
|
+
for (const validationError of validator.errors) {
|
|
328
|
+
/* c8 ignore next - else */
|
|
329
|
+
const path = validationError.instancePath === '' ? '/' : validationError.instancePath
|
|
330
|
+
|
|
331
|
+
validationErrors.push({ path, message: validationError.message, params: validationError.params })
|
|
332
|
+
errors += `\n - ${path}: ${validationError.message}`
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const error = new ConfigurationDoesNotValidateAgainstSchemaError()
|
|
336
|
+
error.message += errors + '\n'
|
|
337
|
+
Object.defineProperty(error, 'validationErrors', { value: validationErrors })
|
|
338
|
+
|
|
339
|
+
throw error
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
319
343
|
export async function loadEnv (root, ignoreProcessEnv = false, additionalEnv = {}) {
|
|
320
344
|
if (!isAbsolute(root)) {
|
|
321
345
|
root = resolve(process.cwd(), root)
|
|
@@ -411,7 +435,7 @@ export function replaceEnv (config, env, onMissingEnv, ignore) {
|
|
|
411
435
|
|
|
412
436
|
export async function loadConfiguration (source, schema, options = {}) {
|
|
413
437
|
const {
|
|
414
|
-
validate,
|
|
438
|
+
validate: shouldValidate,
|
|
415
439
|
validationOptions,
|
|
416
440
|
transform,
|
|
417
441
|
upgrade,
|
|
@@ -470,32 +494,12 @@ export async function loadConfiguration (source, schema, options = {}) {
|
|
|
470
494
|
}
|
|
471
495
|
}
|
|
472
496
|
|
|
473
|
-
if (
|
|
497
|
+
if (shouldValidate) {
|
|
474
498
|
if (typeof schema === 'undefined') {
|
|
475
499
|
throw new SourceMissingError()
|
|
476
500
|
}
|
|
477
501
|
|
|
478
|
-
|
|
479
|
-
const valid = validator(config)
|
|
480
|
-
|
|
481
|
-
if (!valid) {
|
|
482
|
-
const validationErrors = []
|
|
483
|
-
let errors = ':'
|
|
484
|
-
|
|
485
|
-
for (const validationError of validator.errors) {
|
|
486
|
-
/* c8 ignore next - else */
|
|
487
|
-
const path = validationError.instancePath === '' ? '/' : validationError.instancePath
|
|
488
|
-
|
|
489
|
-
validationErrors.push({ path, message: validationError.message, params: validationError.params })
|
|
490
|
-
errors += `\n - ${path}: ${validationError.message}`
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const error = new ConfigurationDoesNotValidateAgainstSchemaError()
|
|
494
|
-
error.message += errors + '\n'
|
|
495
|
-
Object.defineProperty(error, 'validationErrors', { value: validationErrors })
|
|
496
|
-
|
|
497
|
-
throw error
|
|
498
|
-
}
|
|
502
|
+
validate(schema, config, validationOptions, fixPaths, root)
|
|
499
503
|
}
|
|
500
504
|
|
|
501
505
|
if (!skipMetadata) {
|
package/lib/schema.js
CHANGED
|
@@ -744,6 +744,10 @@ export const applications = {
|
|
|
744
744
|
useHttp: {
|
|
745
745
|
type: 'boolean'
|
|
746
746
|
},
|
|
747
|
+
reuseTcpPorts: {
|
|
748
|
+
type: 'boolean',
|
|
749
|
+
default: true
|
|
750
|
+
},
|
|
747
751
|
workers: {
|
|
748
752
|
anyOf: [
|
|
749
753
|
{
|
|
@@ -916,6 +920,10 @@ export const runtimeProperties = {
|
|
|
916
920
|
},
|
|
917
921
|
logger,
|
|
918
922
|
server,
|
|
923
|
+
reuseTcpPorts: {
|
|
924
|
+
type: 'boolean',
|
|
925
|
+
default: true
|
|
926
|
+
},
|
|
919
927
|
startTimeout: {
|
|
920
928
|
default: 30000,
|
|
921
929
|
type: 'number',
|