@flowblade/sql-tag-format 1.1.0 → 1.1.1

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,12 +1,16 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
2
  let sql_formatter = require("sql-formatter");
3
+ //#region \0@oxc-project+runtime@0.115.0/helpers/typeof.js
2
4
  function _typeof(o) {
3
5
  "@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;
6
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
7
+ return typeof o;
8
+ } : function(o) {
9
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
8
10
  }, _typeof(o);
9
11
  }
12
+ //#endregion
13
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPrimitive.js
10
14
  function toPrimitive(t, r) {
11
15
  if ("object" != _typeof(t) || !t) return t;
12
16
  var e = t[Symbol.toPrimitive];
@@ -17,10 +21,14 @@ function toPrimitive(t, r) {
17
21
  }
18
22
  return ("string" === r ? String : Number)(t);
19
23
  }
24
+ //#endregion
25
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPropertyKey.js
20
26
  function toPropertyKey(t) {
21
27
  var i = toPrimitive(t, "string");
22
28
  return "symbol" == _typeof(i) ? i : i + "";
23
29
  }
30
+ //#endregion
31
+ //#region \0@oxc-project+runtime@0.115.0/helpers/defineProperty.js
24
32
  function _defineProperty(e, r, t) {
25
33
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
26
34
  value: t,
@@ -29,12 +37,14 @@ function _defineProperty(e, r, t) {
29
37
  writable: !0
30
38
  }) : e[r] = t, e;
31
39
  }
40
+ //#endregion
41
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectSpread2.js
32
42
  function ownKeys(e, r) {
33
43
  var t = Object.keys(e);
34
44
  if (Object.getOwnPropertySymbols) {
35
45
  var o = Object.getOwnPropertySymbols(e);
36
- r && (o = o.filter(function(r$1) {
37
- return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
46
+ r && (o = o.filter(function(r) {
47
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
38
48
  })), t.push.apply(t, o);
39
49
  }
40
50
  return t;
@@ -42,30 +52,108 @@ function ownKeys(e, r) {
42
52
  function _objectSpread2(e) {
43
53
  for (var r = 1; r < arguments.length; r++) {
44
54
  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));
55
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
56
+ _defineProperty(e, r, t[r]);
57
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
58
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
49
59
  });
50
60
  }
51
61
  return e;
52
62
  }
63
+ //#endregion
64
+ //#region src/sql-formatter.ts
53
65
  var SqlFormatter = class {
66
+ /**
67
+ * SqlFormatter constructor
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const sqlFormatter = new SqlFormatter('postgresql');
72
+ *
73
+ * // Alternatively, you can pass in options
74
+ * // @see https://github.com/sql-formatter-org/sql-formatter/tree/master?tab=readme-ov-file#configuration-options
75
+ *
76
+ * const pgsqlFormatter = new SqlFormatter('postgresql', {
77
+ * keywordCase: 'preserve',
78
+ * identifierCase: 'preserve',
79
+ * dataTypeCase: 'preserve',
80
+ * functionCase: 'preserve',
81
+ * logicalOperatorNewline: 'before',
82
+ * expressionWidth: 50,
83
+ * linesBetweenQueries: 1,
84
+ * denseOperators: false,
85
+ * newlineBeforeSemicolon: false,
86
+ * useTabs: false,
87
+ * tabWidth: 2,
88
+ * });
89
+ *
90
+ * try {
91
+ * const formatted = pgsqlFormatter.formatOrThrow(
92
+ * 'SELECT * FROM table WHERE id = 1'
93
+ * );
94
+ * } catch (e) {
95
+ * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
96
+ * console.log('Error:', e);
97
+ * }
98
+ * ```
99
+ */
54
100
  constructor(dialect, formatterOptions) {
55
101
  this.dialect = dialect;
56
102
  this.formatterOptions = formatterOptions;
57
- _defineProperty(this, "formatOrNull", (sql, params) => {
58
- try {
59
- return this.formatOrThrow(sql, params);
60
- } catch (_unused) {
61
- return null;
103
+ _defineProperty(
104
+ this,
105
+ /**
106
+ * Format sql to string or return null if sql cannot be parsed
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const sqlFormatter = new SqlFormatter('postgresql');
111
+ *
112
+ * const formatted = sqlFormatter.formatOrNull(
113
+ * 'SELECT * FROM table WHERE id = 1'
114
+ * );
115
+ * ```
116
+ *
117
+ * @return string if sql can be parsed, null otherwise
118
+ */
119
+ "formatOrNull",
120
+ (sql, params) => {
121
+ try {
122
+ return this.formatOrThrow(sql, params);
123
+ } catch (_unused) {
124
+ return null;
125
+ }
62
126
  }
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
- });
127
+ );
128
+ _defineProperty(
129
+ this,
130
+ /**
131
+ * Format sql to string or throw an error if sql cannot be parsed
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const sqlFormatter = new SqlFormatter('postgresql');
136
+ *
137
+ * try {
138
+ * const formatted = sqlFormatter.formatOrThrow(
139
+ * 'SELECT * FROM table WHERE id = 1'
140
+ * );
141
+ * } catch (e) {
142
+ * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
143
+ * console.log('Error:', e);
144
+ * }
145
+ * ```
146
+ *
147
+ * @throws Error is sql cannot be parsed
148
+ */
149
+ "formatOrThrow",
150
+ (sql, params) => {
151
+ var _params$options, _params$dialect;
152
+ const options = (_params$options = params === null || params === void 0 ? void 0 : params.options) !== null && _params$options !== void 0 ? _params$options : this.formatterOptions;
153
+ 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));
154
+ }
155
+ );
69
156
  }
70
157
  };
158
+ //#endregion
71
159
  exports.SqlFormatter = SqlFormatter;
package/dist/index.d.cts CHANGED
@@ -1,11 +1,6 @@
1
- import { Sql } from "sql-template-tag";
1
+ import { SqlTag } from "@flowblade/sql-tag";
2
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
4
  //#region src/sql-formatter.d.ts
10
5
  type SqlFormatterOptions = Omit<FormatOptions, 'indentStyle'>;
11
6
  type SqlFormatterDialect = SqlLanguage;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,6 @@
1
1
  import { FormatOptions, SqlLanguage } from "sql-formatter";
2
- import { Sql } from "sql-template-tag";
2
+ import { SqlTag } from "@flowblade/sql-tag";
3
3
 
4
- //#region ../sql-tag/src/types.d.ts
5
- type SqlTag<T> = Sql & {
6
- _columns: T;
7
- };
8
- //#endregion
9
4
  //#region src/sql-formatter.d.ts
10
5
  type SqlFormatterOptions = Omit<FormatOptions, 'indentStyle'>;
11
6
  type SqlFormatterDialect = SqlLanguage;
package/dist/index.js CHANGED
@@ -1,12 +1,15 @@
1
1
  import { format } from "sql-formatter";
2
+ //#region \0@oxc-project+runtime@0.115.0/helpers/typeof.js
2
3
  function _typeof(o) {
3
4
  "@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;
5
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
6
+ return typeof o;
7
+ } : function(o) {
8
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
8
9
  }, _typeof(o);
9
10
  }
11
+ //#endregion
12
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPrimitive.js
10
13
  function toPrimitive(t, r) {
11
14
  if ("object" != _typeof(t) || !t) return t;
12
15
  var e = t[Symbol.toPrimitive];
@@ -17,10 +20,14 @@ function toPrimitive(t, r) {
17
20
  }
18
21
  return ("string" === r ? String : Number)(t);
19
22
  }
23
+ //#endregion
24
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPropertyKey.js
20
25
  function toPropertyKey(t) {
21
26
  var i = toPrimitive(t, "string");
22
27
  return "symbol" == _typeof(i) ? i : i + "";
23
28
  }
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.115.0/helpers/defineProperty.js
24
31
  function _defineProperty(e, r, t) {
25
32
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
26
33
  value: t,
@@ -29,12 +36,14 @@ function _defineProperty(e, r, t) {
29
36
  writable: !0
30
37
  }) : e[r] = t, e;
31
38
  }
39
+ //#endregion
40
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectSpread2.js
32
41
  function ownKeys(e, r) {
33
42
  var t = Object.keys(e);
34
43
  if (Object.getOwnPropertySymbols) {
35
44
  var o = Object.getOwnPropertySymbols(e);
36
- r && (o = o.filter(function(r$1) {
37
- return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
45
+ r && (o = o.filter(function(r) {
46
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
38
47
  })), t.push.apply(t, o);
39
48
  }
40
49
  return t;
@@ -42,30 +51,108 @@ function ownKeys(e, r) {
42
51
  function _objectSpread2(e) {
43
52
  for (var r = 1; r < arguments.length; r++) {
44
53
  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));
54
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
55
+ _defineProperty(e, r, t[r]);
56
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
57
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
49
58
  });
50
59
  }
51
60
  return e;
52
61
  }
62
+ //#endregion
63
+ //#region src/sql-formatter.ts
53
64
  var SqlFormatter = class {
65
+ /**
66
+ * SqlFormatter constructor
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const sqlFormatter = new SqlFormatter('postgresql');
71
+ *
72
+ * // Alternatively, you can pass in options
73
+ * // @see https://github.com/sql-formatter-org/sql-formatter/tree/master?tab=readme-ov-file#configuration-options
74
+ *
75
+ * const pgsqlFormatter = new SqlFormatter('postgresql', {
76
+ * keywordCase: 'preserve',
77
+ * identifierCase: 'preserve',
78
+ * dataTypeCase: 'preserve',
79
+ * functionCase: 'preserve',
80
+ * logicalOperatorNewline: 'before',
81
+ * expressionWidth: 50,
82
+ * linesBetweenQueries: 1,
83
+ * denseOperators: false,
84
+ * newlineBeforeSemicolon: false,
85
+ * useTabs: false,
86
+ * tabWidth: 2,
87
+ * });
88
+ *
89
+ * try {
90
+ * const formatted = pgsqlFormatter.formatOrThrow(
91
+ * 'SELECT * FROM table WHERE id = 1'
92
+ * );
93
+ * } catch (e) {
94
+ * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
95
+ * console.log('Error:', e);
96
+ * }
97
+ * ```
98
+ */
54
99
  constructor(dialect, formatterOptions) {
55
100
  this.dialect = dialect;
56
101
  this.formatterOptions = formatterOptions;
57
- _defineProperty(this, "formatOrNull", (sql, params) => {
58
- try {
59
- return this.formatOrThrow(sql, params);
60
- } catch (_unused) {
61
- return null;
102
+ _defineProperty(
103
+ this,
104
+ /**
105
+ * Format sql to string or return null if sql cannot be parsed
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const sqlFormatter = new SqlFormatter('postgresql');
110
+ *
111
+ * const formatted = sqlFormatter.formatOrNull(
112
+ * 'SELECT * FROM table WHERE id = 1'
113
+ * );
114
+ * ```
115
+ *
116
+ * @return string if sql can be parsed, null otherwise
117
+ */
118
+ "formatOrNull",
119
+ (sql, params) => {
120
+ try {
121
+ return this.formatOrThrow(sql, params);
122
+ } catch (_unused) {
123
+ return null;
124
+ }
62
125
  }
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
- });
126
+ );
127
+ _defineProperty(
128
+ this,
129
+ /**
130
+ * Format sql to string or throw an error if sql cannot be parsed
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const sqlFormatter = new SqlFormatter('postgresql');
135
+ *
136
+ * try {
137
+ * const formatted = sqlFormatter.formatOrThrow(
138
+ * 'SELECT * FROM table WHERE id = 1'
139
+ * );
140
+ * } catch (e) {
141
+ * // Might throw something similar to: Parse error: Unexpected "[col] from" at line 1 column 8
142
+ * console.log('Error:', e);
143
+ * }
144
+ * ```
145
+ *
146
+ * @throws Error is sql cannot be parsed
147
+ */
148
+ "formatOrThrow",
149
+ (sql, params) => {
150
+ var _params$options, _params$dialect;
151
+ const options = (_params$options = params === null || params === void 0 ? void 0 : params.options) !== null && _params$options !== void 0 ? _params$options : this.formatterOptions;
152
+ 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));
153
+ }
154
+ );
69
155
  }
70
156
  };
157
+ //#endregion
71
158
  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": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Vanvelthem Sébastien",
@@ -67,37 +67,37 @@
67
67
  "ci-coverage-upload": "../../.github/scripts/download/codecov -F flowblade-sql-tag-format --dir ./coverage"
68
68
  },
69
69
  "dependencies": {
70
- "@flowblade/sql-tag": "^0.3.0",
71
- "sql-formatter": "^15.7.0"
70
+ "@flowblade/sql-tag": "^0.3.2",
71
+ "sql-formatter": "^15.7.2"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@arethetypeswrong/cli": "0.18.2",
75
- "@belgattitude/eslint-config-bases": "8.9.0",
76
- "@codspeed/vitest-plugin": "5.0.1",
75
+ "@belgattitude/eslint-config-bases": "8.10.0",
76
+ "@codspeed/vitest-plugin": "5.2.0",
77
77
  "@edge-runtime/vm": "5.0.0",
78
- "@size-limit/esbuild": "12.0.0",
79
- "@size-limit/file": "12.0.0",
80
- "@vitest/coverage-istanbul": "4.0.17",
81
- "@vitest/ui": "4.0.17",
78
+ "@size-limit/esbuild": "12.0.1",
79
+ "@size-limit/file": "12.0.1",
80
+ "@vitest/coverage-istanbul": "4.0.18",
81
+ "@vitest/ui": "4.0.18",
82
82
  "browserslist": "4.28.1",
83
83
  "browserslist-to-esbuild": "2.1.1",
84
84
  "cross-env": "10.1.0",
85
- "es-check": "9.5.4",
86
- "esbuild": "0.27.2",
85
+ "es-check": "9.6.2",
86
+ "esbuild": "0.27.3",
87
87
  "eslint": "8.57.1",
88
88
  "execa": "9.6.1",
89
89
  "npm-run-all2": "8.0.4",
90
- "prettier": "3.8.0",
91
- "publint": "0.3.16",
92
- "rimraf": "6.1.2",
93
- "size-limit": "12.0.0",
94
- "tsdown": "0.19.0",
90
+ "prettier": "3.8.1",
91
+ "publint": "0.3.18",
92
+ "rimraf": "6.1.3",
93
+ "size-limit": "12.0.1",
94
+ "tsdown": "0.21.1",
95
95
  "tsx": "4.21.0",
96
- "typedoc": "0.28.16",
97
- "typedoc-plugin-markdown": "4.9.0",
96
+ "typedoc": "0.28.17",
97
+ "typedoc-plugin-markdown": "4.10.0",
98
98
  "typescript": "5.9.3",
99
- "vite-tsconfig-paths": "6.0.4",
100
- "vitest": "4.0.17"
99
+ "vite-tsconfig-paths": "6.1.1",
100
+ "vitest": "4.0.18"
101
101
  },
102
102
  "engines": {
103
103
  "node": ">=20.9.0"