@flowblade/sql-tag-format 0.0.7 → 0.0.9

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/README.md CHANGED
@@ -89,16 +89,16 @@ Bundle size is tracked by a [size-limit configuration](https://github.com/belgat
89
89
 
90
90
  ## Compatibility
91
91
 
92
- | Level | CI | Description |
93
- |------------|----|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
94
- | Node | ✅ | CI for 18.x, 20.x & 22.x. |
95
- | Browser | ✅ | Tested with latest chrome (vitest/playwright) |
96
- | Browsers | ✅ | [> 96%](https://browserslist.dev/?q=ZGVmYXVsdHMsIGNocm9tZSA%2BPSA5NixmaXJlZm94ID49IDkwLGVkZ2UgPj0gMTksc2FmYXJpID49IDEyLGlvcyA%2BPSAxMixvcGVyYSA%2BPSA3Nw%3D%3D) on 07/2024. Mins to [Chrome 96+, Firefox 90+, Edge 19+, iOS 12+, Safari 12+, Opera 77+](https://github.com/belgattitude/flowblade/blob/main/packages/sql-tag/.browserslistrc) |
97
- | Edge | ✅ | Ensured on CI with [@vercel/edge-runtime](https://github.com/vercel/edge-runtime). |
98
- | Cloudflare | ✅ | Ensured with @cloudflare/vitest-pool-workers (see [wrangler.toml](https://github.com/belgattitude/flowblade/blob/main/devtools/vitest/wrangler.toml) |
99
- | Typescript | ✅ | TS 5.0 + / [are-the-type-wrong](https://github.com/arethetypeswrong/arethetypeswrong.github.io) checks on CI. |
100
- | ES2022 | ✅ | Dist files checked with [es-check](https://github.com/yowainwright/es-check) |
101
- | Performance| ✅ | Monitored with [codspeed.io](https://codspeed.io/belgattitude/flowblade) |
92
+ | Level | CI | Description |
93
+ |------------|----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
94
+ | Node | ✅ | CI for 18.x, 20.x & 22.x. |
95
+ | Browser | ✅ | Tested with latest chrome (vitest/playwright) |
96
+ | Browserslist | ✅ | [> 95%](https://browserslist.dev/?q=ZGVmYXVsdHMsIGNocm9tZSA%2BPSA5NiwgZmlyZWZveCA%2BPSAxMDUsIGVkZ2UgPj0gMTEzLCBzYWZhcmkgPj0gMTUsIGlvcyA%2BPSAxNSwgb3BlcmEgPj0gMTAzLCBub3QgZGVhZA%3D%3D) on 01/2025. [Chrome 96+, Firefox 90+, Edge 19+, ios 15+, Safari 15+ and Opera 77+](https://github.com/belgattitude/flowblade/blob/main/packages/sql-tag-format/.browserslistrc) |
97
+ | Edge | ✅ | Ensured on CI with [@vercel/edge-runtime](https://github.com/vercel/edge-runtime). |
98
+ | Cloudflare | ✅ | Ensured with @cloudflare/vitest-pool-workers (see [wrangler.toml](https://github.com/belgattitude/flowblade/blob/main/devtools/vitest/wrangler.toml) |
99
+ | Typescript | ✅ | TS 5.0 + / [are-the-type-wrong](https://github.com/arethetypeswrong/arethetypeswrong.github.io) checks on CI. |
100
+ | ES2022 | ✅ | Dist files checked with [es-check](https://github.com/yowainwright/es-check) |
101
+ | Performance| ✅ | Monitored with [codspeed.io](https://codspeed.io/belgattitude/flowblade) |
102
102
 
103
103
  ## Contributors
104
104
 
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var sqlFormatter=require('sql-formatter');var o=class{constructor(r,t){this.dialect=r;this.formatterOptions=t;}formatOrNull=(r,t)=>{try{return this.formatOrThrow(r,t)}catch{return null}};formatOrThrow=(r,t)=>{let a=t?.options??this.formatterOptions;return sqlFormatter.format(r.sql,{language:t?.dialect??this.dialect,...a})}};exports.SqlFormatter=o;//# sourceMappingURL=index.cjs.map
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
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sql-formatter.ts"],"names":["SqlFormatter","dialect","formatterOptions","sql","params","options","sqlFormat"],"mappings":"uDAqBO,IAAMA,CAAN,CAAA,KAAmB,CAmCxB,WAAA,CACUC,CACAC,CAAAA,CAAAA,CACR,CAFQ,IAAA,CAAA,OAAA,CAAAD,CACA,CAAA,IAAA,CAAA,gBAAA,CAAAC,EACP,CAgBH,YAAe,CAAA,CACbC,CACAC,CAAAA,CAAAA,GACkB,CAClB,GAAI,CACF,OAAO,IAAK,CAAA,aAAA,CAAcD,CAAKC,CAAAA,CAAM,CACvC,CAAA,KAAQ,CACN,OAAO,IACT,CACF,CAqBA,CAAA,aAAA,CAAgB,CAACD,CAAAA,CAAsBC,CAAkC,GAAA,CACvE,IAAMC,CAAAA,CAAUD,CAAQ,EAAA,OAAA,EAAW,IAAK,CAAA,gBAAA,CACxC,OAAOE,mBAAAA,CAAUH,CAAI,CAAA,GAAA,CAAK,CACxB,QAAA,CAAUC,CAAQ,EAAA,OAAA,EAAW,IAAK,CAAA,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>,\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 = (sql: SqlTag<unknown>, params?: FormatParams): string => {\n const options = params?.options ?? this.formatterOptions;\n return sqlFormat(sql.sql, {\n language: params?.dialect ?? this.dialect,\n ...options,\n });\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/sql-formatter.ts"],"names":["SqlFormatter","dialect","formatterOptions","sql","params","options","sqlString","sqlFormat"],"mappings":"uDAqBO,IAAMA,CAAN,CAAA,KAAmB,CAmCxB,WAAA,CACUC,CACAC,CAAAA,CAAAA,CACR,CAFQ,IAAA,CAAA,OAAA,CAAAD,EACA,IAAAC,CAAAA,gBAAAA,CAAAA,EACP,CAgBH,YAAA,CAAe,CACbC,CAAAA,CACAC,CACkB,GAAA,CAClB,GAAI,CACF,OAAO,IAAK,CAAA,aAAA,CAAcD,CAAKC,CAAAA,CAAM,CACvC,CAAA,KAAQ,CACN,OAAO,IACT,CACF,CAAA,CAqBA,aAAgB,CAAA,CACdD,CACAC,CAAAA,CAAAA,GACW,CACX,IAAMC,CAAUD,CAAAA,CAAAA,EAAQ,OAAW,EAAA,IAAA,CAAK,gBAClCE,CAAAA,CAAAA,CAAY,OAAOH,CAAQ,EAAA,QAAA,CAAWA,CAAMA,CAAAA,CAAAA,CAAI,GACtD,CAAA,OAAOI,mBAAUD,CAAAA,CAAAA,CAAW,CAC1B,QAAUF,CAAAA,CAAAA,EAAQ,OAAW,EAAA,IAAA,CAAK,OAClC,CAAA,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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SqlTag } from '@flowblade/sql-tag';
2
- import { FormatOptions, SqlLanguage } from 'sql-formatter';
2
+ import { SqlLanguage, FormatOptions } from 'sql-formatter';
3
3
 
4
4
  type SqlFormatterOptions = Omit<FormatOptions, 'indentStyle'>;
5
5
  type SqlFormatterDialect = SqlLanguage;
@@ -65,7 +65,7 @@ declare class SqlFormatter {
65
65
  *
66
66
  * @return string if sql can be parsed, null otherwise
67
67
  */
68
- formatOrNull: (sql: SqlTag<unknown>, params?: FormatParams) => string | null;
68
+ formatOrNull: (sql: SqlTag<unknown> | string, params?: FormatParams) => string | null;
69
69
  /**
70
70
  * Format sql to string or throw an error if sql cannot be parsed
71
71
  *
@@ -85,7 +85,7 @@ declare class SqlFormatter {
85
85
  *
86
86
  * @throws Error is sql cannot be parsed
87
87
  */
88
- formatOrThrow: (sql: SqlTag<unknown>, params?: FormatParams) => string;
88
+ formatOrThrow: (sql: SqlTag<unknown> | string, params?: FormatParams) => string;
89
89
  }
90
90
 
91
91
  export { SqlFormatter, type SqlFormatterDialect, type SqlFormatterOptions };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SqlTag } from '@flowblade/sql-tag';
2
- import { FormatOptions, SqlLanguage } from 'sql-formatter';
2
+ import { SqlLanguage, FormatOptions } from 'sql-formatter';
3
3
 
4
4
  type SqlFormatterOptions = Omit<FormatOptions, 'indentStyle'>;
5
5
  type SqlFormatterDialect = SqlLanguage;
@@ -65,7 +65,7 @@ declare class SqlFormatter {
65
65
  *
66
66
  * @return string if sql can be parsed, null otherwise
67
67
  */
68
- formatOrNull: (sql: SqlTag<unknown>, params?: FormatParams) => string | null;
68
+ formatOrNull: (sql: SqlTag<unknown> | string, params?: FormatParams) => string | null;
69
69
  /**
70
70
  * Format sql to string or throw an error if sql cannot be parsed
71
71
  *
@@ -85,7 +85,7 @@ declare class SqlFormatter {
85
85
  *
86
86
  * @throws Error is sql cannot be parsed
87
87
  */
88
- formatOrThrow: (sql: SqlTag<unknown>, params?: FormatParams) => string;
88
+ formatOrThrow: (sql: SqlTag<unknown> | string, params?: FormatParams) => string;
89
89
  }
90
90
 
91
91
  export { SqlFormatter, type SqlFormatterDialect, type SqlFormatterOptions };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {format}from'sql-formatter';var o=class{constructor(r,t){this.dialect=r;this.formatterOptions=t;}formatOrNull=(r,t)=>{try{return this.formatOrThrow(r,t)}catch{return null}};formatOrThrow=(r,t)=>{let a=t?.options??this.formatterOptions;return format(r.sql,{language:t?.dialect??this.dialect,...a})}};export{o as SqlFormatter};//# sourceMappingURL=index.mjs.map
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
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sql-formatter.ts"],"names":["SqlFormatter","dialect","formatterOptions","sql","params","options","sqlFormat"],"mappings":"mCAqBO,IAAMA,CAAN,CAAA,KAAmB,CAmCxB,WAAA,CACUC,CACAC,CAAAA,CAAAA,CACR,CAFQ,IAAA,CAAA,OAAA,CAAAD,CACA,CAAA,IAAA,CAAA,gBAAA,CAAAC,EACP,CAgBH,YAAe,CAAA,CACbC,CACAC,CAAAA,CAAAA,GACkB,CAClB,GAAI,CACF,OAAO,IAAK,CAAA,aAAA,CAAcD,CAAKC,CAAAA,CAAM,CACvC,CAAA,KAAQ,CACN,OAAO,IACT,CACF,CAqBA,CAAA,aAAA,CAAgB,CAACD,CAAAA,CAAsBC,CAAkC,GAAA,CACvE,IAAMC,CAAAA,CAAUD,CAAQ,EAAA,OAAA,EAAW,IAAK,CAAA,gBAAA,CACxC,OAAOE,MAAAA,CAAUH,CAAI,CAAA,GAAA,CAAK,CACxB,QAAA,CAAUC,CAAQ,EAAA,OAAA,EAAW,IAAK,CAAA,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>,\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 = (sql: SqlTag<unknown>, params?: FormatParams): string => {\n const options = params?.options ?? this.formatterOptions;\n return sqlFormat(sql.sql, {\n language: params?.dialect ?? this.dialect,\n ...options,\n });\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/sql-formatter.ts"],"names":["SqlFormatter","dialect","formatterOptions","sql","params","options","sqlString","sqlFormat"],"mappings":"mCAqBO,IAAMA,CAAN,CAAA,KAAmB,CAmCxB,WAAA,CACUC,CACAC,CAAAA,CAAAA,CACR,CAFQ,IAAA,CAAA,OAAA,CAAAD,EACA,IAAAC,CAAAA,gBAAAA,CAAAA,EACP,CAgBH,YAAA,CAAe,CACbC,CAAAA,CACAC,CACkB,GAAA,CAClB,GAAI,CACF,OAAO,IAAK,CAAA,aAAA,CAAcD,CAAKC,CAAAA,CAAM,CACvC,CAAA,KAAQ,CACN,OAAO,IACT,CACF,CAAA,CAqBA,aAAgB,CAAA,CACdD,CACAC,CAAAA,CAAAA,GACW,CACX,IAAMC,CAAUD,CAAAA,CAAAA,EAAQ,OAAW,EAAA,IAAA,CAAK,gBAClCE,CAAAA,CAAAA,CAAY,OAAOH,CAAQ,EAAA,QAAA,CAAWA,CAAMA,CAAAA,CAAAA,CAAI,GACtD,CAAA,OAAOI,MAAUD,CAAAA,CAAAA,CAAW,CAC1B,QAAUF,CAAAA,CAAAA,EAAQ,OAAW,EAAA,IAAA,CAAK,OAClC,CAAA,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"]}
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.0.7",
4
+ "version": "0.0.9",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Vanvelthem Sébastien",
@@ -19,6 +19,9 @@
19
19
  "main": "./dist/index.cjs",
20
20
  "module": "./dist/index.mjs",
21
21
  "types": "./dist/index.d.cts",
22
+ "publishConfig": {
23
+ "directory": "_release/package"
24
+ },
22
25
  "exports": {
23
26
  ".": {
24
27
  "import": {
@@ -38,7 +41,7 @@
38
41
  "scripts": {
39
42
  "?build-release": "When https://github.com/atlassian/changesets/issues/432 has a solution we can remove this trick",
40
43
  "build": "run clean && yarn run tsup",
41
- "build-release": "run build",
44
+ "build-release": "yarn build && rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
42
45
  "bench-disabled": "vitest bench --run",
43
46
  "bench-codspeed-disabled": "cross-env CODSPEED=1 vitest bench --run",
44
47
  "bench-watch-disabled": "vitest bench",
@@ -67,17 +70,17 @@
67
70
  "sql-formatter": "^15.4.10"
68
71
  },
69
72
  "peerDependencies": {
70
- "@flowblade/sql-tag": "workspace:^"
73
+ "@flowblade/sql-tag": "^0.1.9"
71
74
  },
72
75
  "devDependencies": {
73
76
  "@arethetypeswrong/cli": "0.17.3",
74
- "@belgattitude/eslint-config-bases": "6.20.0",
77
+ "@belgattitude/eslint-config-bases": "6.22.0",
75
78
  "@codspeed/vitest-plugin": "4.0.0",
76
79
  "@edge-runtime/vm": "5.0.0",
77
80
  "@size-limit/file": "11.1.6",
78
81
  "@size-limit/webpack": "11.1.6",
79
- "@vitest/coverage-istanbul": "3.0.4",
80
- "@vitest/ui": "3.0.4",
82
+ "@vitest/coverage-istanbul": "3.0.5",
83
+ "@vitest/ui": "3.0.5",
81
84
  "browserslist": "4.24.4",
82
85
  "browserslist-to-esbuild": "2.1.1",
83
86
  "cross-env": "7.0.3",
@@ -89,7 +92,7 @@
89
92
  "prettier": "3.4.2",
90
93
  "publint": "0.3.2",
91
94
  "rimraf": "6.0.1",
92
- "rollup": "4.32.1",
95
+ "rollup": "4.34.2",
93
96
  "size-limit": "11.1.6",
94
97
  "tsup": "8.3.6",
95
98
  "tsx": "4.19.2",
@@ -97,10 +100,10 @@
97
100
  "typedoc-plugin-markdown": "4.4.1",
98
101
  "typescript": "5.7.3",
99
102
  "vite-tsconfig-paths": "5.1.4",
100
- "vitest": "3.0.4",
103
+ "vitest": "3.0.5",
101
104
  "webpack": "5.97.1"
102
105
  },
103
106
  "engines": {
104
107
  "node": ">=18.17.0"
105
108
  }
106
- }
109
+ }