@gjermundgaraba/clankerauth-dev 0.26.2 → 0.27.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.
- package/dist/THIRD_PARTY_NOTICES.txt +12 -219
- package/dist/{access-CoaNEa0I.mjs → access-CGVwFSPz.mjs} +1 -1
- package/dist/{dist-Dse7wyrJ.mjs → dist-BwJIqVtn.mjs} +1 -1
- package/dist/dist-CLLAHXOK.mjs +17 -0
- package/dist/{factory-tEOeUNZI.mjs → factory-Cf28yuX6.mjs} +3 -3
- package/dist/{get-id-field-CHlYHt3y.mjs → get-id-field-DvYh1rwM.mjs} +2 -2
- package/dist/index.mjs +1 -1
- package/dist/kysely-adapter-B9j0_OfU.mjs +1 -0
- package/dist/{organization-FxrB4RLj.mjs → organization-B_0UJJOj.mjs} +1 -1
- package/dist/{schema-check-6AE7KkNs.mjs → schema-check-DYtufmXq.mjs} +1 -1
- package/dist/{schemas-CYWNDEcx.mjs → schemas-lRZfTY17.mjs} +1 -1
- package/dist/src-dv9-ePIU.mjs +539 -0
- package/dist/web/assets/index-C-vB7TuL.css +1 -0
- package/dist/web/assets/index-C_9T06d-.js +2300 -0
- package/dist/web/index.html +2 -2
- package/package.json +4 -4
- package/dist/dist-BtO0lgmD.mjs +0 -17
- package/dist/kysely-adapter-BxenTacV.mjs +0 -1
- package/dist/src-mhYy55vF.mjs +0 -539
- package/dist/web/assets/index-kuPpbPut.js +0 -2300
- package/dist/web/assets/index-sZpVl70Z.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@better-auth/api-key@1.7.
|
|
1
|
+
@better-auth/api-key@1.7.12
|
|
2
2
|
LICENSE.md
|
|
3
3
|
The MIT License (MIT)
|
|
4
4
|
Copyright (c) 2024 - present, Bereket Engida
|
|
@@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
@better-auth/cimd@1.7.
|
|
27
|
+
@better-auth/cimd@1.7.12
|
|
28
28
|
LICENSE.md
|
|
29
29
|
The MIT License (MIT)
|
|
30
30
|
Copyright (c) 2024 - present, Bereket Engida
|
|
@@ -50,7 +50,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
50
50
|
|
|
51
51
|
---
|
|
52
52
|
|
|
53
|
-
@better-auth/core@1.7.
|
|
53
|
+
@better-auth/core@1.7.12
|
|
54
54
|
LICENSE.md
|
|
55
55
|
The MIT License (MIT)
|
|
56
56
|
Copyright (c) 2024 - present, Bereket Engida
|
|
@@ -76,7 +76,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
76
76
|
|
|
77
77
|
---
|
|
78
78
|
|
|
79
|
-
@better-auth/kysely-adapter@1.7.
|
|
79
|
+
@better-auth/kysely-adapter@1.7.12
|
|
80
80
|
LICENSE.md
|
|
81
81
|
The MIT License (MIT)
|
|
82
82
|
Copyright (c) 2024 - present, Bereket Engida
|
|
@@ -102,7 +102,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
102
102
|
|
|
103
103
|
---
|
|
104
104
|
|
|
105
|
-
@better-auth/memory-adapter@1.7.
|
|
105
|
+
@better-auth/memory-adapter@1.7.12
|
|
106
106
|
LICENSE.md
|
|
107
107
|
The MIT License (MIT)
|
|
108
108
|
Copyright (c) 2024 - present, Bereket Engida
|
|
@@ -128,7 +128,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
128
128
|
|
|
129
129
|
---
|
|
130
130
|
|
|
131
|
-
@better-auth/oauth-provider@1.7.
|
|
131
|
+
@better-auth/oauth-provider@1.7.12
|
|
132
132
|
LICENSE.md
|
|
133
133
|
The MIT License (MIT)
|
|
134
134
|
Copyright (c) 2024 - present, Bereket Engida
|
|
@@ -154,7 +154,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
154
154
|
|
|
155
155
|
---
|
|
156
156
|
|
|
157
|
-
@better-auth/telemetry@1.7.
|
|
157
|
+
@better-auth/telemetry@1.7.12
|
|
158
158
|
LICENSE.md
|
|
159
159
|
The MIT License (MIT)
|
|
160
160
|
Copyright (c) 2024 - present, Bereket Engida
|
|
@@ -367,7 +367,7 @@ SOFTWARE.
|
|
|
367
367
|
|
|
368
368
|
---
|
|
369
369
|
|
|
370
|
-
@gjermundgaraba/effect-actions@0.
|
|
370
|
+
@gjermundgaraba/effect-actions@0.19.0
|
|
371
371
|
LICENSE
|
|
372
372
|
MIT License
|
|
373
373
|
|
|
@@ -652,213 +652,6 @@ LICENSE
|
|
|
652
652
|
limitations under the License.
|
|
653
653
|
|
|
654
654
|
|
|
655
|
-
---
|
|
656
|
-
|
|
657
|
-
@opentelemetry/semantic-conventions@1.43.0
|
|
658
|
-
LICENSE
|
|
659
|
-
Apache License
|
|
660
|
-
Version 2.0, January 2004
|
|
661
|
-
http://www.apache.org/licenses/
|
|
662
|
-
|
|
663
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
664
|
-
|
|
665
|
-
1. Definitions.
|
|
666
|
-
|
|
667
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
668
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
669
|
-
|
|
670
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
671
|
-
the copyright owner that is granting the License.
|
|
672
|
-
|
|
673
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
674
|
-
other entities that control, are controlled by, or are under common
|
|
675
|
-
control with that entity. For the purposes of this definition,
|
|
676
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
677
|
-
direction or management of such entity, whether by contract or
|
|
678
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
679
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
680
|
-
|
|
681
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
682
|
-
exercising permissions granted by this License.
|
|
683
|
-
|
|
684
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
685
|
-
including but not limited to software source code, documentation
|
|
686
|
-
source, and configuration files.
|
|
687
|
-
|
|
688
|
-
"Object" form shall mean any form resulting from mechanical
|
|
689
|
-
transformation or translation of a Source form, including but
|
|
690
|
-
not limited to compiled object code, generated documentation,
|
|
691
|
-
and conversions to other media types.
|
|
692
|
-
|
|
693
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
694
|
-
Object form, made available under the License, as indicated by a
|
|
695
|
-
copyright notice that is included in or attached to the work
|
|
696
|
-
(an example is provided in the Appendix below).
|
|
697
|
-
|
|
698
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
699
|
-
form, that is based on (or derived from) the Work and for which the
|
|
700
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
701
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
702
|
-
of this License, Derivative Works shall not include works that remain
|
|
703
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
704
|
-
the Work and Derivative Works thereof.
|
|
705
|
-
|
|
706
|
-
"Contribution" shall mean any work of authorship, including
|
|
707
|
-
the original version of the Work and any modifications or additions
|
|
708
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
709
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
710
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
711
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
712
|
-
means any form of electronic, verbal, or written communication sent
|
|
713
|
-
to the Licensor or its representatives, including but not limited to
|
|
714
|
-
communication on electronic mailing lists, source code control systems,
|
|
715
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
716
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
717
|
-
excluding communication that is conspicuously marked or otherwise
|
|
718
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
719
|
-
|
|
720
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
721
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
722
|
-
subsequently incorporated within the Work.
|
|
723
|
-
|
|
724
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
725
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
726
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
727
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
728
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
729
|
-
Work and such Derivative Works in Source or Object form.
|
|
730
|
-
|
|
731
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
732
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
733
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
734
|
-
(except as stated in this section) patent license to make, have made,
|
|
735
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
736
|
-
where such license applies only to those patent claims licensable
|
|
737
|
-
by such Contributor that are necessarily infringed by their
|
|
738
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
739
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
740
|
-
institute patent litigation against any entity (including a
|
|
741
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
742
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
743
|
-
or contributory patent infringement, then any patent licenses
|
|
744
|
-
granted to You under this License for that Work shall terminate
|
|
745
|
-
as of the date such litigation is filed.
|
|
746
|
-
|
|
747
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
748
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
749
|
-
modifications, and in Source or Object form, provided that You
|
|
750
|
-
meet the following conditions:
|
|
751
|
-
|
|
752
|
-
(a) You must give any other recipients of the Work or
|
|
753
|
-
Derivative Works a copy of this License; and
|
|
754
|
-
|
|
755
|
-
(b) You must cause any modified files to carry prominent notices
|
|
756
|
-
stating that You changed the files; and
|
|
757
|
-
|
|
758
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
759
|
-
that You distribute, all copyright, patent, trademark, and
|
|
760
|
-
attribution notices from the Source form of the Work,
|
|
761
|
-
excluding those notices that do not pertain to any part of
|
|
762
|
-
the Derivative Works; and
|
|
763
|
-
|
|
764
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
765
|
-
distribution, then any Derivative Works that You distribute must
|
|
766
|
-
include a readable copy of the attribution notices contained
|
|
767
|
-
within such NOTICE file, excluding those notices that do not
|
|
768
|
-
pertain to any part of the Derivative Works, in at least one
|
|
769
|
-
of the following places: within a NOTICE text file distributed
|
|
770
|
-
as part of the Derivative Works; within the Source form or
|
|
771
|
-
documentation, if provided along with the Derivative Works; or,
|
|
772
|
-
within a display generated by the Derivative Works, if and
|
|
773
|
-
wherever such third-party notices normally appear. The contents
|
|
774
|
-
of the NOTICE file are for informational purposes only and
|
|
775
|
-
do not modify the License. You may add Your own attribution
|
|
776
|
-
notices within Derivative Works that You distribute, alongside
|
|
777
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
778
|
-
that such additional attribution notices cannot be construed
|
|
779
|
-
as modifying the License.
|
|
780
|
-
|
|
781
|
-
You may add Your own copyright statement to Your modifications and
|
|
782
|
-
may provide additional or different license terms and conditions
|
|
783
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
784
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
785
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
786
|
-
the conditions stated in this License.
|
|
787
|
-
|
|
788
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
789
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
790
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
791
|
-
this License, without any additional terms or conditions.
|
|
792
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
793
|
-
the terms of any separate license agreement you may have executed
|
|
794
|
-
with Licensor regarding such Contributions.
|
|
795
|
-
|
|
796
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
797
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
798
|
-
except as required for reasonable and customary use in describing the
|
|
799
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
800
|
-
|
|
801
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
802
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
803
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
804
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
805
|
-
implied, including, without limitation, any warranties or conditions
|
|
806
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
807
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
808
|
-
appropriateness of using or redistributing the Work and assume any
|
|
809
|
-
risks associated with Your exercise of permissions under this License.
|
|
810
|
-
|
|
811
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
812
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
813
|
-
unless required by applicable law (such as deliberate and grossly
|
|
814
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
815
|
-
liable to You for damages, including any direct, indirect, special,
|
|
816
|
-
incidental, or consequential damages of any character arising as a
|
|
817
|
-
result of this License or out of the use or inability to use the
|
|
818
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
819
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
820
|
-
other commercial damages or losses), even if such Contributor
|
|
821
|
-
has been advised of the possibility of such damages.
|
|
822
|
-
|
|
823
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
824
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
825
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
826
|
-
or other liability obligations and/or rights consistent with this
|
|
827
|
-
License. However, in accepting such obligations, You may act only
|
|
828
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
829
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
830
|
-
defend, and hold each Contributor harmless for any liability
|
|
831
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
832
|
-
of your accepting any such warranty or additional liability.
|
|
833
|
-
|
|
834
|
-
END OF TERMS AND CONDITIONS
|
|
835
|
-
|
|
836
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
837
|
-
|
|
838
|
-
To apply the Apache License to your work, attach the following
|
|
839
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
840
|
-
replaced with your own identifying information. (Don't include
|
|
841
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
842
|
-
comment syntax for the file format. We also recommend that a
|
|
843
|
-
file or class name and description of purpose be included on the
|
|
844
|
-
same "printed page" as the copyright notice for easier
|
|
845
|
-
identification within third-party archives.
|
|
846
|
-
|
|
847
|
-
Copyright [yyyy] [name of copyright owner]
|
|
848
|
-
|
|
849
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
850
|
-
you may not use this file except in compliance with the License.
|
|
851
|
-
You may obtain a copy of the License at
|
|
852
|
-
|
|
853
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
854
|
-
|
|
855
|
-
Unless required by applicable law or agreed to in writing, software
|
|
856
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
857
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
858
|
-
See the License for the specific language governing permissions and
|
|
859
|
-
limitations under the License.
|
|
860
|
-
|
|
861
|
-
|
|
862
655
|
---
|
|
863
656
|
|
|
864
657
|
@redis/bloom@6.2.1
|
|
@@ -1090,7 +883,7 @@ No separate license file is shipped by this package. Published metadata:
|
|
|
1090
883
|
|
|
1091
884
|
---
|
|
1092
885
|
|
|
1093
|
-
better-auth@1.7.
|
|
886
|
+
better-auth@1.7.12
|
|
1094
887
|
LICENSE.md
|
|
1095
888
|
The MIT License (MIT)
|
|
1096
889
|
Copyright (c) 2024 - present, Bereket Engida
|
|
@@ -1116,7 +909,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
1116
909
|
|
|
1117
910
|
---
|
|
1118
911
|
|
|
1119
|
-
better-call@1.4.
|
|
912
|
+
better-call@1.4.4
|
|
1120
913
|
LICENSE
|
|
1121
914
|
MIT License
|
|
1122
915
|
|
|
@@ -1216,7 +1009,7 @@ SOFTWARE.
|
|
|
1216
1009
|
|
|
1217
1010
|
---
|
|
1218
1011
|
|
|
1219
|
-
jose@6.2.
|
|
1012
|
+
jose@6.2.13
|
|
1220
1013
|
LICENSE.md
|
|
1221
1014
|
The MIT License (MIT)
|
|
1222
1015
|
|
|
@@ -1243,7 +1036,7 @@ SOFTWARE.
|
|
|
1243
1036
|
|
|
1244
1037
|
---
|
|
1245
1038
|
|
|
1246
|
-
kysely@0.29.
|
|
1039
|
+
kysely@0.29.7
|
|
1247
1040
|
LICENSE
|
|
1248
1041
|
The MIT License (MIT)
|
|
1249
1042
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{N as e}from"./schemas-
|
|
1
|
+
import{N as e}from"./schemas-lRZfTY17.mjs";function t(e){return{success:!1,error:`You are not allowed to access resource: ${e}`}}function n(e){return{success:!1,error:`unauthorized to access resource "${e}"`}}function r(e){return e===`OR`?`OR`:`AND`}function i(e){return Array.isArray(e)}function a(t){if(i(t))return{actions:t,connector:`AND`};if(!t||typeof t!=`object`)throw new e(`Invalid access control request`);let{actions:n,connector:a}=t;return i(n)?{actions:n,connector:r(a)}:{actions:[],connector:r(a)}}function o(e,t){return typeof t==`string`&&e.includes(t)}function s(e,{actions:t,connector:n}){return t.length===0?!1:n===`OR`?t.some(t=>o(e,t)):t.every(t=>o(e,t))}function c(e){return{authorize(r,i=`AND`){let o=!1;for(let[c,l]of Object.entries(r)){let r=e[c];if(!r){if(i===`AND`)return t(c);continue}let u=s(r,a(l));if(u&&(o=!0),u&&i===`OR`)return{success:!0};if(!u&&i===`AND`)return n(c)}return o?{success:!0}:{success:!1,error:`Not authorized`}},statements:e}}function l(e){return{newRole(e){return c(e)},statements:e}}export{c as n,l as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{N as e}from"./get-id-field-DvYh1rwM.mjs";import{t}from"./factory-Cf28yuX6.mjs";function n(e,t){return typeof e==`string`&&typeof t==`string`?e.toLowerCase()===t.toLowerCase():e===t}function r(e,t){return typeof e==`string`?t.some(t=>typeof t==`string`&&e.toLowerCase()===t.toLowerCase()):t.includes(e)}function i(e,t){return!r(e,t)}function a(e,t){return typeof e!=`string`||typeof t!=`string`?!1:e.toLowerCase().includes(t.toLowerCase())}function o(e,t){return typeof e!=`string`||typeof t!=`string`?!1:e.toLowerCase().startsWith(t.toLowerCase())}function s(e,t){return typeof e!=`string`||typeof t!=`string`?!1:e.toLowerCase().endsWith(t.toLowerCase())}function c(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.set(n.id,n);return t}function l(e,t,n){let r=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(n)]);for(let i of r){if(!(i in n)){delete e[i];continue}let r=c(t[i]??[]),a=n[i]??[],o=c(a),s=e[i]??[],l=[],d=/* @__PURE__ */ new Set;for(let e of s){let t=e.id,n=r.get(t),i=o.get(t);(n===void 0||i!==void 0)&&(i!==void 0&&u(n,i)?l.push(i):l.push(e),d.add(t))}for(let e of a)!r.has(e.id)&&!d.has(e.id)&&l.push(e);e[i]=l}}function u(e,t){return e===void 0||JSON.stringify(e)!==JSON.stringify(t)}const d=(c,u)=>{let d=null,f=c=>t({config:{adapterId:`memory`,adapterName:`Memory Adapter`,usePlural:!1,debugLogs:u?.debugLogs||!1,supportsArrays:!0,customTransformInput(e){return e.options.advanced?.database?.generateId===`serial`&&e.field===`id`&&e.action===`create`?c[e.model].length+1:e.data},transaction:async e=>{let t=structuredClone(c),n=structuredClone(c),r=await e(f(n)(d));return l(c,t,n),r}},adapter:({getFieldName:t,getDefaultFieldName:l,options:u})=>{let d=(e,n,r)=>n?e.sort((e,i)=>{let a=t({model:r,field:n.field}),o=e[a],s=i[a],c=0;return c=o==null&&s==null?0:o==null?-1:s==null?1:typeof o==`string`&&typeof s==`string`?o.localeCompare(s):o instanceof Date&&s instanceof Date?o.getTime()-s.getTime():typeof o==`number`&&typeof s==`number`?o-s:typeof o==`boolean`&&typeof s==`boolean`?o===s?0:o?1:-1:String(o).localeCompare(String(s)),n.direction===`asc`?c:-c}):e;function f(t,u,d,f,p){let m=(()=>{let f=c[u];if(!f)throw e.error(`[MemoryAdapter] Model ${u} not found in the DB`,Object.keys(c)),Error(`Model ${u} not found`);let m=(e,t)=>{let{field:c,value:l,operator:u,mode:d=`sensitive`}=t,f=d===`insensitive`&&(typeof l==`string`||Array.isArray(l)&&l.every(e=>typeof e==`string`));switch(u){case`in`:if(!Array.isArray(l))throw Error(`Value must be an array`);return f?r(e[c],l):l.includes(e[c]);case`not_in`:if(!Array.isArray(l))throw Error(`Value must be an array`);return f?i(e[c],l):!l.includes(e[c]);case`contains`:return f?a(e[c],l):e[c]?.includes(l);case`starts_with`:return f?o(e[c],l):e[c].startsWith(l);case`ends_with`:return f?s(e[c],l):e[c].endsWith(l);case`ne`:return f?!n(e[c],l):e[c]!==l;case`gt`:return l!=null&&e[c]>l;case`gte`:return l!=null&&e[c]>=l;case`lt`:return l!=null&&e[c]<l;case`lte`:return l!=null&&e[c]<=l;default:return f?n(e[c],l):l===null?e[c]==null:e[c]===l}},h=f.filter(e=>{if(!t.length||t.length===0)return!0;let n=m(e,t[0]);for(let r of t){let t=m(e,r);r.connector===`OR`?n||=t:n&&=t}return n});return p?.length&&p.length>0&&(h=h.map(e=>Object.fromEntries(Object.entries(e).filter(([e])=>p.includes(l({model:d,field:e})))))),h})();if(!f)return m;let h=/* @__PURE__ */ new Map,g=/* @__PURE__ */ new Map;for(let t of m){let n=String(t.id);if(!h.has(n)){let e={...t};for(let[t,r]of Object.entries(f)){let i=t;r.relation===`one-to-one`?e[i]=null:(e[i]=[],g.set(`${n}-${t}`,/* @__PURE__ */ new Set))}h.set(n,e)}let r=h.get(n);for(let[i,a]of Object.entries(f)){let o=i,s=c[o];if(!s)throw e.error(`[MemoryAdapter] JoinOption model ${o} not found in the DB`,Object.keys(c)),Error(`JoinOption model ${o} not found`);let l=s.filter(e=>e[a.on.to]===t[a.on.from]);if(a.relation===`one-to-one`)r[o]=l[0]||null;else{let e=g.get(`${n}-${i}`),t=a.limit??100,s=0;for(let n of l){if(s>=t)break;e.has(n.id)||(r[o].push(n),e.add(n.id),s++)}}}}return Array.from(h.values())}return{create:async({model:e,data:t})=>(u.advanced?.database?.generateId===`serial`&&(t.id=c[e].length+1),c[e]||(c[e]=[]),c[e].push(t),t),findOne:async({model:e,modelKey:t=e,where:n,select:r,join:i})=>{let a=f(n,e,t,i,r);if(i){let e=a;return e.length?e[0]:null}return a[0]||null},findMany:async({model:e,modelKey:t=e,where:n,sortBy:r,limit:i,select:a,offset:o,join:s})=>{let c=f(n||[],e,t,s,a);if(s){let e=c;if(!e.length)return[];d(e,r,t);let n=e;return o!==void 0&&(n=n.slice(o)),i!==void 0&&(n=n.slice(0,i)),n}let l=d(c,r,t);return o!==void 0&&(l=l.slice(o)),i!==void 0&&(l=l.slice(0,i)),l||[]},count:async({model:e,modelKey:t=e,where:n})=>n?f(n,e,t).length:c[e].length,update:async({model:e,modelKey:t=e,where:n,update:r})=>{if(n.length===0)return null;let i=f(n,e,t);return i.forEach(e=>{Object.assign(e,r)}),i[0]||null},delete:async({model:e,modelKey:t=e,where:n})=>{if(n.length===0)return;let r=c[e],i=f(n,e,t);c[e]=r.filter(e=>!i.includes(e))},deleteMany:async({model:e,modelKey:t=e,where:n})=>{let r=c[e],i=f(n,e,t),a=0;return c[e]=r.filter(e=>i.includes(e)?(a++,!1):!i.includes(e)),a},consumeOne:async({model:e,modelKey:t=e,where:n})=>{let r=c[e],i=f(n,e,t)[0];return i?(c[e]=r.filter(e=>e!==i),i):null},incrementOne:async({model:e,modelKey:t=e,where:n,increment:r,set:i})=>{let a=f(n,e,t)[0];if(!a)return null;for(let[e,t]of Object.entries(r))a[e]=(typeof a[e]==`number`?a[e]:0)+t;return i&&Object.assign(a,i),a},updateMany:async({model:e,modelKey:t=e,where:n,update:r})=>{let i=f(n,e,t);return i.forEach(e=>{Object.assign(e,r)}),i.length}}}}),p=f(c);return e=>(d=e,p(e))};export{d as memoryAdapter};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as f,M as p,N as m,O as h,P as g,Q as _,R as ee,S as v,T as y,U as b,V as te,W as x,X as ne,Y as re,Z as ie,_ as ae,b as S,c as C,d as oe,et as se,f as w,g as ce,h as le,i as ue,it as T,j as de,k as fe,l as E,m as pe,nt as D,p as O,q as k,rt as me,s as he,tt as A,u as j,v as ge,w as _e,x as ve,y as ye,z as be}from"./sqlite-introspector-DSCAP82F-CISODKY3.mjs";import{t as M}from"./compiled-query-C8AL3JwF.mjs";import{n as xe,r as Se,t as Ce}from"./sqlite-adapter-CS5jtB3L.mjs";import{N as we}from"./get-id-field-DvYh1rwM.mjs";import{N as Te}from"./schemas-lRZfTY17.mjs";import{c as Ee,i as De,n as Oe,t as ke,u as Ae}from"./schema-check-DYtufmXq.mjs";import{t as je}from"./factory-Cf28yuX6.mjs";const N=k({is(e){return e.kind===`AlterTableNode`},create(e){return k({kind:`AlterTableNode`,table:e})},cloneWithTableProps(e,t){return k({...e,...t})},cloneWithColumnAlteration(e,t){return k({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}}),P=k({is(e){return e.kind===`CreateIndexNode`},create(e){return k({kind:`CreateIndexNode`,name:d.create(e)})},cloneWith(e,t){return k({...e,...t})},cloneWithColumns(e,t){return k({...e,columns:[...e.columns||[],...t]})}}),Me=k({is(e){return e.kind===`CreateSchemaNode`},create(e,t){return k({kind:`CreateSchemaNode`,schema:d.create(e),...t})},cloneWith(e,t){return k({...e,...t})}}),F=k({is(e){return e.kind===`DropIndexNode`},create(e,t){return k({kind:`DropIndexNode`,name:b.create(e),...t})},cloneWith(e,t){return k({...e,...t})}}),Ne=k({is(e){return e.kind===`DropSchemaNode`},create(e,t){return k({kind:`DropSchemaNode`,schema:d.create(e),...t})},cloneWith(e,t){return k({...e,...t})}}),Pe=k({is(e){return e.kind===`DropTableNode`},create(e,t){return k({kind:`DropTableNode`,table:e,...t})},cloneWith(e,t){return k({...e,...t})}}),Fe=k({is(e){return e.kind===`AddColumnNode`},create(e){return k({kind:`AddColumnNode`,column:e})}}),I=k({is(e){return e.kind===`ColumnDefinitionNode`},create(e,t){return k({kind:`ColumnDefinitionNode`,column:n.create(e),dataType:t})},cloneWithFrontModifier(e,t){return k({...e,frontModifiers:e.frontModifiers?k([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return k({...e,endModifiers:e.endModifiers?k([...e.endModifiers,t]):[t]})},cloneWith(e,t){return k({...e,...t})}}),Ie=k({is(e){return e.kind===`DropColumnNode`},create(e){return k({kind:`DropColumnNode`,column:n.create(e)})},cloneWith(e,t){return k({...e,...t})}}),Le=k({is(e){return e.kind===`RenameColumnNode`},create(e,t){return k({kind:`RenameColumnNode`,column:n.create(e),renameTo:n.create(t)})}}),Re=k({is(e){return e.kind===`CheckConstraintNode`},create(e,t){return k({kind:`CheckConstraintNode`,expression:e,name:t?d.create(t):void 0})}}),ze=k({cascade:!0,"no action":!0,restrict:!0,"set default":!0,"set null":!0});Object.keys(ze);const Be=k({is(e){return e.kind===`ReferencesNode`},create(e,t){return k({kind:`ReferencesNode`,table:e,columns:k([...t])})},cloneWithOnDelete(e,t){return k({...e,onDelete:t})},cloneWithOnUpdate(e,t){return k({...e,onUpdate:t})}});function Ve(e){return D(e)&&ze[e]}function He(e){return te(e)?e.toOperationNode():t.createImmediate(e)}const L=k({is(e){return e.kind===`GeneratedNode`},create(e){return k({kind:`GeneratedNode`,...e})},createWithExpression(e){return k({kind:`GeneratedNode`,always:!0,expression:e})},cloneWith(e,t){return k({...e,...t})}}),Ue=k({is(e){return e.kind===`DefaultValueNode`},create(e){return k({kind:`DefaultValueNode`,defaultValue:e})}});function R(e){if(Ve(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}var z=class e{#e;constructor(e){this.#e=e}autoIncrement(){return new e(I.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new e(I.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new e(I.cloneWith(this.#e,{primaryKey:!0}))}references(t){let n=g(t);if(!n.table||be.is(n.column))throw Error(`invalid call references('${t}'). The reference must have format table.column or schema.table.column`);return new e(I.cloneWith(this.#e,{references:Be.create(n.table,[n.column])}))}onDelete(t){if(!this.#e.references)throw Error(`on delete constraint can only be added for foreign keys`);return new e(I.cloneWith(this.#e,{references:Be.cloneWithOnDelete(this.#e.references,R(t))}))}onUpdate(t){if(!this.#e.references)throw Error(`on update constraint can only be added for foreign keys`);return new e(I.cloneWith(this.#e,{references:Be.cloneWithOnUpdate(this.#e.references,R(t))}))}unique(){return new e(I.cloneWith(this.#e,{unique:!0}))}notNull(){return new e(I.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new e(I.cloneWith(this.#e,{unsigned:!0}))}defaultTo(t){return new e(I.cloneWith(this.#e,{defaultTo:Ue.create(He(t))}))}check(t){return new e(I.cloneWith(this.#e,{check:Re.create(t.toOperationNode())}))}generatedAlwaysAs(t){return new e(I.cloneWith(this.#e,{generated:L.createWithExpression(t.toOperationNode())}))}generatedAlwaysAsIdentity(){return new e(I.cloneWith(this.#e,{generated:L.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new e(I.cloneWith(this.#e,{generated:L.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error(`stored() can only be called after generatedAlwaysAs`);return new e(I.cloneWith(this.#e,{generated:L.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(t){return new e(I.cloneWithFrontModifier(this.#e,t.toOperationNode()))}nullsNotDistinct(){return new e(I.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new e(I.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(t){return new e(I.cloneWithEndModifier(this.#e,t.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};const We=k({is(e){return e.kind===`ModifyColumnNode`},create(e){return k({kind:`ModifyColumnNode`,column:e})}}),B=k({is(e){return e.kind===`ForeignKeyConstraintNode`},create(e,t,n,r){return k({kind:`ForeignKeyConstraintNode`,columns:e,references:Be.create(t,n),name:r?d.create(r):void 0})},cloneWith(e,t){return k({...e,...t})}});var Ge=class e{#e;constructor(e){this.#e=e}onDelete(t){return new e(B.cloneWith(this.#e,{onDelete:R(t)}))}onUpdate(t){return new e(B.cloneWith(this.#e,{onUpdate:R(t)}))}deferrable(){return new e(B.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(B.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(B.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(B.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};const V=k({is(e){return e.kind===`AddConstraintNode`},create(e){return k({kind:`AddConstraintNode`,constraint:e})}}),H=k({is(e){return e.kind===`UniqueConstraintNode`},create(e,t,r){return D(e.at(0))&&(o("`UniqueConstraintNode.create(columns: string[], ...)` is deprecated - pass `ColumnNode[]` instead."),e=e.map(n.create)),k({kind:`UniqueConstraintNode`,columns:k(e),name:t?d.create(t):void 0,nullsNotDistinct:r})},cloneWith(e,t){return k({...e,...t})}}),Ke=k({is(e){return e.kind===`DropConstraintNode`},create(e){return k({kind:`DropConstraintNode`,constraintName:d.create(e)})},cloneWith(e,t){return k({...e,...t})}}),U=k({is(e){return e.kind===`AlterColumnNode`},create(e,t,r){return k({kind:`AlterColumnNode`,column:n.create(e),[t]:r})}});var qe=class{#e;constructor(e){this.#e=e}setDataType(e){return new W(U.create(this.#e,`dataType`,O(e)))}setDefault(e){return new W(U.create(this.#e,`setDefault`,He(e)))}dropDefault(){return new W(U.create(this.#e,`dropDefault`,!0))}setNotNull(){return new W(U.create(this.#e,`setNotNull`,!0))}dropNotNull(){return new W(U.create(this.#e,`dropNotNull`,!0))}$call(e){return e(this)}},W=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}},G=class{#e;constructor(e){this.#e=k(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Je=class e{#e;constructor(e){this.#e=k(e)}onDelete(t){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(t)})}onUpdate(t){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(t)})}deferrable(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(N.cloneWithTableProps(this.#e.node,{addConstraint:V.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Ye=class e{#e;constructor(e){this.#e=k(e)}ifExists(){return new e({...this.#e,node:N.cloneWithTableProps(this.#e.node,{dropConstraint:Ke.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new e({...this.#e,node:N.cloneWithTableProps(this.#e.node,{dropConstraint:Ke.cloneWith(this.#e.node.dropConstraint,{modifier:`cascade`})})})}restrict(){return new e({...this.#e,node:N.cloneWithTableProps(this.#e.node,{dropConstraint:Ke.cloneWith(this.#e.node.dropConstraint,{modifier:`restrict`})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};const K=k({is(e){return e.kind===`PrimaryKeyConstraintNode`},create(e,t){return k({kind:`PrimaryKeyConstraintNode`,columns:k(e.map(n.create)),name:t?d.create(t):void 0})},cloneWith(e,t){return k({...e,...t})}}),q=k({is(e){return e.kind===`AddIndexNode`},create(e){return k({kind:`AddIndexNode`,name:d.create(e)})},cloneWith(e,t){return k({...e,...t})},cloneWithColumns(e,t){return k({...e,columns:[...e.columns||[],...t]})}});var Xe=class e{#e;constructor(e){this.#e=k(e)}unique(){return new e({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(t){return new e({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,[D(t)?m(t):t.toOperationNode()])})})}columns(t){return new e({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,t.map(e=>D(e)?m(e):e.toOperationNode()))})})}expression(t){return new e({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,[t.toOperationNode()])})})}using(t){return new e({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWith(this.#e.node.addIndex,{using:l.createWithSql(t)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Ze=class e{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new e(H.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new e(H.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(H.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(H.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(H.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},Qe=class e{#e;constructor(e){this.#e=e}deferrable(){return new e(K.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(K.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(K.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(K.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},$e=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}};const et=k({is(e){return e.kind===`RenameConstraintNode`},create(e,t){return k({kind:`RenameConstraintNode`,oldName:d.create(e),newName:d.create(t)})}});var tt=class e{#e;constructor(e){this.#e=k({...e})}ifExists(){return new e({...this.#e,node:Ie.cloneWith(this.#e.node,{ifExists:!0})})}toOperationNode(){return this.#e.node}},nt=class{#e;constructor(e){this.#e=k(e)}renameTo(e){return new G({...this.#e,node:N.cloneWithTableProps(this.#e.node,{renameTo:j(e)})})}setSchema(e){return new G({...this.#e,node:N.cloneWithTableProps(this.#e.node,{setSchema:d.create(e)})})}alterColumn(e,t){let n=t(new qe(e));return new J({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}dropColumn(e,t=T){let n=t(new tt({node:Ie.create(e)}));return new J({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}renameColumn(e,t){return new J({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,Le.create(e,t))})}addColumn(e,t,n=T){let r=n(new z(I.create(e,O(t))));return new J({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,Fe.create(r.toOperationNode()))})}modifyColumn(e,t,n=T){let r=n(new z(I.create(e,O(t))));return new J({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,We.create(r.toOperationNode()))})}addUniqueConstraint(e,t,r=T){let i=r(new Ze(H.create(t.map(e=>D(e)?n.create(e):w(e)),e)));return new G({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addConstraint:V.create(i.toOperationNode())})})}addCheckConstraint(e,t,n=T){let r=n(new $e(Re.create(t.toOperationNode(),e)));return new G({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addConstraint:V.create(r.toOperationNode())})})}addForeignKeyConstraint(e,t,r,i,a=T){let o=a(new Ge(B.create(t.map(n.create),j(r),i.map(n.create),e)));return new Je({...this.#e,constraintBuilder:o})}addPrimaryKeyConstraint(e,t,n=T){let r=n(new Qe(K.create(t,e)));return new G({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addConstraint:V.create(r.toOperationNode())})})}dropConstraint(e){return new Ye({...this.#e,node:N.cloneWithTableProps(this.#e.node,{dropConstraint:Ke.create(e)})})}renameConstraint(e,t){return new Ye({...this.#e,node:N.cloneWithTableProps(this.#e.node,{renameConstraint:et.create(e,t)})})}addIndex(e){return new Xe({...this.#e,node:N.cloneWithTableProps(this.#e.node,{addIndex:q.create(e)})})}dropIndex(e){return new G({...this.#e,node:N.cloneWithTableProps(this.#e.node,{dropIndex:F.create(e)})})}$call(e){return e(this)}},J=class e{#e;constructor(e){this.#e=k(e)}alterColumn(t,n){let r=n(new qe(t));return new e({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(t,n=T){let r=n(new tt({node:Ie.create(t)}));return new e({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}renameColumn(t,n){return new e({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,Le.create(t,n))})}addColumn(t,n,r=T){let i=r(new z(I.create(t,O(n))));return new e({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,Fe.create(i.toOperationNode()))})}modifyColumn(t,n,r=T){let i=r(new z(I.create(t,O(n))));return new e({...this.#e,node:N.cloneWithColumnAlteration(this.#e.node,We.create(i.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},rt=class extends _e{transformPrimitiveValueList(e){return de.create(e.values.map(t.createImmediate))}transformValue(e){return t.createImmediate(e.value)}},it=class e{#e;constructor(e){this.#e=k(e)}ifNotExists(){return new e({...this.#e,node:P.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new e({...this.#e,node:P.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new e({...this.#e,node:P.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(t){return new e({...this.#e,node:P.cloneWith(this.#e.node,{table:j(t)})})}column(t){return new e({...this.#e,node:P.cloneWithColumns(this.#e.node,[D(t)?m(t):t.toOperationNode()])})}columns(t){return new e({...this.#e,node:P.cloneWithColumns(this.#e.node,t.map(e=>D(e)?m(e):e.toOperationNode()))})}expression(t){return new e({...this.#e,node:P.cloneWithColumns(this.#e.node,[t.toOperationNode()])})}using(t){return new e({...this.#e,node:P.cloneWith(this.#e.node,{using:l.createWithSql(t)})})}where(...t){let n=new rt;return new e({...this.#e,node:h.cloneWithWhere(this.#e.node,n.transformNode(fe(t),this.#e.queryId))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},at=class e{#e;constructor(e){this.#e=k(e)}ifNotExists(){return new e({...this.#e,node:Me.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};function ot(e){if(s.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}var st=class e{#e;constructor(e){this.#e=e}using(t){return new e(q.cloneWith(this.#e,{using:l.createWithSql(t)}))}$call(e){return e(this)}toOperationNode(){return this.#e}},ct=class e{#e;constructor(e){this.#e=k(e)}temporary(){return new e({...this.#e,node:x.cloneWith(this.#e.node,{temporary:!0})})}onCommit(t){return new e({...this.#e,node:x.cloneWith(this.#e.node,{onCommit:ot(t)})})}ifNotExists(){return new e({...this.#e,node:x.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(t,n,r=T){let i=r(new z(I.create(t,O(n))));return new e({...this.#e,node:x.cloneWithColumn(this.#e.node,i.toOperationNode())})}addPrimaryKeyConstraint(t,n,r=T){let i=r(new Qe(K.create(n,t)));return new e({...this.#e,node:x.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addUniqueConstraint(t,r,i=T){let a=i(new Ze(H.create(r.map(e=>D(e)?n.create(e):w(e)),t)));return new e({...this.#e,node:x.cloneWithConstraint(this.#e.node,a.toOperationNode())})}addIndex(t,r,i=T){let a=i(new st(q.cloneWithColumns(q.create(t),r.map(e=>D(e)?n.create(e):w(e)))));return new e({...this.#e,node:x.cloneWithIndex(this.#e.node,a.toOperationNode())})}addCheckConstraint(t,n,r=T){let i=r(new $e(Re.create(n.toOperationNode(),t)));return new e({...this.#e,node:x.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addForeignKeyConstraint(t,r,i,a,o=T){let s=o(new Ge(B.create(r.map(n.create),j(i),a.map(n.create),t)));return new e({...this.#e,node:x.cloneWithConstraint(this.#e.node,s.toOperationNode())})}modifyFront(t){return new e({...this.#e,node:x.cloneWithFrontModifier(this.#e.node,t.toOperationNode())})}modifyEnd(t){return new e({...this.#e,node:x.cloneWithEndModifier(this.#e.node,t.toOperationNode())})}as(t){return new e({...this.#e,node:x.cloneWith(this.#e.node,{selectQuery:w(t)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},lt=class e{#e;constructor(e){this.#e=k(e)}on(t){return new e({...this.#e,node:F.cloneWith(this.#e.node,{table:j(t)})})}ifExists(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},ut=class e{#e;constructor(e){this.#e=k(e)}ifExists(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},dt=class e{#e;constructor(e){this.#e=k(e)}temporary(){return new e({...this.#e,node:Pe.cloneWith(this.#e.node,{temporary:!0})})}ifExists(){return new e({...this.#e,node:Pe.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:Pe.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},ft=class{#e=new rt;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}},pt=class e{#e;constructor(e){this.#e=k(e)}temporary(){return new e({...this.#e,node:E.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new e({...this.#e,node:E.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new e({...this.#e,node:E.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new e({...this.#e,node:E.cloneWith(this.#e.node,{orReplace:!0})})}columns(t){return new e({...this.#e,node:E.cloneWith(this.#e.node,{columns:t.map(p)})})}as(t){let n=t.withPlugin(new ft).toOperationNode();return new e({...this.#e,node:E.cloneWith(this.#e.node,{as:n})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};const mt=k({is(e){return e.kind===`DropViewNode`},create(e){return k({kind:`DropViewNode`,name:b.create(e)})},cloneWith(e,t){return k({...e,...t})}});var ht=class e{#e;constructor(e){this.#e=k(e)}materialized(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};const gt=k({is(e){return e.kind===`CreateTypeNode`},create(e){return k({kind:`CreateTypeNode`,name:e})},cloneWithEnum(e,n){return k({...e,enum:de.create(n.map(t.createImmediate))})}});var _t=class e{#e;constructor(e){this.#e=k(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(t){return new e({...this.#e,node:gt.cloneWithEnum(this.#e.node,t)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};const vt=k({is(e){return e.kind===`DropTypeNode`},create(e){return Array.isArray(e)||(e=[e]),k({kind:`DropTypeNode`,name:e[0],additionalNames:e.slice(1)})},cloneWith(e,t){return k({...e,...t})}});var yt=class e{#e;constructor(e){this.#e=k(e)}ifExists(){return new e({...this.#e,node:vt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:vt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};function bt(e){if(e.includes(`.`)){let t=e.split(`.`).map(St);if(t.length===2)return b.createWithSchema(t[0],t[1]);throw Error(`invalid schemable identifier ${e}`)}return b.create(e)}function xt(e){return Array.isArray(e)||(e=[e]),e.map(bt)}function St(e){return e.trim()}const Ct=k({is(e){return e.kind===`RefreshMaterializedViewNode`},create(e){return k({kind:`RefreshMaterializedViewNode`,name:b.create(e)})},cloneWith(e,t){return k({...e,...t})}});var wt=class e{#e;constructor(e){this.#e=k(e)}concurrently(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};const Y=k({is(e){return e.kind===`AlterTypeNode`},create(e){return k({kind:`AlterTypeNode`,name:e})},cloneWith(e,t){return k({...e,...t})}}),Tt=k({is(e){return e.kind===`AddValueNode`},create(e){return k({kind:`AddValueNode`,value:e})},cloneWith(e,t){return k({...e,...t})}});var Et=class{#e;constructor(e){this.#e=k(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){return await this.#e.executor.executeQuery(this.compile(),e)}},Dt,Ot=class extends Et{#e;constructor(e){super(e),this.#e=e}ifNotExists(){return new Dt({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.cloneWith(this.#e.node.addValue,{ifNotExists:!0})})})}before(e){return this.#t(e,!0)}after(e){return this.#t(e,!1)}#t(e,n){return new Dt({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.cloneWith(this.#e.node.addValue,{isBefore:n,neighborValue:t.createImmediate(e)})})})}};Dt=Ot;const kt=k({is(e){return e.kind===`RenameValueNode`},create(e,t){return k({kind:`RenameValueNode`,oldValue:e,newValue:t})}});var At=class{#e;constructor(e){this.#e=k(e)}addValue(e){return new Ot({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.create(t.createImmediate(e))})})}renameTo(e){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{renameTo:d.create(e)})})}renameValue(e,n){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{renameValue:kt.create(t.createImmediate(e),t.createImmediate(n))})})}setSchema(e){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{setSchema:d.create(e)})})}},jt=class e{#e;constructor(e){this.#e=e}createTable(e){return new ct({queryId:y(),executor:this.#e,node:x.create(j(e))})}dropTable(e){return new dt({queryId:y(),executor:this.#e,node:Pe.create(j(e))})}createIndex(e){return new it({queryId:y(),executor:this.#e,node:P.create(e)})}dropIndex(e){return new lt({queryId:y(),executor:this.#e,node:F.create(e)})}createSchema(e){return new at({queryId:y(),executor:this.#e,node:Me.create(e)})}dropSchema(e){return new ut({queryId:y(),executor:this.#e,node:Ne.create(e)})}alterTable(e){return new nt({queryId:y(),executor:this.#e,node:N.create(j(e))})}createView(e){return new pt({queryId:y(),executor:this.#e,node:E.create(e)})}refreshMaterializedView(e){return new wt({queryId:y(),executor:this.#e,node:Ct.create(e)})}dropView(e){return new ht({queryId:y(),executor:this.#e,node:mt.create(e)})}createType(e){return new _t({queryId:y(),executor:this.#e,node:gt.create(bt(e))})}alterType(e){return new At({executor:this.#e,node:Y.create(bt(e)),queryId:y()})}dropType(e){return new yt({queryId:y(),executor:this.#e,node:vt.create(xt(e))})}withPlugin(t){return new e(this.#e.withPlugin(t))}withoutPlugins(){return new e(this.#e.withoutPlugins())}withSchema(t){return new e(this.#e.withPluginAtFront(new r(t)))}},Mt=class{ref(e){return new f(e)}table(e){return new oe(e)}},Nt=class{#e;constructor(e){this.#e=e}async provideConnection(e,t){let n=await this.#e.acquireConnection(t);try{return await e(n)}finally{await this.#e.releaseConnection(n,t)}}},Pt=class e extends ge{#e;#t;#n;constructor(e,t,n,r=[]){super(r),this.#e=e,this.#t=t,this.#n=n}get adapter(){return this.#t}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e,t){return this.#n.provideConnection(e,t)}withPlugins(t){return new e(this.#e,this.#t,this.#n,[...this.plugins,...t])}withPlugin(t){return new e(this.#e,this.#t,this.#n,[...this.plugins,t])}withPluginAtFront(t){return new e(this.#e,this.#t,this.#n,[t,...this.plugins])}withConnectionProvider(t){return new e(this.#e,this.#t,t,[...this.plugins])}withoutPlugins(){return new e(this.#e,this.#t,this.#n,[])}};function Ft(){return typeof performance<`u`&&_(performance.now)?performance.now():Date.now()}var It=class{#e;#t;async obtainLock(){for(;this.#e;)await this.#e;this.#e=new Promise(e=>{this.#t=e})}releaseLock(){let e=this.#t;this.#e=void 0,this.#t=void 0,e?.()}},Lt=class{#e;#t;#n;#r;#i;#a=/* @__PURE__ */ new WeakSet;#o;constructor(e,t,n){this.#e=e,this.#r=!1,this.#t=n,t.supportsMultipleConnections===!1&&(this.#o=new It)}async init(e){if(this.#i)throw Error(`driver has already been destroyed`);this.#n??=this.#e.init(e).then(()=>{this.#r=!0}).catch(e=>{throw this.#n=void 0,e}),await S(this.#n,e?.signal,`init`)}async acquireConnection(e){if(this.#i)throw Error(`driver has already been destroyed`);if(this.#r||await this.init(e),this.#o){let t=this.#o.obtainLock();await S(t,e?.signal,`acquireConnection:mutex`,()=>t.then(()=>this.#o?.releaseLock()))}let t=this.#e.acquireConnection(e),n=await S(t,e?.signal,`acquireConnection:acquire`,()=>t?.then(e=>this.releaseConnection(e).catch(ye(`driver.releaseConnection`))).catch(ye(`driver.acquireConnection`)));return this.#a.has(n)||(this.#s()&&this.#c(n),this.#a.add(n)),n}async releaseConnection(e,t){await this.#e.releaseConnection(e,t),this.#o?.releaseLock()}async beginTransaction(e,t){return await this.#e.beginTransaction(e,t)}async commitTransaction(e){return await this.#e.commitTransaction(e)}async rollbackTransaction(e){return await this.#e.rollbackTransaction(e)}async savepoint(e,t,n){if(this.#e.savepoint)return await this.#e.savepoint(e,t,n);throw Error("The `savepoint` method is not supported by this driver")}async rollbackToSavepoint(e,t,n){if(this.#e.rollbackToSavepoint)return await this.#e.rollbackToSavepoint(e,t,n);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}async releaseSavepoint(e,t,n){if(this.#e.releaseSavepoint)return await this.#e.releaseSavepoint(e,t,n);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(e){this.#n&&(await S(this.#n,e?.signal,`destroy:initPromise`),this.#i??=this.#e.destroy(e).catch(e=>{throw this.#i=void 0,e}),await S(this.#i,e?.signal,`destroy`))}#s(){return this.#t.isLevelEnabled(`query`)||this.#t.isLevelEnabled(`error`)}#c(e){let t=e.executeQuery,n=e.streamQuery,r=this;e.executeQuery=async(n,i)=>{let a,o=Ft();try{return await t.call(e,n,i)}catch(e){throw a=e,await r.#l(e,n,o),e}finally{a||await r.#u(n,o)}},e.streamQuery=async function*(t,i,a){let o,s=Ft();try{for await(let r of n.call(e,t,i,a))yield r}catch(e){throw o=e,await r.#l(e,t,s),e}finally{o||await r.#u(t,s,!0)}}}async#l(e,t,n){await this.#t.error(()=>({level:`error`,error:e,query:t,queryDurationMillis:this.#d(n)}))}async#u(e,t,n=!1){await this.#t.query(()=>({level:`query`,isStream:n,query:e,queryDurationMillis:this.#d(t)}))}#d(e){return Ft()-e}};const Rt=()=>{};var zt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(Rt);return this.#t=this.#n(e).finally(()=>{this.#t=void 0}),this.#t}async#n(e){return await e(this.#e)}};const Bt=[`read only`,`read write`],Vt=[`read uncommitted`,`read committed`,`repeatable read`,`serializable`,`snapshot`];function Ht(e){if(e.accessMode&&!Bt.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!Vt.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}k([`query`,`error`]);var Ut=class{#e;#t;constructor(e){_(e)?(this.#t=e,this.#e=k({query:!0,error:!0})):(this.#t=Wt,this.#e=k({query:e.includes(`query`),error:e.includes(`error`)}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#t(e())}async error(e){this.#e.error&&await this.#t(e())}};function Wt(e){if(e.level===`query`){let t=`kysely:query:${e.isStream?`stream:`:``}`;console.log(`${t} ${e.query.sql}`),console.log(`${t} duration: ${e.queryDurationMillis.toFixed(1)}ms`)}else e.level===`error`&&(e.error instanceof Error?console.error(`kysely:error: ${e.error.stack??e.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:e.error,query:e.query.sql,queryDurationMillis:e.queryDurationMillis})}`))}function Gt(e){return A(e)&&_(e.compile)}Symbol.asyncDispose??=Symbol(`Symbol.asyncDispose`);var X=class e extends ae{#e;constructor(e){let t,n;if(qt(e))t={executor:e.executor},n={...e};else{let r=e.dialect,i=r.createDriver(),a=r.createQueryCompiler(),o=r.createAdapter(),s=new Lt(i,o,new Ut(e.log??[])),c=new Pt(a,o,new Nt(s),e.plugins??[]);t={executor:c},n={config:e,executor:c,dialect:r,driver:s}}super(t),this.#e=k(n)}get schema(){return new jt(this.#e.executor)}get dynamic(){return new Mt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new pe({node:le.create(me(e)?void 0:w(e))})}get fn(){return ce()}transaction(){return new Yt({...this.#e})}startTransaction(){return new Xt({...this.#e})}connection(){return new Jt({...this.#e})}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new r(t))})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}withTables(){return this.$extendTables()}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}async executeQuery(e,t){let n=Gt(e)?e.compile():e;return await this.#e.executor.executeQuery(n,t)}async[Symbol.asyncDispose](){await this.destroy()}},Kt=class e extends X{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw Error(`calling the transaction method for a Transaction is not supported`)}startTransaction(){throw Error(`calling the controlled transaction method for a Transaction is not supported`)}connection(){throw Error(`calling the connection method for a Transaction is not supported`)}destroy(){throw Error(`calling the destroy method for a Transaction is not supported`)}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new r(t))})}withTables(){return new e({...this.#e})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}};function qt(e){return A(e)&&A(e.config)&&A(e.driver)&&A(e.executor)&&A(e.dialect)}var Jt=class{#e;constructor(e){this.#e=k(e)}async execute(e,t){return this.#e.executor.provideConnection(async t=>{let n=this.#e.executor.withConnectionProvider(new zt(t));return await e(new X({...this.#e,executor:n}))},k({signal:t?.signal}))}},Yt=class e{#e;constructor(e){this.#e=k(e)}setAccessMode(t){return new e({...this.#e,accessMode:t})}setIsolationLevel(t){return new e({...this.#e,isolationLevel:t})}async execute(e){let{isolationLevel:t,accessMode:n,...r}=this.#e,i={isolationLevel:t,accessMode:n};return Ht(i),this.#e.executor.provideConnection(async t=>{let n={isCommitted:!1,isRolledBack:!1},a=new $t(this.#e.executor.withConnectionProvider(new zt(t)),n),o=new Kt({...r,executor:a}),s=!1;try{await this.#e.driver.beginTransaction(t,i),s=!0;let r=await e(o);return await this.#e.driver.commitTransaction(t),n.isCommitted=!0,r}catch(e){throw s&&(await this.#e.driver.rollbackTransaction(t),n.isRolledBack=!0),e}})}},Xt=class e{#e;constructor(e){this.#e=k(e)}setAccessMode(t){return new e({...this.#e,accessMode:t})}setIsolationLevel(t){return new e({...this.#e,isolationLevel:t})}async execute(){let{isolationLevel:e,accessMode:t,...n}=this.#e,r={isolationLevel:e,accessMode:t};Ht(r);let i=await ve(this.#e.executor);try{await this.#e.driver.beginTransaction(i.connection,r)}catch(e){throw i.release(),e}return new Zt({...n,connection:i,state:{isCommitted:!1,isRolledBack:!1},executor:this.#e.executor.withConnectionProvider(new zt(i.connection))})}},Zt=class e extends Kt{#e;#t;constructor(e){e={...e,executor:new $t(e.executor,e.state)};let{connection:t,state:n,...r}=e;super(r),this.#e=k(e);let i=y();this.#t=t=>e.executor.compileQuery(t,i)}get isCommitted(){return this.#e.state.isCommitted}get isRolledBack(){return this.#e.state.isRolledBack}commit(){return new Z(async()=>{await this.#e.executor.provideConnection(async e=>{await this.#e.driver.commitTransaction(e),this.#e.state.isCommitted=!0,this.#e.connection.release()})})}rollback(){return new Z(async()=>{await this.#e.executor.provideConnection(async e=>{try{await this.#e.driver.rollbackTransaction(e)}finally{this.#e.state.isRolledBack=!0,this.#e.connection.release()}})})}savepoint(t){return new Z(async()=>(await this.#e.executor.provideConnection(async e=>{await this.#e.driver.savepoint?.(e,t,this.#t)}),new e({...this.#e})))}rollbackToSavepoint(t){return new Z(async()=>(await this.#e.executor.provideConnection(async e=>{await this.#e.driver.rollbackToSavepoint?.(e,t,this.#t)}),new e({...this.#e})))}releaseSavepoint(t){return new Z(async()=>(await this.#e.executor.provideConnection(async e=>{await this.#e.driver.releaseSavepoint?.(e,t,this.#t)}),new e({...this.#e})))}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new r(t))})}withTables(){return new e({...this.#e})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}},Z=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function Qt(e){if(e.isCommitted)throw Error(`Transaction is already committed`);if(e.isRolledBack)throw Error(`Transaction is already rolled back`)}var $t=class e{#e;#t;constructor(t,n){this.#e=t instanceof e?t.#e:t,this.#t=n}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,t){return this.#e.transformQuery(e,t)}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e,t){return Qt(this.#t),this.#e.provideConnection(async t=>(Qt(this.#t),await e(t)),t)}executeQuery(e,t){return Qt(this.#t),this.#e.withConnectionProvider(this).executeQuery(e,t)}stream(e,t,n){return Qt(this.#t),this.#e.withConnectionProvider(this).stream(e,t,n)}withConnectionProvider(t){return new e(this.#e.withConnectionProvider(t),this.#t)}withPlugin(t){return new e(this.#e.withPlugin(t),this.#t)}withPlugins(t){return new e(this.#e.withPlugins(t),this.#t)}withPluginAtFront(t){return new e(this.#e.withPluginAtFront(t),this.#t)}withoutPlugins(){return new e(this.#e.withoutPlugins(),this.#t)}};function Q(e,t){return l.createWithChildren([l.createWithSql(`${e} `),d.create(t)])}var en=class{#e;#t;#n;constructor(e){this.#e=k({...e})}async init(e){this.#t=_(this.#e.database)?await this.#e.database(e):this.#e.database,this.#n=new tn(this.#t),this.#e.onCreateConnection&&await this.#e.onCreateConnection(this.#n,e)}async acquireConnection(){return this.#n}async beginTransaction(e){await e.executeQuery(M.raw(`begin`))}async commitTransaction(e){await e.executeQuery(M.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(M.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),y()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),y()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release`,t),y()))}async releaseConnection(){}async destroy(){this.#t?.close()}},tn=class{#e;constructor(e){this.#e=e}async executeQuery(e){let{sql:t,parameters:n}=e,r=this.#e.prepare(t);if(r.reader)return{rows:r.all(n)};let{changes:i,lastInsertRowid:a}=r.run(n);return{insertId:a==null?void 0:BigInt(a),numAffectedRows:i==null?void 0:BigInt(i),rows:[]}}async*streamQuery(e,t){let{sql:n,parameters:r,query:a}=e,o=this.#e.prepare(n);if(!i.is(a))throw Error(`Sqlite driver only supports streaming of select queries`);let s=o.iterate(r);for(let e of s)yield{rows:[e]}}};const $=`kysely_migration`,nn=`kysely_migration_lock`;k({__noMigrations__:!0});var rn=class{#e;constructor(e){this.#e=e}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){return await this.#n(e)}#t(e,t){let n=e.selectFrom(`sqlite_master`).where(`type`,`in`,[`table`,`view`]).where(`name`,`not like`,`sqlite_%`).select([`name`,`sql`,`type`]).orderBy(`name`);return t.withInternalKyselyTables||(n=n.where(`name`,`!=`,$).where(`name`,`!=`,nn)),n}async#n(e){let t=await this.#t(this.#e,e).execute(),n=await this.#e.with(`table_list`,t=>this.#t(t,e)).selectFrom([`table_list as tl`,C`pragma_table_info(tl.name)`.as(`p`)]).select([`tl.name as table`,`p.cid`,`p.name`,`p.type`,`p.notnull`,`p.dflt_value`,`p.pk`]).orderBy(`tl.name`).orderBy(`p.cid`).execute(),r={};for(let e of n)r[e.table]??=[],r[e.table].push(e);return t.map(({name:e,sql:t,type:n})=>{let i=t?.split(/[\(\),]/)?.find(e=>e.toLowerCase().includes(`autoincrement`))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,``),a=r[e]??[];if(!i){let e=a.filter(e=>e.pk>0);e.length===1&&e[0].type.toLowerCase()===`integer`&&(i=e[0].name)}return{name:e,isView:n===`view`,isForeign:!1,columns:a.map(e=>({name:e.name,dataType:e.type,isNullable:!e.notnull,isAutoIncrementing:e.name===i,hasDefaultValue:e.dflt_value!=null,comment:void 0}))}})}},an=class{#e;constructor(e){this.#e=k({...e})}createDriver(){return new en(this.#e)}createQueryCompiler(){return new xe}createAdapter(){return new Ce}createIntrospector(e){return new rn(e)}};function on(e,t){if(sn(e)&&t.stack){let n=t.stack.split(`
|
|
2
|
+
`).slice(1).join(`
|
|
3
|
+
`);return e.stack+=`\n${n}`,e}return e}function sn(e){return A(e)&&D(e.stack)}const cn=Symbol();var ln=class{#e;#t=/* @__PURE__ */ new WeakMap;#n;constructor(e){this.#e=k({...e})}async init(e){this.#n=_(this.#e.pool)?await this.#e.pool(e):this.#e.pool}async acquireConnection(e){let t=await this.#r(),n=this.#t.get(t);return n||(n=new dn(t,this.#e.controlConnection),this.#t.set(t,n),this.#e?.onCreateConnection&&await this.#e.onCreateConnection(n,e)),this.#e?.onReserveConnection&&await this.#e.onReserveConnection(n,e),n}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let n=[];t.isolationLevel&&n.push(`isolation level ${t.isolationLevel}`),t.accessMode&&n.push(t.accessMode);let r=`set transaction ${n.join(`, `)}`;await e.executeQuery(M.raw(r))}await e.executeQuery(M.raw(`begin`))}async commitTransaction(e){await e.executeQuery(M.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(M.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),y()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),y()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release savepoint`,t),y()))}async releaseConnection(e){e[cn]()}async destroy(){return new Promise((e,t)=>{this.#n.end(n=>{n?t(n):e()})})}async#r(){return new Promise((e,t)=>{this.#n.getConnection(async(n,r)=>{n?t(n):e(r)})})}};function un(e){return A(e)&&`insertId`in e&&`affectedRows`in e}var dn=class{#e;#t;#n;#r;constructor(e,t){this.#e=e,this.#t=t}async cancelQuery(e){await this.#a(`kill query ${this.#n}`,e)}async collectSessionInfo(){if(this.#n)return;let{threadId:e}=this.#e;if(e!=null)this.#n=e;else{let[{cid:e}]=await this.#i(M.raw(`select connection_id() as cid`));this.#n=Number(e)}}async executeQuery(e){try{this.#r=e.queryId;let t=await this.#i(e);if(!un(t))return{rows:Array.isArray(t)?t:[]};let{insertId:n,affectedRows:r,changedRows:i}=t;return{insertId:n!=null&&n.toString()!==`0`?BigInt(n):void 0,numAffectedRows:r==null?void 0:BigInt(r),numChangedRows:i==null?void 0:BigInt(i),rows:[]}}catch(e){throw on(e,/* @__PURE__ */ Error())}finally{this.#r=void 0}}async killSession(e){try{this.#e.destroy()}catch{}await this.#a(`kill connection ${this.#n}`,e)}async*streamQuery(e,t){this.#r=e.queryId;let n=this.#e.query(e.sql,e.parameters).stream({objectMode:!0});try{for await(let e of n)yield{rows:[e]}}catch(e){if(A(e)&&`code`in e&&e.code===`ERR_STREAM_PREMATURE_CLOSE`)return;throw e}finally{this.#r=void 0}}[cn](){this.#e.release()}#i(e){return new Promise((t,n)=>{this.#e.query(e.sql,e.parameters,(e,r)=>{e?n(e):t(r)})})}async#a(e,t){if(!this.#r)return;let{config:n}=this.#e,r=this.#r;if(!this.#t||!n)return await t(async t=>{r.queryId===this.#r?.queryId&&await t.executeQuery(M.raw(e,[]))});let{clientFlags:i,maxPacketSize:a,...o}=n,s=this.#t(o);try{await new Promise((t,n)=>{s.connect(i=>{if(i)return n(i);if(r.queryId!==this.#r?.queryId)return t();s.query(e,[],e=>{if(e)return n(e);t()})})})}finally{s.destroy()}}};const fn=/[\\']/g,pn=/`/g,mn=/[\\'"]/g;var hn=class extends he{getCurrentParameterPlaceholder(){return`?`}getLeftExplainOptionsWrapper(){return``}getExplainOptionAssignment(){return`=`}getExplainOptionsDelimiter(){return` `}getRightExplainOptionsWrapper(){return``}getLeftIdentifierWrapper(){return pn.source}getRightIdentifierWrapper(){return pn.source}sanitizeIdentifier(e){return e.replace(pn,"``")}sanitizeStringLiteral(e){return e.replace(fn,e=>e===`\\`?`\\\\`:`''`)}sanitizeJSONPathMemberValue(e){return e.replace(mn,e=>e===`\\`?`\\\\\\\\`:e===`'`?`''`:`\\\\"`)}visitCreateIndex(e){this.append(`create `),e.unique&&this.append(`unique `),this.append(`index `),e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.name),e.using&&(this.append(` using `),this.visitNode(e.using)),e.table&&(this.append(` on `),this.visitNode(e.table)),e.columns&&(this.append(` (`),this.compileList(e.columns),this.append(`)`)),e.where&&(this.append(` `),this.visitNode(e.where))}},gn=class{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom(`information_schema.schemata`).select(`schema_name`).$castTo().execute()).map(e=>({name:e.SCHEMA_NAME}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom(`information_schema.columns as columns`).innerJoin(`information_schema.tables as tables`,e=>e.onRef(`columns.TABLE_CATALOG`,`=`,`tables.TABLE_CATALOG`).onRef(`columns.TABLE_SCHEMA`,`=`,`tables.TABLE_SCHEMA`).onRef(`columns.TABLE_NAME`,`=`,`tables.TABLE_NAME`)).select([`columns.COLUMN_NAME`,`columns.COLUMN_DEFAULT`,`columns.TABLE_NAME`,`columns.TABLE_SCHEMA`,`tables.TABLE_TYPE`,`tables.ENGINE`,`columns.IS_NULLABLE`,`columns.DATA_TYPE`,`columns.EXTRA`,`columns.COLUMN_COMMENT`]).where(`columns.TABLE_SCHEMA`,`=`,C`database()`).orderBy(`columns.TABLE_NAME`).orderBy(`columns.ORDINAL_POSITION`).$castTo();e.withInternalKyselyTables||(t=t.where(`columns.TABLE_NAME`,`!=`,$).where(`columns.TABLE_NAME`,`!=`,nn));let n=await t.execute();return this.#t(n)}#t(e){return e.reduce((e,t)=>{let n=e.find(e=>e.name===t.TABLE_NAME);return n||(n=k({name:t.TABLE_NAME,isView:t.TABLE_TYPE===`VIEW`,isForeign:t.ENGINE===`FEDERATED`,schema:t.TABLE_SCHEMA,columns:[]}),e.push(n)),n.columns.push(k({name:t.COLUMN_NAME,dataType:t.DATA_TYPE,isNullable:t.IS_NULLABLE===`YES`,isAutoIncrementing:t.EXTRA.toLowerCase().includes(`auto_increment`),hasDefaultValue:t.COLUMN_DEFAULT!==null,comment:t.COLUMN_COMMENT===``?void 0:t.COLUMN_COMMENT})),e},[])}};const _n=`ea586330-2c93-47c8-908d-981d9d270f9d`;var vn=class extends Se{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await C`select get_lock(${C.lit(_n)}, ${C.lit(3600)})`.execute(e)}async releaseMigrationLock(e,t){await C`select release_lock(${C.lit(_n)})`.execute(e)}},yn=class{#e;constructor(e){this.#e=e}createDriver(){return new ln(this.#e)}createQueryCompiler(){return new hn}createAdapter(){return new vn}createIntrospector(e){return new gn(e)}};const bn=Symbol();var xn=class{#e;#t=/* @__PURE__ */ new WeakMap;#n;constructor(e){this.#e=k({...e})}async init(e){this.#n=_(this.#e.pool)?await this.#e.pool(e):this.#e.pool}async acquireConnection(e){let t=await this.#n.connect();if(!this.#n)throw t.release(),Error(`driver has already been destroyed`);let n=this.#t.get(t);return n||(n=new Sn(t,{controlClient:this.#e.controlClient||this.#n.Client,cursor:this.#e.cursor??null,poolOptions:this.#n.options}),this.#t.set(t,n),this.#e.onCreateConnection&&await this.#e.onCreateConnection(n,e)),this.#e.onReserveConnection&&await this.#e.onReserveConnection(n,e),n}async beginTransaction(e,t){let n=`begin`;(t.isolationLevel||t.accessMode)&&(n=`start transaction`,t.isolationLevel&&(n+=` isolation level ${t.isolationLevel}`),t.accessMode&&(n+=` ${t.accessMode}`)),await e.executeQuery(M.raw(n))}async commitTransaction(e){await e.executeQuery(M.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(M.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),y()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),y()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release`,t),y()))}async releaseConnection(e){e[bn]()}async destroy(){if(this.#n){let e=this.#n;this.#n=void 0,await e.end()}}},Sn=class{#e;#t;#n;#r;constructor(e,t){this.#e=e,this.#t=t}async cancelQuery(e){return await this.#i(`select pg_cancel_backend(${this.#r})`,e)}async collectSessionInfo(){if(this.#r)return;let{processID:e}=this.#e;if(e)this.#r=e;else{let{rows:[{pid:e}]}=await this.#e.query(`select pg_backend_pid() as pid`,[]);this.#r=Number(e)}}async executeQuery(e){try{this.#n=e.queryId;let{command:t,rowCount:n,rows:r}=await this.#e.query(e.sql,e.parameters);return{numAffectedRows:t===`INSERT`||t===`UPDATE`||t===`DELETE`||t===`MERGE`?BigInt(n):void 0,rows:r??[]}}catch(e){throw on(e,/* @__PURE__ */ Error())}finally{this.#n=void 0}}async killSession(e){return await this.#i(`select pg_terminate_backend(${this.#r})`,e)}async*streamQuery(e,t){if(!this.#t.cursor)throw Error("`cursor` is not present in your postgres dialect config. It's required to make streaming work in postgres.");this.#n=e.queryId;let n=this.#e.query(new this.#t.cursor(e.sql,e.parameters.slice()));try{for(;;){let e=await n.read(t);if(e.length===0)break;yield{rows:e}}}finally{await n.close(),this.#n=void 0}}[bn](){this.#e.release()}async#i(e,t){if(!this.#n)return;let{controlClient:n,poolOptions:r}=this.#t,i=this.#n;if(!n)return await t(async t=>{i.queryId===this.#n?.queryId&&await t.executeQuery(M.raw(e,[]))});let a=new n({...r,password:`password`in r?r.password:void 0});try{if(await a.connect(),i.queryId!==this.#n.queryId)return;await a.query(e,[])}finally{a.end()}}},Cn=class{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom(`pg_catalog.pg_namespace`).select(`nspname`).$castTo().execute()).map(e=>({name:e.nspname}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom(`pg_catalog.pg_attribute as a`).innerJoin(`pg_catalog.pg_class as c`,`a.attrelid`,`c.oid`).innerJoin(`pg_catalog.pg_namespace as ns`,`c.relnamespace`,`ns.oid`).innerJoin(`pg_catalog.pg_type as typ`,`a.atttypid`,`typ.oid`).innerJoin(`pg_catalog.pg_namespace as dtns`,`typ.typnamespace`,`dtns.oid`).select([`a.attname as column`,`a.attnotnull as not_null`,`a.atthasdef as has_default`,`c.relname as table`,`c.relkind as table_type`,`ns.nspname as schema`,`typ.typname as type`,`dtns.nspname as type_schema`,C`col_description(a.attrelid, a.attnum)`.as(`column_description`),C`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as(`auto_incrementing`)]).where(`c.relkind`,`in`,[`r`,`v`,`p`,`f`]).where(`ns.nspname`,`!~`,`^pg_`).where(`ns.nspname`,`!=`,`information_schema`).where(`ns.nspname`,`!=`,`crdb_internal`).where(C`has_schema_privilege(ns.nspname, 'USAGE')`).where(`a.attnum`,`>=`,0).where(`a.attisdropped`,`!=`,!0).orderBy(`ns.nspname`).orderBy(`c.relname`).orderBy(`a.attnum`).$castTo();e.withInternalKyselyTables||(t=t.where(`c.relname`,`!=`,$).where(`c.relname`,`!=`,nn));let n=await t.execute();return this.#t(n)}#t(e){let t=[],n=/* @__PURE__ */ new Map;for(let r of e){let e=n.get(r.schema);e||(e=/* @__PURE__ */ new Map,n.set(r.schema,e));let i=e.get(r.table);i||(i=k({columns:[],isForeign:r.table_type===`f`,isView:r.table_type===`v`,name:r.table,schema:r.schema}),e.set(r.table,i),t.push(i)),i.columns.push(k({comment:r.column_description??void 0,dataType:r.type,dataTypeSchema:r.type_schema,hasDefaultValue:r.has_default,isAutoIncrementing:r.auto_incrementing!==null,isNullable:!r.not_null,name:r.column}))}return t}};const wn=/"/g;var Tn=class extends he{sanitizeIdentifier(e){return e.replace(wn,`""`)}};const En=BigInt(`3853314791062309107`);var Dn=class extends Se{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,t){await C`
|
|
4
|
+
with set_timeout as (
|
|
5
|
+
select set_config('lock_timeout', '${C.lit(36e5)}', true) as config_val
|
|
6
|
+
)
|
|
7
|
+
select pg_advisory_lock(${C.lit(En)})
|
|
8
|
+
from set_timeout`.execute(e)}async releaseMigrationLock(e,t){await C`select pg_advisory_unlock(${C.lit(En)})`.execute(e)}},On=class{#e;constructor(e){this.#e=e}createDriver(){return new xn(this.#e)}createQueryCompiler(){return new Tn}createAdapter(){return new Dn}createIntrospector(e){return new Cn(e)}},kn=class extends Se{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(e,t){await C`exec sp_getapplock @DbPrincipal = ${C.lit(`dbo`)}, @Resource = ${C.lit($)}, @LockMode = ${C.lit(`Exclusive`)}, @LockOwner = ${C.lit(`Session`)}`.execute(e)}async releaseMigrationLock(e,t){await C`exec sp_releaseapplock @DbPrincipal = ${C.lit(`dbo`)}, @Resource = ${C.lit($)}, @LockOwner = ${C.lit(`Session`)}`.execute(e)}};const An=Symbol(),jn=Symbol(),Mn=Symbol();var Nn=class{#e;#t;constructor(e){this.#e=k({...e});let{tarn:t,tedious:n,validateConnections:r}=this.#e;this.#t=new t.Pool({...t.options,create:async()=>await new Pn(await n.connectionFactory(),n).connect(),destroy:async e=>{await e[jn]()},validate:r===!1?void 0:e=>e[Mn]()})}async init(){}async acquireConnection(){return await this.#t.acquire().promise}async beginTransaction(e,t){await e.beginTransaction(t)}async commitTransaction(e){await e.commitTransaction()}async rollbackTransaction(e){await e.rollbackTransaction()}async savepoint(e,t){await e.savepoint(t)}async rollbackToSavepoint(e,t){await e.rollbackTransaction(t)}async releaseConnection(e){this.#e.resetConnectionsOnRelease&&await e[An](),this.#t.release(e)}async destroy(){await this.#t.destroy()}},Pn=class{#e;#t;#n;#r;constructor(e,t){this.#e=e,this.#t=!1,this.#n=t}async beginTransaction(e){let{isolationLevel:t}=e;await new Promise((e,n)=>this.#e.beginTransaction(t=>{t?n(t):e(void 0)},t?a(8):void 0,t?this.#i(t):void 0))}async cancelQuery(){if(this.#r)return new Promise(e=>{this.#r?.request.once(`requestCompleted`,e),this.#e.cancel()||(this.#r?.request.off(`requestCompleted`,e),e())})}async commitTransaction(){await new Promise((e,t)=>this.#e.commitTransaction(n=>{n?t(n):e(void 0)}))}async connect(){let{promise:e,reject:t,resolve:n}=new v;this.#e.connect(e=>{if(e)return t(e);n()}),this.#e.on(`error`,e=>{e instanceof Error&&`code`in e&&e.code===`ESOCKET`&&(this.#t=!0),console.error(e),t(e)});function r(){t(/* @__PURE__ */ Error(`The connection ended without ever completing the connection`))}return this.#e.once(`end`,r),await e,this.#e.off(`end`,r),this}async executeQuery(e){try{let t=new v;this.#r=new Fn({compiledQuery:e,tedious:this.#n,onDone:t}),this.#e.execSql(this.#r.request);let{rowCount:n,rows:r}=await t.promise;return{numAffectedRows:n===void 0?void 0:BigInt(n),rows:r}}catch(e){throw on(e,/* @__PURE__ */ Error())}finally{this.#r=void 0}}async rollbackTransaction(e){await new Promise((t,n)=>this.#e.rollbackTransaction(e=>{e?n(e):t(void 0)},e))}async savepoint(e){await new Promise((t,n)=>this.#e.saveTransaction(e=>{e?n(e):t(void 0)},e))}async*streamQuery(e,t){this.#r=new Fn({compiledQuery:e,streamChunkSize:t,tedious:this.#n}),this.#e.execSql(this.#r.request);try{for(;;){let e=await this.#r.readChunk();if(e.length===0||(yield{rows:e},e.length<t))break}}finally{await this.cancelQuery(),this.#r=void 0}}#i(e){let{ISOLATION_LEVEL:t}=this.#n,n={"read committed":t.READ_COMMITTED,"read uncommitted":t.READ_UNCOMMITTED,"repeatable read":t.REPEATABLE_READ,serializable:t.SERIALIZABLE,snapshot:t.SNAPSHOT}[e];if(n===void 0)throw Error(`Unknown isolation level: ${e}`);return n}[jn](){return`closed`in this.#e&&this.#e.closed?Promise.resolve():new Promise(e=>{this.#e.once(`end`,e),this.#e.close()})}async[An](){await new Promise((e,t)=>{this.#e.reset(n=>{if(n)return t(n);e()})})}async[Mn](){if(this.#t||this.#a())return!1;try{let e=new v,t=new Fn({compiledQuery:M.raw(`select 1`),onDone:e,tedious:this.#n});return this.#e.execSql(t.request),await e.promise,!0}catch{return!1}}#a(){return`closed`in this.#e&&!!this.#e.closed}},Fn=class{#e;#t;#n;#r;#i;#a;constructor(e){let{compiledQuery:t,onDone:n,streamChunkSize:r,tedious:i}=e;if(this.#t=[],this.#n=r,this.#r={},this.#i=i,n){let e=`onDone`;this.#r[e]=(t,r)=>{if(t!==`chunkReady`){if(delete this.#r[e],t===`error`)return n.reject(r);n.resolve({rowCount:this.#a,rows:this.#t})}}}this.#e=new this.#i.Request(t.sql,(e,t)=>{if(e)return Object.values(this.#r).forEach(t=>t(`error`,e instanceof AggregateError?e.errors:e));this.#a=t}),this.#o(t.parameters),this.#s()}get request(){return this.#e}readChunk(){let e=this.readChunk.name;return new Promise((t,n)=>{this.#r[e]=(r,i)=>{if(delete this.#r[e],r===`error`)return n(i);t(this.#t.splice(0,this.#n))},this.#e.resume()})}#o(e){for(let t=0;t<e.length;t++){let n=e[t];this.#e.addParameter(String(t+1),this.#c(n),n)}}#s(){let e=this.#n?()=>{this.#n<=this.#t.length&&(this.#e.pause(),Object.values(this.#r).forEach(e=>e(`chunkReady`)))}:()=>{},t=t=>{let n={};for(let e of t)n[e.metadata.colName]=e.value;this.#t.push(n),e()};this.#e.on(`row`,t),this.#e.once(`requestCompleted`,()=>{Object.values(this.#r).forEach(e=>e(`completed`)),this.#e.off(`row`,t)})}#c(t){return e(t)||me(t)||D(t)?this.#i.TYPES.NVarChar:u(t)||se(t)&&t%1==0?t<-2147483648||t>2147483647?this.#i.TYPES.BigInt:this.#i.TYPES.Int:se(t)?this.#i.TYPES.Float:re(t)?this.#i.TYPES.Bit:ie(t)?this.#i.TYPES.DateTime:ne(t)?this.#i.TYPES.VarBinary:this.#i.TYPES.NVarChar}},In=class{#e;constructor(e){this.#e=e}async getSchemas(){return await this.#e.selectFrom(`sys.schemas`).select(`name`).execute()}async getTables(e={withInternalKyselyTables:!1}){let t=await this.#e.selectFrom(`sys.tables as tables`).leftJoin(`sys.schemas as table_schemas`,`table_schemas.schema_id`,`tables.schema_id`).innerJoin(`sys.columns as columns`,`columns.object_id`,`tables.object_id`).innerJoin(`sys.types as types`,`types.user_type_id`,`columns.user_type_id`).leftJoin(`sys.schemas as type_schemas`,`type_schemas.schema_id`,`types.schema_id`).leftJoin(`sys.extended_properties as comments`,e=>e.onRef(`comments.major_id`,`=`,`tables.object_id`).onRef(`comments.minor_id`,`=`,`columns.column_id`).on(`comments.name`,`=`,`MS_Description`)).$if(!e.withInternalKyselyTables,e=>e.where(`tables.name`,`!=`,$).where(`tables.name`,`!=`,nn)).select([`tables.name as table_name`,e=>e.ref(`tables.type`).$castTo().as(`table_type`),`table_schemas.name as table_schema_name`,`columns.default_object_id as column_default_object_id`,`columns.generated_always_type_desc as column_generated_always_type`,`columns.is_computed as column_is_computed`,`columns.is_identity as column_is_identity`,`columns.is_nullable as column_is_nullable`,`columns.is_rowguidcol as column_is_rowguidcol`,`columns.name as column_name`,`types.is_nullable as type_is_nullable`,`types.name as type_name`,`type_schemas.name as type_schema_name`,`comments.value as column_comment`]).unionAll(this.#e.selectFrom(`sys.views as views`).leftJoin(`sys.schemas as view_schemas`,`view_schemas.schema_id`,`views.schema_id`).innerJoin(`sys.columns as columns`,`columns.object_id`,`views.object_id`).innerJoin(`sys.types as types`,`types.user_type_id`,`columns.user_type_id`).leftJoin(`sys.schemas as type_schemas`,`type_schemas.schema_id`,`types.schema_id`).leftJoin(`sys.extended_properties as comments`,e=>e.onRef(`comments.major_id`,`=`,`views.object_id`).onRef(`comments.minor_id`,`=`,`columns.column_id`).on(`comments.name`,`=`,`MS_Description`)).select([`views.name as table_name`,`views.type as table_type`,`view_schemas.name as table_schema_name`,`columns.default_object_id as column_default_object_id`,`columns.generated_always_type_desc as column_generated_always_type`,`columns.is_computed as column_is_computed`,`columns.is_identity as column_is_identity`,`columns.is_nullable as column_is_nullable`,`columns.is_rowguidcol as column_is_rowguidcol`,`columns.name as column_name`,`types.is_nullable as type_is_nullable`,`types.name as type_name`,`type_schemas.name as type_schema_name`,`comments.value as column_comment`])).orderBy(`table_schema_name`).orderBy(`table_name`).orderBy(`column_name`).execute(),n={};for(let e of t){let t=`${e.table_schema_name}.${e.table_name}`;(n[t]=n[t]||k({columns:[],isForeign:!1,isView:e.table_type===`V `,name:e.table_name,schema:e.table_schema_name??void 0})).columns.push(k({dataType:e.type_name,dataTypeSchema:e.type_schema_name??void 0,hasDefaultValue:e.column_default_object_id>0||e.column_generated_always_type!==`NOT_APPLICABLE`||e.column_is_identity||e.column_is_computed||e.column_is_rowguidcol,isAutoIncrementing:e.column_is_identity,isNullable:e.column_is_nullable&&e.type_is_nullable,name:e.column_name,comment:e.column_comment??void 0}))}return Object.values(n)}};const Ln=/^[a-z0-9_]$/i;var Rn=class extends he{getCurrentParameterPlaceholder(){return`@${this.numParameters}`}visitOffset(e){super.visitOffset(e),this.append(` rows`)}compileColumnAlterations(e){let t={};for(let n of e)t[n.kind]||(t[n.kind]=[]),t[n.kind].push(n);let n=!0;t.AddColumnNode&&(this.append(`add `),this.compileList(t.AddColumnNode),n=!1),t.AlterColumnNode&&(n||this.append(`, `),this.compileList(t.AlterColumnNode)),t.DropColumnNode&&(n||this.append(`, `),this.append(`drop `),this.compileList(t.DropColumnNode),n=!1),t.ModifyColumnNode&&(n||this.append(`, `),this.compileList(t.ModifyColumnNode)),t.RenameColumnNode&&(n||this.append(`, `),this.compileList(t.RenameColumnNode))}visitAddColumn(e){this.visitNode(e.column)}visitDropColumn(e){this.append(`column `),e.ifExists&&this.append(`if exists `),this.visitNode(e.column)}visitMergeQuery(e){super.visitMergeQuery(e),this.append(`;`)}visitCollate(e){this.append(`collate `);let{name:t}=e.collation;for(let e of t)if(!Ln.test(e))throw Error(`Invalid collation: ${t}`);this.append(t)}announcesNewColumnDataType(){return!1}},zn=class{#e;constructor(e){this.#e=e}createDriver(){return new Nn(this.#e)}createQueryCompiler(){return new Rn}createAdapter(){return new kn}createIntrospector(e){return new In(e)}};function Bn(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Vn(e){if(!e)return null;if(`dialect`in e)return Vn(e.dialect);if(`createDriver`in e){if(e instanceof an)return`sqlite`;if(e instanceof yn)return`mysql`;if(e instanceof On)return`postgres`;if(e instanceof zn)return`mssql`}return`aggregate`in e?`sqlite`:`getConnection`in e?`mysql`:`connect`in e?`postgres`:`fileControl`in e||`open`in e&&`close`in e&&`prepare`in e||`batch`in e&&`exec`in e&&`prepare`in e?`sqlite`:null}function Hn(e,t){if(e!==void 0){if(typeof e!=`string`||e.length===0)throw new Te("`database.schemaName` must be a non-empty schema name.");if(t!==`postgres`)throw new Te(`\`database.schemaName\` is only supported on PostgreSQL, but the configured database type is "${t??`unknown`}".`)}}const Un=async e=>{let t=e.database;if(!t)return{kysely:null,databaseType:null,introspectIndexes:void 0,schemaName:void 0,transaction:void 0};if(`db`in t){let e=t.schemaName;return Hn(e,t.type),{kysely:e?t.db.withSchema(e):t.db,databaseType:t.type,introspectIndexes:void 0,schemaName:e,transaction:t.transaction}}if(`dialect`in t){let e=t.schemaName;Hn(e,t.type);let n=new X({dialect:t.dialect});return{kysely:e?n.withSchema(e):n,databaseType:t.type,introspectIndexes:void 0,schemaName:e,transaction:t.transaction}}let n,r,i,a=Vn(t);if(`createDriver`in t&&(n=t),`aggregate`in t&&!(`createSession`in t)&&(n=new an({database:t}),i=!0),`getConnection`in t&&(n=new yn(t),i=!0),`connect`in t&&(n=new On({pool:t}),i=!0),`fileControl`in t){let{BunSqliteDialect:e}=await import(`./bun-sqlite-dialect-DoOVo4ja-DD-Erl56.mjs`);n=new e({database:t}),i=!0}if(`createSession`in t){let e;try{({DatabaseSync:e}=await import(
|
|
9
|
+
/* @vite-ignore */
|
|
10
|
+
/* webpackIgnore: true */
|
|
11
|
+
`node:sqlite`))}catch(e){if(typeof e==`object`&&e&&`code`in e&&e.code!==`ERR_UNKNOWN_BUILTIN_MODULE`)throw e}if(e&&t instanceof e){let{NodeSqliteDialect:e}=await import(`./src-dv9-ePIU.mjs`).then(e=>e.n);n=new e({database:t}),i=!0}}if(`batch`in t&&`exec`in t&&`prepare`in t){let{createD1IndexIntrospector:e,D1SqliteDialect:a}=await import(`./d1-sqlite-dialect-m0f01-4z-C492fKQn.mjs`);n=new a({database:t}),r=e(t),i=!1}return{kysely:n?new X({dialect:n}):null,databaseType:a,introspectIndexes:r,schemaName:void 0,transaction:i}};function Wn(e,t,n){return n===`postgres`?C`${C.ref(e)} ILIKE ${t}`:C`LOWER(${C.ref(e)}) LIKE LOWER(${t})`}function Gn(e,t){return{lhs:C`LOWER(${C.ref(e)})`,values:t.map(e=>e.toLowerCase())}}function Kn(e,t){return{lhs:C`LOWER(${C.ref(e)})`,values:t.map(e=>e.toLowerCase())}}function qn(e,t){return{lhs:C`LOWER(${C.ref(e)})`,value:t.toLowerCase()}}function Jn(e,t){return{lhs:C`LOWER(${C.ref(e)})`,value:t.toLowerCase()}}function Yn(e){return e.map(e=>({name:e.name,schema:e.schema,columns:e.columns.map(e=>({name:e.name,nullable:e.isNullable,hasDefault:e.hasDefaultValue||e.isAutoIncrementing}))}))}function Xn(e,t){let n={};for(let[r,i]of Object.entries(t)){let t=Object.entries(i.fields),a=Zn(e,r,[i.idColumn??`id`,...t.map(([e])=>e)]),o={};t.forEach(([e,t],n)=>{o[a.columns[n+1]??e]=t}),n[a.table]={...i,fields:o,schema:a.schema??i.schema,...a.columns[0]!==`id`&&{idColumn:a.columns[0]}}}return n}function Zn(e,t,r){let{query:a}=e.selectFrom(t).select(r).compile();if(!i.is(a))return{table:t,columns:[]};let o=a.from?.froms[0],s=o&&c.is(o)?o.table:void 0;return{schema:s?.schema?.name,table:s?.identifier.name??t,columns:(a.selections??[]).map(({selection:e})=>ee.is(e)&&n.is(e.column)?e.column.column.name:void 0)}}async function Qn(e){return(await C`
|
|
12
|
+
SELECT pg_catalog.current_schema() AS schema
|
|
13
|
+
`.execute(e.withoutPlugins())).rows[0]?.schema??`public`}async function $n(e){return(await C`
|
|
14
|
+
SELECT SCHEMA_NAME() AS "schemaName"
|
|
15
|
+
`.execute(e.withoutPlugins())).rows[0]?.schemaName||`dbo`}async function er(e,t){if(t===`postgres`)return(await C`
|
|
16
|
+
SELECT pg_catalog.current_schemas(true)::text[] AS schemas
|
|
17
|
+
`.execute(e.withoutPlugins())).rows[0]?.schemas??[];if(t===`mssql`)return[await $n(e),`dbo`]}async function tr(e,t,n){let r=Xn(e,n);return t===`sqlite`?Ee(r,Yn(await ue(e,Object.entries(r).flatMap(([e,t])=>t.disableMigrations?[]:[e])))):e.connection().execute(async e=>{let n=await er(e,t),i=Yn(await e.introspection.getTables());for(let[e,t]of Object.entries(r))t.schema===void 0&&n&&(t.schema=n.find(t=>i.some(n=>n.name===e&&n.schema===t))??``);return Ee(r,i)})}const nr=(e,t)=>{let n=null,r=!1,i=(e,n=!1)=>({getFieldName:i,schema:a,getDefaultFieldName:o,getDefaultModelName:s,getFieldAttributes:c,getModelName:l,options:u})=>{t?.type===`mysql`&&u.advanced?.database?.generateId===!1&&!r&&(r=!0,we.warn(`[Kysely Adapter] MySQL does not support INSERT...RETURNING. With generateId set to false, the adapter uses best-effort fallback strategies (unique columns, full-field match) to retrieve inserted rows. For reliable behavior, use Better Auth's default ID generation, a custom generateId function, or generateId: "serial" for auto-increment.`));let d=e=>{let t=[],n=[];if(e)for(let[r,i]of Object.entries(e)){let e=a[i.modelKey??s(r)]?.fields,[o,c]=r.includes(`.`)?r.split(`.`):[void 0,r];if(e){e.id={type:`string`};for(let[i,a]of Object.entries(e))t.push(C`${C.ref(`join_${c}`)}.${C.ref(a.fieldName||i)} as ${C.ref(`_joined_${c}_${a.fieldName||i}`)}`),n.push({joinModel:r,joinModelRef:c,fieldName:a.fieldName||i})}}return{allSelectsStr:n,allSelects:t}},f=async(r,o,s,c,l)=>{if(t?.type===`mysql`){if(l.length>0){let t=await o.executeTakeFirst();if(!t||Number(t.numUpdatedRows??0)===0)return null;let n=l.find(e=>e.field===`id`&&(e.operator===void 0||e.operator===`eq`)&&e.connector!==`OR`&&e.value!==void 0&&e.value!==null),a,u;if(r.id!==void 0&&r.id!==null)a=`id`,u=r.id;else if(n)a=`id`,u=n.value;else if(l[0]?.field)a=l[0].field,u=r[a]===void 0?l[0].value:r[a];else return null;return await e.selectFrom(s).selectAll().where(i({model:c,field:a}),u===null?`is`:`=`,u).limit(1).executeTakeFirst()}await o.execute();let t=async e=>{if(r.id)return await e.selectFrom(s).selectAll().where(i({model:c,field:`id`}),`=`,r.id).limit(1).executeTakeFirst();if(u.advanced?.database?.generateId===`serial`){let t=(await C`SELECT LAST_INSERT_ID() as id`.execute(e)).rows[0]?.id;if(t)return await e.selectFrom(s).selectAll().where(i({model:c,field:`id`}),`=`,t).limit(1).executeTakeFirst()}let t=a[c]?.fields;if(t)for(let[n,a]of Object.entries(t)){if(!a.unique)continue;let t=i({model:c,field:n}),o=r[t];if(o==null)continue;let l=await e.selectFrom(s).selectAll().where(t,`=`,o).limit(1).executeTakeFirst();if(l)return l}let n=e.selectFrom(s).selectAll(),o=!1;for(let[e,t]of Object.entries(r))t!==void 0&&(n=n.where(e,t===null?`is`:`=`,t),o=!0);if(o){let e=await n.limit(2).execute();if(e.length===1)return e[0]}return we.warn(`[Kysely Adapter] Unable to safely identify the inserted "${s}" row on MySQL. Enable Better Auth ID generation or use generateId: "serial" for reliable behavior.`),null};return n?t(e):e.transaction().execute(t)}return t?.type===`mssql`?await o.outputAll(`inserted`).executeTakeFirst():await o.returningAll().executeTakeFirst()};function p(e,n,r){if(!r)return{and:null,or:null};let a={and:[],or:[]};return r.forEach(r=>{let{field:o,value:s,operator:c=`eq`,connector:l=`AND`,mode:u=`sensitive`}=r,d=s,f=i({model:n,field:o}),p=u===`insensitive`&&(typeof d==`string`||Array.isArray(d)&&d.every(e=>typeof e==`string`)),m=n=>{let r=`${e}.${f}`;if(c.toLowerCase()===`in`){if(p){let{lhs:e,values:t}=Gn(r,Array.isArray(d)?d:[d]);return n(e,`in`,t)}return n(r,`in`,Array.isArray(d)?d:[d])}if(c.toLowerCase()===`not_in`){if(p){let{lhs:e,values:t}=Kn(r,Array.isArray(d)?d:[d]);return n(e,`not in`,t)}return n(r,`not in`,Array.isArray(d)?d:[d])}if(c===`contains`)return p&&typeof d==`string`?Wn(r,`%${d}%`,t?.type):n(r,`like`,`%${d}%`);if(c===`starts_with`)return p&&typeof d==`string`?Wn(r,`${d}%`,t?.type):n(r,`like`,`${d}%`);if(c===`ends_with`)return p&&typeof d==`string`?Wn(r,`%${d}`,t?.type):n(r,`like`,`%${d}`);if(c===`eq`){if(d===null)return n(r,`is`,null);if(p&&typeof d==`string`){let{lhs:e,value:t}=qn(r,d);return n(e,`=`,t)}return n(r,`=`,d)}if(c===`ne`){if(d===null)return n(r,`is not`,null);if(p&&typeof d==`string`){let{lhs:e,value:t}=Jn(r,d);return n(e,`<>`,t)}return n(r,`<>`,d)}return c===`gt`?n(r,`>`,d):c===`gte`?n(r,`>=`,d):c===`lt`?n(r,`<`,d):c===`lte`?n(r,`<=`,d):n(r,c,d)};l===`OR`?a.or.push(m):a.and.push(m)}),{and:a.and.length?a.and:null,or:a.or.length?a.or:null}}function m(e,t,n){if(!t||!e.length)return e;let r=/* @__PURE__ */ new Map;for(let a of e){let e={},o={};for(let[e]of Object.entries(t))o[e]={};for(let[r,s]of Object.entries(a)){let a=String(r),c=!1;for(let{joinModel:e,fieldName:r,joinModelRef:l}of n)if(a===`_joined_${l}_${r}`||a===`_Joined${Bn(l)}${Bn(r)}`){o[e][i({model:t[e]?.modelKey??e,field:r})]=s,c=!0;break}c||(e[r]=s)}let s=e.id;if(!s)continue;if(!r.has(s)){let n={...e};for(let[e,r]of Object.entries(t))n[e]=r.relation===`one-to-one`?null:[];r.set(s,n)}let c=r.get(s);for(let[e,n]of Object.entries(t)){let t=n.relation===`one-to-one`,r=n.limit??100,a=o[e],s=a&&Object.keys(a).length>0&&Object.values(a).some(e=>e!=null);if(t)c[e]=s?a:null;else{let t=e;if(Array.isArray(c[t])&&s){if(c[t].length>=r)continue;let o=i({model:n.modelKey??e,field:`id`}),s=a[o];s?!c[t].some(e=>e[o]===s)&&c[t].length<r&&c[t].push(a):c[t].length<r&&c[t].push(a)}}}}let a=Array.from(r.values());for(let e of a)for(let[n,r]of Object.entries(t))if(r.relation!==`one-to-one`){let t=n;if(Array.isArray(e[t])){let n=r.limit??100;e[t].length>n&&(e[t]=e[t].slice(0,n))}}return a}return{async create({data:t,model:n,modelKey:r=n}){return await f(t,e.insertInto(n).values(t),n,r,[])},async findOne({model:t,modelKey:n=t,where:r,select:a,join:o}){let{and:s,or:c}=p(t,n,r),l=e.selectFrom(e=>{let r=e.selectFrom(t);return s&&(r=r.where(e=>e.and(s.map(t=>t(e))))),c&&(r=r.where(e=>e.or(c.map(t=>t(e))))),r=a?.length&&a.length>0?r.select(a.map(e=>i({model:n,field:e}))):r.selectAll(),r.as(`primary`)}).selectAll(`primary`);if(o)for(let[e,t]of Object.entries(o)){let[n,r]=e.includes(`.`)?e.split(`.`):[void 0,e];l=l.leftJoin(`${e} as join_${r}`,e=>e.onRef(`join_${r}.${t.on.to}`,`=`,`primary.${t.on.from}`))}let{allSelectsStr:u,allSelects:f}=d(o);l=l.select(f);let h=await l.execute();if(!h||!Array.isArray(h)||h.length===0)return null;let g=h[0];return o?m(h,o,u)[0]:g},async findMany({model:n,modelKey:r=n,where:a,limit:o,select:s,offset:c,sortBy:l,join:u}){let{and:f,or:h}=p(n,r,a),g=e.selectFrom(e=>{let a=e.selectFrom(n);return t?.type===`mssql`?c===void 0?o!==void 0&&(a=a.top(o)):(l||(a=a.orderBy(i({model:r,field:`id`}))),a=a.offset(c).fetch(o||100)):(o!==void 0&&(a=a.limit(o)),c!==void 0&&(a=a.offset(c))),l?.field&&(a=a.orderBy(`${i({model:r,field:l.field})}`,l.direction)),f&&(a=a.where(e=>e.and(f.map(t=>t(e))))),h&&(a=a.where(e=>e.or(h.map(t=>t(e))))),a=s?.length&&s.length>0?a.select(s.map(e=>i({model:r,field:e}))):a.selectAll(),a.as(`primary`)}).selectAll(`primary`);if(u)for(let[e,t]of Object.entries(u)){let[n,r]=e.includes(`.`)?e.split(`.`):[void 0,e];g=g.leftJoin(`${e} as join_${r}`,e=>e.onRef(`join_${r}.${t.on.to}`,`=`,`primary.${t.on.from}`))}let{allSelectsStr:_,allSelects:ee}=d(u);g=g.select(ee),l?.field&&(g=g.orderBy(`${i({model:r,field:l.field})}`,l.direction));let v=await g.execute();return v?u?m(v,u,_):v:[]},async update({model:t,modelKey:n=t,where:r,update:i}){if(r.length===0)return null;let{and:a,or:o}=p(t,n,r),s=e.updateTable(t).set(i);return a&&(s=s.where(e=>e.and(a.map(t=>t(e))))),o&&(s=s.where(e=>e.or(o.map(t=>t(e))))),await f(i,s,t,n,r)},async updateMany({model:t,modelKey:n=t,where:r,update:i}){let{and:a,or:o}=p(t,n,r),s=e.updateTable(t).set(i);a&&(s=s.where(e=>e.and(a.map(t=>t(e))))),o&&(s=s.where(e=>e.or(o.map(t=>t(e)))));let c=(await s.executeTakeFirst()).numUpdatedRows;return c>2**53-1?2**53-1:Number(c)},async count({model:t,modelKey:n=t,where:r}){let{and:i,or:a}=p(t,n,r),o=e.selectFrom(t).select(e.fn.count(`id`).as(`count`));i&&(o=o.where(e=>e.and(i.map(t=>t(e))))),a&&(o=o.where(e=>e.or(a.map(t=>t(e)))));let s=await o.execute();return typeof s[0].count==`number`?s[0].count:typeof s[0].count==`bigint`?Number(s[0].count):parseInt(s[0].count)},async delete({model:t,modelKey:n=t,where:r}){let{and:i,or:a}=p(t,n,r),o=e.deleteFrom(t);i&&(o=o.where(e=>e.and(i.map(t=>t(e))))),a&&(o=o.where(e=>e.or(a.map(t=>t(e))))),await o.execute()},async deleteMany({model:t,modelKey:n=t,where:r}){let{and:i,or:a}=p(t,n,r),o=e.deleteFrom(t);i&&(o=o.where(e=>e.and(i.map(t=>t(e))))),a&&(o=o.where(e=>e.or(a.map(t=>t(e)))));let s=(await o.executeTakeFirst()).numDeletedRows;return s>2**53-1?2**53-1:Number(s)},async consumeOne({model:r,modelKey:a=r,where:o}){let{and:s,or:c}=p(r,a,o),l=e=>(s&&(e=e.where(e=>e.and(s.map(t=>t(e))))),c&&(e=e.where(e=>e.or(c.map(t=>t(e))))),e),u=i({model:a,field:`id`}),d=async(e,n)=>{let i=n[u]??n.id;if(i==null)return null;let a=e.deleteFrom(r).where(`${r}.${u}`,`=`,i);if(t?.type===`mysql`){let e=await a.executeTakeFirst();return Number(e.numDeletedRows)>0?n:null}return t?.type===`mssql`?await a.outputAll(`deleted`).executeTakeFirst()??null:await a.returningAll().executeTakeFirst()??null},f=async e=>t?.type===`mssql`?await e.outputAll(`deleted`).executeTakeFirst()??null:await e.returningAll().executeTakeFirst()??null;if(t?.type===`mysql`){let t=async e=>{let t=await l(e.selectFrom(r).selectAll().forUpdate()).limit(1).executeTakeFirst();return t?d(e,t):null};return n?t(e):e.transaction().execute(t)}let m=l(e.selectFrom(r).select(`${r}.${u}`)),h=t?.type===`mssql`?m.top(1):m.limit(1);return f(l(e.deleteFrom(r).where(`${r}.${u}`,`in`,h)))},async incrementOne({model:r,modelKey:a=r,where:o,increment:s,set:c}){let{and:l,or:u}=p(r,a,o),d=e=>(l&&(e=e.where(e=>e.and(l.map(t=>t(e))))),u&&(e=e.where(e=>e.or(u.map(t=>t(e))))),e),f={...c??{}};for(let[e,t]of Object.entries(s))f[e]=C`${C.ref(e)} + ${t}`;let m=i({model:a,field:`id`});if(t?.type===`mysql`){let t=async e=>{let t=await d(e.selectFrom(r).select(`${r}.${m}`).forUpdate()).limit(1).executeTakeFirst();if(!t)return null;let n=t[m]??t.id;if(n==null)return null;let i=await d(e.updateTable(r).set(f)).where(`${r}.${m}`,`=`,n).executeTakeFirst();return Number(i.numUpdatedRows)===0?null:await e.selectFrom(r).selectAll().where(`${r}.${m}`,`=`,n).limit(1).executeTakeFirst()??null};return n?t(e):e.transaction().execute(t)}let h=d(e.selectFrom(r).select(`${r}.${m}`)),g=t?.type===`mssql`?h.top(1):h.limit(1),_=d(e.updateTable(r).set(f)).where(`${r}.${m}`,`in`,g);return t?.type===`mssql`?await _.outputAll(`inserted`).executeTakeFirst()??null:await _.returningAll().executeTakeFirst()??null},options:t}},a=null;a={config:{adapterId:`kysely`,adapterName:`Kysely Adapter`,usePlural:t?.usePlural,debugLogs:t?.debugLogs,supportsBooleans:!(t?.type===`sqlite`||t?.type===`mssql`||t?.type===`mysql`||!t?.type),supportsDates:!(t?.type===`sqlite`||t?.type===`mssql`||!t?.type),supportsJSON:t?.type===`postgres`,supportsArrays:!1,supportsUUIDs:t?.type===`postgres`,transaction:t?.transaction?t=>e.transaction().execute(e=>t(je({config:{...a.config,transaction:!1},adapter:i(e,!0)})(n))):!1},adapter:i(e)};let o=je(a);return r=>{n=r;let i=o(r);return De(i,Oe(()=>tr(e,t?.type,Ae(r,{usePlural:t?.usePlural})),`database`,r.database),{runtimeEnabled:ke(r)}),i}};export{nr as a,X as c,Qn as i,Vn as n,Yn as o,$n as r,Xn as s,Un as t};
|