Skip to content

Commit

Permalink
add deprecation notices to type generator output when feature is comp…
Browse files Browse the repository at this point in the history
…lete (#430)

* add deprecation notices to type generator output when feature is complete

* cleanup
  • Loading branch information
ajwootto authored Sep 4, 2024
1 parent 0b7193d commit d14fd24
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 320 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ $ npm install -g @devcycle/cli
$ dvc COMMAND
running command...
$ dvc (--version)
@devcycle/cli/5.16.2 linux-x64 node-v20.10.0
@devcycle/cli/5.16.2 darwin-arm64 node-v20.10.0
$ dvc --help [COMMAND]
USAGE
$ dvc COMMAND
Expand Down
18 changes: 9 additions & 9 deletions docs/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ Generate Variable Types from the management API
USAGE
$ dvc generate types [--config-path <value>] [--auth-path <value>] [--repo-config-path <value>] [--client-id
<value>] [--client-secret <value>] [--project <value>] [--no-api] [--headless] [--output-dir <value>] [--react]
[--nextjs] [--old-repos] [--inline-comments] [--include-descriptions] [--obfuscate]
[--nextjs] [--old-repos] [--include-descriptions] [--obfuscate] [--include-deprecation-warnings]
FLAGS
--include-descriptions Include variable descriptions in the variable information comment
--inline-comments Inline variable informaton comment on the same line as the type definition
--nextjs Generate types for use with Next.js
--obfuscate Obfuscate the variable keys.
--old-repos Generate types for use with old DevCycle repos (@devcycle/devcycle-react-sdk,
@devcycle/devcycle-js-sdk)
--output-dir=<value> [default: .] Directory to output the generated types to
--react Generate types for use with React
--include-deprecation-warnings Include @deprecated tags for variables of completed features
--include-descriptions Include variable descriptions in the variable information comment
--nextjs Generate types for use with Next.js
--obfuscate Obfuscate the variable keys.
--old-repos Generate types for use with old DevCycle repos (@devcycle/devcycle-react-sdk,
@devcycle/devcycle-js-sdk)
--output-dir=<value> [default: .] Directory to output the generated types to
--react Generate types for use with React
GLOBAL FLAGS
--auth-path=<value> Override the default location to look for an auth.yml file
Expand Down
9 changes: 8 additions & 1 deletion oclif.manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "5.16.1",
"version": "5.16.2",
"commands": {
"authCommand": {
"id": "authCommand",
Expand Down Expand Up @@ -2236,6 +2236,7 @@
"name": "inline-comments",
"type": "boolean",
"description": "Inline variable informaton comment on the same line as the type definition",
"hidden": true,
"allowNo": false
},
"include-descriptions": {
Expand All @@ -2249,6 +2250,12 @@
"type": "boolean",
"description": "Obfuscate the variable keys.",
"allowNo": false
},
"include-deprecation-warnings": {
"name": "include-deprecation-warnings",
"type": "boolean",
"description": "Include @deprecated tags for variables of completed features",
"allowNo": false
}
},
"args": {}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"prepack": "yarn build && oclif manifest && oclif readme --multi",
"test": "mocha test/*.ts \"src/**/*.test.ts\"",
"test:ci": "yarn test --forbid-only",
"test:update-snapshots": "UPDATE_SNAPSHOT=1 yarn test",
"version": "oclif readme --multi && git add README.md"
},
"engines": {
Expand Down
43 changes: 42 additions & 1 deletion src/api/features.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AxiosError } from 'axios'
import apiClient from './apiClient'
import apiClient, { axiosClient } from './apiClient'
import { CreateFeatureParams, Feature, UpdateFeatureParams } from './schemas'
import 'reflect-metadata'
import { buildHeaders } from './common'
Expand Down Expand Up @@ -91,3 +91,44 @@ export const deleteFeature = async (
},
})
}

export const fetchAllCompletedOrArchivedFeatures = async (token: string, project_id: string): Promise<Feature[]> => {
const statuses = ['complete', 'archived']
const perPage = 1000
const firstPage = 1

const fetchFeaturesForStatus = async (status: string): Promise<Feature[]> => {
const url = generatePaginatedFeatureUrl(project_id, firstPage, perPage, status)
const response = await axiosClient.get(url, {
headers: buildHeaders(token),
})

const { headers } = response
const total = Number(headers['count'])
const totalPages = Math.ceil(total / perPage)

const promises = Array.from({ length: totalPages - 1 }, (_, i) => {
const url = generatePaginatedFeatureUrl(project_id, i + 2, perPage, status)
return axiosClient.get(url, {
headers: buildHeaders(token),
})
})

const responses = await Promise.all(promises)
return responses.reduce<Feature[]>((acc, response) => {
return acc.concat(response.data)
}, response.data)
}

const allFeatures = await Promise.all(statuses.map(fetchFeaturesForStatus))
return allFeatures.flat()
}

const generatePaginatedFeatureUrl = (
project_id: string,
page: number,
perPage: number,
status: string
): string => {
return `/v1/projects/${project_id}/features?perPage=${perPage}&page=${page}&status=${status}`
}
2 changes: 2 additions & 0 deletions src/api/zodClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ const Variable = z.object({
createdAt: z.string().datetime(),
updatedAt: z.string().datetime(),
validationSchema: VariableValidationEntity.optional(),
persistent: z.boolean().optional(),
})
const UpdateVariableDto = z
.object({
Expand Down Expand Up @@ -452,6 +453,7 @@ const Feature = z.object({
'cli',
]),
type: z.enum(['release', 'experiment', 'permission', 'ops']).optional(),
status: z.enum(['active', 'complete', 'archived']).optional(),
_createdBy: z.string().optional(),
createdAt: z.string().datetime(),
updatedAt: z.string().datetime(),
Expand Down
Loading

0 comments on commit d14fd24

Please sign in to comment.