rawsql-ts 0.24.0 → 0.24.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.
Files changed (34) hide show
  1. package/dist/esm/index.min.js +5 -5
  2. package/dist/esm/index.min.js.map +4 -4
  3. package/dist/esm/parsers/SqlPrintTokenParser.d.ts +11 -0
  4. package/dist/esm/parsers/SqlPrintTokenParser.js +17 -6
  5. package/dist/esm/parsers/SqlPrintTokenParser.js.map +1 -1
  6. package/dist/esm/parsers/SqlTokenizer.js +2 -2
  7. package/dist/esm/parsers/SqlTokenizer.js.map +1 -1
  8. package/dist/esm/tokenReaders/FunctionTokenReader.d.ts +1 -0
  9. package/dist/esm/tokenReaders/FunctionTokenReader.js +7 -0
  10. package/dist/esm/tokenReaders/FunctionTokenReader.js.map +1 -1
  11. package/dist/esm/tokenReaders/PostgresFunctionTokenReader.d.ts +5 -0
  12. package/dist/esm/tokenReaders/PostgresFunctionTokenReader.js +12 -0
  13. package/dist/esm/tokenReaders/PostgresFunctionTokenReader.js.map +1 -0
  14. package/dist/esm/transformers/SqlFormatter.d.ts +5 -1
  15. package/dist/esm/transformers/SqlFormatter.js +3 -3
  16. package/dist/esm/transformers/SqlFormatter.js.map +1 -1
  17. package/dist/index.min.js +5 -5
  18. package/dist/index.min.js.map +4 -4
  19. package/dist/parsers/SqlPrintTokenParser.js +17 -6
  20. package/dist/parsers/SqlPrintTokenParser.js.map +1 -1
  21. package/dist/parsers/SqlTokenizer.js +2 -2
  22. package/dist/parsers/SqlTokenizer.js.map +1 -1
  23. package/dist/src/parsers/SqlPrintTokenParser.d.ts +11 -0
  24. package/dist/src/tokenReaders/FunctionTokenReader.d.ts +1 -0
  25. package/dist/src/tokenReaders/PostgresFunctionTokenReader.d.ts +5 -0
  26. package/dist/src/transformers/SqlFormatter.d.ts +5 -1
  27. package/dist/tokenReaders/FunctionTokenReader.js +7 -0
  28. package/dist/tokenReaders/FunctionTokenReader.js.map +1 -1
  29. package/dist/tokenReaders/PostgresFunctionTokenReader.js +16 -0
  30. package/dist/tokenReaders/PostgresFunctionTokenReader.js.map +1 -0
  31. package/dist/transformers/SqlFormatter.js +4 -2
  32. package/dist/transformers/SqlFormatter.js.map +1 -1
  33. package/dist/tsconfig.browser.tsbuildinfo +1 -1
  34. package/package.json +1 -1
@@ -13,6 +13,8 @@ export declare enum ParameterStyle {
13
13
  }
14
14
  export type CastStyle = 'postgres' | 'standard';
15
15
  export type ConstraintStyle = 'postgres' | 'mysql';
16
+ export type SourceAliasStyle = 'as' | 'implicit';
17
+ export type OrderByDefaultDirectionStyle = 'omit' | 'explicit';
16
18
  export interface FormatterConfig {
17
19
  identifierEscape?: {
18
20
  start: string;
@@ -31,6 +33,10 @@ export interface FormatterConfig {
31
33
  castStyle?: CastStyle;
32
34
  /** Controls how table/column constraints are rendered */
33
35
  constraintStyle?: ConstraintStyle;
36
+ /** Controls whether source aliases are rendered with an explicit AS keyword */
37
+ sourceAliasStyle?: SourceAliasStyle;
38
+ /** Controls whether the default ASC direction is omitted or rendered explicitly */
39
+ orderByDefaultDirectionStyle?: OrderByDefaultDirectionStyle;
34
40
  }
35
41
  export declare const PRESETS: Record<string, FormatterConfig>;
36
42
  export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrintToken> {
@@ -48,6 +54,8 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
48
54
  index: number;
49
55
  private castStyle;
50
56
  private constraintStyle;
57
+ private sourceAliasStyle;
58
+ private orderByDefaultDirectionStyle;
51
59
  private readonly normalizeJoinConditionOrder;
52
60
  private joinConditionContexts;
53
61
  constructor(options?: {
@@ -64,6 +72,8 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
64
72
  parameterStyle?: 'anonymous' | 'indexed' | 'named';
65
73
  castStyle?: CastStyle;
66
74
  constraintStyle?: ConstraintStyle;
75
+ sourceAliasStyle?: SourceAliasStyle;
76
+ orderByDefaultDirectionStyle?: OrderByDefaultDirectionStyle;
67
77
  joinConditionOrderByDeclaration?: boolean;
68
78
  });
69
79
  /**
@@ -246,6 +256,7 @@ export declare class SqlPrintTokenParser implements SqlComponentVisitor<SqlPrint
246
256
  private visitDistinctOn;
247
257
  private visitTableSource;
248
258
  private visitSourceExpression;
259
+ private appendSourceAliasKeyword;
249
260
  visitFromClause(arg: FromClause): SqlPrintToken;
250
261
  visitJoinClause(arg: JoinClause): SqlPrintToken;
251
262
  visitJoinOnClause(arg: JoinOnClause): SqlPrintToken;
@@ -154,7 +154,7 @@ export class SqlPrintTokenParser {
154
154
  return this._selfHandlingComponentTypes;
155
155
  }
156
156
  constructor(options) {
157
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
157
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
158
158
  this.handlers = new Map();
159
159
  this.index = 1;
160
160
  this.joinConditionContexts = [];
@@ -174,7 +174,9 @@ export class SqlPrintTokenParser {
174
174
  });
175
175
  this.castStyle = (_j = options === null || options === void 0 ? void 0 : options.castStyle) !== null && _j !== void 0 ? _j : 'standard';
176
176
  this.constraintStyle = (_k = options === null || options === void 0 ? void 0 : options.constraintStyle) !== null && _k !== void 0 ? _k : 'postgres';
177
- this.normalizeJoinConditionOrder = (_l = options === null || options === void 0 ? void 0 : options.joinConditionOrderByDeclaration) !== null && _l !== void 0 ? _l : false;
177
+ this.sourceAliasStyle = (_l = options === null || options === void 0 ? void 0 : options.sourceAliasStyle) !== null && _l !== void 0 ? _l : 'as';
178
+ this.orderByDefaultDirectionStyle = (_m = options === null || options === void 0 ? void 0 : options.orderByDefaultDirectionStyle) !== null && _m !== void 0 ? _m : 'omit';
179
+ this.normalizeJoinConditionOrder = (_o = options === null || options === void 0 ? void 0 : options.joinConditionOrderByDeclaration) !== null && _o !== void 0 ? _o : false;
178
180
  this.handlers.set(ValueList.kind, (expr) => this.visitValueList(expr));
179
181
  this.handlers.set(ColumnReference.kind, (expr) => this.visitColumnReference(expr));
180
182
  this.handlers.set(QualifiedName.kind, (expr) => this.visitQualifiedName(expr));
@@ -400,6 +402,10 @@ export class SqlPrintTokenParser {
400
402
  token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
401
403
  token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'desc'));
402
404
  }
405
+ else if (this.orderByDefaultDirectionStyle === 'explicit') {
406
+ token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
407
+ token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'asc'));
408
+ }
403
409
  if (arg.nullsPosition) {
404
410
  if (arg.nullsPosition === NullsSortDirection.First) {
405
411
  token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
@@ -1769,8 +1775,7 @@ export class SqlPrintTokenParser {
1769
1775
  return token;
1770
1776
  }
1771
1777
  token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
1772
- token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
1773
- token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
1778
+ this.appendSourceAliasKeyword(token);
1774
1779
  // exclude column aliases
1775
1780
  token.innerTokens.push(arg.aliasExpression.accept(this));
1776
1781
  return token;
@@ -1778,13 +1783,19 @@ export class SqlPrintTokenParser {
1778
1783
  else {
1779
1784
  // For other source types, just print the alias
1780
1785
  token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
1781
- token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
1782
- token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
1786
+ this.appendSourceAliasKeyword(token);
1783
1787
  // included column aliases
1784
1788
  token.innerTokens.push(arg.aliasExpression.accept(this));
1785
1789
  return token;
1786
1790
  }
1787
1791
  }
1792
+ appendSourceAliasKeyword(token) {
1793
+ if (this.sourceAliasStyle === 'implicit') {
1794
+ return;
1795
+ }
1796
+ token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
1797
+ token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
1798
+ }
1788
1799
  visitFromClause(arg) {
1789
1800
  // Build a declaration order map so JOIN ON operands can be normalized later.
1790
1801
  let contextPushed = false;