Skip to content

Commit 785720e

Browse files
authored
add type declarations for json formatting dialects (#129)
1 parent 55f56a8 commit 785720e

File tree

5 files changed

+360
-100
lines changed

5 files changed

+360
-100
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

eslint.config.mjs

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import globals from "globals";
2-
import path from "node:path";
3-
import { fileURLToPath } from "node:url";
4-
import js from "@eslint/js";
5-
import { FlatCompat } from "@eslint/eslintrc";
1+
import globals from 'globals';
2+
import babelParser from '@babel/eslint-parser';
3+
import typescriptPlugin from '@typescript-eslint/eslint-plugin';
4+
import tsParser from '@typescript-eslint/parser';
5+
import path from 'node:path';
6+
import { fileURLToPath } from 'node:url';
7+
import js from '@eslint/js';
8+
import { FlatCompat } from '@eslint/eslintrc';
9+
import jest from 'eslint-plugin-jest';
610

711
const __filename = fileURLToPath(import.meta.url);
812
const __dirname = path.dirname(__filename);
@@ -13,21 +17,46 @@ const compat = new FlatCompat({
1317
});
1418

1519
export default [{
16-
ignores: ["**/*.d.ts",
17-
"coverage/**",
18-
"spec",
19-
"eslint.config.mjs",
20-
],
21-
}, ...compat.extends("eslint:recommended"), {
22-
plugins: {
20+
ignores: ['**/dist', '**/node_modules'],
21+
}, {
22+
files: ['spec/**'],
23+
...jest.configs['flat/recommended'],
24+
rules: {
25+
...jest.configs['flat/recommended'].rules,
26+
'jest/prefer-expect-assertions': 'off',
2327
},
24-
28+
}, ...compat.extends('eslint:recommended'), {
2529
languageOptions: {
2630
globals: {
27-
...globals.browser,
28-
...globals.node,
31+
...globals.node
2932
},
30-
ecmaVersion: 2020,
31-
sourceType: "commonjs",
32-
}
33+
parser: babelParser,
34+
},
35+
rules: {
36+
'no-console': 'off',
37+
'no-invalid-this': 'warn',
38+
'no-undef': 'error',
39+
'no-unused-vars': 'warn',
40+
'no-var': ['error'],
41+
quotes: ['error', 'single'],
42+
strict: [2, 'never'],
43+
},
44+
}, ...compat.extends(
45+
'eslint:recommended',
46+
'plugin:@typescript-eslint/eslint-recommended',
47+
'plugin:@typescript-eslint/recommended',
48+
).map(config => ({
49+
...config,
50+
files: ['*.d.ts'],
51+
})), {
52+
files: ['*.d.ts'],
53+
plugins: {
54+
'@typescript-eslint': typescriptPlugin,
55+
},
56+
rules: {
57+
'@typescript-eslint/no-explicit-any': 'off',
58+
},
59+
languageOptions: {
60+
parser: tsParser,
61+
},
3362
}];

formatter.d.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// MOST Web Framework Codename Blueshift Copyright (c) 2017-2022, THEMOST LP All rights reserved
2-
import {QueryExpression} from "./query";
2+
import {QueryExpression} from './query';
33

44
export declare interface FormatterSettings {
55
nameFormat: string;
66
forceAlias?: boolean;
77
useAliasKeyword?: boolean;
88
}
99

10+
export type QueryToken = string | any;
11+
1012
export declare class SqlFormatter {
1113
provider: any;
1214
settings: FormatterSettings;
@@ -83,3 +85,44 @@ export declare class SqlFormatter {
8385
format(obj: any, s?: string);
8486

8587
}
88+
89+
export declare interface SqlFormatterFactory {
90+
formatterClass: (...args: any[]) => SqlFormatter;
91+
}
92+
93+
/**
94+
* Interface representing a JSON Get Formatter.
95+
* Provides a method to format a JSON get expression.
96+
*/
97+
export declare interface JsonGetFormatter {
98+
$jsonGet(expr: QueryField | { $name: string }): QueryToken;
99+
$jsonEach(expr: (QueryField | Record<string, unknown>)): QueryToken;
100+
}
101+
102+
/**
103+
* Interface representing a JSON object formatter.
104+
*
105+
* @interface JsonObjectFormatter
106+
*/
107+
export declare interface JsonObjectFormatter {
108+
$jsonObject(...expr: (QueryField | Record<string, unknown>)[]): QueryToken;
109+
}
110+
111+
/**
112+
* Interface representing a JSON array formatter.
113+
*/
114+
export declare interface JsonArrayFormatter {
115+
/**
116+
* Formats the given query expression as a JSON array.
117+
* @param expr - The query expression to format.
118+
* @returns A query token representing the formatted JSON array.
119+
*/
120+
$jsonArray(expr: QueryExpression): QueryToken;
121+
122+
/**
123+
* Formats the given query expression as a grouped JSON array.
124+
* @param expr - The query expression to format.
125+
* @returns A query token representing the formatted grouped JSON array.
126+
*/
127+
$jsonGroupArray(expr: QueryExpression): QueryToken;
128+
}

0 commit comments

Comments
 (0)