Skip to content

Commit

Permalink
Merge pull request #6 from commercelayer/fetch
Browse files Browse the repository at this point in the history
breaking: remove axios and support to node <20
  • Loading branch information
pviti authored Apr 4, 2024
2 parents 832c925 + ab1627d commit de3f118
Show file tree
Hide file tree
Showing 55 changed files with 2,546 additions and 1,419 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [ main, beta ]
pull_request:
branches: [ main ]
schedule:
Expand All @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: [ 'javascript-typescript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3
with:
version: latest
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'pnpm'
Expand Down
2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github",
"@semantic-release/npm",
"@semantic-release/github",
["@semantic-release/changelog", {
"changelogFile": "CHANGELOG.md"
}],
Expand Down
63 changes: 57 additions & 6 deletions gen/fixer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable no-console */
import { ApiSchema } from './schema'
import resSchema from './resources.js'
import { sortObjectFields } from '../src/util'
import { inspect } from 'util'
import Inflector from './inflector.js'
import { CONFIG } from './generator.js'



Expand Down Expand Up @@ -30,24 +32,69 @@ const fixRedundantComponents = (schema: ApiSchema): ApiSchema => {
res.components = sortObjectFields(res.components)

})

console.log('Redundant components have been replaced')

return schema

}


const fixSchema = (schema: ApiSchema): ApiSchema => {
const fixSchema = async (schema: ApiSchema): Promise<ApiSchema> => {

console.log('Fixing parsed schema...')
const fixedSchema = fixRedundantComponents(schema)

let fixedSchema = schema
fixedSchema = fixRedundantComponents(fixedSchema)
fixedSchema = await enrichSchema(fixedSchema)

console.log('Schema fixed.')

return fixedSchema

}


export default fixSchema
const enrichSchema = async (schema: ApiSchema): Promise<ApiSchema> => {

const resourcesInfo = CONFIG.LOCAL? resSchema.load() : await resSchema.download()

if (!resourcesInfo) {
console.log('Error reading reasources data')
process.exit()
}

Object.entries(schema.components).forEach(([key, val]) => {
const resId = Inflector.snakeCase(key)
const resFields = resSchema.getResourceFields(resourcesInfo, resId)
if (resFields) Object.entries(val.attributes).forEach(([name, info]) => {
const field = resFields[name]
if (!field) console.log(`Warning, field not found in resources data: ${resId}.${name}`)
info.sortable = field?.sortable || false
info.filterable = field?.filterable || false
})
})


Object.values(schema.resources).forEach(r => {
Object.entries(r.components).forEach(([key, val]) => {
const resId = Inflector.snakeCase(key)
const resFields = resSchema.getResourceFields(resourcesInfo, resId)
if (resFields) Object.entries(val.attributes).forEach(([name, info]) => {
const field = resFields[name]
if (!field) console.log(`Warning, field not found in resources data: ${resId}.${name}`)
info.sortable = field?.sortable || false
info.filterable = field?.filterable || false
})
})
})


console.log('Api schema has been enriched with resources data')

return schema

}


const fixHeadingEmptyLines = (lines: string[]): string[] => {
Expand All @@ -62,4 +109,8 @@ const fixHeadingEmptyLines = (lines: string[]): string[] => {
}


export { fixHeadingEmptyLines }

export default {
fixSchema,
fixHeadingEmptyLines
}
Loading

0 comments on commit de3f118

Please sign in to comment.