Skip to content

Commit

Permalink
fix: crash on envelopItems.filter (#6662)
Browse files Browse the repository at this point in the history
* refactor: remove typescript type error suppresion

* fix: type error

* fix: another type error supression
  • Loading branch information
Skn0tt authored May 24, 2024
1 parent 6ae6de0 commit 5e15f12
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/commands/env/env-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const envGet = async (name: string, options: OptionValues, command: BaseC
const { siteInfo } = cachedConfig
const env = await getEnvelopeEnv({ api, context, env: cachedConfig.env, key: name, scope, siteInfo })

// @ts-expect-error TS(7053) - Element implicitly has an 'any' type
const { value } = env[name] || {}

// Return json response for piping commands
Expand Down
43 changes: 25 additions & 18 deletions src/utils/env/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { $TSFixMe } from '../../commands/types.js'
import { error } from '../command-helpers.js'

export const AVAILABLE_CONTEXTS = ['all', 'production', 'deploy-preview', 'branch-deploy', 'dev']
Expand Down Expand Up @@ -57,18 +58,20 @@ export const filterEnvBySource = (env, source) =>
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
Object.fromEntries(Object.entries(env).filter(([, variable]) => variable.sources[0] === source))

/**
* Fetches data from Envelope
* @param {string} accountId - The account id
* @param {object} api - The api singleton object
* @param {string} key - If present, fetch a single key (case-sensitive)
* @param {string} siteId - The site id
* @returns {Array<object>} An array of environment variables from the Envelope service
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'accountId' implicitly has an 'any... Remove this comment to see the full error message
const fetchEnvelopeItems = async function ({ accountId, api, key, siteId }) {
// Fetches data from Envelope
const fetchEnvelopeItems = async function ({
accountId,
api,
key,
siteId,
}: {
accountId: string
api: $TSFixMe
key: string
siteId: string
}): Promise<$TSFixMe[]> {
if (accountId === undefined) {
return {}
return []
}
try {
// if a single key is passed, fetch that single env var
Expand Down Expand Up @@ -109,28 +112,32 @@ const fetchEnvelopeItems = async function ({ accountId, api, key, siteId }) {
* },
* }
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'source' implicitly has an 'any' t... Remove this comment to see the full error message
export const formatEnvelopeData = ({ context = 'dev', envelopeItems = [], scope = 'any', source }) =>
export const formatEnvelopeData = ({
context = 'dev',
envelopeItems = [],
scope = 'any',
source,
}: {
context?: string
envelopeItems: $TSFixMe[]
scope?: string
source: string
}) =>
envelopeItems
// filter by context
.filter(({ values }) => Boolean(findValueInValues(values, context)))
// filter by scope
// @ts-expect-error TS(2339) FIXME: Property 'includes' does not exist on type 'never'... Remove this comment to see the full error message
.filter(({ scopes }) => (scope === 'any' ? true : scopes.includes(scope)))
// sort alphabetically, case insensitive
// @ts-expect-error TS(2339) FIXME: Property 'key' does not exist on type 'never'.
.sort((left, right) => (left.key.toLowerCase() < right.key.toLowerCase() ? -1 : 1))
// format the data
.reduce((acc, cur) => {
// @ts-expect-error TS(2339) FIXME: Property 'values' does not exist on type 'never'.
const { context: ctx, context_parameter: branch, value } = findValueInValues(cur.values, context)
return {
...acc,
// @ts-expect-error TS(2339) FIXME: Property 'key' does not exist on type 'never'.
[cur.key]: {
context: ctx,
branch,
// @ts-expect-error TS(2339) FIXME: Property 'scopes' does not exist on type 'never'.
scopes: cur.scopes,
sources: [source],
value,
Expand Down

2 comments on commit 5e15f12

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,231
  • Package size: 295 MB
  • Number of ts-expect-error directives: 989

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,231
  • Package size: 295 MB
  • Number of ts-expect-error directives: 989

Please sign in to comment.