@platformatic/foundation 3.63.0 → 3.65.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 CHANGED
@@ -6,6 +6,7 @@ import { LevelWithSilentOrString, Logger } from 'pino'
6
6
 
7
7
  // Symbols
8
8
  export declare const kCanceled: unique symbol
9
+ export declare const kEnvFileFallbackKeys: unique symbol
9
10
  export declare const kFailedImport: unique symbol
10
11
  export declare const kHandledError: unique symbol
11
12
  export declare const kMetadata: unique symbol
@@ -78,7 +79,17 @@ export interface ValidationError {
78
79
  export type ConfigurationOptions<T = {}> = Partial<{
79
80
  validate: boolean
80
81
  validationOptions: object
81
- transform: (config: Configuration<T>) => Promise<Configuration<T>> | Configuration<T>
82
+ // Read directly off the context by every capability package (astro, basic,
83
+ // next, node, service, ...) to pick a development/production code path.
84
+ isProduction: boolean
85
+ // loadConfiguration() always invokes the caller-supplied transform hook
86
+ // with all three arguments (config, schema, options), mirroring the
87
+ // exported transform() function's own parameter list.
88
+ transform: (
89
+ config: Configuration<T>,
90
+ schema: object,
91
+ options: ConfigurationOptions<T>
92
+ ) => Promise<Configuration<T>> | Configuration<T>
82
93
  upgrade: (logger: Logger, config: RawConfiguration, version: string) => Promise<RawConfiguration> | RawConfiguration
83
94
  env: Record<string, string>
84
95
  ignoreProcessEnv: boolean
@@ -155,9 +166,13 @@ export declare function replaceEnv (
155
166
  onMissingEnv?: (key: string) => string | undefined,
156
167
  ignore?: string[]
157
168
  ): RawConfiguration
169
+ // `config` also accepts an array: the exported `applications` schema is a
170
+ // JSONSchemaType<object[]> (an ARRAY schema), and validate() is called with
171
+ // a matching array of application configs before they are handed to
172
+ // prepareApplication()/addApplications().
158
173
  export declare function validate (
159
174
  schema: JSONSchemaType<any>,
160
- config: RawConfiguration,
175
+ config: RawConfiguration | RawConfiguration[],
161
176
  validationOptions?: object,
162
177
  fixPaths?: boolean,
163
178
  root?: string
@@ -167,7 +182,22 @@ export declare function loadConfiguration (
167
182
  schema?: any,
168
183
  options?: ConfigurationOptions
169
184
  ): Promise<Configuration>
170
- export declare function loadConfigurationModule (root: string, config: RawConfiguration | ModuleWithVersion): any
185
+
186
+ // The capability module object returned by loadConfigurationModule(): the
187
+ // object a capability exports (its shape is otherwise capability-defined,
188
+ // hence the index signature).
189
+ export interface ConfigurationModule {
190
+ loadConfiguration?: (configPath: string) => Promise<unknown>
191
+ skipTelemetryHooks?: boolean
192
+ createCommands?: (applicationId: string) => unknown
193
+ modulesToLoad?: string[]
194
+ [key: string]: unknown
195
+ }
196
+ export declare function loadConfigurationModule (
197
+ root: string,
198
+ config: RawConfiguration | ModuleWithVersion,
199
+ pkg?: string
200
+ ): Promise<ConfigurationModule>
171
201
 
172
202
  // Error types
173
203
  export declare const ERROR_PREFIX: string
@@ -18,7 +18,7 @@ import {
18
18
  } from './errors.js'
19
19
  import { isFileAccessible } from './file-system.js'
20
20
  import { loadModule, splitModuleFromVersion } from './module.js'
21
- import { kMetadata } from './symbols.js'
21
+ import { kEnvFileFallbackKeys, kMetadata } from './symbols.js'
22
22
 
23
23
  const { parse: parseJSON5, stringify: rawStringifyJSON5 } = JSON5
24
24
  const { parse: parseTOML, stringify: stringifyTOML } = toml
@@ -386,11 +386,21 @@ export async function loadEnv (root, ignoreProcessEnv = false, additionalEnv = {
386
386
  // The env file provides fallback defaults: variables already set in the real
387
387
  // environment (and explicit programmatic values) take precedence over it,
388
388
  // matching the dotenv/docker-compose/Vite convention.
389
- return {
389
+ const env = {
390
390
  ...envFromFile,
391
391
  ...baseEnv,
392
392
  ...additionalEnv
393
393
  }
394
+
395
+ // Keys whose only source is the env file are not real environment variables, they are defaults:
396
+ // a more specific env file, like the one of a single application inside a runtime, must still be
397
+ // able to override them. The list is attached non enumerably, so spreading, Object.keys,
398
+ // JSON.stringify and structuredClone of the returned environment are all unchanged.
399
+ const fallbackKeys = Object.keys(envFromFile).filter(key => !(key in baseEnv) && !(key in additionalEnv))
400
+
401
+ Object.defineProperty(env, kEnvFileFallbackKeys, { value: fallbackKeys, enumerable: false })
402
+
403
+ return env
394
404
  }
395
405
 
396
406
  export function replaceEnv (config, env, onMissingEnv, ignore) {
package/lib/schema.js CHANGED
@@ -596,6 +596,18 @@ export const fastifyServer = {
596
596
  }
597
597
  }
598
598
  },
599
+ ajv: {
600
+ type: 'object',
601
+ description:
602
+ 'Options for the Fastify request-validation Ajv instance (the Fastify `ajv` server option). Only `customOptions` is configurable from the config file; for example set `customOptions.coerceTypes` to `false` to reject empty strings on fields that allow the `null` type instead of coercing them to `null`.',
603
+ properties: {
604
+ customOptions: {
605
+ type: 'object',
606
+ additionalProperties: true
607
+ }
608
+ },
609
+ additionalProperties: false
610
+ },
599
611
  caseSensitive: {
600
612
  type: 'boolean'
601
613
  },
package/lib/symbols.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export const kCanceled = Symbol('plt.foundation.canceled')
2
+ export const kEnvFileFallbackKeys = Symbol('plt.foundation.envFileFallbackKeys')
2
3
  export const kFailedImport = Symbol('plt.foundation.failedImport')
3
4
  export const kHandledError = Symbol('plt.foundation.handledError')
4
5
  export const kMetadata = Symbol('plt.foundation.metadata')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/foundation",
3
- "version": "3.63.0",
3
+ "version": "3.65.0",
4
4
  "description": "Platformatic Foundation",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",