2025-06-25 04:00:49 +00:00
|
|
|
import ky from 'ky'
|
|
|
|
import pMap from 'p-map'
|
|
|
|
|
2025-06-03 19:57:33 +00:00
|
|
|
import { dereference, type Schema } from '../src/index'
|
|
|
|
|
|
|
|
let lookup: Record<string, Schema> | undefined
|
|
|
|
|
|
|
|
export async function loadMeta() {
|
|
|
|
if (lookup) {
|
|
|
|
return lookup
|
|
|
|
}
|
2025-06-25 04:00:49 +00:00
|
|
|
|
2025-06-03 19:57:33 +00:00
|
|
|
lookup = Object.create({})
|
|
|
|
const ids = [
|
|
|
|
'http://json-schema.org/draft-04/schema',
|
|
|
|
'http://json-schema.org/draft-07/schema',
|
|
|
|
'https://json-schema.org/draft/2019-09/schema',
|
|
|
|
'https://json-schema.org/draft/2019-09/meta/core',
|
|
|
|
'https://json-schema.org/draft/2019-09/meta/applicator',
|
|
|
|
'https://json-schema.org/draft/2019-09/meta/validation',
|
|
|
|
'https://json-schema.org/draft/2019-09/meta/meta-data',
|
|
|
|
'https://json-schema.org/draft/2019-09/meta/format',
|
|
|
|
'https://json-schema.org/draft/2019-09/meta/content',
|
|
|
|
'https://json-schema.org/draft/2020-12/schema',
|
|
|
|
'https://json-schema.org/draft/2020-12/meta/core',
|
|
|
|
'https://json-schema.org/draft/2020-12/meta/applicator',
|
|
|
|
'https://json-schema.org/draft/2020-12/meta/validation',
|
|
|
|
'https://json-schema.org/draft/2020-12/meta/meta-data',
|
|
|
|
'https://json-schema.org/draft/2020-12/meta/format-annotation',
|
|
|
|
'https://json-schema.org/draft/2020-12/meta/content',
|
|
|
|
'https://json-schema.org/draft/2020-12/meta/unevaluated'
|
|
|
|
]
|
|
|
|
|
2025-06-25 04:00:49 +00:00
|
|
|
await pMap(
|
|
|
|
ids,
|
|
|
|
async (id) => {
|
|
|
|
const schema = await ky.get(id).json<Schema>()
|
2025-06-03 19:57:33 +00:00
|
|
|
dereference(schema, lookup)
|
2025-06-25 04:00:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
concurrency: 4
|
|
|
|
}
|
2025-06-03 19:57:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
Object.freeze(lookup)
|
|
|
|
return lookup
|
|
|
|
}
|