import { NotNull, PickAny } from "type-fns"; import { HelpfulError } from "helpful-errors"; import { Environment } from "sdk-environment"; import { CloudWatchLogsClient, CreateLogGroupCommand, CreateLogStreamCommand, PutLogEventsCommand, ResourceAlreadyExistsException } from "@aws-sdk/client-cloudwatch-logs"; import { Serializable } from "serde-fns"; //#region node_modules/.pnpm/domain-glossary-procedure@1.0.0/node_modules/domain-glossary-procedure/dist/domain/objects/Procedure.d.ts /** * what: the shape of an observable procedure * * what^2: * - observable = easy to read, monitor, and maintain * - procedure = an executable of a tactic; tactic.how.procedure::Executable * * note * - javascript's "functions" are actually, by definition, procedures */ type Procedure = ( /** * the input of the procedure */ input: TInput, /** * the context within which the procedure runs */ context: TContext) => TOutput; /** * extracts the input::Type of a procedure */ type ProcedureInput = Parameters[0]; /** * extracts the context::Type of a procedure */ type ProcedureContext = Parameters[1]; /** * extracts the output::Type of a procedure */ type ProcedureOutput = ReturnType; //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.objects/constants.d.ts /** * define the supported log levels */ declare enum LogLevel { ERROR = "error", WARN = "warn", INFO = "info", DEBUG = "debug", } //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.objects/LogOutlet.d.ts /** * .what = a log event that flows through outlets * .why = standardized shape for log data across destinations */ interface LogEvent { level: LogLevel; timestamp: string; message: string; metadata?: Record; env?: Partial; } /** * .what = an outlet that receives log events * .why = enables logs to route to external destinations (e.g., CloudWatch) */ interface LogOutlet { /** * .what = send a log event to this outlet * .why = buffers or dispatches the event to the destination */ send: (event: LogEvent) => void; /** * .what = flush buffered events to the destination * .why = ensures all buffered logs are sent before process exit */ flush: () => Promise; /** * .what = close the outlet and release resources * .why = cleans up timers and process listeners to prevent leaks in tests * .note = optional - not all outlets require cleanup */ close?: () => void; } //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.objects/LogMethods.d.ts /** * .what = a log method that outputs a message with optional metadata */ type LogMethod = (message: string, metadata?: any) => void; /** * .what = the log methods available for use */ interface LogMethods { /** * `error` level logs are used to indicate a critical and urgent failure that requires immediate resolution * - these logs are often associated with someone on-call being notified immediately, regardless of the time or day * - when choosing to log something with a log level of "error", you are saying that someone should be woken up in the middle of the night if this occurs */ error: LogMethod; /** * `warn` level logs are used to indicate that something is going wrong, but can wait to be resolved until a convenient time * - these logs are often associated with someone following up on them during business hours * - when choosing to log something with a log level of "warn", you are saying that someone should look at this as soon as reasonably possible */ warn: LogMethod; /** * `info` level logs are used to indicate an interesting event that should be kept track of * - these logs are often associated with health metrics, dashboard statistics, or custom log queries for investigations or reporting * - when choosing to log something with a log level of "info", you are saying that someone will be interested in this information indefinitely */ info: LogMethod; /** * `debug` level logs are used to output information that can aid users in tracking down bugs or confirming that things are working as expected * - these logs are often associated with common actions that happen within code, that may only be relevant when debugging your applications * - when choosing to log something with a log level of "debug", you are saying that someone will only be interested in this information when debugging */ debug: LogMethod; /** * .what = internal config for log methods */ readonly _: Readonly<{ level: LogLevel; }>; /** * .what = the environment context baked into these log methods * .why = enables withLogTrail to inherit env from outer log */ readonly env?: Partial; } //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.objects/LogTrail.d.ts /** * .what = the procedure invocation trail with external identifier */ interface LogTrail { /** * .what = external identifier for request correlation * .why = enables log correlation across a single request */ exid: string | null; /** * .what = the procedure call stack * .why = tracks call depth through withLogTrail wraps */ stack: string[]; } interface ContextLogTrail { /** * .what = the log context which can be used; methods, trail, etc */ log: LogMethods & { _orig?: LogMethods; /** * .what = the log trail which has been collected */ trail?: LogTrail; /** * .what = environment context for log output */ env?: Partial; }; } type HasContextLogTrail = ProcedureContext extends ContextLogTrail ? T : never; //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.operations/genContextLogTrail.d.ts /** * .what = create a log context with trail and env injection * .why = enables request correlation via trail.exid and code version via env.commit */ declare const genContextLogTrail: ({ trail, env, level }: { /** * .what = the trail context for log correlation * .why = forces caller to explicitly provide or pass null */ trail: { exid: string | null; stack: string[]; } | null; /** * .what = the environment context * .why = forces caller to explicitly provide or pass null */ env: Partial | null; /** * .what = the minimum log level to emit * .why = allows filter of logs by level */ level?: { minimum?: LogLevel; }; }) => ContextLogTrail; //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.operations/genLogMethods.d.ts /** * define how to generate the log methods * - allows you to specify the minimal log level to use for your application * - defaults to recommended levels for the environment * - allows you to specify outlets for log events to flow to external destinations * - allows you to specify env for environment context (e.g., commit hash) */ declare const genLogMethods: ({ level, outlets, env }?: { level?: { minimum?: LogLevel; }; outlets?: LogOutlet[]; env?: Partial | null; }) => LogMethods; //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.operations/outlets/cloudwatch/asDefaultLogStreamName.d.ts /** * .what = generates a default log stream name for CloudWatch * .why = matches Lambda's log stream format: YYYY/MM/DD/[$LATEST]instance-id * .note = explicit opt-in: user adds outlet only when automatic forwarder absent */ declare const asDefaultLogStreamName: () => string; //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.operations/outlets/cloudwatch/asLambdaStyleLogGroupName.d.ts /** * .what = generates a lambda-style log group name * .why = CloudWatch log groups follow `/aws/lambda/{service}-{env}` pattern * * .note = performs I/O when service is not provided: * - reads package.json from cwd for service name * - reads env vars (ENVIRONMENT_ACCESS, ENV_ACCESS, STAGE, NODE_ENV) for env.access * for pure usage, pass both service and env.access explicitly. * * @param service - service name (default: reads from package.json) * @param env.access - environment access level (default: from env vars, fallback 'local') */ declare const asLambdaStyleLogGroupName: ({ service, env }?: { service?: string; env?: { access?: string; }; }) => string; //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.operations/outlets/cloudwatch/genCloudwatchOutlet.d.ts /** * .what = the AWS CloudWatch Logs SDK module * .why = dependency injection removes runtime AWS SDK dependency from sdk-logs * * .usage * import * as sdkAwsCloudwatch from '@aws-sdk/client-cloudwatch-logs'; * genCloudwatchOutlet({ ... }, { cloudwatch: { sdk: sdkAwsCloudwatch } }); */ type SdkAwsCloudwatch = { CloudWatchLogsClient: typeof CloudWatchLogsClient; CreateLogGroupCommand: typeof CreateLogGroupCommand; CreateLogStreamCommand: typeof CreateLogStreamCommand; PutLogEventsCommand: typeof PutLogEventsCommand; ResourceAlreadyExistsException: typeof ResourceAlreadyExistsException; }; /** * .what = generates a CloudWatch outlet for log events * .why = enables log events to flow to CloudWatch in environments without automatic collection * * .note = explicit opt-in: add this outlet only when automatic log collection is absent. * AWS Lambda and CloudWatch Agent environments auto-collect console.log output. * in those environments, omit this outlet to avoid duplicate logs. * * @param input.region - AWS region (required: from option or AWS_REGION/AWS_DEFAULT_REGION env) * @param input.logGroup - CloudWatch log group name (default: /aws/lambda/{service}-{env}) * @param input.logStream - CloudWatch log stream name (default: Lambda-style YYYY/MM/DD/[$LATEST]uuid) * @param input.skipLogGroupCreation - skip log group findsert (default: false) * @param input.flushInterval - auto-flush interval in ms (default: 5000) * @param input.maxBufferSize - buffer size threshold in bytes for force-flush (default: 256000) * @param context.cloudwatch.sdk - the @aws-sdk/client-cloudwatch-logs module * @param context.cloudwatch.client - optional pre-configured CloudWatchLogsClient */ declare const genCloudwatchOutlet: (input: { region?: string; logGroup?: string; logStream?: string; skipLogGroupCreation?: boolean; flushInterval?: number; maxBufferSize?: number; }, context: { cloudwatch: { sdk: SdkAwsCloudwatch; client?: CloudWatchLogsClient; }; }) => LogOutlet; //#endregion //#region node_modules/.pnpm/domain-glossaries@1.0.0/node_modules/domain-glossaries/dist/AsOfGlossary.d.ts /** * the shape of a type which is declared as part of a particular glossary */ interface OfGlossary { /** * a metadata identifier for the glossary this domain object is part of */ _dglo: G; } /** * .what = extends the decorated type to specify which glossary it is a part of * .why = * - explicitly declare types as part of a domain-glossary * - for example, assign "" * - ensure that a simple type alias does not get reduced by typescript * - e.g., `type UniDate = string` would get introspected as just `string` * - but., `type UniDate = AsOfGlossary` will get introspected as `UniDate` */ type AsOfGlossary * type TimestampWithout = OfGlossary * * const isOfTimestamp = (input: string): input is TimestampWithReq => {...}; * * const input = '2024, Nov 1'; * const attemptOne: TimestampWithReq = // 🛑 fails as `string is not assignable to TimestampWithReq` * if (isOfTimestamp(input)) { * const attemptTwo: TimestampWithReq = input; // ✅ passes as the domain check confirmed it is the correct shape * } * const attemptThree: TimestampWithoutReq = input; // ✅ passes as there was no requirement to ensure it passed through the domain check * ``` */ R = true> = R extends true ? T & OfGlossary : T & Partial>; //#endregion //#region node_modules/.pnpm/iso-time@1.11.7/node_modules/iso-time/dist/domain.objects/IsoDurationShape.d.ts /** * .what = duration as structured object * .why = enables programmatic manipulation of duration components * .note = no brand needed; the union type IsoDuration provides the brand */ type IsoDurationShape = PickAny<{ years: number; months: number; weeks: number; days: number; hours: number; minutes: number; seconds: number; milliseconds: number; }>; //#endregion //#region node_modules/.pnpm/iso-time@1.11.7/node_modules/iso-time/dist/domain.objects/IsoDurationWords.d.ts /** * .what = iso 8601 duration string format * .why = enables concise duration literals with compile-time validation * .note = no brand needed; template literal union is specific enough */ type IsoDurationWordsOnlyTime = `PT${number}S` | `PT${number}M` | `PT${number}H` | `PT${number}M${number}S` | `PT${number}H${number}S` | `PT${number}H${number}M` | `PT${number}H${number}M${number}S` | `PT${number}.${number}S` | `PT${number}H${number}.${number}S` | `PT${number}M${number}.${number}S` | `PT${number}H${number}M${number}.${number}S`; type IsoDurationWordsOnlyDate = `P${number}Y` | `P${number}M` | `P${number}W` | `P${number}D` | `P${number}Y${number}M` | `P${number}Y${number}D` | `P${number}M${number}D` | `P${number}Y${number}M${number}D` | `P${number}W${number}D`; type IsoDurationWordsCombined = `P${number}DT${number}H` | `P${number}DT${number}M` | `P${number}DT${number}S` | `P${number}DT${number}H${number}M` | `P${number}DT${number}H${number}S` | `P${number}DT${number}M${number}S` | `P${number}DT${number}H${number}M${number}S` | `P${number}DT${number}H${number}M${number}.${number}S` | `P${number}Y${number}M${number}DT${number}H${number}M${number}S` | `P${number}Y${number}M${number}DT${number}H${number}M${number}.${number}S` | `P${number}YT${number}H` | `P${number}YT${number}M` | `P${number}YT${number}S` | `P${number}Y${number}MT${number}H${number}M` | `P${number}Y${number}MT${number}H${number}M${number}S`; type IsoDurationWords = IsoDurationWordsOnlyTime | IsoDurationWordsOnlyDate | IsoDurationWordsCombined; //#endregion //#region node_modules/.pnpm/iso-time@1.11.7/node_modules/iso-time/dist/domain.objects/IsoDuration.d.ts /** * .what = duration in either string or object format * .why = enables users to choose most convenient format per context */ type IsoDuration = AsOfGlossary; //#endregion //#region node_modules/.pnpm/sdk-logs@0.9.2/node_modules/sdk-logs/dist/domain.operations/withLogTrail.d.ts /** * enables input output logging and tracing for a method * * todo: - add tracing identifier w/ async-context * todo: - hookup visual tracing w/ external lib (vi...lo...) * todo: - bundle this with its own logging library which supports scoped logs */ declare const withLogTrail: (logic: (input: TInput, context: TContext) => TOutput, { name: declaredName, log: logOptions, duration }: { /** * specifies the name of the function, if the function does not have a name assigned already */ name?: string | undefined; /** * enable redacting parts of the input or output from logging */ log?: { /** * specifies the level to log the trail with * * note: * - defaults input & output logs to level .debug // todo: debug to .trail * - defaults error logs to level .warn * - error level is only overridable via the object form (to prevent accidental downgrade of error logs) */ level?: LogLevel | { input?: LogLevel | undefined; output?: LogLevel | undefined; error?: LogLevel | undefined; } | undefined; /** * what of the input to log */ input?: ((input: TInput, context: TContext) => any) | undefined; /** * what of the output to log */ output?: ((value: Awaited) => any) | undefined; /** * what of the error to log */ error?: ((error: Error) => any) | undefined; } | undefined; /** * specifies the threshold after which a duration will be included on the output log */ duration?: { threshold: IsoDuration; } | undefined; }) => (input: TInput, context: TContext) => TOutput; //#endregion //#region src/domain.objects/HasName.d.ts type HasName = T & { name: string; }; declare const hasName: (input: T) => input is HasName; declare const getName: (input: HasName) => string; //#endregion //#region src/domain.operations/asProcedure.d.ts /** * .what = declares a javascript:function to be a procedure * * .todo = * - extract name from caller fn by default * - withWrappers by default */ declare const asProcedure: (logic: HasContextLogTrail) => TProcedure; //#endregion //#region src/domain.operations/withExpectOutkey.d.ts type AsExpectOutkey> = (key: K, operation: 'isPresent') => Promise>>; type WithExpectOutkey Promise>> = (...args: Parameters) => ReturnType & { expect: AsExpectOutkey>>; }; declare const withExpectOutkey: >>(procedure: Procedure) => WithExpectOutkey>; //#endregion //#region src/domain.operations/withExpectOutput.d.ts type ExpectOutputIsPresent | null> = (operation: 'isPresent') => Promise>; type ExpectOutput | null> = ExpectOutputIsPresent; type WithExpectOutput Promise | null>> = (...args: Parameters) => ReturnType & { expect: ExpectOutput>>; }; declare const withExpectOutput: | null, TLogic extends (...args: any[]) => Promise>(logic: TLogic) => WithExpectOutput; //#endregion export { type ContextLogTrail, type HasContextLogTrail, HasName, type LogEvent, LogLevel, type LogMethod, type LogMethods, type LogOutlet, type LogTrail, Procedure, ProcedureContext, ProcedureInput, ProcedureOutput, type SdkAwsCloudwatch, WithExpectOutkey, WithExpectOutput, asDefaultLogStreamName, asLambdaStyleLogGroupName, asProcedure, genCloudwatchOutlet, genContextLogTrail, genLogMethods, getName, hasName, withExpectOutkey, withExpectOutput, withLogTrail };