-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/dynamic functional context #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
magmacomputing
wants to merge
6
commits into
main
Choose a base branch
from
feature/dynamic-functional-context
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c03dfdf
chore: initialize branch and bump versions for dynamic functional con…
magmacomputing 712cf7e
chore: configure npm provenance repository directories, update README…
magmacomputing ff9ec2f
pre-evaluate()
magmacomputing ddf4975
PR initial review
magmacomputing d8f858a
PR 1st review
magmacomputing 82a196f
PR 2nd review
magmacomputing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| name: Publish Package with Provenance | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| package: | ||
| description: 'Package to publish' | ||
| required: true | ||
| type: choice | ||
| options: | ||
| - '@magmacomputing/tempo' | ||
| - '@magmacomputing/tempo-fns' | ||
| - '@magmacomputing/tempo-plugin-ai' | ||
| - '@magmacomputing/tempo-plugin-astro' | ||
| - '@magmacomputing/tempo-plugin-batch' | ||
| - '@magmacomputing/tempo-plugin-finance' | ||
| - '@magmacomputing/tempo-plugin-snap' | ||
| - '@magmacomputing/tempo-plugin-sync' | ||
| - 'all' | ||
| dry_run: | ||
| description: 'Dry run (simulate without uploading to registry)' | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write # Mandatory for npm Sigstore/OIDC cryptographic provenance | ||
|
|
||
| jobs: | ||
| validate-and-publish: | ||
| name: Publish with Provenance | ||
| if: github.ref == 'refs/heads/main' | ||
| environment: | ||
| name: npm | ||
| url: https://www.npmjs.com/org/magmacomputing | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| env: | ||
| TZ: America/New_York | ||
| LANG: en_US.UTF-8 | ||
| LC_ALL: en_US.UTF-8 | ||
| TEMPO_LICENSE_KEY: ${{ secrets.TEMPO_LICENSE_KEY || '' }} | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Setup Node.js 22 | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Setup Tempo License Key | ||
| run: | | ||
| if [ -n "$TEMPO_LICENSE_KEY" ]; then | ||
| LICENSE_FILE="${{ runner.temp }}/tempo.key" | ||
| echo "$TEMPO_LICENSE_KEY" > "$LICENSE_FILE" | ||
| echo "TEMPO_LICENSE_PATH=$LICENSE_FILE" >> $GITHUB_ENV | ||
| fi | ||
|
|
||
| - name: Build Monorepo Workspaces | ||
| run: | | ||
| npm run build:library | ||
| npm run build:tempo | ||
| npm run build --workspace=@magmacomputing/tempo-plugin-ai --workspace=@magmacomputing/tempo-plugin-astro --workspace=@magmacomputing/tempo-plugin-batch --workspace=@magmacomputing/tempo-plugin-finance --workspace=@magmacomputing/tempo-plugin-snap --workspace=@magmacomputing/tempo-plugin-sync --if-present | ||
|
|
||
| - name: Run Tests | ||
| run: npm run test | ||
|
|
||
| - name: Publish Selected Package | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| SELECTED_PKG: ${{ inputs.package }} | ||
| DRY_RUN: ${{ inputs.dry_run }} | ||
| run: | | ||
| PROVENANCE_FLAG="--provenance --access public" | ||
| if [ "$DRY_RUN" = "true" ]; then | ||
| PROVENANCE_FLAG="$PROVENANCE_FLAG --dry-run" | ||
| echo "🔍 DRY RUN MODE ACTIVATED — Simulating publication..." | ||
| fi | ||
|
|
||
| WORKSPACES=( | ||
| "@magmacomputing/tempo" | ||
| "@magmacomputing/tempo-fns" | ||
| "@magmacomputing/tempo-plugin-ai" | ||
| "@magmacomputing/tempo-plugin-astro" | ||
| "@magmacomputing/tempo-plugin-batch" | ||
| "@magmacomputing/tempo-plugin-finance" | ||
| "@magmacomputing/tempo-plugin-snap" | ||
| "@magmacomputing/tempo-plugin-sync" | ||
| ) | ||
|
|
||
| publish_workspace() { | ||
| local pkg="$1" | ||
| local ver | ||
| ver=$(npm pkg get version --workspace="$pkg" | awk '{print $NF}' | tr -d '"') | ||
| echo "Checking $pkg@$ver on npm..." | ||
|
|
||
| if [ "$DRY_RUN" != "true" ] && npm view "$pkg@$ver" version >/dev/null 2>&1; then | ||
| echo "⏩ $pkg@$ver is already published on npm. Skipping to support partial release recovery." | ||
| return 0 | ||
| fi | ||
|
|
||
| echo "🚀 Publishing $pkg@$ver..." | ||
| npm publish --workspace="$pkg" $PROVENANCE_FLAG | ||
| } | ||
|
|
||
| if [ "$SELECTED_PKG" = "all" ]; then | ||
| echo "🔎 Preflighting all 8 package versions..." | ||
| for pkg in "${WORKSPACES[@]}"; do | ||
| ver=$(npm pkg get version --workspace="$pkg" | awk '{print $NF}' | tr -d '"') | ||
| echo " - $pkg: $ver" | ||
| if [ -z "$ver" ] || [ "$ver" = "null" ]; then | ||
| echo "❌ Failed to resolve version for $pkg" | ||
| exit 1 | ||
| fi | ||
|
magmacomputing marked this conversation as resolved.
|
||
| done | ||
|
|
||
| echo "🚀 Publishing all workspaces..." | ||
| for pkg in "${WORKSPACES[@]}"; do | ||
| publish_workspace "$pkg" | ||
| done | ||
| else | ||
| publish_workspace "$SELECTED_PKG" | ||
| fi | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { isFunction, isNullish, isObject, isPromise } from '#library/assertion.library.js'; | ||
| import type { Evaluable, AsyncEvaluable, Evaluated, AsyncEvaluated } from '#library/type.library.js'; | ||
|
|
||
| /** | ||
| * Evaluates candidate synchronous scalars or supplier functions in order, returning the first defined result (lazy coalesce). | ||
| * If a candidate is a function, it is invoked with zero arguments. | ||
| * Candidates after the first defined value are never evaluated (short-circuiting). | ||
| * If all candidates evaluate to undefined, returns undefined. | ||
| * Any exception thrown by an evaluated supplier function bubbles directly to the caller. | ||
| * | ||
| * @param values - One or more scalars or synchronous supplier functions to evaluate in sequence | ||
| * @returns The first resolved defined value, or undefined if none resolved | ||
| * @example | ||
| * ```ts | ||
| * evaluate(42); // 42 | ||
| * evaluate(() => 'UTC'); // 'UTC' | ||
| * evaluate(undefined, 'fallback'); // 'fallback' | ||
| * evaluate(undefined, () => undefined, () => 'dynamic-fallback', 'final'); // 'dynamic-fallback' | ||
| * ``` | ||
| */ | ||
| export function evaluate<T>(first: Evaluable<T> | undefined, fallback: Evaluable<T>, ...rest: Evaluable<T>[]): T; | ||
| export function evaluate<T>(...values: (Evaluable<T> | undefined)[]): T | undefined; | ||
| export function evaluate<T>(...values: (Evaluable<T> | undefined)[]): T | undefined { | ||
| for (const val of values) { | ||
| const resolved = isFunction(val) ? (val as () => T)() : val; | ||
| if (resolved !== undefined) return resolved as T; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Evaluates candidate synchronous or asynchronous scalars, Promises, or supplier functions in order, returning the first defined result (async lazy coalesce). | ||
| * Supplier functions represent deferred asynchronous work and are invoked lazily only when reached during evaluation. | ||
| * Rejection handlers are attached upfront to direct Promise candidates to prevent unobserved rejections if iteration short-circuits on an earlier defined candidate. | ||
| * If all candidates evaluate to undefined, returns undefined. | ||
| * Any exception or rejection thrown by an evaluated candidate bubbles directly to the caller. | ||
| * | ||
| * @param values - One or more scalars, Promises, or async supplier functions to evaluate in sequence | ||
| * @returns A Promise resolving to the first defined value, or undefined if none resolved | ||
| * @example | ||
| * ```ts | ||
| * await evaluateAsync('apiKey123'); // 'apiKey123' | ||
| * await evaluateAsync(undefined, async () => fetchSecret(), 'defaultKey'); // 'secret' | ||
| * ``` | ||
| */ | ||
| export function evaluateAsync<T>(first: AsyncEvaluable<T> | undefined, fallback: AsyncEvaluable<T>, ...rest: AsyncEvaluable<T>[]): Promise<T>; | ||
| export function evaluateAsync<T>(...values: (AsyncEvaluable<T> | undefined)[]): Promise<T | undefined>; | ||
| export async function evaluateAsync<T>(...values: (AsyncEvaluable<T> | undefined)[]): Promise<T | undefined> { | ||
| for (const val of values) | ||
| if (!isFunction(val) && isFunction((val as any)?.then)) | ||
| (val as PromiseLike<any>).then(undefined, () => {}); | ||
|
magmacomputing marked this conversation as resolved.
|
||
|
|
||
| for (const val of values) { | ||
| const resolved = isFunction(val) ? await (val as () => T | Promise<T>)() : await val; | ||
| if (resolved !== undefined) return resolved as T; | ||
| } | ||
| return undefined; | ||
|
magmacomputing marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Resolves all top-level properties of a configuration object synchronously. | ||
| * For each property whose value is a function, executes the function and sets the property to its return value. | ||
| * | ||
| * @param config - The configuration object to evaluate | ||
| * @returns A new object with all properties synchronously resolved | ||
| * @example | ||
| * ```ts | ||
| * const evaluated = evaluateConfig({ | ||
| * timeZone: () => 'America/New_York', | ||
| * locale: 'en-US' | ||
| * }); | ||
| * // { timeZone: 'America/New_York', locale: 'en-US' } | ||
| * ``` | ||
| */ | ||
| export function evaluateConfig<T extends object>(config: T): Evaluated<T> { | ||
| if (isNullish(config) || !isObject(config)) return config as any; | ||
| const result = { ...config } as any; | ||
|
|
||
| for (const key of Object.keys(config) as (keyof T)[]) { | ||
| const val = config[key]; | ||
| result[key] = isFunction(val) ? (val as () => any)() : val; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves all top-level properties of a configuration object asynchronously. | ||
| * For each property whose value is a function or Promise, executes/awaits the value and sets the property. | ||
| * | ||
| * @param config - The configuration object to evaluate | ||
| * @returns A Promise resolving to a new object with all properties resolved | ||
| * @example | ||
| * ```ts | ||
| * const evaluated = await evaluateConfigAsync({ | ||
| * key: async () => fetchKey(), | ||
| * url: 'https://api.openai.com/v1' | ||
| * }); | ||
| * // { key: 'sk-...', url: 'https://api.openai.com/v1' } | ||
| * ``` | ||
| */ | ||
| export async function evaluateConfigAsync<T extends object>(config: T): Promise<AsyncEvaluated<T>> { | ||
| if (isNullish(config) || !isObject(config)) return config as any; | ||
| const result = { ...config } as any; | ||
| const keys = Object.keys(config) as (keyof T)[]; | ||
| const values = await Promise.all( | ||
| keys.map(key => { | ||
| const val = config[key]; | ||
| return isFunction(val) ? (val as () => any)() : val; | ||
| }) | ||
| ); | ||
|
|
||
| for (let i = 0; i < keys.length; i++) | ||
| result[keys[i]] = values[i]; | ||
|
|
||
| return result; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.