Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type declarations #129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

65 changes: 47 additions & 18 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
import globals from 'globals';
import babelParser from '@babel/eslint-parser';
import typescriptPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
import jest from 'eslint-plugin-jest';

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

export default [{
ignores: ["**/*.d.ts",
"coverage/**",
"spec",
"eslint.config.mjs",
],
}, ...compat.extends("eslint:recommended"), {
plugins: {
ignores: ['**/dist', '**/node_modules'],
}, {
files: ['spec/**'],
...jest.configs['flat/recommended'],
rules: {
...jest.configs['flat/recommended'].rules,
'jest/prefer-expect-assertions': 'off',
},

}, ...compat.extends('eslint:recommended'), {
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.node
},
ecmaVersion: 2020,
sourceType: "commonjs",
}
parser: babelParser,
},
rules: {
'no-console': 'off',
'no-invalid-this': 'warn',
'no-undef': 'error',
'no-unused-vars': 'warn',
'no-var': ['error'],
quotes: ['error', 'single'],
strict: [2, 'never'],
},
}, ...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
).map(config => ({
...config,
files: ['*.d.ts'],
})), {
files: ['*.d.ts'],
plugins: {
'@typescript-eslint': typescriptPlugin,
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
languageOptions: {
parser: tsParser,
},
}];
45 changes: 44 additions & 1 deletion formatter.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// MOST Web Framework Codename Blueshift Copyright (c) 2017-2022, THEMOST LP All rights reserved
import {QueryExpression} from "./query";
import {QueryExpression} from './query';

export declare interface FormatterSettings {
nameFormat: string;
forceAlias?: boolean;
useAliasKeyword?: boolean;
}

export type QueryToken = string | any;

export declare class SqlFormatter {
provider: any;
settings: FormatterSettings;
Expand Down Expand Up @@ -83,3 +85,44 @@ export declare class SqlFormatter {
format(obj: any, s?: string);

}

export declare interface SqlFormatterFactory {
formatterClass: (...args: any[]) => SqlFormatter;
}

/**
* Interface representing a JSON Get Formatter.
* Provides a method to format a JSON get expression.
*/
export declare interface JsonGetFormatter {
$jsonGet(expr: QueryField | { $name: string }): QueryToken;
$jsonEach(expr: (QueryField | Record<string, unknown>)): QueryToken;
}

/**
* Interface representing a JSON object formatter.
*
* @interface JsonObjectFormatter
*/
export declare interface JsonObjectFormatter {
$jsonObject(...expr: (QueryField | Record<string, unknown>)[]): QueryToken;
}

/**
* Interface representing a JSON array formatter.
*/
export declare interface JsonArrayFormatter {
/**
* Formats the given query expression as a JSON array.
* @param expr - The query expression to format.
* @returns A query token representing the formatted JSON array.
*/
$jsonArray(expr: QueryExpression): QueryToken;

/**
* Formats the given query expression as a grouped JSON array.
* @param expr - The query expression to format.
* @returns A query token representing the formatted grouped JSON array.
*/
$jsonGroupArray(expr: QueryExpression): QueryToken;
}
Loading