@memberjunction/sql-dialect 6.1.0-edge.2 → 6.1.0-edge.3
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/LICENSE +180 -4
- package/README.md +21 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/postgresqlAutoQuote.d.ts +154 -0
- package/dist/postgresqlAutoQuote.d.ts.map +1 -0
- package/dist/postgresqlAutoQuote.js +676 -0
- package/dist/postgresqlAutoQuote.js.map +1 -0
- package/dist/postgresqlDialect.d.ts +1 -0
- package/dist/postgresqlDialect.d.ts.map +1 -1
- package/dist/postgresqlDialect.js +6 -0
- package/dist/postgresqlDialect.js.map +1 -1
- package/dist/sqlDialect.d.ts +12 -0
- package/dist/sqlDialect.d.ts.map +1 -1
- package/dist/sqlDialect.js.map +1 -1
- package/dist/sqlServerDialect.d.ts +1 -0
- package/dist/sqlServerDialect.d.ts.map +1 -1
- package/dist/sqlServerDialect.js +3 -0
- package/dist/sqlServerDialect.js.map +1 -1
- package/package.json +2 -1
package/LICENSE
CHANGED
|
@@ -1,7 +1,183 @@
|
|
|
1
|
-
|
|
1
|
+
Business Source License 1.1
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
License text copyright (c) 2024 MariaDB plc, All Rights Reserved.
|
|
4
|
+
"Business Source License" is a trademark of MariaDB plc.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
-----------------------------------------------------------------------------
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Parameters
|
|
9
|
+
|
|
10
|
+
Licensor: Blue Cypress, Inc.
|
|
11
|
+
|
|
12
|
+
Licensed Work: MemberJunction.
|
|
13
|
+
The Licensed Work is (c) 2023-2026 Blue Cypress, Inc.
|
|
14
|
+
|
|
15
|
+
Additional Use Grant: Subject to the terms of this License, Licensor grants
|
|
16
|
+
you the following additional rights to make Production
|
|
17
|
+
Use of the Licensed Work.
|
|
18
|
+
|
|
19
|
+
1. Internal Use
|
|
20
|
+
|
|
21
|
+
You may make production use of the Licensed Work for
|
|
22
|
+
your own internal business or organizational operations.
|
|
23
|
+
|
|
24
|
+
2. Nonprofit Use
|
|
25
|
+
|
|
26
|
+
If you are a Nonprofit, you may make production use of
|
|
27
|
+
the Licensed Work for the operations and activities of
|
|
28
|
+
your Organizational Family.
|
|
29
|
+
|
|
30
|
+
3. MemberJunction Certified Program Use
|
|
31
|
+
|
|
32
|
+
If you are authorized by Licensor under the
|
|
33
|
+
MemberJunction Certified Program to provide professional
|
|
34
|
+
services using the Licensed Work, you may make
|
|
35
|
+
production use of the Licensed Work in providing such
|
|
36
|
+
professional services to a client, provided that:
|
|
37
|
+
|
|
38
|
+
(a) the Licensed Work is deployed in, and the applicable
|
|
39
|
+
production use occurs within, an environment owned,
|
|
40
|
+
leased, licensed, subscribed to, or otherwise controlled
|
|
41
|
+
by that client; and
|
|
42
|
+
|
|
43
|
+
(b) the production use is for that client's own internal
|
|
44
|
+
business or organizational operations or is otherwise
|
|
45
|
+
independently permitted to that client under this
|
|
46
|
+
Additional Use Grant.
|
|
47
|
+
|
|
48
|
+
4. Definitions Applicable to the Additional Use Grant
|
|
49
|
+
|
|
50
|
+
"Affiliate" means, with respect to a specified Person,
|
|
51
|
+
any other Person that directly or indirectly Controls,
|
|
52
|
+
is Controlled by, or is under common Control with such
|
|
53
|
+
specified Person.
|
|
54
|
+
|
|
55
|
+
"Control" (including the terms "Controls," "Controlled
|
|
56
|
+
by," and "under common Control with") means the direct
|
|
57
|
+
or indirect possession of the power to direct or cause
|
|
58
|
+
the direction of the management and policies of a
|
|
59
|
+
Person, whether through ownership of voting interests,
|
|
60
|
+
by contract, or otherwise.
|
|
61
|
+
|
|
62
|
+
"Organizational Family" means, with respect to a Person,
|
|
63
|
+
(a) such Person and its Affiliates, and (b) any
|
|
64
|
+
nonprofit organization, governmental entity, chapter,
|
|
65
|
+
division, local affiliate, regional affiliate, state
|
|
66
|
+
affiliate, national affiliate, or other entity that is
|
|
67
|
+
formally affiliated with such Person through governing
|
|
68
|
+
documents, a charter, bylaws, a membership agreement, or
|
|
69
|
+
another written organizational instrument, and is
|
|
70
|
+
recognized under such documents as part of the same
|
|
71
|
+
organizational structure.
|
|
72
|
+
|
|
73
|
+
"Nonprofit" means a Person recognized by the Internal
|
|
74
|
+
Revenue Service as exempt from federal income taxation
|
|
75
|
+
under Section 501(c)(3), 501(c)(4), 501(c)(5), or
|
|
76
|
+
501(c)(6) of the Internal Revenue Code, or a foreign
|
|
77
|
+
organization recognized under substantially equivalent
|
|
78
|
+
laws.
|
|
79
|
+
|
|
80
|
+
A Person claiming eligibility as a Nonprofit shall, upon
|
|
81
|
+
Licensor's reasonable request, provide documentation
|
|
82
|
+
reasonably sufficient to demonstrate that it qualifies
|
|
83
|
+
as a Nonprofit. If such Person materially misrepresents,
|
|
84
|
+
or is unable to demonstrate, its qualification as a
|
|
85
|
+
Nonprofit, the rights granted to such Person under
|
|
86
|
+
Section 2 of this Additional Use Grant shall terminate.
|
|
87
|
+
|
|
88
|
+
"MemberJunction Certified Program" means Licensor's
|
|
89
|
+
then-current program for certifying and authorizing a
|
|
90
|
+
Person to provide professional services using the
|
|
91
|
+
Licensed Work.
|
|
92
|
+
|
|
93
|
+
"Person" means any individual, corporation, limited
|
|
94
|
+
liability company, partnership, association, nonprofit
|
|
95
|
+
organization, governmental entity, or other legal or
|
|
96
|
+
organizational entity.
|
|
97
|
+
|
|
98
|
+
Change Date: Four (4) years from the date the Licensed Work is first
|
|
99
|
+
made available.
|
|
100
|
+
|
|
101
|
+
Change License: MIT License.
|
|
102
|
+
|
|
103
|
+
For information about alternative licensing arrangements for the Licensed
|
|
104
|
+
Work, please contact Blue Cypress, Inc.
|
|
105
|
+
|
|
106
|
+
-----------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
Terms
|
|
109
|
+
|
|
110
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
111
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
112
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
113
|
+
production use.
|
|
114
|
+
|
|
115
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
116
|
+
available distribution of a specific version of the Licensed Work under this
|
|
117
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
118
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
119
|
+
above terminate.
|
|
120
|
+
|
|
121
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
122
|
+
currently in effect as described in this License, you must purchase a
|
|
123
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
124
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
125
|
+
|
|
126
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
127
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
128
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
129
|
+
for each version of the Licensed Work released by Licensor.
|
|
130
|
+
|
|
131
|
+
You must conspicuously display this License on each original or modified copy
|
|
132
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
133
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
134
|
+
License apply to your use of that work.
|
|
135
|
+
|
|
136
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
137
|
+
terminate your rights under this License for the current and all other
|
|
138
|
+
versions of the Licensed Work.
|
|
139
|
+
|
|
140
|
+
This License does not grant you any right in any trademark or logo of
|
|
141
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
142
|
+
Licensor as expressly required by this License).
|
|
143
|
+
|
|
144
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
145
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
146
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
147
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
148
|
+
TITLE.
|
|
149
|
+
|
|
150
|
+
MariaDB hereby grants you permission to use this License's text to license
|
|
151
|
+
your works, and to refer to it using the trademark "Business Source License",
|
|
152
|
+
as long as you comply with the Covenants of Licensor below.
|
|
153
|
+
|
|
154
|
+
-----------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
Covenants of Licensor
|
|
157
|
+
|
|
158
|
+
In consideration of the right to use this License's text and the "Business
|
|
159
|
+
Source License" name and trademark, Licensor covenants to MariaDB, and to all
|
|
160
|
+
other recipients of the licensed work to be provided by Licensor:
|
|
161
|
+
|
|
162
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
163
|
+
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
164
|
+
where "compatible" means that software provided under the Change License
|
|
165
|
+
can be included in a program with software provided under GPL Version 2.0
|
|
166
|
+
or a later version. Licensor may specify additional Change Licenses without
|
|
167
|
+
limitation.
|
|
168
|
+
|
|
169
|
+
2. To either: (a) specify an additional grant of rights to use that does not
|
|
170
|
+
impose any additional restriction on the right granted in this License, as
|
|
171
|
+
the Additional Use Grant; or (b) insert the text "None".
|
|
172
|
+
|
|
173
|
+
3. To specify a Change Date.
|
|
174
|
+
|
|
175
|
+
4. Not to modify this License in any other way.
|
|
176
|
+
|
|
177
|
+
-----------------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
Notice
|
|
180
|
+
|
|
181
|
+
The Business Source License (this document, or the "License") is not an Open
|
|
182
|
+
Source license. However, the Licensed Work will eventually be made available
|
|
183
|
+
under an Open Source License, as stated in this License.
|
package/README.md
CHANGED
|
@@ -42,6 +42,26 @@ SQLDialect (abstract base)
|
|
|
42
42
|
| `QuoteIdentifier(name)` | Wraps a single identifier | `[name]` | `"name"` |
|
|
43
43
|
| `QuoteSchema(schema, object)` | Schema-qualified reference | `[schema].[object]` | `schema."object"` |
|
|
44
44
|
|
|
45
|
+
#### PostgreSQL auto-quoting (whole-statement)
|
|
46
|
+
|
|
47
|
+
The two methods above quote one identifier you have already identified. `postgresqlAutoQuote.ts`
|
|
48
|
+
solves the harder problem: taking arbitrary SQL and deciding which of its bare words are
|
|
49
|
+
identifiers that must be quoted to survive PostgreSQL's lowercase folding.
|
|
50
|
+
|
|
51
|
+
| Export | Description |
|
|
52
|
+
|---|---|
|
|
53
|
+
| `AutoQuotePostgreSQLIdentifiers(sql)` | Tokenizes a statement and quotes the words that are identifiers. Skips string literals, dollar-quoted bodies and comments. Idempotent. |
|
|
54
|
+
| `PostgreSQLQuotingKeywords` | Keywords recognized **case-sensitively, ALL-CAPS only**. A word here is safe even when it is also an MJ column name — only the ALL-CAPS spelling is exempted, so the mixed-case column form still quotes. |
|
|
55
|
+
| `PostgreSQLStructuralKeywords` | A small tier matched case-INsensitively, so stored `UserView.OrderBy` / `ExtraFilter` fragments written in Title Case keep working. Guarded by a test that fails if a real column ever collides. |
|
|
56
|
+
|
|
57
|
+
The ALL-CAPS rule is the load-bearing part: the set of SQL keywords and the set of MJ column names
|
|
58
|
+
intersect (`Name`, `Text`, `Length`, `Values`, `Rank`, …), so a case-insensitive denylist emits
|
|
59
|
+
those columns bare and PostgreSQL then rejects them. `TEXT` is the type; `Text` is the column.
|
|
60
|
+
|
|
61
|
+
This is **not** the only quoter — `PostgreSQLDataProvider` has a metadata-driven one that knows an
|
|
62
|
+
entity's field list and is used where that context exists. See the module docblock; they are not
|
|
63
|
+
duplicates.
|
|
64
|
+
|
|
45
65
|
### Pagination
|
|
46
66
|
|
|
47
67
|
| Method | Description | SQL Server | PostgreSQL |
|
|
@@ -402,4 +422,4 @@ Or, in a MemberJunction workspace, add the dependency to your package's `package
|
|
|
402
422
|
|
|
403
423
|
## License
|
|
404
424
|
|
|
405
|
-
|
|
425
|
+
Business Source License 1.1 — see [LICENSE](../../LICENSE) for details.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export type { SchemaFieldType } from './sqlDialect.js';
|
|
|
5
5
|
export { SQLServerDialect } from './sqlServerDialect.js';
|
|
6
6
|
export { PostgreSQLDialect } from './postgresqlDialect.js';
|
|
7
7
|
export { GetDialect } from './dialectFactory.js';
|
|
8
|
+
export { AutoQuotePostgreSQLIdentifiers, PostgreSQLQuotingKeywords, PostgreSQLStructuralKeywords, PostgreSQLContextualStructuralKeywords, } from './postgresqlAutoQuote.js';
|
|
8
9
|
export { IsBooleanSQLType, IsStringSQLType, IsFixedWidthStringSQLType, IsDateSQLType, IsIntegerSQLType, IsFloatSQLType, IsUuidSQLType, IsBinarySQLType, IsJsonSQLType, IsCurrencySQLType, IsIntervalSQLType, IsNetworkSQLType, IsNumericSQLType, } from './typeClassification.js';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACH,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACrB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACnB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACH,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACrB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACH,8BAA8B,EAC9B,yBAAyB,EACzB,4BAA4B,EAC5B,sCAAsC,GACzC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACnB,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,6 @@ export { SQLDialect, } from './sqlDialect.js';
|
|
|
2
2
|
export { SQLServerDialect } from './sqlServerDialect.js';
|
|
3
3
|
export { PostgreSQLDialect } from './postgresqlDialect.js';
|
|
4
4
|
export { GetDialect } from './dialectFactory.js';
|
|
5
|
+
export { AutoQuotePostgreSQLIdentifiers, PostgreSQLQuotingKeywords, PostgreSQLStructuralKeywords, PostgreSQLContextualStructuralKeywords, } from './postgresqlAutoQuote.js';
|
|
5
6
|
export { IsBooleanSQLType, IsStringSQLType, IsFixedWidthStringSQLType, IsDateSQLType, IsIntegerSQLType, IsFloatSQLType, IsUuidSQLType, IsBinarySQLType, IsJsonSQLType, IsCurrencySQLType, IsIntervalSQLType, IsNetworkSQLType, IsNumericSQLType, } from './typeClassification.js';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,GASb,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACnB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,GASb,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACH,8BAA8B,EAC9B,yBAAyB,EACzB,4BAA4B,EAC5B,sCAAsC,GACzC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACnB,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL keywords, type names and built-in function names that must NOT be quoted.
|
|
3
|
+
*
|
|
4
|
+
* Matched **case-SENSITIVELY against the ALL-CAPS form only** — see
|
|
5
|
+
* {@link AutoQuotePostgreSQLIdentifiers} for why. This set is the union of the two
|
|
6
|
+
* former per-provider sets plus `TYPE`/`DATA` (previously a separate case-sensitive
|
|
7
|
+
* tier, now subsumed by the all-caps-only rule).
|
|
8
|
+
*
|
|
9
|
+
* Adding a word here only suppresses quoting of its ALL-CAPS spelling, so a word that
|
|
10
|
+
* is also an MJ column name (`NAME`, `TEXT`, `VALUES`, `LENGTH`, …) is safe to include:
|
|
11
|
+
* the mixed-case column form still quotes.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Known tokenization limitations (comments containing an apostrophe, and `E'...'` escape
|
|
15
|
+
* strings) are tracked as **MJ #3775** — pre-existing, unchanged by the consolidation, and now
|
|
16
|
+
* fixable in one place rather than two.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* NOT the only identifier quoter in MJ, and deliberately so.
|
|
20
|
+
*
|
|
21
|
+
* `PostgreSQLDataProvider` carries a separate, METADATA-DRIVEN quoter
|
|
22
|
+
* (`quoteIdentifiersInSQL` / `quoteFieldNamesInToken`, used by `TransformExternalSQLClause`) which
|
|
23
|
+
* knows the entity's actual field list and can therefore quote precisely, without any keyword
|
|
24
|
+
* heuristic. This module is the fallback for SQL where no entity context exists — hand-authored
|
|
25
|
+
* and stored SQL reaching `ExecuteSQL`.
|
|
26
|
+
*
|
|
27
|
+
* They are not duplicates and this is not an unfinished consolidation: a metadata-driven quoter
|
|
28
|
+
* cannot serve arbitrary SQL, and a heuristic one should not be used where the field list is
|
|
29
|
+
* known. Do not merge them.
|
|
30
|
+
*/
|
|
31
|
+
export declare const PostgreSQLQuotingKeywords: ReadonlySet<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Structural words matched **case-INsensitively**, unlike {@link PostgreSQLQuotingKeywords}.
|
|
34
|
+
*
|
|
35
|
+
* These are the only words exempt from the all-caps-only rule, and the exemption is
|
|
36
|
+
* deliberately tiny: it covers SQL fragments authored OUTSIDE this repo that reach
|
|
37
|
+
* `ExecuteSQL` — a saved `UserView.OrderBy` of `Name Desc`, a GraphQL `ExtraFilter` of
|
|
38
|
+
* `A=1 And B=2`. Those work today (keywords used to match case-insensitively) and would
|
|
39
|
+
* otherwise become `"Name" "Desc"` — a syntax error in stored user data this change
|
|
40
|
+
* cannot reach and fix.
|
|
41
|
+
*
|
|
42
|
+
* Every word here is one that can never legally be an MJ column name. That invariant is
|
|
43
|
+
* not a judgement call — `postgresqlAutoQuote.baseline.test.ts` derives every column name
|
|
44
|
+
* from the shipped PostgreSQL baseline DDL and fails the build if any of them ever matches
|
|
45
|
+
* this set case-insensitively. Do not add a word without keeping that guard green.
|
|
46
|
+
*/
|
|
47
|
+
export declare const PostgreSQLStructuralKeywords: ReadonlySet<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Words that are structural **only when followed by a specific next word**, and ordinary
|
|
50
|
+
* quotable identifiers otherwise.
|
|
51
|
+
*
|
|
52
|
+
* This is how the two-word clause forms are covered without giving up column names. `Order` and
|
|
53
|
+
* `Group` are believable columns; `Order By` and `Group By` are not columns at all.
|
|
54
|
+
* `Left`/`Right`/`Full` are believable columns AND scalar functions; `Left Join` is neither.
|
|
55
|
+
* Gating on the following word separates the cases exactly, rather than trading one breakage for
|
|
56
|
+
* another — which is why this tier is safe to extend and {@link PostgreSQLStructuralKeywords}
|
|
57
|
+
* is not.
|
|
58
|
+
*
|
|
59
|
+
* Matched case-insensitively on both sides.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Words that are structural **only when followed by a specific next word**, and ordinary
|
|
63
|
+
* quotable identifiers otherwise.
|
|
64
|
+
*
|
|
65
|
+
* This exists so the clause skeleton can be covered without giving up column names that
|
|
66
|
+
* genuinely occur. `Order` and `Group` are believable columns; `Order By` and `Group By` are
|
|
67
|
+
* not columns at all. `Left`/`Right`/`Full` are believable columns AND scalar functions;
|
|
68
|
+
* `Left Join` is neither. Gating on the following word separates the two cases exactly,
|
|
69
|
+
* rather than trading one breakage for another.
|
|
70
|
+
*
|
|
71
|
+
* Matched case-insensitively on both sides, like {@link PostgreSQLStructuralKeywords}.
|
|
72
|
+
*/
|
|
73
|
+
export declare const PostgreSQLContextualStructuralKeywords: ReadonlyMap<string, ReadonlySet<string>>;
|
|
74
|
+
/**
|
|
75
|
+
* Quotes mixed-case identifiers in a raw SQL string so PostgreSQL preserves their case.
|
|
76
|
+
*
|
|
77
|
+
* MJ has a great deal of hand-written SQL — in resolvers, engines, dashboard components,
|
|
78
|
+
* and codegen templates — that references PascalCase columns and views unquoted
|
|
79
|
+
* (`FROM __mj.vwAIAgentRuns`, `WHERE TestRun IS NULL`). SQL Server resolves those
|
|
80
|
+
* case-insensitively; PostgreSQL folds an unquoted identifier to lowercase and then fails
|
|
81
|
+
* to find the mixed-case column codegen actually created. This function bridges that gap.
|
|
82
|
+
*
|
|
83
|
+
* ## Keywords are recognized ONLY in ALL-CAPS
|
|
84
|
+
*
|
|
85
|
+
* The keyword set is matched case-SENSITIVELY. This is the crux of the design, and it
|
|
86
|
+
* replaces a case-insensitive denylist that was wrong by construction: the set of SQL
|
|
87
|
+
* keywords and the set of MJ column names overlap (`Name`, `Values`, `Length`, `Precision`,
|
|
88
|
+
* `Log`, `Rank`, `Action`, `Columns`, `Language`, `Month`, `Text` are all real columns AND
|
|
89
|
+
* all keywords/type names/functions). Under case-insensitive matching every name in that
|
|
90
|
+
* intersection was emitted unquoted, folded to lowercase on PG, and failed with
|
|
91
|
+
* `column "..." does not exist` — while SQL Server, being case-insensitive, hid the defect
|
|
92
|
+
* from T-SQL-first authoring entirely.
|
|
93
|
+
*
|
|
94
|
+
* Case-sensitive matching resolves the overlap cleanly because SQL dialects always emit
|
|
95
|
+
* keywords in upper case, so the keyword form and the column form are textually distinct:
|
|
96
|
+
* `TEXT` is the type, `Text` is the column.
|
|
97
|
+
*
|
|
98
|
+
* **An ALL-CAPS word that is NOT a keyword is still an identifier.** `ID` and `URL` are
|
|
99
|
+
* all-caps by nature, so the predicate is `!(isAllUpper && isKeyword)` rather than a pure
|
|
100
|
+
* case rule — a pure case rule would fold them to `id`/`url`.
|
|
101
|
+
*
|
|
102
|
+
* ## The rule
|
|
103
|
+
*
|
|
104
|
+
* Applied to each bare word, in this order (order is load-bearing — the keyword branch
|
|
105
|
+
* runs before the function-call branch so `VALUES(` stays a keyword):
|
|
106
|
+
*
|
|
107
|
+
* 1. ALL-CAPS and in {@link PostgreSQLQuotingKeywords} → keyword/type → do not quote
|
|
108
|
+
* 2. In {@link PostgreSQLStructuralKeywords} (any case) → do not quote
|
|
109
|
+
* 2a. In {@link PostgreSQLContextualStructuralKeywords} AND followed by one of its permitted
|
|
110
|
+
* next words (`Order By`, `Left Join`) → do not quote. Anywhere else, an identifier.
|
|
111
|
+
* 3. Immediately followed by `(` and not preceded by `.` → function call → do not quote
|
|
112
|
+
* 4. All-lowercase, or `__mj_`-prefixed → unchanged → do not quote
|
|
113
|
+
* 5. Starts uppercase, or is preceded by `.` → identifier → QUOTE
|
|
114
|
+
*
|
|
115
|
+
* Rule 3 keeps mixed-case function spellings (`Coalesce(`, `IsNull(`) working now that
|
|
116
|
+
* keyword matching is case-sensitive, and additionally fixes ALL-CAPS functions that were
|
|
117
|
+
* simply missing from the set (`JSONB_BUILD_OBJECT(` used to be quoted, and broke). The
|
|
118
|
+
* `.`-guard exists because MJ creates its stored procedures with quoted mixed-case names,
|
|
119
|
+
* so hand-written `__mj.spCreateFoo(...)` must still be quoted — a dot-qualified callable
|
|
120
|
+
* is far more likely to be an MJ object than a built-in. Rule 5's `.` clause is what makes
|
|
121
|
+
* `__mj.vwAIAgentRuns` work (MJ's `vwXxx` view convention starts lowercase).
|
|
122
|
+
*
|
|
123
|
+
* Known caveat of rule 3: `INSERT INTO Target(Name)` with no space leaves `Target` bare,
|
|
124
|
+
* because a bare word before `(` is indistinguishable from a call. There are no such
|
|
125
|
+
* occurrences in this repo, and the spaced form `INSERT INTO Target (Name)` quotes
|
|
126
|
+
* correctly. Related: `x::Text` now yields `x::"Text"`; write the cast as `::text` or
|
|
127
|
+
* `::TEXT`.
|
|
128
|
+
*
|
|
129
|
+
* ## What is skipped
|
|
130
|
+
*
|
|
131
|
+
* String literals (with `''` escapes and `E`/`N`/`U&` prefixes), `--` line comments,
|
|
132
|
+
* `/* *\/` block comments (nested, as PostgreSQL specifies), dollar-quoted blocks
|
|
133
|
+
* (`$$`/`$tag$`), already-quoted identifiers (with `""` escapes), square-bracketed
|
|
134
|
+
* SQL-Server-style identifiers, `@`-prefixed parameters, and PG positional parameters (`$1`).
|
|
135
|
+
* Skipping already-quoted identifiers is what makes this function **idempotent** —
|
|
136
|
+
* `f(f(x)) === f(x)`.
|
|
137
|
+
*
|
|
138
|
+
* ## Why comments are skipped rather than tolerated
|
|
139
|
+
*
|
|
140
|
+
* Comment handling is not cosmetic. The scanner is a parity machine: an apostrophe inside an
|
|
141
|
+
* unrecognized comment opens a string-literal scan that runs to the next `'`, which is the
|
|
142
|
+
* OPENING quote of a real literal. From there every literal and every code region swaps roles.
|
|
143
|
+
* Against this repository's own shipped query SQL that rewrote literal VALUES —
|
|
144
|
+
* `WHERE "StepType" = 'Prompt'` became `= '"Prompt"'`, and the `jsonb_build_object` keys in
|
|
145
|
+
* `get-conversation-complete.pg.sql` became `'"ID"'` — because line 10 of
|
|
146
|
+
* `calculate-ai-agent-run-cost.pg.sql` contains the word `doesn't` in a comment. Nothing
|
|
147
|
+
* throws; the query simply returns the wrong rows. `postgresqlAutoQuote.shippedQueries.test.ts`
|
|
148
|
+
* pins that whole file set as a no-op so it cannot come back.
|
|
149
|
+
*
|
|
150
|
+
* @param sql Raw SQL text.
|
|
151
|
+
* @returns The same SQL with mixed-case identifiers double-quoted.
|
|
152
|
+
*/
|
|
153
|
+
export declare function AutoQuotePostgreSQLIdentifiers(sql: string): string;
|
|
154
|
+
//# sourceMappingURL=postgresqlAutoQuote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresqlAutoQuote.d.ts","sourceRoot":"","sources":["../src/postgresqlAutoQuote.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;GAWG;AACH;;;;GAIG;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,EAAE,WAAW,CAAC,MAAM,CA4ExD,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,4BAA4B,EAAE,WAAW,CAAC,MAAM,CAI3D,CAAC;AAuBH;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sCAAsC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAS1F,CAAC;AAYH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA+DlE"}
|