diff --git a/codegenerator/cli/templates/dynamic/codegen/package.json.hbs b/codegenerator/cli/templates/dynamic/codegen/package.json.hbs index 6eef9e382..7177f5ee8 100644 --- a/codegenerator/cli/templates/dynamic/codegen/package.json.hbs +++ b/codegenerator/cli/templates/dynamic/codegen/package.json.hbs @@ -39,7 +39,7 @@ "postgres": "3.4.1", "prom-client": "15.0.0", "react": "18.2.0", - "rescript-envsafe": "3.1.0", + "rescript-envsafe": "4.0.0", "rescript-express": "0.4.1", "rescript-schema": "6.4.0", "viem": "1.16.6", diff --git a/codegenerator/cli/templates/static/codegen/src/Env.res b/codegenerator/cli/templates/static/codegen/src/Env.res index 78d2f2ca3..346ac4a87 100644 --- a/codegenerator/cli/templates/static/codegen/src/Env.res +++ b/codegenerator/cli/templates/static/codegen/src/Env.res @@ -15,13 +15,13 @@ S.literal(#uinfo), S.literal(#uwarn), S.literal(#uerror), - S.literal("")->S.variant((. _) => default), - S.literal(None)->S.variant((. _) => default), ]), + ~fallback=default ) ) // resets the timestampCaughtUpToHeadOrEndblock after a restart when true -let updateSyncTimeOnRestart = envSafe->EnvSafe.get(. "UPDATE_SYNC_TIME_ON_RESTART", S.bool, ~fallback=true) +let updateSyncTimeOnRestart = + envSafe->EnvSafe.get(. "UPDATE_SYNC_TIME_ON_RESTART", S.bool, ~fallback=true) let maxEventFetchedQueueSize = envSafe->EnvSafe.get(. "MAX_QUEUE_SIZE", S.int, ~fallback=100_000) let maxProcessBatchSize = envSafe->EnvSafe.get(. "MAX_BATCH_SIZE", S.int, ~fallback=5_000) @@ -51,10 +51,8 @@ let logStrategy = envSafe->EnvSafe.get(. S.literal(ConsoleRaw), S.literal(ConsolePretty), S.literal(Both), - // The default value to pretty print to the console only. - S.literal("")->S.variant((. _) => ConsolePretty), - S.literal(None)->S.variant((. _) => ConsolePretty), ]), + ~fallback=ConsolePretty, ) module Db = { @@ -65,10 +63,10 @@ module Db = { let database = envSafe->EnvSafe.get(. "ENVIO_PG_DATABASE", S.string, ~devFallback="envio-dev") let ssl = envSafe->EnvSafe.get(. "ENVIO_PG_SSL_MODE", - S.bool, + Postgres.sslOptionsSchema, //this is a dev fallback option for local deployments, shouldn't run in the prod env //the SSL modes should be provided as string otherwise as 'require' | 'allow' | 'prefer' | 'verify-full' - ~devFallback=false, + ~devFallback=Bool(false), ) } diff --git a/codegenerator/cli/templates/static/codegen/src/bindings/Postgres.res b/codegenerator/cli/templates/static/codegen/src/bindings/Postgres.res index 5c0788394..f9e6c9a96 100644 --- a/codegenerator/cli/templates/static/codegen/src/bindings/Postgres.res +++ b/codegenerator/cli/templates/static/codegen/src/bindings/Postgres.res @@ -13,6 +13,54 @@ type connectionConfig = { applicationName?: string, // Default application_name (default: 'postgres.js') // Other connection parameters, see https://www.postgresql.org/docs/current/runtime-config-client.html } +type streamDuplex +type buffer +type secureContext + +type onread = { + buffer: Js.Nullable.t> => array, + callback: (int, array) => unit, +} + +type tlsConnectOptions = { + enableTrace?: bool, + host?: string /* Default: "localhost" */, + port?: int, + path?: string, + socket?: streamDuplex, + allowHalfOpen?: bool /* Default: false */, + rejectUnauthorized?: bool /* Default: true */, + pskCallback?: unit => unit, + @as("ALPNProtocols") alpnProtocols?: array, //| array | array | array | Buffer | typedArray | DataView, + servername?: string, + checkServerIdentity?: 'a. (string, 'a) => option, + session?: buffer, + minDHSize?: int /* Default: 1024 */, + highWaterMark?: int /* Default: 16 * 1024 */, + secureContext?: secureContext, + onread?: onread, + /* Additional properties from tls.createSecureContext() and socket.connect() */ + // [key: string]: Js.Json.t, +} + +@unboxed +type sslOptions = + | Bool(bool) + | TLSConnectOptions(tlsConnectOptions) + | @as("require") Require + | @as("allow") Allow + | @as("prefer") Prefer + | @as("verify-full") VerifyFull + +let sslOptionsSchema: S.schema = S.union([ + S.literal(Bool(true)), + S.literal(Bool(false)), + S.literal(Require), + S.literal(Allow), + S.literal(Prefer), + S.literal(VerifyFull), + //No schema created for tlsConnectOptions obj +]) type poolConfig = { host?: string, // Postgres ip address[es] or domain name[s] (default: '') @@ -21,7 +69,7 @@ type poolConfig = { database?: string, // Name of database to connect to (default: '') username?: string, // Username of database user (default: '') password?: string, // Password of database user (default: '') - ssl?: bool, // true, prefer, require, tls.connect options (default: false) + ssl?: sslOptions, // true, prefer, require, tls.connect options (default: false) max?: int, // Max number of connections (default: 10) maxLifetime?: option, // Max lifetime in seconds (more info below) (default: null) idleTimeout?: int, // Idle connection timeout in seconds (default: 0)