@checkdigit/eslint-plugin 7.18.0-PR.143-e2e9 → 7.18.0-PR.143-b47c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@ import { generateSchemasForService } from "../openapi/generate-schema.mjs";
|
|
|
5
5
|
var log = debug("eslint-plugin:athena:api-locator");
|
|
6
6
|
var SERVICES_ROOT_FOLDER = "src/services";
|
|
7
7
|
var LEGACY_TABLE_SUFFIX = "_logs";
|
|
8
|
+
var SCHEMA_MAX_AGE_MS = 60 * 60 * 1e3;
|
|
8
9
|
function upperCaseFirstCharacter(value) {
|
|
9
10
|
return `${value[0]?.toUpperCase()}${value.slice(1)}`;
|
|
10
11
|
}
|
|
@@ -21,16 +22,27 @@ function locateApi(originalServiceName) {
|
|
|
21
22
|
);
|
|
22
23
|
const allSchemaFilenames = fs.globSync(`${SERVICES_ROOT_FOLDER}/${camelCaseServiceName}/*/swagger.schema.deref.json`);
|
|
23
24
|
log(`${allSchemaFilenames.length} versions of API schemas located for service ${serviceName}`, allSchemaFilenames);
|
|
25
|
+
const outputDir = `${SERVICES_ROOT_FOLDER}/${camelCaseServiceName}`;
|
|
24
26
|
if (allSchemaFilenames.length > 0) {
|
|
27
|
+
const hasStaleSchema = allSchemaFilenames.some(
|
|
28
|
+
(schemaFilename) => Date.now() - fs.statSync(schemaFilename).mtimeMs > SCHEMA_MAX_AGE_MS
|
|
29
|
+
);
|
|
30
|
+
if (hasStaleSchema) {
|
|
31
|
+
log("cached schema(s) are stale (older than 1 hour), regenerating for service", serviceName);
|
|
32
|
+
const regenerated = generateSchemasForService(serviceName, outputDir);
|
|
33
|
+
if (regenerated.length > 0) {
|
|
34
|
+
return regenerated.map(({ schema }) => schema);
|
|
35
|
+
}
|
|
36
|
+
log("regeneration failed, falling back to stale cached schemas for service", serviceName);
|
|
37
|
+
}
|
|
25
38
|
return allSchemaFilenames.map(
|
|
26
39
|
(schemaFilename) => JSON.parse(fs.readFileSync(schemaFilename, "utf-8"))
|
|
27
40
|
);
|
|
28
41
|
}
|
|
29
42
|
log("no pre-generated schemas found, attempting on-demand generation for service", serviceName);
|
|
30
|
-
const outputDir = `${SERVICES_ROOT_FOLDER}/${camelCaseServiceName}`;
|
|
31
43
|
return generateSchemasForService(serviceName, outputDir).map(({ schema }) => schema);
|
|
32
44
|
}
|
|
33
45
|
export {
|
|
34
46
|
locateApi
|
|
35
47
|
};
|
|
36
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
48
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL2F0aGVuYS9hcGktbG9jYXRvci50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFFQSxPQUFPLFFBQVE7QUFFZixPQUFPLFdBQVc7QUFFbEIsU0FBMEIsaUNBQWlDO0FBRTNELElBQU0sTUFBTSxNQUFNLGtDQUFrQztBQUVwRCxJQUFNLHVCQUF1QjtBQUM3QixJQUFNLHNCQUFzQjtBQUU1QixJQUFNLG9CQUFvQixLQUFLLEtBQUs7QUFFcEMsU0FBUyx3QkFBd0IsT0FBdUI7QUFFdEQsU0FBTyxHQUFHLE1BQU0sQ0FBQyxHQUFHLFlBQVksQ0FBQyxHQUFHLE1BQU0sTUFBTSxDQUFDLENBQUM7QUFDcEQ7QUFFTyxTQUFTLFVBQVUscUJBQTJDO0FBQ25FLE1BQUksNEJBQTRCLG1CQUFtQjtBQUVuRCxNQUFJLGNBQWM7QUFDbEIsTUFBSSxZQUFZLFNBQVMsbUJBQW1CLEdBQUc7QUFDN0MsUUFBSSwrRkFBK0YsV0FBVztBQUM5RyxrQkFBYyxZQUFZLE1BQU0sR0FBRyxDQUFDLG9CQUFvQixNQUFNO0FBQUEsRUFDaEU7QUFFQSxRQUFNLG1CQUFtQixZQUFZLE1BQU0sR0FBRztBQUM5QyxRQUFNLHVCQUF1QixDQUFDLGlCQUFpQixDQUFDLE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kdigit/eslint-plugin","version":"7.18.0-PR.143-
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"7.18.0-PR.143-b47c","description":"Check Digit eslint plugins","keywords":["eslint","eslintplugin"],"homepage":"https://github.com/checkdigit/eslint-plugin#readme","bugs":{"url":"https://github.com/checkdigit/eslint-plugin/issues"},"repository":{"type":"git","url":"https://github.com/checkdigit/eslint-plugin"},"license":"MIT","author":"Check Digit, LLC","sideEffects":false,"type":"module","exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/test/**","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/test/**","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/test/**","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","ci:compile":"tsc --noEmit","ci:coverage":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true","ci:lint":"npm run lint","ci:style":"npm run prettier","ci:test":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false","lint":"eslint --max-warnings 0 .","lint:fix":"eslint --max-warnings 0 --fix .","peggy":"for file in ./src/peggy/*.peggy; do peggy \"$file\" --format es --output \"${file%.peggy}-peggy.ts\"; done","peggy-watch":"for file in ./src/peggy/*.peggy; do peggy \"$file\" --format=es --watch --output=\"${file%.peggy}-peggy.ts\"; done","prepare":"","prepublishOnly":"npm run build:dist-types && npm run build:dist-mjs","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"},"prettier":"@checkdigit/prettier-config","jest":{"preset":"@checkdigit/jest-config"},"dependencies":{"@apidevtools/json-schema-ref-parser":"^15.3.5","@typescript-eslint/type-utils":"^8.60.1","@typescript-eslint/utils":"^8.60.1","ajv":"^8.20.0","debug":"^4.4.3","glob":"^13.0.6","http-status-codes":"^2.3.0","js-yaml":"^4.2.0","json-pointer":"^0.6.2","jsonpath-plus":"^10.4.0","ts-api-utils":"^2.5.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^6.1.0","@checkdigit/typescript-config":"10.0.0","@eslint/js":"^9.37.0","@types/debug":"^4.1.13","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@types/js-yaml":"^4.0.9","@types/json-pointer":"^1.0.34","@typescript-eslint/parser":"^8.60.1","@typescript-eslint/rule-tester":"^8.60.1","eslint":"^9.37.0","eslint-config-prettier":"^10.1.8","eslint-import-resolver-typescript":"^4.4.5","eslint-plugin-eslint-plugin":"^6.4.0","eslint-plugin-import":"^2.32.0","eslint-plugin-no-only-tests":"^3.4.0","eslint-plugin-no-secrets":"^2.3.3","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"^1.0.4","openapi-types":"^12.1.3","peggy":"^4.2.0","rimraf":"^6.1.3","typescript-eslint":"^8.60.1"},"peerDependencies":{"eslint":">=9 <10"},"engines":{"node":">=24.14.1"},"service":{"api":{"root":"src","endpoints":["api/v1"]}}}
|
|
@@ -10,6 +10,8 @@ const log = debug('eslint-plugin:athena:api-locator');
|
|
|
10
10
|
|
|
11
11
|
const SERVICES_ROOT_FOLDER = 'src/services';
|
|
12
12
|
const LEGACY_TABLE_SUFFIX = '_logs';
|
|
13
|
+
// eslint-disable-next-line no-magic-numbers
|
|
14
|
+
const SCHEMA_MAX_AGE_MS = 60 * 60 * 1000; // 1 hour
|
|
13
15
|
|
|
14
16
|
function upperCaseFirstCharacter(value: string): string {
|
|
15
17
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
@@ -34,13 +36,25 @@ export function locateApi(originalServiceName: string): ApiSchemas[] {
|
|
|
34
36
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
35
37
|
log(`${allSchemaFilenames.length} versions of API schemas located for service ${serviceName}`, allSchemaFilenames);
|
|
36
38
|
|
|
39
|
+
const outputDir = `${SERVICES_ROOT_FOLDER}/${camelCaseServiceName}`;
|
|
40
|
+
|
|
37
41
|
if (allSchemaFilenames.length > 0) {
|
|
42
|
+
const hasStaleSchema = allSchemaFilenames.some(
|
|
43
|
+
(schemaFilename) => Date.now() - fs.statSync(schemaFilename).mtimeMs > SCHEMA_MAX_AGE_MS,
|
|
44
|
+
);
|
|
45
|
+
if (hasStaleSchema) {
|
|
46
|
+
log('cached schema(s) are stale (older than 1 hour), regenerating for service', serviceName);
|
|
47
|
+
const regenerated = generateSchemasForService(serviceName, outputDir);
|
|
48
|
+
if (regenerated.length > 0) {
|
|
49
|
+
return regenerated.map(({ schema }) => schema);
|
|
50
|
+
}
|
|
51
|
+
log('regeneration failed, falling back to stale cached schemas for service', serviceName);
|
|
52
|
+
}
|
|
38
53
|
return allSchemaFilenames.map(
|
|
39
54
|
(schemaFilename) => JSON.parse(fs.readFileSync(schemaFilename, 'utf-8')) as ApiSchemas,
|
|
40
55
|
);
|
|
41
56
|
}
|
|
42
57
|
|
|
43
58
|
log('no pre-generated schemas found, attempting on-demand generation for service', serviceName);
|
|
44
|
-
const outputDir = `${SERVICES_ROOT_FOLDER}/${camelCaseServiceName}`;
|
|
45
59
|
return generateSchemasForService(serviceName, outputDir).map(({ schema }) => schema);
|
|
46
60
|
}
|