@platformatic/foundation
Advanced tools
| export const kCanceled = Symbol('plt.foundation.canceled') | ||
| export const kFailedImport = Symbol('plt.foundation.failedImport') | ||
| export const kHandledError = Symbol('plt.foundation.handledError') | ||
| export const kMetadata = Symbol('plt.foundation.metadata') | ||
| export const kTimeout = Symbol('plt.foundation.timeout') |
+13
-3
@@ -6,4 +6,10 @@ import { FastifyError } from '@fastify/error' | ||
| // Symbols | ||
| export declare const kCanceled: unique symbol | ||
| export declare const kFailedImport: unique symbol | ||
| export declare const kHandledError: unique symbol | ||
| export declare const kMetadata: unique symbol | ||
| export declare const kTimeout: unique symbol | ||
| // Configuration types | ||
| export declare const kMetadata: unique symbol | ||
| export declare const envVariablePattern: RegExp | ||
@@ -121,4 +127,9 @@ export declare const knownConfigurationFilesExtensions: string[] | ||
| // Execution types | ||
| export declare const kTimeout: unique symbol | ||
| export declare function executeWithTimeout<T> (promise: Promise<T>, timeout: number, timeoutValue?: any): Promise<T> | ||
| export declare function executeInParallel<T, Args extends any[]> ( | ||
| fn: (...args: Args) => Promise<T>, | ||
| args: Args[], | ||
| concurrency?: number, | ||
| throwOnRejections?: boolean | ||
| ): Promise<T[]> | ||
@@ -190,3 +201,2 @@ // File system types | ||
| // Module types | ||
| export declare const kFailedImport: unique symbol | ||
| export declare const defaultPackageManager: string | ||
@@ -193,0 +203,0 @@ |
+1
-0
@@ -13,1 +13,2 @@ export * from './lib/cli.js' | ||
| export * from './lib/string.js' | ||
| export * from './lib/symbols.js' |
@@ -20,2 +20,3 @@ import toml from '@iarna/toml' | ||
| import { loadModule, splitModuleFromVersion } from './module.js' | ||
| import { kMetadata } from './symbols.js' | ||
@@ -27,3 +28,2 @@ const { parse: parseJSON5, stringify: rawStringifyJSON5 } = JSON5 | ||
| export const kMetadata = Symbol('plt.foundation.metadata') | ||
| export const envVariablePattern = /(?:\{{1,2})([a-z0-9_]+)(?:\}{1,2})/i | ||
@@ -30,0 +30,0 @@ |
+60
-2
| import { Unpromise } from '@watchable/unpromise' | ||
| import { setTimeout as sleep } from 'node:timers/promises' | ||
| import { kCanceled, kTimeout } from './symbols.js' | ||
| export const kTimeout = Symbol('plt.utils.timeout') | ||
| export async function executeWithTimeout (promise, timeout, timeoutValue = kTimeout) { | ||
@@ -14,1 +13,60 @@ const ac = new AbortController() | ||
| } | ||
| export async function executeInParallel (fn, args, concurrency = 5, throwOnRejections = true, throwAllErrors = false) { | ||
| const { promise, resolve } = Promise.withResolvers() | ||
| const results = new Map() | ||
| let current = 0 | ||
| let pending = 0 | ||
| let firstError | ||
| let terminated = false | ||
| if (args.length === 0) { | ||
| return [] | ||
| } | ||
| function scheduleNext () { | ||
| // While we have capacity and there are still items to process | ||
| while (current < args.length && pending < concurrency) { | ||
| const i = current++ | ||
| pending++ | ||
| // Perform the async operation | ||
| fn(...args[i]) | ||
| .then(result => { | ||
| results.set(i, result) | ||
| }) | ||
| .catch(err => { | ||
| results.set(i, err) | ||
| firstError = err | ||
| }) | ||
| .finally(() => { | ||
| pending-- | ||
| if (terminated) { | ||
| return | ||
| } | ||
| if ((current === args.length && pending === 0) || (firstError && throwOnRejections)) { | ||
| terminated = true | ||
| resolve() | ||
| } else { | ||
| scheduleNext() | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| scheduleNext() | ||
| await promise | ||
| const returnedValues = [] | ||
| for (let j = 0; j < args.length; j++) { | ||
| returnedValues.push(results.has(j) ? results.get(j) : kCanceled) | ||
| } | ||
| if (firstError && throwOnRejections) { | ||
| throw throwAllErrors ? AggregateError(returnedValues, 'One or more operations failed.') : firstError | ||
| } | ||
| return returnedValues | ||
| } |
+1
-2
@@ -7,7 +7,6 @@ import { existsSync } from 'node:fs' | ||
| import { hasJavascriptFiles } from './file-system.js' | ||
| import { kFailedImport } from './symbols.js' | ||
| let platformaticPackageVersion | ||
| export const kFailedImport = Symbol('plt.utils.failedImport') | ||
| export const defaultPackageManager = 'npm' | ||
@@ -14,0 +13,0 @@ |
+13
-0
@@ -692,2 +692,9 @@ export function overridableValue (spec, defaultValue) { | ||
| health: { ...healthWithoutDefaults }, | ||
| dependencies: { | ||
| type: 'array', | ||
| items: { | ||
| type: 'string' | ||
| }, | ||
| default: [] | ||
| }, | ||
| arguments: { | ||
@@ -807,2 +814,8 @@ type: 'array', | ||
| preload, | ||
| dependencies: { | ||
| type: 'array', | ||
| items: { | ||
| type: 'string' | ||
| } | ||
| }, | ||
| arguments: { | ||
@@ -809,0 +822,0 @@ type: 'array', |
+1
-1
| { | ||
| "name": "@platformatic/foundation", | ||
| "version": "3.0.0-alpha.6", | ||
| "version": "3.0.0-alpha.7", | ||
| "description": "Platformatic Foundation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
96030
2.46%18
5.88%2812
2.82%