Compare commits

...

2 Commits

Author SHA1 Message Date
Michael B. Gale
0cf61911ea Generate UserConfig from schema ... ish 2025-10-17 16:19:12 +01:00
Michael B. Gale
816fc30181 Add command for turning JSON schemas into TypeScript typings 2025-10-17 16:12:28 +01:00
18 changed files with 188 additions and 36 deletions

29
json-schemas.mjs Normal file
View File

@@ -0,0 +1,29 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { globSync } from "glob";
import { compileFromFile } from 'json-schema-to-typescript';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const SRC_DIR = path.join(__dirname, "schemas");
const OUT_DIR = path.join(__dirname, "src");
async function generateTypings() {
const schemas = globSync(`${SRC_DIR}/*.json`);
for (const schema of schemas) {
const outPath = path.join(
OUT_DIR,
`${path.basename(schema, ".json")}.d.ts`,
);
const ts = await compileFromFile(schema, {
bannerComment:
"/* This file was automatically generated by `npm run generate:schemas`. Do not edit by hand. */",
});
fs.writeFileSync(outPath, ts, "utf-8");
}
}
await generateTypings();

View File

@@ -26472,7 +26472,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -26538,6 +26539,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

4
lib/analyze-action.js generated
View File

@@ -32321,7 +32321,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -32387,6 +32388,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

View File

@@ -26472,7 +26472,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -26538,6 +26539,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

View File

@@ -32321,7 +32321,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -32387,6 +32388,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

10
lib/init-action.js generated
View File

@@ -32321,7 +32321,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -32387,6 +32388,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"
@@ -35283,12 +35285,12 @@ var require_lib2 = __commonJS({
}
});
// src/db-config-schema.json
// schemas/db-config-schema.json
var require_db_config_schema = __commonJS({
"src/db-config-schema.json"(exports2, module2) {
"schemas/db-config-schema.json"(exports2, module2) {
module2.exports = {
$schema: "https://json-schema.org/draft/2020-12/schema",
title: "CodeQL Database Configuration",
title: "UserConfig",
description: "Format of the config file supplied by the user for CodeQL analysis",
type: "object",
properties: {

View File

@@ -26472,7 +26472,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -26538,6 +26539,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

View File

@@ -32321,7 +32321,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -32387,6 +32388,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

View File

@@ -26472,7 +26472,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -26538,6 +26539,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

View File

@@ -45008,7 +45008,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -45074,6 +45075,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

4
lib/upload-lib.js generated
View File

@@ -33618,7 +33618,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -33684,6 +33685,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

View File

@@ -26472,7 +26472,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -26538,6 +26539,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

View File

@@ -32321,7 +32321,8 @@ var require_package = __commonJS({
ava: "npm run transpile && ava --serial --verbose",
test: "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
transpile: "tsc --build --verbose"
transpile: "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
ava: {
typescript: {
@@ -32387,6 +32388,7 @@ var require_package = __commonJS({
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
glob: "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
nock: "^14.0.10",
sinon: "^21.0.0",
typescript: "^5.9.3"

57
package-lock.json generated
View File

@@ -63,6 +63,7 @@
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
"glob": "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
"nock": "^14.0.10",
"sinon": "^21.0.0",
"typescript": "^5.9.3"
@@ -429,6 +430,24 @@
"semver": "^6.1.0"
}
},
"node_modules/@apidevtools/json-schema-ref-parser": {
"version": "11.9.3",
"resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.9.3.tgz",
"integrity": "sha512-60vepv88RwcJtSHrD6MjIL6Ta3SOYbgfnkHb+ppAVK+o9mXprRtulx7VlRl3lN3bbvysAfCS7WMVfhUYemB0IQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@jsdevtools/ono": "^7.1.3",
"@types/json-schema": "^7.0.15",
"js-yaml": "^4.1.0"
},
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://github.com/sponsors/philsturgeon"
}
},
"node_modules/@ava/typescript": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@ava/typescript/-/typescript-6.0.0.tgz",
@@ -1525,6 +1544,13 @@
"node": ">=18.0.0"
}
},
"node_modules/@jsdevtools/ono": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz",
"integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==",
"dev": true,
"license": "MIT"
},
"node_modules/@mapbox/node-pre-gyp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-2.0.0.tgz",
@@ -2644,6 +2670,13 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/lodash": {
"version": "4.17.20",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.20.tgz",
"integrity": "sha512-H3MHACvFUEiujabxhaI/ImO6gUrd8oOurg7LQtS7mbwIXA/cUqWrvBsaeJ23aZEPk1TAYkurjfMbSELfoCXlGA==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/node": {
"version": "20.19.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.9.tgz",
@@ -6952,6 +6985,30 @@
"node": ">=0.1.90"
}
},
"node_modules/json-schema-to-typescript": {
"version": "15.0.4",
"resolved": "https://registry.npmjs.org/json-schema-to-typescript/-/json-schema-to-typescript-15.0.4.tgz",
"integrity": "sha512-Su9oK8DR4xCmDsLlyvadkXzX6+GGXJpbhwoLtOGArAG61dvbW4YQmSEno2y66ahpIdmLMg6YUf/QHLgiwvkrHQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^11.5.5",
"@types/json-schema": "^7.0.15",
"@types/lodash": "^4.17.7",
"is-glob": "^4.0.3",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"minimist": "^1.2.8",
"prettier": "^3.2.5",
"tinyglobby": "^0.2.9"
},
"bin": {
"json2ts": "dist/src/cli.js"
},
"engines": {
"node": ">=16.0.0"
}
},
"node_modules/json-schema-traverse": {
"version": "0.4.1",
"dev": true,

View File

@@ -12,7 +12,8 @@
"ava": "npm run transpile && ava --serial --verbose",
"test": "npm run ava -- src/",
"test-debug": "npm run test -- --timeout=20m",
"transpile": "tsc --build --verbose"
"transpile": "npm run generate:schemas && tsc --build --verbose",
"generate:schemas": "node json-schemas.mjs"
},
"ava": {
"typescript": {
@@ -78,6 +79,7 @@
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
"glob": "^11.0.3",
"json-schema-to-typescript": "^15.0.4",
"nock": "^14.0.10",
"sinon": "^21.0.0",
"typescript": "^5.9.3"

View File

@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "CodeQL Database Configuration",
"title": "UserConfig",
"description": "Format of the config file supplied by the user for CodeQL analysis",
"type": "object",
"properties": {

View File

@@ -4,6 +4,7 @@ import * as yaml from "js-yaml";
import * as jsonschema from "jsonschema";
import * as semver from "semver";
import type { UserConfig as DbConfig, QuerySpec } from "../db-config-schema";
import * as errorMessages from "../error-messages";
import {
RepositoryProperties,
@@ -13,6 +14,8 @@ import { Language } from "../languages";
import { Logger } from "../logging";
import { cloneObject, ConfigurationError, prettyPrintPack } from "../util";
export type { QuerySpec } from "../db-config-schema";
export interface ExcludeQueryFilter {
exclude: Record<string, string[] | string>;
}
@@ -23,30 +26,14 @@ export interface IncludeQueryFilter {
export type QueryFilter = ExcludeQueryFilter | IncludeQueryFilter;
export interface QuerySpec {
name?: string;
uses: string;
}
/**
* Format of the config file supplied by the user.
*/
export interface UserConfig {
name?: string;
"disable-default-queries"?: boolean;
queries?: QuerySpec[];
"paths-ignore"?: string[];
paths?: string[];
// If this is a multi-language analysis, then the packages must be split by
// language. If this is a single language analysis, then no split by
// language is necessary.
packs?: Record<string, string[]> | string[];
export type UserConfig = DbConfig & {
// Set of query filters to include and exclude extra queries based on
// codeql query suite `include` and `exclude` properties
"query-filters"?: QueryFilter[];
}
};
/**
* Represents additional configuration data from a source other than
@@ -496,7 +483,7 @@ export function parseUserConfig(
try {
const schema =
// eslint-disable-next-line @typescript-eslint/no-require-imports
require("../../src/db-config-schema.json") as jsonschema.Schema;
require("../../schemas/db-config-schema.json") as jsonschema.Schema;
const doc = yaml.load(contents);

53
src/db-config-schema.d.ts vendored Normal file
View File

@@ -0,0 +1,53 @@
/* This file was automatically generated by `npm run generate:schemas`. Do not edit by hand. */
/**
* Format of the config file supplied by the user for CodeQL analysis
*/
export interface UserConfig {
/**
* Name of the configuration
*/
name?: string;
/**
* Whether to disable default queries
*/
"disable-default-queries"?: boolean;
/**
* List of additional queries to run
*/
queries?: QuerySpec[];
/**
* Paths to ignore during analysis
*/
"paths-ignore"?: string[];
/**
* Paths to include in analysis
*/
paths?: string[];
/**
* Query packs to include. Can be a simple array for single-language analysis or an object with language-specific arrays for multi-language analysis
*/
packs?:
| string[]
| {
[k: string]: string[];
};
/**
* Set of query filters to include and exclude extra queries based on CodeQL query suite include and exclude properties
*/
"query-filters"?: unknown[];
[k: string]: unknown;
}
/**
* Detailed query specification object
*/
export interface QuerySpec {
/**
* Optional name for the query
*/
name?: string;
/**
* The query or query suite to use
*/
uses: string;
}