@flowblade/sql-tag-format 0.1.6 → 0.1.7

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.
package/dist/index.cjs CHANGED
@@ -1,2 +1,71 @@
1
- 'use strict';var sqlFormatter=require('sql-formatter');var o=class{constructor(t,r){this.dialect=t;this.formatterOptions=r;}formatOrNull=(t,r)=>{try{return this.formatOrThrow(t,r)}catch{return null}};formatOrThrow=(t,r)=>{let a=r?.options??this.formatterOptions,e=typeof t=="string"?t:t.sql;return sqlFormatter.format(e,{language:r?.dialect??this.dialect,...a})}};exports.SqlFormatter=o;//# sourceMappingURL=index.cjs.map
2
- //# sourceMappingURL=index.cjs.map
1
+ let sql_formatter = require("sql-formatter");
2
+ function _typeof(o) {
3
+ "@babel/helpers - typeof";
4
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
5
+ return typeof o$1;
6
+ } : function(o$1) {
7
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
8
+ }, _typeof(o);
9
+ }
10
+ function toPrimitive(t, r) {
11
+ if ("object" != _typeof(t) || !t) return t;
12
+ var e = t[Symbol.toPrimitive];
13
+ if (void 0 !== e) {
14
+ var i = e.call(t, r || "default");
15
+ if ("object" != _typeof(i)) return i;
16
+ throw new TypeError("@@toPrimitive must return a primitive value.");
17
+ }
18
+ return ("string" === r ? String : Number)(t);
19
+ }
20
+ function toPropertyKey(t) {
21
+ var i = toPrimitive(t, "string");
22
+ return "symbol" == _typeof(i) ? i : i + "";
23
+ }
24
+ function _defineProperty(e, r, t) {
25
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
26
+ value: t,
27
+ enumerable: !0,
28
+ configurable: !0,
29
+ writable: !0
30
+ }) : e[r] = t, e;
31
+ }
32
+ function ownKeys(e, r) {
33
+ var t = Object.keys(e);
34
+ if (Object.getOwnPropertySymbols) {
35
+ var o = Object.getOwnPropertySymbols(e);
36
+ r && (o = o.filter(function(r$1) {
37
+ return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
38
+ })), t.push.apply(t, o);
39
+ }
40
+ return t;
41
+ }
42
+ function _objectSpread2(e) {
43
+ for (var r = 1; r < arguments.length; r++) {
44
+ var t = null != arguments[r] ? arguments[r] : {};
45
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
46
+ _defineProperty(e, r$1, t[r$1]);
47
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
48
+ Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
49
+ });
50
+ }
51
+ return e;
52
+ }
53
+ var SqlFormatter = class {
54
+ constructor(dialect, formatterOptions) {
55
+ this.dialect = dialect;
56
+ this.formatterOptions = formatterOptions;
57
+ _defineProperty(this, "formatOrNull", (sql, params) => {
58
+ try {
59
+ return this.formatOrThrow(sql, params);
60
+ } catch (_unused) {
61
+ return null;
62
+ }
63
+ });
64
+ _defineProperty(this, "formatOrThrow", (sql, params) => {
65
+ var _params$options, _params$dialect;
66
+ const options = (_params$options = params === null || params === void 0 ? void 0 : params.options) !== null && _params$options !== void 0 ? _params$options : this.formatterOptions;
67
+ return (0, sql_formatter.format)(typeof sql === "string" ? sql : sql.sql, _objectSpread2({ language: (_params$dialect = params === null || params === void 0 ? void 0 : params.dialect) !== null && _params$dialect !== void 0 ? _params$dialect : this.dialect }, options));
68
+ });
69
+ }
70
+ };
71
+ exports.SqlFormatter = SqlFormatter;
package/dist/index.d.cts CHANGED
@@ -1,91 +1,97 @@
1
- import { SqlTag } from '@flowblade/sql-tag';
2
- import { SqlLanguage, FormatOptions } from 'sql-formatter';
1
+ import { Sql } from "sql-template-tag";
2
+ import { FormatOptions, SqlLanguage } from "sql-formatter";
3
3
 
4
+ //#region ../sql-tag/src/types.d.ts
5
+ type SqlTag<T> = Sql & {
6
+ _columns: T;
7
+ };
8
+ //#endregion
9
+ //#region src/sql-formatter.d.ts
4
10
  type SqlFormatterOptions = Omit<FormatOptions, 'indentStyle'>;
5
11
  type SqlFormatterDialect = SqlLanguage;
6
12
  type FormatParams = {
7
- /**
8
- * If not provided will default to the dialect provided in the constructor
9
- */
10
- dialect?: SqlFormatterDialect;
11
- /**
12
- * If not provided will default to the formatter options provided in the constructor
13
- */
14
- options?: Partial<SqlFormatterOptions>;
13
+ /**
14
+ * If not provided will default to the dialect provided in the constructor
15
+ */
16
+ dialect?: SqlFormatterDialect;
17
+ /**
18
+ * If not provided will default to the formatter options provided in the constructor
19
+ */
20
+ options?: Partial<SqlFormatterOptions>;
15
21
  };
16
22
  declare class SqlFormatter {
17
- private dialect;
18
- private formatterOptions?;
19
- /**
20
- * SqlFormatter constructor
21
- *
22
- * @example
23
- * ```typescript
24
- * const sqlFormatter = new SqlFormatter('postgresql');
25
- *
26
- * // Alternatively, you can pass in options
27
- * // @see https://github.com/sql-formatter-org/sql-formatter/tree/master?tab=readme-ov-file#configuration-options
28
- *
29
- * const pgsqlFormatter = new SqlFormatter('postgresql', {
30
- * keywordCase: 'preserve',
31
- * identifierCase: 'preserve',
32
- * dataTypeCase: 'preserve',
33
- * functionCase: 'preserve',
34
- * logicalOperatorNewline: 'before',
35
- * expressionWidth: 50,
36
- * linesBetweenQueries: 1,
37
- * denseOperators: false,
38
- * newlineBeforeSemicolon: false,
39
- * useTabs: false,
40
- * tabWidth: 2,
41
- * });
42
- *
43
- * try {
44
- * const formatted = pgsqlFormatter.formatOrThrow(
45
- * 'SELECT * FROM table WHERE id = 1'
46
- * );
47
- * } catch (e) {
48
- * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
49
- * console.log('Error:', e);
50
- * }
51
- * ```
52
- */
53
- constructor(dialect: SqlFormatterDialect, formatterOptions?: SqlFormatterOptions | undefined);
54
- /**
55
- * Format sql to string or return null if sql cannot be parsed
56
- *
57
- * @example
58
- * ```typescript
59
- * const sqlFormatter = new SqlFormatter('postgresql');
60
- *
61
- * const formatted = sqlFormatter.formatOrNull(
62
- * 'SELECT * FROM table WHERE id = 1'
63
- * );
64
- * ```
65
- *
66
- * @return string if sql can be parsed, null otherwise
67
- */
68
- formatOrNull: (sql: SqlTag<unknown> | string, params?: FormatParams) => string | null;
69
- /**
70
- * Format sql to string or throw an error if sql cannot be parsed
71
- *
72
- * @example
73
- * ```typescript
74
- * const sqlFormatter = new SqlFormatter('postgresql');
75
- *
76
- * try {
77
- * const formatted = sqlFormatter.formatOrThrow(
78
- * 'SELECT * FROM table WHERE id = 1'
79
- * );
80
- * } catch (e) {
81
- * // Might throw something similat to: Parse error: Unexpected "[col] from" at line 1 column 8
82
- * console.log('Error:', e);
83
- * }
84
- * ```
85
- *
86
- * @throws Error is sql cannot be parsed
87
- */
88
- formatOrThrow: (sql: SqlTag<unknown> | string, params?: FormatParams) => string;
23
+ private dialect;
24
+ private formatterOptions?;
25
+ /**
26
+ * SqlFormatter constructor
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const sqlFormatter = new SqlFormatter('postgresql');
31
+ *
32
+ * // Alternatively, you can pass in options
33
+ * // @see https://github.com/sql-formatter-org/sql-formatter/tree/master?tab=readme-ov-file#configuration-options
34
+ *
35
+ * const pgsqlFormatter = new SqlFormatter('postgresql', {
36
+ * keywordCase: 'preserve',
37
+ * identifierCase: 'preserve',
38
+ * dataTypeCase: 'preserve',
39
+ * functionCase: 'preserve',
40
+ * logicalOperatorNewline: 'before',
41
+ * expressionWidth: 50,
42
+ * linesBetweenQueries: 1,
43
+ * denseOperators: false,
44
+ * newlineBeforeSemicolon: false,
45
+ * useTabs: false,
46
+ * tabWidth: 2,
47
+ * });
48
+ *
49
+ * try {
50
+ * const formatted = pgsqlFormatter.formatOrThrow(
51
+ * 'SELECT * FROM table WHERE id = 1'
52
+ * );
53
+ * } catch (e) {
54
+ * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
55
+ * console.log('Error:', e);
56
+ * }
57
+ * ```
58
+ */
59
+ constructor(dialect: SqlFormatterDialect, formatterOptions?: SqlFormatterOptions | undefined);
60
+ /**
61
+ * Format sql to string or return null if sql cannot be parsed
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const sqlFormatter = new SqlFormatter('postgresql');
66
+ *
67
+ * const formatted = sqlFormatter.formatOrNull(
68
+ * 'SELECT * FROM table WHERE id = 1'
69
+ * );
70
+ * ```
71
+ *
72
+ * @return string if sql can be parsed, null otherwise
73
+ */
74
+ formatOrNull: (sql: SqlTag<unknown> | string, params?: FormatParams) => string | null;
75
+ /**
76
+ * Format sql to string or throw an error if sql cannot be parsed
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const sqlFormatter = new SqlFormatter('postgresql');
81
+ *
82
+ * try {
83
+ * const formatted = sqlFormatter.formatOrThrow(
84
+ * 'SELECT * FROM table WHERE id = 1'
85
+ * );
86
+ * } catch (e) {
87
+ * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
88
+ * console.log('Error:', e);
89
+ * }
90
+ * ```
91
+ *
92
+ * @throws Error is sql cannot be parsed
93
+ */
94
+ formatOrThrow: (sql: SqlTag<unknown> | string, params?: FormatParams) => string;
89
95
  }
90
-
91
- export { SqlFormatter, type SqlFormatterDialect, type SqlFormatterOptions };
96
+ //#endregion
97
+ export { SqlFormatter, type SqlFormatterDialect, type SqlFormatterOptions };
package/dist/index.d.ts CHANGED
@@ -1,91 +1,97 @@
1
- import { SqlTag } from '@flowblade/sql-tag';
2
- import { SqlLanguage, FormatOptions } from 'sql-formatter';
1
+ import { FormatOptions, SqlLanguage } from "sql-formatter";
2
+ import { Sql } from "sql-template-tag";
3
3
 
4
+ //#region ../sql-tag/src/types.d.ts
5
+ type SqlTag<T> = Sql & {
6
+ _columns: T;
7
+ };
8
+ //#endregion
9
+ //#region src/sql-formatter.d.ts
4
10
  type SqlFormatterOptions = Omit<FormatOptions, 'indentStyle'>;
5
11
  type SqlFormatterDialect = SqlLanguage;
6
12
  type FormatParams = {
7
- /**
8
- * If not provided will default to the dialect provided in the constructor
9
- */
10
- dialect?: SqlFormatterDialect;
11
- /**
12
- * If not provided will default to the formatter options provided in the constructor
13
- */
14
- options?: Partial<SqlFormatterOptions>;
13
+ /**
14
+ * If not provided will default to the dialect provided in the constructor
15
+ */
16
+ dialect?: SqlFormatterDialect;
17
+ /**
18
+ * If not provided will default to the formatter options provided in the constructor
19
+ */
20
+ options?: Partial<SqlFormatterOptions>;
15
21
  };
16
22
  declare class SqlFormatter {
17
- private dialect;
18
- private formatterOptions?;
19
- /**
20
- * SqlFormatter constructor
21
- *
22
- * @example
23
- * ```typescript
24
- * const sqlFormatter = new SqlFormatter('postgresql');
25
- *
26
- * // Alternatively, you can pass in options
27
- * // @see https://github.com/sql-formatter-org/sql-formatter/tree/master?tab=readme-ov-file#configuration-options
28
- *
29
- * const pgsqlFormatter = new SqlFormatter('postgresql', {
30
- * keywordCase: 'preserve',
31
- * identifierCase: 'preserve',
32
- * dataTypeCase: 'preserve',
33
- * functionCase: 'preserve',
34
- * logicalOperatorNewline: 'before',
35
- * expressionWidth: 50,
36
- * linesBetweenQueries: 1,
37
- * denseOperators: false,
38
- * newlineBeforeSemicolon: false,
39
- * useTabs: false,
40
- * tabWidth: 2,
41
- * });
42
- *
43
- * try {
44
- * const formatted = pgsqlFormatter.formatOrThrow(
45
- * 'SELECT * FROM table WHERE id = 1'
46
- * );
47
- * } catch (e) {
48
- * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
49
- * console.log('Error:', e);
50
- * }
51
- * ```
52
- */
53
- constructor(dialect: SqlFormatterDialect, formatterOptions?: SqlFormatterOptions | undefined);
54
- /**
55
- * Format sql to string or return null if sql cannot be parsed
56
- *
57
- * @example
58
- * ```typescript
59
- * const sqlFormatter = new SqlFormatter('postgresql');
60
- *
61
- * const formatted = sqlFormatter.formatOrNull(
62
- * 'SELECT * FROM table WHERE id = 1'
63
- * );
64
- * ```
65
- *
66
- * @return string if sql can be parsed, null otherwise
67
- */
68
- formatOrNull: (sql: SqlTag<unknown> | string, params?: FormatParams) => string | null;
69
- /**
70
- * Format sql to string or throw an error if sql cannot be parsed
71
- *
72
- * @example
73
- * ```typescript
74
- * const sqlFormatter = new SqlFormatter('postgresql');
75
- *
76
- * try {
77
- * const formatted = sqlFormatter.formatOrThrow(
78
- * 'SELECT * FROM table WHERE id = 1'
79
- * );
80
- * } catch (e) {
81
- * // Might throw something similat to: Parse error: Unexpected "[col] from" at line 1 column 8
82
- * console.log('Error:', e);
83
- * }
84
- * ```
85
- *
86
- * @throws Error is sql cannot be parsed
87
- */
88
- formatOrThrow: (sql: SqlTag<unknown> | string, params?: FormatParams) => string;
23
+ private dialect;
24
+ private formatterOptions?;
25
+ /**
26
+ * SqlFormatter constructor
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const sqlFormatter = new SqlFormatter('postgresql');
31
+ *
32
+ * // Alternatively, you can pass in options
33
+ * // @see https://github.com/sql-formatter-org/sql-formatter/tree/master?tab=readme-ov-file#configuration-options
34
+ *
35
+ * const pgsqlFormatter = new SqlFormatter('postgresql', {
36
+ * keywordCase: 'preserve',
37
+ * identifierCase: 'preserve',
38
+ * dataTypeCase: 'preserve',
39
+ * functionCase: 'preserve',
40
+ * logicalOperatorNewline: 'before',
41
+ * expressionWidth: 50,
42
+ * linesBetweenQueries: 1,
43
+ * denseOperators: false,
44
+ * newlineBeforeSemicolon: false,
45
+ * useTabs: false,
46
+ * tabWidth: 2,
47
+ * });
48
+ *
49
+ * try {
50
+ * const formatted = pgsqlFormatter.formatOrThrow(
51
+ * 'SELECT * FROM table WHERE id = 1'
52
+ * );
53
+ * } catch (e) {
54
+ * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
55
+ * console.log('Error:', e);
56
+ * }
57
+ * ```
58
+ */
59
+ constructor(dialect: SqlFormatterDialect, formatterOptions?: SqlFormatterOptions | undefined);
60
+ /**
61
+ * Format sql to string or return null if sql cannot be parsed
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const sqlFormatter = new SqlFormatter('postgresql');
66
+ *
67
+ * const formatted = sqlFormatter.formatOrNull(
68
+ * 'SELECT * FROM table WHERE id = 1'
69
+ * );
70
+ * ```
71
+ *
72
+ * @return string if sql can be parsed, null otherwise
73
+ */
74
+ formatOrNull: (sql: SqlTag<unknown> | string, params?: FormatParams) => string | null;
75
+ /**
76
+ * Format sql to string or throw an error if sql cannot be parsed
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const sqlFormatter = new SqlFormatter('postgresql');
81
+ *
82
+ * try {
83
+ * const formatted = sqlFormatter.formatOrThrow(
84
+ * 'SELECT * FROM table WHERE id = 1'
85
+ * );
86
+ * } catch (e) {
87
+ * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
88
+ * console.log('Error:', e);
89
+ * }
90
+ * ```
91
+ *
92
+ * @throws Error is sql cannot be parsed
93
+ */
94
+ formatOrThrow: (sql: SqlTag<unknown> | string, params?: FormatParams) => string;
89
95
  }
90
-
91
- export { SqlFormatter, type SqlFormatterDialect, type SqlFormatterOptions };
96
+ //#endregion
97
+ export { SqlFormatter, type SqlFormatterDialect, type SqlFormatterOptions };
package/dist/index.js ADDED
@@ -0,0 +1,71 @@
1
+ import { format } from "sql-formatter";
2
+ function _typeof(o) {
3
+ "@babel/helpers - typeof";
4
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
5
+ return typeof o$1;
6
+ } : function(o$1) {
7
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
8
+ }, _typeof(o);
9
+ }
10
+ function toPrimitive(t, r) {
11
+ if ("object" != _typeof(t) || !t) return t;
12
+ var e = t[Symbol.toPrimitive];
13
+ if (void 0 !== e) {
14
+ var i = e.call(t, r || "default");
15
+ if ("object" != _typeof(i)) return i;
16
+ throw new TypeError("@@toPrimitive must return a primitive value.");
17
+ }
18
+ return ("string" === r ? String : Number)(t);
19
+ }
20
+ function toPropertyKey(t) {
21
+ var i = toPrimitive(t, "string");
22
+ return "symbol" == _typeof(i) ? i : i + "";
23
+ }
24
+ function _defineProperty(e, r, t) {
25
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
26
+ value: t,
27
+ enumerable: !0,
28
+ configurable: !0,
29
+ writable: !0
30
+ }) : e[r] = t, e;
31
+ }
32
+ function ownKeys(e, r) {
33
+ var t = Object.keys(e);
34
+ if (Object.getOwnPropertySymbols) {
35
+ var o = Object.getOwnPropertySymbols(e);
36
+ r && (o = o.filter(function(r$1) {
37
+ return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
38
+ })), t.push.apply(t, o);
39
+ }
40
+ return t;
41
+ }
42
+ function _objectSpread2(e) {
43
+ for (var r = 1; r < arguments.length; r++) {
44
+ var t = null != arguments[r] ? arguments[r] : {};
45
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
46
+ _defineProperty(e, r$1, t[r$1]);
47
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
48
+ Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
49
+ });
50
+ }
51
+ return e;
52
+ }
53
+ var SqlFormatter = class {
54
+ constructor(dialect, formatterOptions) {
55
+ this.dialect = dialect;
56
+ this.formatterOptions = formatterOptions;
57
+ _defineProperty(this, "formatOrNull", (sql, params) => {
58
+ try {
59
+ return this.formatOrThrow(sql, params);
60
+ } catch (_unused) {
61
+ return null;
62
+ }
63
+ });
64
+ _defineProperty(this, "formatOrThrow", (sql, params) => {
65
+ var _params$options, _params$dialect;
66
+ const options = (_params$options = params === null || params === void 0 ? void 0 : params.options) !== null && _params$options !== void 0 ? _params$options : this.formatterOptions;
67
+ return format(typeof sql === "string" ? sql : sql.sql, _objectSpread2({ language: (_params$dialect = params === null || params === void 0 ? void 0 : params.dialect) !== null && _params$dialect !== void 0 ? _params$dialect : this.dialect }, options));
68
+ });
69
+ }
70
+ };
71
+ export { SqlFormatter };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@flowblade/sql-tag-format",
3
3
  "description": "Formatter utilities for @flowblade/sql-tag",
4
- "version": "0.1.6",
4
+ "version": "0.1.7",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Vanvelthem Sébastien",
@@ -17,7 +17,7 @@
17
17
  "sideEffects": false,
18
18
  "type": "module",
19
19
  "main": "./dist/index.cjs",
20
- "module": "./dist/index.mjs",
20
+ "module": "./dist/index.js",
21
21
  "types": "./dist/index.d.cts",
22
22
  "publishConfig": {
23
23
  "directory": "_release/package"
@@ -26,7 +26,7 @@
26
26
  ".": {
27
27
  "import": {
28
28
  "types": "./dist/index.d.ts",
29
- "default": "./dist/index.mjs"
29
+ "default": "./dist/index.js"
30
30
  },
31
31
  "require": {
32
32
  "types": "./dist/index.d.cts",
@@ -40,7 +40,7 @@
40
40
  ],
41
41
  "scripts": {
42
42
  "?build-release": "When https://github.com/atlassian/changesets/issues/432 has a solution we can remove this trick",
43
- "build": "run clean && yarn run tsup",
43
+ "build": "tsdown",
44
44
  "build-release": "yarn build && rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
45
45
  "bench-disabled": "vitest bench --run",
46
46
  "bench-codspeed-disabled": "cross-env CODSPEED=1 vitest bench --run",
@@ -49,16 +49,16 @@
49
49
  "docgen-typedoc": "rimraf ./docs/api && typedoc --plugin typedoc-plugin-markdown --out ./docs/api",
50
50
  "check-dist": "run-s check-dist-esm check-dist-cjs",
51
51
  "check-dist-cjs": "es-check es2022 './dist/**/*.cjs' --not './dist/*.map.js'",
52
- "check-dist-esm": "es-check es2022 './dist/**/*.mjs' --not './dist/*.map.js' --module",
52
+ "check-dist-esm": "es-check es2022 './dist/**/*.js' --not './dist/*.map.js' --module",
53
53
  "check-pub": "attw --pack && publint",
54
54
  "check-size": "size-limit",
55
55
  "clean": "rimraf --glob ./dist ./build ./coverage ./_release './tsconfig*.tsbuildinfo'",
56
- "dev": "tsup --watch",
56
+ "dev": "tsdown --watch",
57
57
  "fix-staged": "lint-staged --allow-empty",
58
58
  "lint": "eslint . --ext .ts,.tsx,.js,.jsx,.mjs,.cjs,.mts,.cts --cache --cache-location ../../.cache/eslint/sql-tag-format.eslintcache",
59
59
  "test": "vitest run",
60
60
  "test-unit": "vitest run",
61
- "test-e2e": "vitest --config=vitest.e2e.config.ts run",
61
+ "test-unit-bun": "bun --bun run vitest run",
62
62
  "test-unit-coverage": "vitest run --coverage",
63
63
  "test-unit-edge": "vitest run --environment edge-runtime",
64
64
  "test-unit-watch": "vitest --ui --api 4515",
@@ -70,21 +70,21 @@
70
70
  "sql-formatter": "^15.6.12"
71
71
  },
72
72
  "peerDependencies": {
73
- "@flowblade/sql-tag": "^0.1.17"
73
+ "@flowblade/sql-tag": "^0.1.18"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@arethetypeswrong/cli": "0.18.2",
77
77
  "@belgattitude/eslint-config-bases": "8.8.0",
78
78
  "@codspeed/vitest-plugin": "5.0.1",
79
79
  "@edge-runtime/vm": "5.0.0",
80
+ "@size-limit/esbuild": "12.0.0",
80
81
  "@size-limit/file": "12.0.0",
81
- "@size-limit/webpack": "12.0.0",
82
82
  "@vitest/coverage-istanbul": "4.0.16",
83
83
  "@vitest/ui": "4.0.16",
84
84
  "browserslist": "4.28.1",
85
85
  "browserslist-to-esbuild": "2.1.1",
86
86
  "cross-env": "10.1.0",
87
- "es-check": "9.5.2",
87
+ "es-check": "9.5.3",
88
88
  "esbuild": "0.27.2",
89
89
  "eslint": "8.57.1",
90
90
  "execa": "9.6.1",
@@ -93,14 +93,13 @@
93
93
  "publint": "0.3.16",
94
94
  "rimraf": "6.1.2",
95
95
  "size-limit": "12.0.0",
96
- "tsup": "8.5.1",
96
+ "tsdown": "0.18.3",
97
97
  "tsx": "4.21.0",
98
98
  "typedoc": "0.28.15",
99
99
  "typedoc-plugin-markdown": "4.9.0",
100
100
  "typescript": "5.9.3",
101
- "vite-tsconfig-paths": "5.1.4",
102
- "vitest": "4.0.16",
103
- "webpack": "5.103.0"
101
+ "vite-tsconfig-paths": "6.0.3",
102
+ "vitest": "4.0.16"
104
103
  },
105
104
  "engines": {
106
105
  "node": ">=20.9.0"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/sql-formatter.ts"],"names":["SqlFormatter","dialect","formatterOptions","sql","params","options","sqlString","sqlFormat"],"mappings":"uDAqBO,IAAMA,CAAAA,CAAN,KAAmB,CAmCxB,WAAA,CACUC,CAAAA,CACAC,CAAAA,CACR,CAFQ,IAAA,CAAA,OAAA,CAAAD,EACA,IAAA,CAAA,gBAAA,CAAAC,EACP,CAgBH,YAAA,CAAe,CACbC,CAAAA,CACAC,CAAAA,GACkB,CAClB,GAAI,CACF,OAAO,IAAA,CAAK,aAAA,CAAcD,CAAAA,CAAKC,CAAM,CACvC,CAAA,KAAQ,CACN,OAAO,IACT,CACF,CAAA,CAqBA,aAAA,CAAgB,CACdD,CAAAA,CACAC,CAAAA,GACW,CACX,IAAMC,CAAAA,CAAUD,CAAAA,EAAQ,OAAA,EAAW,IAAA,CAAK,gBAAA,CAClCE,CAAAA,CAAY,OAAOH,CAAAA,EAAQ,QAAA,CAAWA,CAAAA,CAAMA,CAAAA,CAAI,GAAA,CACtD,OAAOI,mBAAAA,CAAUD,CAAAA,CAAW,CAC1B,QAAA,CAAUF,CAAAA,EAAQ,OAAA,EAAW,IAAA,CAAK,OAAA,CAClC,GAAGC,CACL,CAAC,CACH,CACF","file":"index.cjs","sourcesContent":["import type { SqlTag } from '@flowblade/sql-tag';\nimport {\n format as sqlFormat,\n type FormatOptions,\n type SqlLanguage,\n} from 'sql-formatter';\n\nexport type SqlFormatterOptions = Omit<FormatOptions, 'indentStyle'>;\nexport type SqlFormatterDialect = SqlLanguage;\n\ntype FormatParams = {\n /**\n * If not provided will default to the dialect provided in the constructor\n */\n dialect?: SqlFormatterDialect;\n /**\n * If not provided will default to the formatter options provided in the constructor\n */\n options?: Partial<SqlFormatterOptions>;\n};\n\nexport class SqlFormatter {\n /**\n * SqlFormatter constructor\n *\n * @example\n * ```typescript\n * const sqlFormatter = new SqlFormatter('postgresql');\n *\n * // Alternatively, you can pass in options\n * // @see https://github.com/sql-formatter-org/sql-formatter/tree/master?tab=readme-ov-file#configuration-options\n *\n * const pgsqlFormatter = new SqlFormatter('postgresql', {\n * keywordCase: 'preserve',\n * identifierCase: 'preserve',\n * dataTypeCase: 'preserve',\n * functionCase: 'preserve',\n * logicalOperatorNewline: 'before',\n * expressionWidth: 50,\n * linesBetweenQueries: 1,\n * denseOperators: false,\n * newlineBeforeSemicolon: false,\n * useTabs: false,\n * tabWidth: 2,\n * });\n *\n * try {\n * const formatted = pgsqlFormatter.formatOrThrow(\n * 'SELECT * FROM table WHERE id = 1'\n * );\n * } catch (e) {\n * // Might throw something similar to: Parse error: Unexpected \"[col] from\" at line 1 column 8\n * console.log('Error:', e);\n * }\n * ```\n */\n constructor(\n private dialect: SqlFormatterDialect,\n private formatterOptions?: SqlFormatterOptions\n ) {}\n\n /**\n * Format sql to string or return null if sql cannot be parsed\n *\n * @example\n * ```typescript\n * const sqlFormatter = new SqlFormatter('postgresql');\n *\n * const formatted = sqlFormatter.formatOrNull(\n * 'SELECT * FROM table WHERE id = 1'\n * );\n * ```\n *\n * @return string if sql can be parsed, null otherwise\n */\n formatOrNull = (\n sql: SqlTag<unknown> | string,\n params?: FormatParams\n ): string | null => {\n try {\n return this.formatOrThrow(sql, params);\n } catch {\n return null;\n }\n };\n\n /**\n * Format sql to string or throw an error if sql cannot be parsed\n *\n * @example\n * ```typescript\n * const sqlFormatter = new SqlFormatter('postgresql');\n *\n * try {\n * const formatted = sqlFormatter.formatOrThrow(\n * 'SELECT * FROM table WHERE id = 1'\n * );\n * } catch (e) {\n * // Might throw something similat to: Parse error: Unexpected \"[col] from\" at line 1 column 8\n * console.log('Error:', e);\n * }\n * ```\n *\n * @throws Error is sql cannot be parsed\n */\n formatOrThrow = (\n sql: SqlTag<unknown> | string,\n params?: FormatParams\n ): string => {\n const options = params?.options ?? this.formatterOptions;\n const sqlString = typeof sql === 'string' ? sql : sql.sql;\n return sqlFormat(sqlString, {\n language: params?.dialect ?? this.dialect,\n ...options,\n });\n };\n}\n"]}
package/dist/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- import {format}from'sql-formatter';var o=class{constructor(t,r){this.dialect=t;this.formatterOptions=r;}formatOrNull=(t,r)=>{try{return this.formatOrThrow(t,r)}catch{return null}};formatOrThrow=(t,r)=>{let a=r?.options??this.formatterOptions,e=typeof t=="string"?t:t.sql;return format(e,{language:r?.dialect??this.dialect,...a})}};export{o as SqlFormatter};//# sourceMappingURL=index.mjs.map
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/sql-formatter.ts"],"names":["SqlFormatter","dialect","formatterOptions","sql","params","options","sqlString","sqlFormat"],"mappings":"mCAqBO,IAAMA,CAAAA,CAAN,KAAmB,CAmCxB,WAAA,CACUC,CAAAA,CACAC,CAAAA,CACR,CAFQ,IAAA,CAAA,OAAA,CAAAD,EACA,IAAA,CAAA,gBAAA,CAAAC,EACP,CAgBH,YAAA,CAAe,CACbC,CAAAA,CACAC,CAAAA,GACkB,CAClB,GAAI,CACF,OAAO,IAAA,CAAK,aAAA,CAAcD,CAAAA,CAAKC,CAAM,CACvC,CAAA,KAAQ,CACN,OAAO,IACT,CACF,CAAA,CAqBA,aAAA,CAAgB,CACdD,CAAAA,CACAC,CAAAA,GACW,CACX,IAAMC,CAAAA,CAAUD,CAAAA,EAAQ,OAAA,EAAW,IAAA,CAAK,gBAAA,CAClCE,CAAAA,CAAY,OAAOH,CAAAA,EAAQ,QAAA,CAAWA,CAAAA,CAAMA,CAAAA,CAAI,GAAA,CACtD,OAAOI,MAAAA,CAAUD,CAAAA,CAAW,CAC1B,QAAA,CAAUF,CAAAA,EAAQ,OAAA,EAAW,IAAA,CAAK,OAAA,CAClC,GAAGC,CACL,CAAC,CACH,CACF","file":"index.mjs","sourcesContent":["import type { SqlTag } from '@flowblade/sql-tag';\nimport {\n format as sqlFormat,\n type FormatOptions,\n type SqlLanguage,\n} from 'sql-formatter';\n\nexport type SqlFormatterOptions = Omit<FormatOptions, 'indentStyle'>;\nexport type SqlFormatterDialect = SqlLanguage;\n\ntype FormatParams = {\n /**\n * If not provided will default to the dialect provided in the constructor\n */\n dialect?: SqlFormatterDialect;\n /**\n * If not provided will default to the formatter options provided in the constructor\n */\n options?: Partial<SqlFormatterOptions>;\n};\n\nexport class SqlFormatter {\n /**\n * SqlFormatter constructor\n *\n * @example\n * ```typescript\n * const sqlFormatter = new SqlFormatter('postgresql');\n *\n * // Alternatively, you can pass in options\n * // @see https://github.com/sql-formatter-org/sql-formatter/tree/master?tab=readme-ov-file#configuration-options\n *\n * const pgsqlFormatter = new SqlFormatter('postgresql', {\n * keywordCase: 'preserve',\n * identifierCase: 'preserve',\n * dataTypeCase: 'preserve',\n * functionCase: 'preserve',\n * logicalOperatorNewline: 'before',\n * expressionWidth: 50,\n * linesBetweenQueries: 1,\n * denseOperators: false,\n * newlineBeforeSemicolon: false,\n * useTabs: false,\n * tabWidth: 2,\n * });\n *\n * try {\n * const formatted = pgsqlFormatter.formatOrThrow(\n * 'SELECT * FROM table WHERE id = 1'\n * );\n * } catch (e) {\n * // Might throw something similar to: Parse error: Unexpected \"[col] from\" at line 1 column 8\n * console.log('Error:', e);\n * }\n * ```\n */\n constructor(\n private dialect: SqlFormatterDialect,\n private formatterOptions?: SqlFormatterOptions\n ) {}\n\n /**\n * Format sql to string or return null if sql cannot be parsed\n *\n * @example\n * ```typescript\n * const sqlFormatter = new SqlFormatter('postgresql');\n *\n * const formatted = sqlFormatter.formatOrNull(\n * 'SELECT * FROM table WHERE id = 1'\n * );\n * ```\n *\n * @return string if sql can be parsed, null otherwise\n */\n formatOrNull = (\n sql: SqlTag<unknown> | string,\n params?: FormatParams\n ): string | null => {\n try {\n return this.formatOrThrow(sql, params);\n } catch {\n return null;\n }\n };\n\n /**\n * Format sql to string or throw an error if sql cannot be parsed\n *\n * @example\n * ```typescript\n * const sqlFormatter = new SqlFormatter('postgresql');\n *\n * try {\n * const formatted = sqlFormatter.formatOrThrow(\n * 'SELECT * FROM table WHERE id = 1'\n * );\n * } catch (e) {\n * // Might throw something similat to: Parse error: Unexpected \"[col] from\" at line 1 column 8\n * console.log('Error:', e);\n * }\n * ```\n *\n * @throws Error is sql cannot be parsed\n */\n formatOrThrow = (\n sql: SqlTag<unknown> | string,\n params?: FormatParams\n ): string => {\n const options = params?.options ?? this.formatterOptions;\n const sqlString = typeof sql === 'string' ? sql : sql.sql;\n return sqlFormat(sqlString, {\n language: params?.dialect ?? this.dialect,\n ...options,\n });\n };\n}\n"]}