@flowblade/sql-tag-format 0.0.6 → 0.0.8

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 m=Object.defineProperty;var s=(o,r,t)=>r in o?m(o,r,{enumerable:true,configurable:true,writable:true,value:t}):o[r]=t;var e=(o,r,t)=>s(o,typeof r!="symbol"?r+"":r,t);var l=class{constructor(r,t){this.dialect=r;this.formatterOptions=t;e(this,"formatOrNull",(r,t)=>{try{return this.formatOrThrow(r,t)}catch{return null}});e(this,"formatOrThrow",(r,t)=>{var a,i;let n=(a=t==null?undefined:t.options)!=null?a:this.formatterOptions;return sqlFormatter.format(r.sql,{language:(i=t==null?undefined:t.dialect)!=null?i:this.dialect,...n})});}};exports.SqlFormatter=l;//# sourceMappingURL=index.cjs.map
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
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sql-formatter.ts"],"names":["SqlFormatter","dialect","formatterOptions","__publicField","sql","params","_a","_b","options","sqlFormat"],"mappings":"uDACA,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,UAAA,CAAA,IAAA,CAAA,YAAA,CAAA,IAAA,CAAA,QAAA,CAAA,IAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,OAAA,CAAA,EAAA,QAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAoBO,IAAMA,EAAN,KAAmB,CAmCxB,WACUC,CAAAA,CAAAA,CACAC,EACR,CAFQ,IAAA,CAAA,OAAA,CAAAD,CACA,CAAA,IAAA,CAAA,gBAAA,CAAAC,EAiBVC,CAAA,CAAA,IAAA,CAAA,cAAA,CAAe,CACbC,CAAAA,CACAC,IACkB,CAClB,GAAI,CACF,OAAO,KAAK,aAAcD,CAAAA,CAAAA,CAAKC,CAAM,CACvC,MAAQ,CACN,OAAO,IACT,CACF,GAqBAF,CAAA,CAAA,IAAA,CAAA,eAAA,CAAgB,CAACC,CAAAA,CAAsBC,IAAkC,CAzG3E,IAAAC,CAAAC,CAAAA,CAAAA,CA0GI,IAAMC,CAAUF,CAAAA,CAAAA,CAAAA,CAAAD,CAAA,EAAA,IAAA,CAAA,SAAA,CAAAA,EAAQ,OAAR,GAAA,IAAA,CAAAC,CAAmB,CAAA,IAAA,CAAK,iBACxC,OAAOG,mBAAAA,CAAUL,CAAI,CAAA,GAAA,CAAK,CACxB,QAAUG,CAAAA,CAAAA,CAAAA,CAAAF,CAAA,EAAA,IAAA,CAAA,SAAA,CAAAA,EAAQ,OAAR,GAAA,IAAA,CAAAE,CAAmB,CAAA,IAAA,CAAK,QAClC,GAAGC,CACL,CAAC,CACH,GApDG,CAqDL","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","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"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {format}from'sql-formatter';var m=Object.defineProperty;var s=(o,r,t)=>r in o?m(o,r,{enumerable:true,configurable:true,writable:true,value:t}):o[r]=t;var e=(o,r,t)=>s(o,typeof r!="symbol"?r+"":r,t);var l=class{constructor(r,t){this.dialect=r;this.formatterOptions=t;e(this,"formatOrNull",(r,t)=>{try{return this.formatOrThrow(r,t)}catch{return null}});e(this,"formatOrThrow",(r,t)=>{var a,i;let n=(a=t==null?undefined:t.options)!=null?a:this.formatterOptions;return format(r.sql,{language:(i=t==null?undefined:t.dialect)!=null?i:this.dialect,...n})});}};export{l as SqlFormatter};//# sourceMappingURL=index.mjs.map
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
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sql-formatter.ts"],"names":["SqlFormatter","dialect","formatterOptions","__publicField","sql","params","_a","_b","options","sqlFormat"],"mappings":"mCACA,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,UAAA,CAAA,IAAA,CAAA,YAAA,CAAA,IAAA,CAAA,QAAA,CAAA,IAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,OAAA,CAAA,EAAA,QAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAoBO,IAAMA,EAAN,KAAmB,CAmCxB,WACUC,CAAAA,CAAAA,CACAC,EACR,CAFQ,IAAA,CAAA,OAAA,CAAAD,CACA,CAAA,IAAA,CAAA,gBAAA,CAAAC,EAiBVC,CAAA,CAAA,IAAA,CAAA,cAAA,CAAe,CACbC,CAAAA,CACAC,IACkB,CAClB,GAAI,CACF,OAAO,KAAK,aAAcD,CAAAA,CAAAA,CAAKC,CAAM,CACvC,MAAQ,CACN,OAAO,IACT,CACF,GAqBAF,CAAA,CAAA,IAAA,CAAA,eAAA,CAAgB,CAACC,CAAAA,CAAsBC,IAAkC,CAzG3E,IAAAC,CAAAC,CAAAA,CAAAA,CA0GI,IAAMC,CAAUF,CAAAA,CAAAA,CAAAA,CAAAD,CAAA,EAAA,IAAA,CAAA,SAAA,CAAAA,EAAQ,OAAR,GAAA,IAAA,CAAAC,CAAmB,CAAA,IAAA,CAAK,iBACxC,OAAOG,MAAAA,CAAUL,CAAI,CAAA,GAAA,CAAK,CACxB,QAAUG,CAAAA,CAAAA,CAAAA,CAAAF,CAAA,EAAA,IAAA,CAAA,SAAA,CAAAA,EAAQ,OAAR,GAAA,IAAA,CAAAE,CAAmB,CAAA,IAAA,CAAK,QAClC,GAAGC,CACL,CAAC,CACH,GApDG,CAqDL","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","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"]}
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.6",
4
+ "version": "0.0.8",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Vanvelthem Sébastien",
@@ -64,20 +64,20 @@
64
64
  "ci-coverage-upload": "../../.github/scripts/download/codecov -F flowblade-sql-tag-format --dir ./coverage"
65
65
  },
66
66
  "dependencies": {
67
- "sql-formatter": "^15.4.9"
67
+ "sql-formatter": "^15.4.10"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@flowblade/sql-tag": "workspace:^"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@arethetypeswrong/cli": "0.17.3",
74
- "@belgattitude/eslint-config-bases": "6.19.0",
74
+ "@belgattitude/eslint-config-bases": "6.21.0",
75
75
  "@codspeed/vitest-plugin": "4.0.0",
76
76
  "@edge-runtime/vm": "5.0.0",
77
77
  "@size-limit/file": "11.1.6",
78
78
  "@size-limit/webpack": "11.1.6",
79
- "@vitest/coverage-istanbul": "2.1.8",
80
- "@vitest/ui": "2.1.8",
79
+ "@vitest/coverage-istanbul": "3.0.4",
80
+ "@vitest/ui": "3.0.4",
81
81
  "browserslist": "4.24.4",
82
82
  "browserslist-to-esbuild": "2.1.1",
83
83
  "cross-env": "7.0.3",
@@ -89,15 +89,15 @@
89
89
  "prettier": "3.4.2",
90
90
  "publint": "0.3.2",
91
91
  "rimraf": "6.0.1",
92
- "rollup": "4.30.1",
92
+ "rollup": "4.32.1",
93
93
  "size-limit": "11.1.6",
94
- "tsup": "8.3.5",
94
+ "tsup": "8.3.6",
95
95
  "tsx": "4.19.2",
96
96
  "typedoc": "0.27.6",
97
97
  "typedoc-plugin-markdown": "4.4.1",
98
98
  "typescript": "5.7.3",
99
99
  "vite-tsconfig-paths": "5.1.4",
100
- "vitest": "2.1.8",
100
+ "vitest": "3.0.4",
101
101
  "webpack": "5.97.1"
102
102
  },
103
103
  "engines": {