@relq/orm 0.1.0

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 (254) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +236 -0
  3. package/dist/cjs/__test-types.cjs +17 -0
  4. package/dist/cjs/addon/cursor.cjs +1473 -0
  5. package/dist/cjs/addon/pg.cjs +4969 -0
  6. package/dist/cjs/cache/index.cjs +9 -0
  7. package/dist/cjs/cache/query-cache.cjs +311 -0
  8. package/dist/cjs/condition/array-condition-builder.cjs +527 -0
  9. package/dist/cjs/condition/array-numeric-condition-builder.cjs +186 -0
  10. package/dist/cjs/condition/array-specialized-condition-builder.cjs +206 -0
  11. package/dist/cjs/condition/array-string-condition-builder.cjs +146 -0
  12. package/dist/cjs/condition/base-condition-builder.cjs +2 -0
  13. package/dist/cjs/condition/condition-collector.cjs +461 -0
  14. package/dist/cjs/condition/fulltext-condition-builder.cjs +61 -0
  15. package/dist/cjs/condition/geometric-condition-builder.cjs +228 -0
  16. package/dist/cjs/condition/index.cjs +29 -0
  17. package/dist/cjs/condition/jsonb-condition-builder.cjs +448 -0
  18. package/dist/cjs/condition/network-condition-builder.cjs +237 -0
  19. package/dist/cjs/condition/postgis-condition-builder.cjs +188 -0
  20. package/dist/cjs/condition/range-condition-builder.cjs +98 -0
  21. package/dist/cjs/core/helpers/ConnectedAggregateBuilder.cjs +132 -0
  22. package/dist/cjs/core/helpers/ConnectedCTEBuilder.cjs +53 -0
  23. package/dist/cjs/core/helpers/ConnectedCountBuilder.cjs +73 -0
  24. package/dist/cjs/core/helpers/ConnectedDeleteBuilder.cjs +65 -0
  25. package/dist/cjs/core/helpers/ConnectedInsertBuilder.cjs +112 -0
  26. package/dist/cjs/core/helpers/ConnectedInsertFromSelectBuilder.cjs +66 -0
  27. package/dist/cjs/core/helpers/ConnectedQueryBuilder.cjs +146 -0
  28. package/dist/cjs/core/helpers/ConnectedRawQueryBuilder.cjs +46 -0
  29. package/dist/cjs/core/helpers/ConnectedSelectBuilder.cjs +331 -0
  30. package/dist/cjs/core/helpers/ConnectedTransactionBuilder.cjs +105 -0
  31. package/dist/cjs/core/helpers/ConnectedUpdateBuilder.cjs +79 -0
  32. package/dist/cjs/core/helpers/PaginateBuilder.cjs +178 -0
  33. package/dist/cjs/core/helpers/ReturningExecutor.cjs +70 -0
  34. package/dist/cjs/core/helpers/capability-guard.cjs +10 -0
  35. package/dist/cjs/core/helpers/index.cjs +31 -0
  36. package/dist/cjs/core/helpers/methods.cjs +10 -0
  37. package/dist/cjs/core/helpers/query-convenience.cjs +238 -0
  38. package/dist/cjs/core/helpers/select-joins.cjs +251 -0
  39. package/dist/cjs/core/helpers/select-pagination.cjs +233 -0
  40. package/dist/cjs/core/helpers/select-types.cjs +2 -0
  41. package/dist/cjs/core/pg-family/cockroachdb-client/capabilities.cjs +31 -0
  42. package/dist/cjs/core/pg-family/cockroachdb-client/index.cjs +7 -0
  43. package/dist/cjs/core/pg-family/cockroachdb-client/relq-cockroach.cjs +16 -0
  44. package/dist/cjs/core/pg-family/dsql-client/capabilities.cjs +31 -0
  45. package/dist/cjs/core/pg-family/dsql-client/index.cjs +7 -0
  46. package/dist/cjs/core/pg-family/dsql-client/relq-dsql.cjs +16 -0
  47. package/dist/cjs/core/pg-family/index.cjs +19 -0
  48. package/dist/cjs/core/pg-family/nile-client/capabilities.cjs +31 -0
  49. package/dist/cjs/core/pg-family/nile-client/index.cjs +7 -0
  50. package/dist/cjs/core/pg-family/nile-client/relq-nile.cjs +36 -0
  51. package/dist/cjs/core/pg-family/nile-client/tenant-context.cjs +44 -0
  52. package/dist/cjs/core/pg-family/pg-client/capabilities.cjs +31 -0
  53. package/dist/cjs/core/pg-family/pg-client/index.cjs +7 -0
  54. package/dist/cjs/core/pg-family/pg-client/relq-postgres.cjs +43 -0
  55. package/dist/cjs/core/pg-family/shared/pg-base.cjs +385 -0
  56. package/dist/cjs/core/pg-family/shared/pg-dialect.cjs +67 -0
  57. package/dist/cjs/core/pg-family/shared/pg-error-parser.cjs +34 -0
  58. package/dist/cjs/core/pg-family/shared/pg-type-coercion.cjs +14 -0
  59. package/dist/cjs/core/relq-base.cjs +307 -0
  60. package/dist/cjs/core/relq-client.cjs +56 -0
  61. package/dist/cjs/core/shared/cleanup.cjs +36 -0
  62. package/dist/cjs/core/shared/column-mapping.cjs +97 -0
  63. package/dist/cjs/core/shared/errors.cjs +17 -0
  64. package/dist/cjs/core/shared/index.cjs +24 -0
  65. package/dist/cjs/core/shared/table-accessor.cjs +22 -0
  66. package/dist/cjs/core/shared/transform.cjs +35 -0
  67. package/dist/cjs/core/shared/types.cjs +2 -0
  68. package/dist/cjs/core/shared/validation.cjs +140 -0
  69. package/dist/cjs/core/types/core.types.cjs +2 -0
  70. package/dist/cjs/count/count-builder.cjs +88 -0
  71. package/dist/cjs/count/index.cjs +5 -0
  72. package/dist/cjs/delete/delete-builder.cjs +176 -0
  73. package/dist/cjs/delete/index.cjs +5 -0
  74. package/dist/cjs/explain/explain-builder.cjs +99 -0
  75. package/dist/cjs/explain/index.cjs +5 -0
  76. package/dist/cjs/index.cjs +26 -0
  77. package/dist/cjs/insert/conflict-builder.cjs +213 -0
  78. package/dist/cjs/insert/index.cjs +5 -0
  79. package/dist/cjs/insert/insert-builder.cjs +320 -0
  80. package/dist/cjs/insert/insert-from-select-builder.cjs +86 -0
  81. package/dist/cjs/pubsub/index.cjs +7 -0
  82. package/dist/cjs/pubsub/listen-notify-builder.cjs +57 -0
  83. package/dist/cjs/pubsub/listener-connection.cjs +180 -0
  84. package/dist/cjs/raw/index.cjs +8 -0
  85. package/dist/cjs/raw/raw-query-builder.cjs +27 -0
  86. package/dist/cjs/raw/sql-template.cjs +73 -0
  87. package/dist/cjs/select/aggregate-builder.cjs +179 -0
  88. package/dist/cjs/select/index.cjs +16 -0
  89. package/dist/cjs/select/join-builder.cjs +192 -0
  90. package/dist/cjs/select/join-condition-builder.cjs +189 -0
  91. package/dist/cjs/select/join-internals.cjs +5 -0
  92. package/dist/cjs/select/join-many-condition-builder.cjs +159 -0
  93. package/dist/cjs/select/scalar-query-builder.cjs +134 -0
  94. package/dist/cjs/select/scalar-select-builder.cjs +78 -0
  95. package/dist/cjs/select/select-builder.cjs +426 -0
  96. package/dist/cjs/select/sql-expression.cjs +38 -0
  97. package/dist/cjs/select/table-proxy.cjs +99 -0
  98. package/dist/cjs/shared/aws-dsql.cjs +181 -0
  99. package/dist/cjs/shared/errors/relq-errors.cjs +361 -0
  100. package/dist/cjs/shared/pg-format.cjs +383 -0
  101. package/dist/cjs/shared/types/config-types.cjs +51 -0
  102. package/dist/cjs/transaction/index.cjs +6 -0
  103. package/dist/cjs/transaction/transaction-builder.cjs +78 -0
  104. package/dist/cjs/types/aggregate-types.cjs +2 -0
  105. package/dist/cjs/types/inference-types.cjs +18 -0
  106. package/dist/cjs/types/pagination-types.cjs +7 -0
  107. package/dist/cjs/types/result-types.cjs +2 -0
  108. package/dist/cjs/types/scalar-types.cjs +2 -0
  109. package/dist/cjs/types/schema-types.cjs +2 -0
  110. package/dist/cjs/types/subscription-types.cjs +2 -0
  111. package/dist/cjs/types.cjs +2 -0
  112. package/dist/cjs/update/array-update-builder.cjs +232 -0
  113. package/dist/cjs/update/index.cjs +16 -0
  114. package/dist/cjs/update/jsonb-update-builder.cjs +219 -0
  115. package/dist/cjs/update/update-builder.cjs +274 -0
  116. package/dist/cjs/utils/addon/pg/cursor.cjs +8 -0
  117. package/dist/cjs/utils/addon/pg/pg.cjs +23 -0
  118. package/dist/cjs/utils/case-converter.cjs +58 -0
  119. package/dist/cjs/utils/env-resolver.cjs +226 -0
  120. package/dist/cjs/utils/environment-detection.cjs +124 -0
  121. package/dist/cjs/utils/fk-resolver.cjs +186 -0
  122. package/dist/cjs/utils/index.cjs +25 -0
  123. package/dist/cjs/utils/pool-defaults.cjs +91 -0
  124. package/dist/cjs/utils/type-coercion.cjs +120 -0
  125. package/dist/cjs/window/index.cjs +5 -0
  126. package/dist/cjs/window/window-builder.cjs +80 -0
  127. package/dist/esm/__test-types.js +15 -0
  128. package/dist/esm/addon/cursor.js +1440 -0
  129. package/dist/esm/addon/pg.js +4931 -0
  130. package/dist/esm/cache/index.js +1 -0
  131. package/dist/esm/cache/query-cache.js +303 -0
  132. package/dist/esm/condition/array-condition-builder.js +519 -0
  133. package/dist/esm/condition/array-numeric-condition-builder.js +182 -0
  134. package/dist/esm/condition/array-specialized-condition-builder.js +200 -0
  135. package/dist/esm/condition/array-string-condition-builder.js +142 -0
  136. package/dist/esm/condition/base-condition-builder.js +1 -0
  137. package/dist/esm/condition/condition-collector.js +452 -0
  138. package/dist/esm/condition/fulltext-condition-builder.js +53 -0
  139. package/dist/esm/condition/geometric-condition-builder.js +220 -0
  140. package/dist/esm/condition/index.js +8 -0
  141. package/dist/esm/condition/jsonb-condition-builder.js +439 -0
  142. package/dist/esm/condition/network-condition-builder.js +229 -0
  143. package/dist/esm/condition/postgis-condition-builder.js +180 -0
  144. package/dist/esm/condition/range-condition-builder.js +90 -0
  145. package/dist/esm/core/helpers/ConnectedAggregateBuilder.js +128 -0
  146. package/dist/esm/core/helpers/ConnectedCTEBuilder.js +49 -0
  147. package/dist/esm/core/helpers/ConnectedCountBuilder.js +69 -0
  148. package/dist/esm/core/helpers/ConnectedDeleteBuilder.js +61 -0
  149. package/dist/esm/core/helpers/ConnectedInsertBuilder.js +108 -0
  150. package/dist/esm/core/helpers/ConnectedInsertFromSelectBuilder.js +62 -0
  151. package/dist/esm/core/helpers/ConnectedQueryBuilder.js +142 -0
  152. package/dist/esm/core/helpers/ConnectedRawQueryBuilder.js +42 -0
  153. package/dist/esm/core/helpers/ConnectedSelectBuilder.js +327 -0
  154. package/dist/esm/core/helpers/ConnectedTransactionBuilder.js +100 -0
  155. package/dist/esm/core/helpers/ConnectedUpdateBuilder.js +75 -0
  156. package/dist/esm/core/helpers/PaginateBuilder.js +174 -0
  157. package/dist/esm/core/helpers/ReturningExecutor.js +66 -0
  158. package/dist/esm/core/helpers/capability-guard.js +7 -0
  159. package/dist/esm/core/helpers/index.js +13 -0
  160. package/dist/esm/core/helpers/methods.js +6 -0
  161. package/dist/esm/core/helpers/query-convenience.js +194 -0
  162. package/dist/esm/core/helpers/select-joins.js +246 -0
  163. package/dist/esm/core/helpers/select-pagination.js +226 -0
  164. package/dist/esm/core/helpers/select-types.js +1 -0
  165. package/dist/esm/core/pg-family/cockroachdb-client/capabilities.js +28 -0
  166. package/dist/esm/core/pg-family/cockroachdb-client/index.js +2 -0
  167. package/dist/esm/core/pg-family/cockroachdb-client/relq-cockroach.js +12 -0
  168. package/dist/esm/core/pg-family/dsql-client/capabilities.js +28 -0
  169. package/dist/esm/core/pg-family/dsql-client/index.js +2 -0
  170. package/dist/esm/core/pg-family/dsql-client/relq-dsql.js +12 -0
  171. package/dist/esm/core/pg-family/index.js +6 -0
  172. package/dist/esm/core/pg-family/nile-client/capabilities.js +28 -0
  173. package/dist/esm/core/pg-family/nile-client/index.js +2 -0
  174. package/dist/esm/core/pg-family/nile-client/relq-nile.js +32 -0
  175. package/dist/esm/core/pg-family/nile-client/tenant-context.js +40 -0
  176. package/dist/esm/core/pg-family/pg-client/capabilities.js +28 -0
  177. package/dist/esm/core/pg-family/pg-client/index.js +2 -0
  178. package/dist/esm/core/pg-family/pg-client/relq-postgres.js +39 -0
  179. package/dist/esm/core/pg-family/shared/pg-base.js +347 -0
  180. package/dist/esm/core/pg-family/shared/pg-dialect.js +63 -0
  181. package/dist/esm/core/pg-family/shared/pg-error-parser.js +29 -0
  182. package/dist/esm/core/pg-family/shared/pg-type-coercion.js +6 -0
  183. package/dist/esm/core/relq-base.js +270 -0
  184. package/dist/esm/core/relq-client.js +48 -0
  185. package/dist/esm/core/shared/cleanup.js +27 -0
  186. package/dist/esm/core/shared/column-mapping.js +90 -0
  187. package/dist/esm/core/shared/errors.js +13 -0
  188. package/dist/esm/core/shared/index.js +6 -0
  189. package/dist/esm/core/shared/table-accessor.js +19 -0
  190. package/dist/esm/core/shared/transform.js +30 -0
  191. package/dist/esm/core/shared/types.js +1 -0
  192. package/dist/esm/core/shared/validation.js +136 -0
  193. package/dist/esm/core/types/core.types.js +1 -0
  194. package/dist/esm/count/count-builder.js +81 -0
  195. package/dist/esm/count/index.js +1 -0
  196. package/dist/esm/delete/delete-builder.js +169 -0
  197. package/dist/esm/delete/index.js +1 -0
  198. package/dist/esm/explain/explain-builder.js +95 -0
  199. package/dist/esm/explain/index.js +1 -0
  200. package/dist/esm/index.js +7 -0
  201. package/dist/esm/insert/conflict-builder.js +202 -0
  202. package/dist/esm/insert/index.js +1 -0
  203. package/dist/esm/insert/insert-builder.js +313 -0
  204. package/dist/esm/insert/insert-from-select-builder.js +79 -0
  205. package/dist/esm/pubsub/index.js +1 -0
  206. package/dist/esm/pubsub/listen-notify-builder.js +48 -0
  207. package/dist/esm/pubsub/listener-connection.js +173 -0
  208. package/dist/esm/raw/index.js +2 -0
  209. package/dist/esm/raw/raw-query-builder.js +20 -0
  210. package/dist/esm/raw/sql-template.js +66 -0
  211. package/dist/esm/select/aggregate-builder.js +172 -0
  212. package/dist/esm/select/index.js +4 -0
  213. package/dist/esm/select/join-builder.js +184 -0
  214. package/dist/esm/select/join-condition-builder.js +181 -0
  215. package/dist/esm/select/join-internals.js +2 -0
  216. package/dist/esm/select/join-many-condition-builder.js +151 -0
  217. package/dist/esm/select/scalar-query-builder.js +126 -0
  218. package/dist/esm/select/scalar-select-builder.js +70 -0
  219. package/dist/esm/select/select-builder.js +419 -0
  220. package/dist/esm/select/sql-expression.js +33 -0
  221. package/dist/esm/select/table-proxy.js +91 -0
  222. package/dist/esm/shared/aws-dsql.js +140 -0
  223. package/dist/esm/shared/errors/relq-errors.js +339 -0
  224. package/dist/esm/shared/pg-format.js +375 -0
  225. package/dist/esm/shared/types/config-types.js +46 -0
  226. package/dist/esm/transaction/index.js +1 -0
  227. package/dist/esm/transaction/transaction-builder.js +70 -0
  228. package/dist/esm/types/aggregate-types.js +1 -0
  229. package/dist/esm/types/inference-types.js +12 -0
  230. package/dist/esm/types/pagination-types.js +4 -0
  231. package/dist/esm/types/result-types.js +1 -0
  232. package/dist/esm/types/scalar-types.js +1 -0
  233. package/dist/esm/types/schema-types.js +1 -0
  234. package/dist/esm/types/subscription-types.js +1 -0
  235. package/dist/esm/types.js +1 -0
  236. package/dist/esm/update/array-update-builder.js +219 -0
  237. package/dist/esm/update/index.js +3 -0
  238. package/dist/esm/update/jsonb-update-builder.js +211 -0
  239. package/dist/esm/update/update-builder.js +267 -0
  240. package/dist/esm/utils/addon/pg/cursor.js +1 -0
  241. package/dist/esm/utils/addon/pg/pg.js +2 -0
  242. package/dist/esm/utils/case-converter.js +55 -0
  243. package/dist/esm/utils/env-resolver.js +213 -0
  244. package/dist/esm/utils/environment-detection.js +114 -0
  245. package/dist/esm/utils/fk-resolver.js +178 -0
  246. package/dist/esm/utils/index.js +4 -0
  247. package/dist/esm/utils/pool-defaults.js +85 -0
  248. package/dist/esm/utils/type-coercion.js +112 -0
  249. package/dist/esm/window/index.js +1 -0
  250. package/dist/esm/window/window-builder.js +73 -0
  251. package/dist/index.cjs +1 -0
  252. package/dist/index.d.ts +7281 -0
  253. package/dist/index.js +1 -0
  254. package/package.json +52 -0
@@ -0,0 +1,448 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.JsonbConditionCollector = exports.JsonbArrayConditionBuilder = void 0;
7
+ exports.buildJsonbConditionSQL = buildJsonbConditionSQL;
8
+ const pg_format_1 = __importDefault(require("../shared/pg-format.cjs"));
9
+ class JsonbArrayConditionBuilder {
10
+ parent;
11
+ constructor(parent) {
12
+ this.parent = parent;
13
+ }
14
+ length(column, operator, value) {
15
+ this.parent.conditions.push({
16
+ method: 'jsonb_array_length',
17
+ column,
18
+ values: { operator, value }
19
+ });
20
+ return this.parent;
21
+ }
22
+ isEmpty(column) {
23
+ this.parent.conditions.push({
24
+ method: 'jsonb_array_empty',
25
+ column,
26
+ values: true
27
+ });
28
+ return this.parent;
29
+ }
30
+ isNotEmpty(column) {
31
+ this.parent.conditions.push({
32
+ method: 'jsonb_array_empty',
33
+ column,
34
+ values: false
35
+ });
36
+ return this.parent;
37
+ }
38
+ contains(column, element) {
39
+ this.parent.conditions.push({
40
+ method: 'jsonb_array_contains_element',
41
+ column,
42
+ values: element
43
+ });
44
+ return this.parent;
45
+ }
46
+ containsAll(column, elements) {
47
+ this.parent.conditions.push({
48
+ method: 'jsonb_array_contains_all',
49
+ column,
50
+ values: elements
51
+ });
52
+ return this.parent;
53
+ }
54
+ containsAny(column, elements) {
55
+ this.parent.conditions.push({
56
+ method: 'jsonb_array_contains_any',
57
+ column,
58
+ values: elements
59
+ });
60
+ return this.parent;
61
+ }
62
+ any(column, key, operator, value) {
63
+ this.parent.conditions.push({
64
+ method: 'jsonb_array_any',
65
+ column,
66
+ values: { key, operator, value }
67
+ });
68
+ return this.parent;
69
+ }
70
+ all(column, key, operator, value) {
71
+ this.parent.conditions.push({
72
+ method: 'jsonb_array_all',
73
+ column,
74
+ values: { key, operator, value }
75
+ });
76
+ return this.parent;
77
+ }
78
+ anyIn(column, key, values) {
79
+ this.parent.conditions.push({
80
+ method: 'jsonb_array_any_in',
81
+ column,
82
+ values: { key, values }
83
+ });
84
+ return this.parent;
85
+ }
86
+ anyLike(column, key, pattern) {
87
+ this.parent.conditions.push({
88
+ method: 'jsonb_array_any_like',
89
+ column,
90
+ values: { key, pattern }
91
+ });
92
+ return this.parent;
93
+ }
94
+ anyILike(column, key, pattern) {
95
+ this.parent.conditions.push({
96
+ method: 'jsonb_array_any_ilike',
97
+ column,
98
+ values: { key, pattern }
99
+ });
100
+ return this.parent;
101
+ }
102
+ }
103
+ exports.JsonbArrayConditionBuilder = JsonbArrayConditionBuilder;
104
+ class JsonbConditionCollector {
105
+ parent;
106
+ _array = null;
107
+ constructor(parent) {
108
+ this.parent = parent;
109
+ }
110
+ get array() {
111
+ if (!this._array) {
112
+ this._array = new JsonbArrayConditionBuilder(this.parent);
113
+ }
114
+ return this._array;
115
+ }
116
+ contains(column, value) {
117
+ this.parent.conditions.push({
118
+ method: 'jsonb_contains',
119
+ column,
120
+ values: value
121
+ });
122
+ return this.parent;
123
+ }
124
+ containedBy(column, value) {
125
+ this.parent.conditions.push({
126
+ method: 'jsonb_contained_by',
127
+ column,
128
+ values: value
129
+ });
130
+ return this.parent;
131
+ }
132
+ hasKey(column, key) {
133
+ this.parent.conditions.push({
134
+ method: 'jsonb_has_key',
135
+ column,
136
+ values: key
137
+ });
138
+ return this.parent;
139
+ }
140
+ hasAnyKeys(column, keys) {
141
+ this.parent.conditions.push({
142
+ method: 'jsonb_has_any_keys',
143
+ column,
144
+ values: keys
145
+ });
146
+ return this.parent;
147
+ }
148
+ hasAllKeys(column, keys) {
149
+ this.parent.conditions.push({
150
+ method: 'jsonb_has_all_keys',
151
+ column,
152
+ values: keys
153
+ });
154
+ return this.parent;
155
+ }
156
+ isNull(column) {
157
+ this.parent.conditions.push({
158
+ method: 'jsonb_is_null',
159
+ column,
160
+ values: true
161
+ });
162
+ return this.parent;
163
+ }
164
+ isNotNull(column) {
165
+ this.parent.conditions.push({
166
+ method: 'jsonb_is_null',
167
+ column,
168
+ values: false
169
+ });
170
+ return this.parent;
171
+ }
172
+ typeOf(column, path, type) {
173
+ this.parent.conditions.push({
174
+ method: 'jsonb_typeof',
175
+ column,
176
+ values: { path: Array.isArray(path) ? path : [path], type }
177
+ });
178
+ return this.parent;
179
+ }
180
+ extract(column, path) {
181
+ this.parent.conditions.push({
182
+ method: 'jsonb_extract',
183
+ column,
184
+ values: path
185
+ });
186
+ return this.parent;
187
+ }
188
+ extractText(column, path) {
189
+ this.parent.conditions.push({
190
+ method: 'jsonb_extract_text',
191
+ column,
192
+ values: path
193
+ });
194
+ return this.parent;
195
+ }
196
+ get(column, key) {
197
+ this.parent.conditions.push({
198
+ method: 'jsonb_get',
199
+ column,
200
+ values: key
201
+ });
202
+ return this.parent;
203
+ }
204
+ getText(column, key) {
205
+ this.parent.conditions.push({
206
+ method: 'jsonb_get_text',
207
+ column,
208
+ values: key
209
+ });
210
+ return this.parent;
211
+ }
212
+ extractEqual(column, path, value) {
213
+ this.parent.conditions.push({
214
+ method: 'jsonb_extract_equal',
215
+ column,
216
+ values: { path, value }
217
+ });
218
+ return this.parent;
219
+ }
220
+ extractNotEqual(column, path, value) {
221
+ this.parent.conditions.push({
222
+ method: 'jsonb_extract_not_equal',
223
+ column,
224
+ values: { path, value }
225
+ });
226
+ return this.parent;
227
+ }
228
+ extractGreaterThan(column, path, value) {
229
+ this.parent.conditions.push({
230
+ method: 'jsonb_extract_gt',
231
+ column,
232
+ values: { path, value }
233
+ });
234
+ return this.parent;
235
+ }
236
+ extractGreaterThanOrEqual(column, path, value) {
237
+ this.parent.conditions.push({
238
+ method: 'jsonb_extract_gte',
239
+ column,
240
+ values: { path, value }
241
+ });
242
+ return this.parent;
243
+ }
244
+ extractLessThan(column, path, value) {
245
+ this.parent.conditions.push({
246
+ method: 'jsonb_extract_lt',
247
+ column,
248
+ values: { path, value }
249
+ });
250
+ return this.parent;
251
+ }
252
+ extractLessThanOrEqual(column, path, value) {
253
+ this.parent.conditions.push({
254
+ method: 'jsonb_extract_lte',
255
+ column,
256
+ values: { path, value }
257
+ });
258
+ return this.parent;
259
+ }
260
+ extractBetween(column, path, min, max) {
261
+ this.parent.conditions.push({
262
+ method: 'jsonb_extract_between',
263
+ column,
264
+ values: { path, min, max }
265
+ });
266
+ return this.parent;
267
+ }
268
+ extractIn(column, path, values) {
269
+ this.parent.conditions.push({
270
+ method: 'jsonb_extract_in',
271
+ column,
272
+ values: { path, values }
273
+ });
274
+ return this.parent;
275
+ }
276
+ extractNotIn(column, path, values) {
277
+ this.parent.conditions.push({
278
+ method: 'jsonb_extract_not_in',
279
+ column,
280
+ values: { path, values }
281
+ });
282
+ return this.parent;
283
+ }
284
+ extractLike(column, path, pattern) {
285
+ this.parent.conditions.push({
286
+ method: 'jsonb_extract_like',
287
+ column,
288
+ values: { path, pattern }
289
+ });
290
+ return this.parent;
291
+ }
292
+ extractILike(column, path, pattern) {
293
+ this.parent.conditions.push({
294
+ method: 'jsonb_extract_ilike',
295
+ column,
296
+ values: { path, pattern }
297
+ });
298
+ return this.parent;
299
+ }
300
+ extractIsNull(column, path) {
301
+ this.parent.conditions.push({
302
+ method: 'jsonb_extract_is_null',
303
+ column,
304
+ values: { path, isNull: true }
305
+ });
306
+ return this.parent;
307
+ }
308
+ extractIsNotNull(column, path) {
309
+ this.parent.conditions.push({
310
+ method: 'jsonb_extract_is_null',
311
+ column,
312
+ values: { path, isNull: false }
313
+ });
314
+ return this.parent;
315
+ }
316
+ }
317
+ exports.JsonbConditionCollector = JsonbConditionCollector;
318
+ function buildJsonbConditionSQL(condition) {
319
+ const { method, column, values } = condition;
320
+ switch (method) {
321
+ case 'jsonb_contains':
322
+ return (0, pg_format_1.default)('%I @> %L', column, JSON.stringify(values));
323
+ case 'jsonb_contained_by':
324
+ return (0, pg_format_1.default)('%I <@ %L', column, JSON.stringify(values));
325
+ case 'jsonb_has_key':
326
+ return (0, pg_format_1.default)('%I ? %L', column, values);
327
+ case 'jsonb_has_any_keys':
328
+ return (0, pg_format_1.default)('%I ?| ARRAY[%s]', column, values.map(k => (0, pg_format_1.default)('%L', k)).join(','));
329
+ case 'jsonb_has_all_keys':
330
+ return (0, pg_format_1.default)('%I ?& ARRAY[%s]', column, values.map(k => (0, pg_format_1.default)('%L', k)).join(','));
331
+ case 'jsonb_is_null':
332
+ return values ? (0, pg_format_1.default)('%I IS NULL', column) : (0, pg_format_1.default)('%I IS NOT NULL', column);
333
+ case 'jsonb_typeof': {
334
+ const { path, type } = values;
335
+ const pathStr = `{${path.join(',')}}`;
336
+ return (0, pg_format_1.default)('jsonb_typeof(%I#>%L) = %L', column, pathStr, type);
337
+ }
338
+ case 'jsonb_extract':
339
+ return (0, pg_format_1.default)('%I#>%L', column, `{${values.join(',')}}`);
340
+ case 'jsonb_extract_text':
341
+ return (0, pg_format_1.default)('%I#>>%L', column, `{${values.join(',')}}`);
342
+ case 'jsonb_get':
343
+ return (0, pg_format_1.default)('%I->%L', column, values);
344
+ case 'jsonb_get_text':
345
+ return (0, pg_format_1.default)('%I->>%L', column, values);
346
+ case 'jsonb_extract_equal': {
347
+ const { path, value } = values;
348
+ return (0, pg_format_1.default)('%I#>>%L = %L', column, `{${path.join(',')}}`, value);
349
+ }
350
+ case 'jsonb_extract_not_equal': {
351
+ const { path, value } = values;
352
+ return (0, pg_format_1.default)('%I#>>%L != %L', column, `{${path.join(',')}}`, value);
353
+ }
354
+ case 'jsonb_extract_gt': {
355
+ const { path, value } = values;
356
+ return (0, pg_format_1.default)('(%I#>>%L)::numeric > %L', column, `{${path.join(',')}}`, value);
357
+ }
358
+ case 'jsonb_extract_gte': {
359
+ const { path, value } = values;
360
+ return (0, pg_format_1.default)('(%I#>>%L)::numeric >= %L', column, `{${path.join(',')}}`, value);
361
+ }
362
+ case 'jsonb_extract_lt': {
363
+ const { path, value } = values;
364
+ return (0, pg_format_1.default)('(%I#>>%L)::numeric < %L', column, `{${path.join(',')}}`, value);
365
+ }
366
+ case 'jsonb_extract_lte': {
367
+ const { path, value } = values;
368
+ return (0, pg_format_1.default)('(%I#>>%L)::numeric <= %L', column, `{${path.join(',')}}`, value);
369
+ }
370
+ case 'jsonb_extract_between': {
371
+ const { path, min, max } = values;
372
+ return (0, pg_format_1.default)('(%I#>>%L)::numeric BETWEEN %L AND %L', column, `{${path.join(',')}}`, min, max);
373
+ }
374
+ case 'jsonb_extract_in': {
375
+ const { path, values: inValues } = values;
376
+ const inList = inValues.map(v => (0, pg_format_1.default)('%L', v)).join(', ');
377
+ return (0, pg_format_1.default)('%I#>>%L IN (%s)', column, `{${path.join(',')}}`, inList);
378
+ }
379
+ case 'jsonb_extract_not_in': {
380
+ const { path, values: inValues } = values;
381
+ const inList = inValues.map(v => (0, pg_format_1.default)('%L', v)).join(', ');
382
+ return (0, pg_format_1.default)('%I#>>%L NOT IN (%s)', column, `{${path.join(',')}}`, inList);
383
+ }
384
+ case 'jsonb_extract_like': {
385
+ const { path, pattern } = values;
386
+ return (0, pg_format_1.default)('%I#>>%L LIKE %L', column, `{${path.join(',')}}`, pattern);
387
+ }
388
+ case 'jsonb_extract_ilike': {
389
+ const { path, pattern } = values;
390
+ return (0, pg_format_1.default)('%I#>>%L ILIKE %L', column, `{${path.join(',')}}`, pattern);
391
+ }
392
+ case 'jsonb_extract_is_null': {
393
+ const { path, isNull } = values;
394
+ const pathStr = `{${path.join(',')}}`;
395
+ if (isNull) {
396
+ return (0, pg_format_1.default)('(%I#>%L IS NULL OR %I#>%L = \'null\'::jsonb)', column, pathStr, column, pathStr);
397
+ }
398
+ return (0, pg_format_1.default)('(%I#>%L IS NOT NULL AND %I#>%L != \'null\'::jsonb)', column, pathStr, column, pathStr);
399
+ }
400
+ case 'jsonb_array_length': {
401
+ const { operator, value } = values;
402
+ return (0, pg_format_1.default)('jsonb_array_length(COALESCE(%I, \'[]\'::jsonb)) %s %s', column, operator, value);
403
+ }
404
+ case 'jsonb_array_empty': {
405
+ const isEmpty = values;
406
+ if (isEmpty) {
407
+ return (0, pg_format_1.default)('jsonb_array_length(COALESCE(%I, \'[]\'::jsonb)) = 0', column);
408
+ }
409
+ return (0, pg_format_1.default)('jsonb_array_length(COALESCE(%I, \'[]\'::jsonb)) > 0', column);
410
+ }
411
+ case 'jsonb_array_contains_element':
412
+ return (0, pg_format_1.default)('%I @> %L', column, JSON.stringify([values]));
413
+ case 'jsonb_array_contains_all':
414
+ return (0, pg_format_1.default)('%I @> %L', column, JSON.stringify(values));
415
+ case 'jsonb_array_contains_any': {
416
+ const elements = values;
417
+ const conditions = elements.map(el => (0, pg_format_1.default)('%I @> %L', column, JSON.stringify([el])));
418
+ return `(${conditions.join(' OR ')})`;
419
+ }
420
+ case 'jsonb_array_any': {
421
+ const { key, operator, value } = values;
422
+ const isNumeric = typeof value === 'number';
423
+ const cast = isNumeric ? '::numeric' : '';
424
+ return (0, pg_format_1.default)('EXISTS (SELECT 1 FROM jsonb_array_elements(COALESCE(%I, \'[]\'::jsonb)) elem WHERE (elem->>%L)%s %s %L)', column, key, cast, operator, value);
425
+ }
426
+ case 'jsonb_array_all': {
427
+ const { key, operator, value } = values;
428
+ const isNumeric = typeof value === 'number';
429
+ const cast = isNumeric ? '::numeric' : '';
430
+ return (0, pg_format_1.default)('NOT EXISTS (SELECT 1 FROM jsonb_array_elements(COALESCE(%I, \'[]\'::jsonb)) elem WHERE NOT ((elem->>%L)%s %s %L))', column, key, cast, operator, value);
431
+ }
432
+ case 'jsonb_array_any_in': {
433
+ const { key, values: inValues } = values;
434
+ const inList = inValues.map(v => (0, pg_format_1.default)('%L', v)).join(', ');
435
+ return (0, pg_format_1.default)('EXISTS (SELECT 1 FROM jsonb_array_elements(COALESCE(%I, \'[]\'::jsonb)) elem WHERE elem->>%L IN (%s))', column, key, inList);
436
+ }
437
+ case 'jsonb_array_any_like': {
438
+ const { key, pattern } = values;
439
+ return (0, pg_format_1.default)('EXISTS (SELECT 1 FROM jsonb_array_elements(COALESCE(%I, \'[]\'::jsonb)) elem WHERE elem->>%L LIKE %L)', column, key, pattern);
440
+ }
441
+ case 'jsonb_array_any_ilike': {
442
+ const { key, pattern } = values;
443
+ return (0, pg_format_1.default)('EXISTS (SELECT 1 FROM jsonb_array_elements(COALESCE(%I, \'[]\'::jsonb)) elem WHERE elem->>%L ILIKE %L)', column, key, pattern);
444
+ }
445
+ default:
446
+ return '';
447
+ }
448
+ }
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NetworkConditionCollector = void 0;
7
+ exports.buildNetworkConditionSQL = buildNetworkConditionSQL;
8
+ const pg_format_1 = __importDefault(require("../shared/pg-format.cjs"));
9
+ function networkToSQL(address) {
10
+ if (typeof address === 'string')
11
+ return address;
12
+ const { octets, mask } = address;
13
+ const ip = octets.join('.');
14
+ return mask !== undefined ? `${ip}/${mask}` : ip;
15
+ }
16
+ class NetworkConditionCollector {
17
+ parent;
18
+ constructor(parent) {
19
+ this.parent = parent;
20
+ }
21
+ containedByStrict(column, value) {
22
+ this.parent.conditions.push({
23
+ method: 'network_contained_by_strict',
24
+ column,
25
+ values: networkToSQL(value)
26
+ });
27
+ return this.parent;
28
+ }
29
+ containedByOrEqual(column, value) {
30
+ this.parent.conditions.push({
31
+ method: 'network_contained_by_or_equal',
32
+ column,
33
+ values: networkToSQL(value)
34
+ });
35
+ return this.parent;
36
+ }
37
+ containsStrict(column, value) {
38
+ this.parent.conditions.push({
39
+ method: 'network_contains_strict',
40
+ column,
41
+ values: networkToSQL(value)
42
+ });
43
+ return this.parent;
44
+ }
45
+ containsOrEqual(column, value) {
46
+ this.parent.conditions.push({
47
+ method: 'network_contains_or_equal',
48
+ column,
49
+ values: networkToSQL(value)
50
+ });
51
+ return this.parent;
52
+ }
53
+ overlaps(column, value) {
54
+ this.parent.conditions.push({
55
+ method: 'network_overlaps',
56
+ column,
57
+ values: networkToSQL(value)
58
+ });
59
+ return this.parent;
60
+ }
61
+ sameFamily(column, value) {
62
+ this.parent.conditions.push({
63
+ method: 'network_same_family',
64
+ column,
65
+ values: networkToSQL(value)
66
+ });
67
+ return this.parent;
68
+ }
69
+ isIPv4(column) {
70
+ this.parent.conditions.push({
71
+ method: 'network_is_ipv4',
72
+ column
73
+ });
74
+ return this.parent;
75
+ }
76
+ isIPv6(column) {
77
+ this.parent.conditions.push({
78
+ method: 'network_is_ipv6',
79
+ column
80
+ });
81
+ return this.parent;
82
+ }
83
+ maskLengthEquals(column, length) {
84
+ this.parent.conditions.push({
85
+ method: 'network_masklen_eq',
86
+ column,
87
+ values: length
88
+ });
89
+ return this.parent;
90
+ }
91
+ maskLengthGreaterThan(column, length) {
92
+ this.parent.conditions.push({
93
+ method: 'network_masklen_gt',
94
+ column,
95
+ values: length
96
+ });
97
+ return this.parent;
98
+ }
99
+ maskLengthLessThan(column, length) {
100
+ this.parent.conditions.push({
101
+ method: 'network_masklen_lt',
102
+ column,
103
+ values: length
104
+ });
105
+ return this.parent;
106
+ }
107
+ bitwiseAnd(column, mask, expected) {
108
+ this.parent.conditions.push({
109
+ method: 'network_bitwise_and',
110
+ column,
111
+ values: { mask, expected }
112
+ });
113
+ return this.parent;
114
+ }
115
+ bitwiseOr(column, value, expected) {
116
+ this.parent.conditions.push({
117
+ method: 'network_bitwise_or',
118
+ column,
119
+ values: { value, expected }
120
+ });
121
+ return this.parent;
122
+ }
123
+ macEquals(column, value) {
124
+ this.parent.conditions.push({
125
+ method: 'network_mac_equals',
126
+ column,
127
+ values: value
128
+ });
129
+ return this.parent;
130
+ }
131
+ macNotEquals(column, value) {
132
+ this.parent.conditions.push({
133
+ method: 'network_mac_not_equals',
134
+ column,
135
+ values: value
136
+ });
137
+ return this.parent;
138
+ }
139
+ macGreaterThan(column, value) {
140
+ this.parent.conditions.push({
141
+ method: 'network_mac_gt',
142
+ column,
143
+ values: value
144
+ });
145
+ return this.parent;
146
+ }
147
+ macLessThan(column, value) {
148
+ this.parent.conditions.push({
149
+ method: 'network_mac_lt',
150
+ column,
151
+ values: value
152
+ });
153
+ return this.parent;
154
+ }
155
+ macTruncEquals(column, oui) {
156
+ this.parent.conditions.push({
157
+ method: 'network_mac_trunc_equals',
158
+ column,
159
+ values: oui
160
+ });
161
+ return this.parent;
162
+ }
163
+ hostEquals(column, value) {
164
+ this.parent.conditions.push({
165
+ method: 'network_host_equals',
166
+ column,
167
+ values: value
168
+ });
169
+ return this.parent;
170
+ }
171
+ networkEquals(column, value) {
172
+ this.parent.conditions.push({
173
+ method: 'network_network_equals',
174
+ column,
175
+ values: value
176
+ });
177
+ return this.parent;
178
+ }
179
+ broadcastEquals(column, value) {
180
+ this.parent.conditions.push({
181
+ method: 'network_broadcast_equals',
182
+ column,
183
+ values: value
184
+ });
185
+ return this.parent;
186
+ }
187
+ }
188
+ exports.NetworkConditionCollector = NetworkConditionCollector;
189
+ function buildNetworkConditionSQL(condition) {
190
+ const { method, column, values } = condition;
191
+ switch (method) {
192
+ case 'network_contained_by_strict':
193
+ return (0, pg_format_1.default)('%I << inet %L', column, values);
194
+ case 'network_contained_by_or_equal':
195
+ return (0, pg_format_1.default)('%I <<= inet %L', column, values);
196
+ case 'network_contains_strict':
197
+ return (0, pg_format_1.default)('%I >> inet %L', column, values);
198
+ case 'network_contains_or_equal':
199
+ return (0, pg_format_1.default)('%I >>= inet %L', column, values);
200
+ case 'network_overlaps':
201
+ return (0, pg_format_1.default)('%I && inet %L', column, values);
202
+ case 'network_same_family':
203
+ return (0, pg_format_1.default)('inet_same_family(%I, inet %L)', column, values);
204
+ case 'network_is_ipv4':
205
+ return (0, pg_format_1.default)('family(%I) = 4', column);
206
+ case 'network_is_ipv6':
207
+ return (0, pg_format_1.default)('family(%I) = 6', column);
208
+ case 'network_masklen_eq':
209
+ return (0, pg_format_1.default)('masklen(%I) = %s', column, values);
210
+ case 'network_masklen_gt':
211
+ return (0, pg_format_1.default)('masklen(%I) > %s', column, values);
212
+ case 'network_masklen_lt':
213
+ return (0, pg_format_1.default)('masklen(%I) < %s', column, values);
214
+ case 'network_bitwise_and':
215
+ return (0, pg_format_1.default)('(%I & inet %L) = inet %L', column, values.mask, values.expected);
216
+ case 'network_bitwise_or':
217
+ return (0, pg_format_1.default)('(%I | inet %L) = inet %L', column, values.value, values.expected);
218
+ case 'network_mac_equals':
219
+ return (0, pg_format_1.default)('%I = macaddr %L', column, values);
220
+ case 'network_mac_not_equals':
221
+ return (0, pg_format_1.default)('%I <> macaddr %L', column, values);
222
+ case 'network_mac_gt':
223
+ return (0, pg_format_1.default)('%I > macaddr %L', column, values);
224
+ case 'network_mac_lt':
225
+ return (0, pg_format_1.default)('%I < macaddr %L', column, values);
226
+ case 'network_mac_trunc_equals':
227
+ return (0, pg_format_1.default)('trunc(%I) = macaddr %L', column, values);
228
+ case 'network_host_equals':
229
+ return (0, pg_format_1.default)('host(%I) = %L', column, values);
230
+ case 'network_network_equals':
231
+ return (0, pg_format_1.default)('network(%I) = cidr %L', column, values);
232
+ case 'network_broadcast_equals':
233
+ return (0, pg_format_1.default)('broadcast(%I) = inet %L', column, values);
234
+ default:
235
+ return '';
236
+ }
237
+ }