Skip to content

Commit

Permalink
Remove cache (#8)
Browse files Browse the repository at this point in the history
* ..

* ..
  • Loading branch information
tinchoz49 authored Jul 25, 2024
1 parent 5d600f4 commit 5ba7070
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 22.x
- name: Install dependencies
run: npm install
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22
46 changes: 19 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,37 @@
"scripts": {
"start": "node index.js",
"build": "tsup src/client.js src/writer.js --dts --format esm,cjs",
"test": "node --test",
"posttest": "npm run lint",
"test": "node --test --experimental-test-snapshots",
"test:update": "node --run test -- --test-update-snapshots",
"posttest": "node --run lint",
"lint": "eslint .",
"test:types": "tsc",
"prepublishOnly": "npm test && npm run build"
"prepublishOnly": "node --run test && node --run build"
},
"peerDependencies": {
"@sinclair/typebox": ">=0.26"
"@sinclair/typebox": ">=0.32.35"
},
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@sindresorhus/safe-stringify": "^1.0.0",
"code-block-writer": "^12.0.0",
"@apidevtools/json-schema-ref-parser": "^11.6.4",
"code-block-writer": "^13.0.1",
"fast-querystring": "^1.1.2",
"meow": "^12.1.1",
"ora": "^7.0.1",
"prettier": "^3.0.1",
"undici": "^5.24.0"
"meow": "^13.2.0",
"ora": "^8.0.1",
"pascalcase": "^2.0.0",
"prettier": "^3.3.3",
"undici": "^6.19.4"
},
"devDependencies": {
"@fastify/swagger": "^8.8.0",
"@sinclair/typebox": "^0.31.17",
"@types/node": "^20.6.2",
"eslint": "^8.46.0",
"eslint-config-standard-ext": "^0.0.27",
"eslint-plugin-jsdoc": "^46.8.1",
"@fastify/swagger": "^8.15.0",
"@sinclair/typebox": "^0.32.35",
"@types/node": "^20.14.12",
"eslint": "^9.7.0",
"eslint-config-standard-ext": "^1.0.4",
"expect-type": "^0.16.0",
"fastify": "^4.21.0",
"openapi-types": "^12.1.3",
"qs": "^6.11.2",
"standard": "^17.1.0",
"tsup": "^8.0.2",
"typescript": "^5.2.2"
},
"standard": {
"env": [
"node",
"browser"
]
"tsup": "^8.2.3",
"typescript": "^5.5.4"
},
"publishConfig": {
"access": "public"
Expand Down
20 changes: 20 additions & 0 deletions src/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ const validFields = new Set([
'oneOf',
'anyOf',
'not',
'readOnly',
'writeOnly',
])

const schemaOptions = new Set(['x-status-code', 'x-content-type', 'x-in', 'default', 'readOnly', 'writeOnly'])

export const kRef = Symbol('ref')

export function cleanupSchema(val) {
const out = {} // null
let k
Expand All @@ -37,5 +43,19 @@ export function cleanupSchema(val) {
out[k] = val[k]
}
}
if (val[kRef]) {
out[kRef] = val[kRef]
}
return out
}

export function extractSchemaOptions(val) {
const out = {} // null
let k
for (k in val) {
if (schemaOptions.has(k)) {
out[k] = val[k]
}
}
return out
}
84 changes: 84 additions & 0 deletions src/head-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
export default (cjs = false) => `/* eslint eslint-comments/no-unlimited-disable: off */
/* eslint-disable */
// This document was generated automatically by openapi-box
/**
* @typedef {import('@sinclair/typebox').TSchema} TSchema
*/
/**
* @template {TSchema} T
* @typedef {import('@sinclair/typebox').Static<T>} Static
*/
/**
* @typedef {import('@sinclair/typebox').SchemaOptions} SchemaOptions
*/
/**
* @typedef {{
* [Path in keyof typeof schema]: {
* [Method in keyof typeof schema[Path]]: {
* [Prop in keyof typeof schema[Path][Method]]: typeof schema[Path][Method][Prop] extends TSchema ?
* Static<typeof schema[Path][Method][Prop]> :
* undefined
* }
* }
* }} SchemaType
*/
/**
* @typedef {{
* [ComponentType in keyof typeof _components]: {
* [ComponentName in keyof typeof _components[ComponentType]]: typeof _components[ComponentType][ComponentName] extends TSchema ?
* Static<typeof _components[ComponentType][ComponentName]> :
* undefined
* }
* }} ComponentType
*/
${cjs ? "const { Type: T, TypeRegistry, Kind, CloneType } = require('@sinclair/typebox')" : "import { Type as T, TypeRegistry, Kind, CloneType } from '@sinclair/typebox'"}
${cjs ? "const { Value } = require('@sinclair/typebox/value')" : "import { Value } from '@sinclair/typebox/value'"}
/**
* @template {TSchema[]} T
* @typedef {{
* [Kind]: 'UnionOneOf'
* static: { [K in keyof T]: Static<T[K]> }[number]
* oneOf: T
* } & TSchema} TUnionOneOf
*/
/**
* @template {TSchema[]} T
* @param {[...T]} oneOf
* @param {SchemaOptions} [options={}]
* @returns {TUnionOneOf<T>}
*/
const UnionOneOf = (oneOf, options = {}) => {
/**
* Checks if the value matches exactly one schema in the union.
*
* @param {TUnionOneOf<TSchema[]>} schema - The union schema to check against.
* @param {unknown} value - The value to check.
* @returns {boolean} True if the value matches exactly one schema, otherwise false.
*/
function UnionOneOfCheck(schema, value) {
return (
1 ===
schema.oneOf.reduce(
(acc, schema) => (Value.Check(schema, value) ? acc + 1 : acc),
0
)
)
}
if (!TypeRegistry.Has('UnionOneOf'))
TypeRegistry.Set('UnionOneOf', UnionOneOfCheck)
return /** @type {TUnionOneOf<typeof oneOf>} */({
...options,
[Kind]: 'UnionOneOf',
oneOf
})
}`
Loading

0 comments on commit 5ba7070

Please sign in to comment.