@postgres.ai/shared 3.5.1-pr-1027.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/.gitlab-ci.yml +60 -0
  2. package/components/AlertSnackbar/index.tsx +23 -0
  3. package/components/AlertSnackbar/useAlertSnackbar.tsx +65 -0
  4. package/components/Button/index.tsx +79 -0
  5. package/components/Button2/index.tsx +43 -0
  6. package/components/Button2/styles.module.scss +82 -0
  7. package/components/DestroyCloneModal/index.tsx +56 -0
  8. package/components/DestroyCloneRestrictionModal/index.tsx +50 -0
  9. package/components/ErrorStub/index.tsx +83 -0
  10. package/components/FormattedText/index.tsx +44 -0
  11. package/components/FormattedText/styles.module.scss +34 -0
  12. package/components/GatewayLink/index.tsx +33 -0
  13. package/components/HorizontalScrollContainer/index.tsx +131 -0
  14. package/components/HorizontalScrollContainer/types.ts +12 -0
  15. package/components/HorizontalScrollContainer/utils.ts +16 -0
  16. package/components/ImportantText/index.tsx +29 -0
  17. package/components/Link2/index.tsx +31 -0
  18. package/components/Link2/styles.module.scss +12 -0
  19. package/components/MenuButton/index.tsx +80 -0
  20. package/components/MenuButton/styles.module.scss +42 -0
  21. package/components/Modal/index.tsx +93 -0
  22. package/components/PageSpinner/index.tsx +18 -0
  23. package/components/PageSpinner/styles.module.scss +13 -0
  24. package/components/ResetCloneModal/index.tsx +154 -0
  25. package/components/SectionTitle/index.tsx +74 -0
  26. package/components/Select/index.tsx +42 -0
  27. package/components/SimpleModalControls/index.tsx +56 -0
  28. package/components/Spinner/icon.tsx +29 -0
  29. package/components/Spinner/index.tsx +16 -0
  30. package/components/Spinner/styles.module.scss +33 -0
  31. package/components/Status/index.tsx +61 -0
  32. package/components/Status/styles.module.scss +45 -0
  33. package/components/StubContainer/index.tsx +41 -0
  34. package/components/StubSpinner/index.tsx +49 -0
  35. package/components/StubSpinnerFlex/index.tsx +20 -0
  36. package/components/StubSpinnerFlex/styles.module.scss +20 -0
  37. package/components/SyntaxHighlight/index.tsx +107 -0
  38. package/components/Table/RowMenu/index.tsx +111 -0
  39. package/components/Table/index.tsx +140 -0
  40. package/components/Text/index.tsx +28 -0
  41. package/components/TextField/index.tsx +117 -0
  42. package/components/Tooltip/index.tsx +52 -0
  43. package/config/index.ts +32 -0
  44. package/config/links.ts +6 -0
  45. package/craco.config.js +80 -0
  46. package/helpers/getEntropy.ts +232 -0
  47. package/helpers/localStorage.ts +15 -0
  48. package/helpers/request.ts +47 -0
  49. package/hooks/useWindowDimensions.ts +16 -0
  50. package/icons/ArrowDropDown/index.tsx +29 -0
  51. package/icons/Circle/index.tsx +27 -0
  52. package/icons/External/index.tsx +14 -0
  53. package/icons/Info/index.tsx +12 -0
  54. package/icons/Renewable/index.tsx +65 -0
  55. package/icons/Shield/index.tsx +33 -0
  56. package/icons/Warning/index.tsx +29 -0
  57. package/meta.json +1 -0
  58. package/package.json +55 -0
  59. package/pages/Clone/Status/index.tsx +73 -0
  60. package/pages/Clone/context.ts +22 -0
  61. package/pages/Clone/index.tsx +634 -0
  62. package/pages/Clone/stores/Main.ts +206 -0
  63. package/pages/Clone/useCreatedStores.ts +11 -0
  64. package/pages/Configuration/Header/index.tsx +84 -0
  65. package/pages/Configuration/InputWithTooltip/index.tsx +240 -0
  66. package/pages/Configuration/ResponseMessage/index.tsx +71 -0
  67. package/pages/Configuration/configOptions.ts +60 -0
  68. package/pages/Configuration/index.tsx +1184 -0
  69. package/pages/Configuration/styles.module.scss +122 -0
  70. package/pages/Configuration/tooltipText.tsx +157 -0
  71. package/pages/Configuration/useForm.ts +108 -0
  72. package/pages/Configuration/utils/index.ts +153 -0
  73. package/pages/CreateClone/index.tsx +311 -0
  74. package/pages/CreateClone/stores/Main.ts +107 -0
  75. package/pages/CreateClone/styles.module.scss +71 -0
  76. package/pages/CreateClone/useCreatedStores.ts +11 -0
  77. package/pages/CreateClone/useForm.ts +36 -0
  78. package/pages/Instance/Clones/Header/Item/index.tsx +15 -0
  79. package/pages/Instance/Clones/Header/Item/styles.module.scss +17 -0
  80. package/pages/Instance/Clones/Header/index.tsx +74 -0
  81. package/pages/Instance/Clones/Header/styles.module.scss +11 -0
  82. package/pages/Instance/Clones/index.tsx +135 -0
  83. package/pages/Instance/ClonesModal/index.tsx +71 -0
  84. package/pages/Instance/ClonesModal/utils.ts +21 -0
  85. package/pages/Instance/InactiveInstance/index.tsx +165 -0
  86. package/pages/Instance/InactiveInstance/utils.ts +9 -0
  87. package/pages/Instance/Info/Connection/ConnectModal/Content/index.tsx +176 -0
  88. package/pages/Instance/Info/Connection/ConnectModal/Content/utils.ts +24 -0
  89. package/pages/Instance/Info/Connection/ConnectModal/index.tsx +36 -0
  90. package/pages/Instance/Info/Connection/index.tsx +81 -0
  91. package/pages/Instance/Info/Details/index.tsx +20 -0
  92. package/pages/Instance/Info/Disks/Disk/ActionsMenu/index.tsx +100 -0
  93. package/pages/Instance/Info/Disks/Disk/Marker/index.tsx +26 -0
  94. package/pages/Instance/Info/Disks/Disk/ProgressBar/PointerIcon.tsx +20 -0
  95. package/pages/Instance/Info/Disks/Disk/ProgressBar/index.tsx +73 -0
  96. package/pages/Instance/Info/Disks/Disk/Status/index.tsx +75 -0
  97. package/pages/Instance/Info/Disks/Disk/index.tsx +168 -0
  98. package/pages/Instance/Info/Disks/index.tsx +65 -0
  99. package/pages/Instance/Info/Icons/index.tsx +39 -0
  100. package/pages/Instance/Info/Retrieval/RefreshFailedAlert/index.tsx +32 -0
  101. package/pages/Instance/Info/Retrieval/RefreshFailedAlert/styles.module.scss +33 -0
  102. package/pages/Instance/Info/Retrieval/RetrievalModal/index.tsx +49 -0
  103. package/pages/Instance/Info/Retrieval/RetrievalModal/styles.module.scss +6 -0
  104. package/pages/Instance/Info/Retrieval/RetrievalTable/index.tsx +53 -0
  105. package/pages/Instance/Info/Retrieval/RetrievalTable/styles.module.scss +29 -0
  106. package/pages/Instance/Info/Retrieval/index.tsx +95 -0
  107. package/pages/Instance/Info/Retrieval/utils.ts +10 -0
  108. package/pages/Instance/Info/Snapshots/Calendar/Day/index.tsx +125 -0
  109. package/pages/Instance/Info/Snapshots/Calendar/index.tsx +133 -0
  110. package/pages/Instance/Info/Snapshots/Calendar/utils.ts +74 -0
  111. package/pages/Instance/Info/Snapshots/TimeLine/Day/index.tsx +79 -0
  112. package/pages/Instance/Info/Snapshots/TimeLine/index.tsx +57 -0
  113. package/pages/Instance/Info/Snapshots/index.tsx +97 -0
  114. package/pages/Instance/Info/Snapshots/utils.ts +18 -0
  115. package/pages/Instance/Info/Status/InstanceResponseModal/index.tsx +32 -0
  116. package/pages/Instance/Info/Status/InstanceResponseModal/styles.module.scss +3 -0
  117. package/pages/Instance/Info/Status/index.tsx +85 -0
  118. package/pages/Instance/Info/Status/styles.module.scss +12 -0
  119. package/pages/Instance/Info/Status/utils.ts +24 -0
  120. package/pages/Instance/Info/components/Property/index.tsx +32 -0
  121. package/pages/Instance/Info/components/Property/styles.module.scss +21 -0
  122. package/pages/Instance/Info/components/Section/index.tsx +50 -0
  123. package/pages/Instance/Info/components/ValueStatus/index.tsx +51 -0
  124. package/pages/Instance/Info/index.tsx +129 -0
  125. package/pages/Instance/SnapshotsModal/index.tsx +169 -0
  126. package/pages/Instance/SnapshotsModal/utils.ts +17 -0
  127. package/pages/Instance/Tabs/index.tsx +98 -0
  128. package/pages/Instance/components/ClonesList/ConnectionModal/index.tsx +196 -0
  129. package/pages/Instance/components/ClonesList/MenuCell/index.tsx +98 -0
  130. package/pages/Instance/components/ClonesList/MenuCell/utils.ts +21 -0
  131. package/pages/Instance/components/ClonesList/index.tsx +189 -0
  132. package/pages/Instance/components/ClonesList/styles.module.scss +32 -0
  133. package/pages/Instance/components/ErrorStub/index.tsx +77 -0
  134. package/pages/Instance/components/ModalReloadButton/index.tsx +43 -0
  135. package/pages/Instance/components/Tags/Tag/index.tsx +60 -0
  136. package/pages/Instance/components/Tags/index.tsx +42 -0
  137. package/pages/Instance/context.ts +39 -0
  138. package/pages/Instance/index.tsx +235 -0
  139. package/pages/Instance/stores/ClonesModal.ts +35 -0
  140. package/pages/Instance/stores/Main.ts +335 -0
  141. package/pages/Instance/stores/SnapshotsModal.ts +35 -0
  142. package/pages/Instance/styles.scss +40 -0
  143. package/pages/Instance/useCreatedStores.ts +14 -0
  144. package/pages/Logs/Icons/PlusIcon.tsx +8 -0
  145. package/pages/Logs/constants/index.ts +7 -0
  146. package/pages/Logs/hooks/useWsScroll.tsx +44 -0
  147. package/pages/Logs/index.tsx +267 -0
  148. package/pages/Logs/utils/index.ts +20 -0
  149. package/pages/Logs/wsLogs.ts +110 -0
  150. package/pages/Logs/wsSnackbar.ts +27 -0
  151. package/postgres.ai-shared-3.5.0.tgz +0 -0
  152. package/react-app-env.d.ts +71 -0
  153. package/scripts/copy-assets.js +30 -0
  154. package/scripts/pack.js +70 -0
  155. package/stores/Snapshots.ts +54 -0
  156. package/styles/colors.ts +67 -0
  157. package/styles/global.scss +29 -0
  158. package/styles/icons.tsx +1917 -0
  159. package/styles/mixins.scss +30 -0
  160. package/styles/styles.ts +87 -0
  161. package/styles/theme.ts +53 -0
  162. package/styles/vars.scss +43 -0
  163. package/styles/vars.ts +40 -0
  164. package/tsconfig.build.json +37 -0
  165. package/tsconfig.json +30 -0
  166. package/types/api/endpoints/createClone.ts +10 -0
  167. package/types/api/endpoints/destroyClone.ts +7 -0
  168. package/types/api/endpoints/getClone.ts +6 -0
  169. package/types/api/endpoints/getConfig.ts +6 -0
  170. package/types/api/endpoints/getEngine.ts +13 -0
  171. package/types/api/endpoints/getFullConfig.ts +4 -0
  172. package/types/api/endpoints/getInstance.ts +6 -0
  173. package/types/api/endpoints/getInstanceRetrieval.ts +6 -0
  174. package/types/api/endpoints/getSeImages.ts +22 -0
  175. package/types/api/endpoints/getSnapshots.ts +6 -0
  176. package/types/api/endpoints/getWSToken.ts +6 -0
  177. package/types/api/endpoints/initWS.ts +1 -0
  178. package/types/api/endpoints/refreshInstance.ts +4 -0
  179. package/types/api/endpoints/resetClone.ts +8 -0
  180. package/types/api/endpoints/testDbSource.ts +48 -0
  181. package/types/api/endpoints/updateClone.ts +10 -0
  182. package/types/api/endpoints/updateConfig.ts +6 -0
  183. package/types/api/entities/clone.ts +42 -0
  184. package/types/api/entities/config.ts +114 -0
  185. package/types/api/entities/dbSource.ts +13 -0
  186. package/types/api/entities/instance.ts +67 -0
  187. package/types/api/entities/instanceRetrieval.ts +46 -0
  188. package/types/api/entities/instanceState.ts +102 -0
  189. package/types/api/entities/pool.ts +27 -0
  190. package/types/api/entities/snapshot.ts +18 -0
  191. package/types/api/entities/wsToken.ts +7 -0
  192. package/types/byte-size/index.d.ts +22 -0
  193. package/utils/api.ts +30 -0
  194. package/utils/clone.ts +31 -0
  195. package/utils/connection.ts +38 -0
  196. package/utils/date.ts +87 -0
  197. package/utils/instance.ts +10 -0
  198. package/utils/numbers.ts +11 -0
  199. package/utils/react.ts +10 -0
  200. package/utils/snapshot.ts +4 -0
  201. package/utils/strings.ts +11 -0
  202. package/utils/units.ts +23 -0
@@ -0,0 +1,122 @@
1
+ .textField {
2
+ width: 400px;
3
+ max-width: 100%;
4
+
5
+ input,
6
+ label {
7
+ font-family: 'Fira Code', monospace;
8
+ color: #000;
9
+ }
10
+
11
+ label {
12
+ font-size: 10px;
13
+ }
14
+
15
+ :disabled {
16
+ cursor: not-allowed;
17
+ color: rgba(0, 0, 0, 0.38);
18
+ }
19
+
20
+ @media (max-width: 600px) {
21
+ width: 100%;
22
+ }
23
+ }
24
+
25
+ .chipContainer {
26
+ width: 350px;
27
+ max-width: 100%;
28
+ margin-bottom: 0;
29
+ }
30
+
31
+ .databasesContainer {
32
+ width: 350px;
33
+ max-width: 100%;
34
+ }
35
+
36
+ .chip {
37
+ margin-right: 8px;
38
+ margin-top: 8px;
39
+ }
40
+
41
+ .underline {
42
+ text-decoration: underline;
43
+ cursor: pointer;
44
+ }
45
+
46
+ .root {
47
+ font-size: 12px;
48
+ max-width: 450px;
49
+ }
50
+
51
+ .spinner {
52
+ margin-left: 8px;
53
+ }
54
+
55
+ .spinnerContainer {
56
+ position: absolute;
57
+ top: 50%;
58
+ left: 50%;
59
+ transform: translate(-50%, -50%);
60
+ }
61
+
62
+ .infoIcon {
63
+ margin-left: 6px;
64
+ height: 12px;
65
+ width: 12px;
66
+ }
67
+
68
+ .externalIcon {
69
+ margin-left: 2px;
70
+ height: 12px;
71
+ width: 12px;
72
+ }
73
+
74
+ .externalLink {
75
+ display: inline-flex;
76
+ align-items: center;
77
+ width: max-content;
78
+
79
+ &:link,
80
+ &:hover {
81
+ color: #0000ee;
82
+ }
83
+
84
+ &:visited {
85
+ color: #551a8b;
86
+ }
87
+ }
88
+
89
+ .largeIcon {
90
+ height: 15px;
91
+ width: 15px;
92
+ }
93
+
94
+ .subsection {
95
+ margin-bottom: 0.25rem;
96
+ font-size: 13px;
97
+ font-weight: 500;
98
+ }
99
+
100
+ .modalTitle {
101
+ font-size: 16px;
102
+ font-weight: bold !important;
103
+ }
104
+
105
+ .sectionTitle {
106
+ display: flex;
107
+ align-items: center;
108
+ gap: 3px;
109
+ }
110
+
111
+ .firaCodeFont {
112
+ font-family: 'Fira Code', monospace !important;
113
+ }
114
+
115
+ .snackbar {
116
+ div {
117
+ background-color: #ff6212;
118
+ color: #fff;
119
+ border-radius: 4px;
120
+ cursor: pointer;
121
+ }
122
+ }
@@ -0,0 +1,157 @@
1
+ import styles from './styles.module.scss'
2
+
3
+ export const tooltipText = {
4
+ dockerTag: () => (
5
+ <div>
6
+ Docker image version - latest ones listed first. If unsure, pick the top
7
+ one
8
+ </div>
9
+ ),
10
+ dockerImage: () => (
11
+ <div>
12
+ Major PostgreSQL version (e.g., "9.6", "15"). For logical provisioning
13
+ mode, the version used by DBLab doesn't need to match the version used on
14
+ the source (although, it's recommended). <br />
15
+ If you need a version that is not listed here, contact support.
16
+ </div>
17
+ ),
18
+ dockerImageType: () => (
19
+ <div>
20
+ Docker image used to run all database containers – clones, snapshot
21
+ preparation containers, sync containers. Although such images are based on
22
+ traditional Docker images for Postgres, DBLab expects slightly different
23
+ behavior: e.g., Postgres is not the first process used to start container,
24
+ so Postgres restarts are possible, they do not trigger container state
25
+ change. For details, see{' '}
26
+ <a
27
+ target={'_blank'}
28
+ href={'https://postgres.ai/docs/database-lab/supported-databases'}
29
+ className={styles.externalLink}
30
+ >
31
+ the docs
32
+ </a>
33
+ .
34
+ </div>
35
+ ),
36
+ sharedBuffers: () => (
37
+ <div>
38
+ Defines default buffer pool size of each Postgres instance managed by DBLab.
39
+ Note, that this amount of RAM is immediately allocated at Postgres startup
40
+ time. For example, if the machine running DBLab has 32 GiB of RAM, and the
41
+ value used here is '1GB', then the theoretical limit of the number of
42
+ clones is 32. Practically, this limit is even lower because some memory is
43
+ consumed by various other processes. If you need more clones, reduce the
44
+ value of{' '}
45
+ <span className={styles.firaCodeFont}>configs.shared_buffers</span>.
46
+ </div>
47
+ ),
48
+ sharedPreloadLibraries: () => (
49
+ <div>
50
+ Specifies one or more shared libraries (comma-separated list) to be
51
+ preloaded at Postgres server start (
52
+ <a
53
+ target={'_blank'}
54
+ href={'https://postgresqlco.nf/doc/en/param/shared_preload_libraries/'}
55
+ className={styles.externalLink}
56
+ >
57
+ details
58
+ </a>
59
+ ). If some libraries/extensions are missing, Postgres fails to start, so
60
+ make sure that <span className={styles.firaCodeFont}>dockerImage</span>{' '}
61
+ used above contains all the needed extensions.
62
+ </div>
63
+ ),
64
+ host: () => (
65
+ <div>
66
+ Hostname/IP of database that will be used as source for data retrieval
67
+ (full data refresh).
68
+ </div>
69
+ ),
70
+ port: () => (
71
+ <div>
72
+ Port of database that will be used as source for data retrieval (full data
73
+ refresh).
74
+ </div>
75
+ ),
76
+ username: () => (
77
+ <div>
78
+ Username used to connect to database that will be used as source for data
79
+ retrieval (full data refresh).
80
+ </div>
81
+ ),
82
+ password: () => (
83
+ <div>
84
+ Password used to connect to database that will be used as source for data
85
+ retrieval (full data refresh).
86
+ </div>
87
+ ),
88
+ dbname: () => (
89
+ <div>
90
+ Database name used to connect to the source to run diagnostics queries.
91
+ This database is not necesserarily to be copied (another field,{' '}
92
+ <span className={styles.firaCodeFont}>databases</span>, defines which
93
+ database to copy).
94
+ </div>
95
+ ),
96
+ databases: () => (
97
+ <div>
98
+ Specifies list of databases Postgres server to copy at data retrieval
99
+ (full data refresh). To specify multiple database names, provide each
100
+ value in a separte line or use space as a divider. To copy all available
101
+ databases, leave this value empty.
102
+ </div>
103
+ ),
104
+ dumpParallelJobs: () => (
105
+ <div>
106
+ Number of parallel workers used to dump the source databases to disk. If
107
+ the source is production server under load, it is not recommended to use
108
+ more than 50% of its number of vCPUs. The higher number, the faster
109
+ dumping is, but the higher risks of performance issues on the source
110
+ (e.g., due to CPU or disk IO saturation).
111
+ </div>
112
+ ),
113
+ pgDumpCustomOptions: () => (
114
+ <div>
115
+ pg_dump options to be used to create a database dump, for example:
116
+ '--exclude-schema=repack --exclude-schema="camelStyleSchemaName"'. Note
117
+ that due to security reasons, the current implementation supports only
118
+ letters, numbers, hyphen, underscore, equal sign, and double quotes.
119
+ </div>
120
+ ),
121
+ restoreParallelJobs: () => (
122
+ <div>
123
+ Number of parallel workers used to restore databases from dump to Postgres
124
+ managed by DBLab. For initial data retrieval (very first data refresh), it
125
+ is recommended to use the number of vCPUs available on machine running
126
+ DBLab. With this approach, we have faster restore time, but we need to keep
127
+ in mind that we can also have higher usage of CPU and disk IO on this
128
+ machine (up to temporary saturation of resources). For subsequent
129
+ refreshes, if DBLab is constantly used, it is recommended to reduce this
130
+ value by 50% to keep some room for normal use of DBLab (such as work with
131
+ clones).
132
+ </div>
133
+ ),
134
+ pgRestoreCustomOptions: () => (
135
+ <div>
136
+ pg_restore options to be used to restore from a database dump, for
137
+ example: '--exclude-schema=repack
138
+ --exclude-schema="camelStyleSchemaName"'. Note that due to security
139
+ reasons, the current implementation supports only letters, numbers,
140
+ hyphen, underscore, equal sign, and double quotes.
141
+ </div>
142
+ ),
143
+ timetable: () => (
144
+ <div>
145
+ Schedule for full data refreshes, in{' '}
146
+ <a
147
+ target={'_blank'}
148
+ href={'https://en.wikipedia.org/wiki/Cron#Overview'}
149
+ className={styles.externalLink}
150
+ >
151
+ crontab format
152
+ </a>
153
+ .
154
+ </div>
155
+ ),
156
+ tuningParams: () => <div>Test</div>,
157
+ }
@@ -0,0 +1,108 @@
1
+ /*--------------------------------------------------------------------------
2
+ * Copyright (c) 2019-2021, Postgres.ai, Nikolay Samokhvalov nik@postgres.ai
3
+ * All Rights Reserved. Proprietary and confidential.
4
+ * Unauthorized copying of this file, via any medium is strictly prohibited
5
+ *--------------------------------------------------------------------------
6
+ */
7
+
8
+ import { useFormik } from 'formik'
9
+ import * as Yup from 'yup'
10
+
11
+ export type FormValues = {
12
+ debug: boolean
13
+ dockerImage: string
14
+ dockerTag: string
15
+ dockerPath: string
16
+ dockerImageType: string
17
+ sharedBuffers: string
18
+ sharedPreloadLibraries: string
19
+ tuningParams: string
20
+ timetable: string
21
+ dbname: string
22
+ host: string
23
+ port: string
24
+ username: string
25
+ password: string
26
+ databases: string
27
+ dumpParallelJobs: string
28
+ dumpIgnoreErrors: boolean
29
+ restoreParallelJobs: string
30
+ restoreIgnoreErrors: boolean
31
+ pgDumpCustomOptions: string
32
+ pgRestoreCustomOptions: string
33
+ }
34
+
35
+ const Schema = Yup.object().shape({
36
+ dockerImage: Yup.string().required('Docker image is required'),
37
+ dbname: Yup.string().required('Dbname is required'),
38
+ host: Yup.string().required('Host is required'),
39
+ port: Yup.string().required('Port is required'),
40
+ username: Yup.string().required('Username is required'),
41
+ })
42
+
43
+ export const useForm = (onSubmit: (values: FormValues) => void) => {
44
+ const formik = useFormik<FormValues>({
45
+ initialValues: {
46
+ debug: false,
47
+ dockerImage: '',
48
+ dockerTag: '',
49
+ dockerPath: '',
50
+ dockerImageType: '',
51
+ sharedBuffers: '',
52
+ sharedPreloadLibraries: '',
53
+ tuningParams: '',
54
+ timetable: '',
55
+ dbname: '',
56
+ host: '',
57
+ port: '',
58
+ username: '',
59
+ password: '',
60
+ databases: '',
61
+ dumpParallelJobs: '',
62
+ restoreParallelJobs: '',
63
+ pgDumpCustomOptions: '',
64
+ pgRestoreCustomOptions: '',
65
+ dumpIgnoreErrors: false,
66
+ restoreIgnoreErrors: false,
67
+ },
68
+ validationSchema: Schema,
69
+ onSubmit,
70
+ validateOnBlur: false,
71
+ validateOnChange: false,
72
+ })
73
+
74
+ const formatDatabaseArray = (database: string) => {
75
+ let databases = []
76
+ const splitDatabaseArray = database.split(/[,(\s)(\n)(\r)(\t)(\r\n)]/)
77
+
78
+ for (let i = 0; i < splitDatabaseArray.length; i++) {
79
+ if (splitDatabaseArray[i] !== '') {
80
+ databases.push(splitDatabaseArray[i])
81
+ }
82
+ }
83
+
84
+ return databases
85
+ }
86
+
87
+ const connectionData = {
88
+ host: formik.values.host,
89
+ port: formik.values.port,
90
+ username: formik.values.username,
91
+ password: formik.values.password,
92
+ dbname: formik.values.dbname,
93
+ ...(formik.values.databases && {
94
+ db_list: formatDatabaseArray(formik.values.databases),
95
+ }),
96
+ ...(formik.values.dockerImageType === 'custom' && {
97
+ dockerImage: formik.values.dockerImage,
98
+ }),
99
+ }
100
+
101
+ const isConnectionDataValid =
102
+ formik.values.host &&
103
+ formik.values.port &&
104
+ formik.values.username &&
105
+ formik.values.dbname
106
+
107
+ return [{ formik, connectionData, isConnectionDataValid }]
108
+ }
@@ -0,0 +1,153 @@
1
+ import { DatabaseType } from '@postgres.ai/shared/types/api/entities/config'
2
+
3
+ import { dockerImageOptions } from '../configOptions'
4
+ import { FormValues } from '../useForm'
5
+
6
+ const seContainerRegistry = 'se-images'
7
+ const genericImagePrefix = 'postgresai/extended-postgres'
8
+ // since some tags are rc, we need to specify the exact tags to use
9
+ const dockerImagesConfig = {
10
+ '9.6': ['0.5.2', '0.5.1', '0.4.6'],
11
+ '10': ['0.5.2', '0.5.1', '0.4.6'],
12
+ '11': ['0.5.2', '0.5.1', '0.4.6'],
13
+ '12': ['0.5.2', '0.5.1', '0.4.6'],
14
+ '13': ['0.5.2', '0.5.1', '0.4.6'],
15
+ '14': ['0.5.2', '0.5.1', '0.4.6'],
16
+ '15': ['0.5.2', '0.5.1', '0.4.6'],
17
+ '16': ['0.5.2', '0.5.1', '0.4.6'],
18
+ '17': ['0.5.2', '0.5.1'],
19
+ }
20
+
21
+ export type FormValuesKey = keyof FormValues
22
+
23
+ interface DockerImage {
24
+ package_group: string
25
+ pg_major_version: string
26
+ tag: string
27
+ location: string
28
+ }
29
+
30
+ type DockerImagesConfig = Record<string, string[]>
31
+
32
+ export const uniqueChipValue = (values: string) => {
33
+ const splitChipArray = values.split(/[,(\s)(\n)(\r)(\t)(\r\n)]/)
34
+ let databaseArray = []
35
+
36
+ for (let i in splitChipArray) {
37
+ if (
38
+ splitChipArray[i] !== '' &&
39
+ databaseArray.indexOf(splitChipArray[i]) === -1
40
+ ) {
41
+ databaseArray.push(splitChipArray[i])
42
+ }
43
+ }
44
+
45
+ return databaseArray.join(' ')
46
+ }
47
+
48
+ export const postUniqueDatabases = (values: string) => {
49
+ const splitDatabaseArray = values.split(/[,(\s)(\n)(\r)(\t)(\r\n)]/)
50
+
51
+ const databases = splitDatabaseArray.reduce((acc: DatabaseType, curr) => {
52
+ acc[curr] = {}
53
+ return acc
54
+ }, {})
55
+
56
+ const nonEmptyDatabase = Object.fromEntries(
57
+ Object.entries(databases).filter(([name]) => name != ''),
58
+ )
59
+
60
+ return values.length !== 0 ? nonEmptyDatabase : null
61
+ }
62
+
63
+ const createDockerImages = (
64
+ dockerImagesConfig: DockerImagesConfig,
65
+ ): DockerImage[] => {
66
+ const dockerImages: DockerImage[] = []
67
+
68
+ for (const pg_major_version in dockerImagesConfig) {
69
+ if (dockerImagesConfig.hasOwnProperty(pg_major_version)) {
70
+ const customTags = dockerImagesConfig[pg_major_version]
71
+
72
+ customTags.forEach((tag) => {
73
+ const image: DockerImage = {
74
+ package_group: 'postgresai',
75
+ pg_major_version,
76
+ tag: `${pg_major_version}-${tag}`,
77
+ location: `${genericImagePrefix}:${pg_major_version}-${tag}`,
78
+ }
79
+
80
+ dockerImages.push(image)
81
+ })
82
+ }
83
+ }
84
+
85
+ return dockerImages
86
+ }
87
+
88
+ export const genericDockerImages = createDockerImages(dockerImagesConfig)
89
+
90
+ export const isSeDockerImage = (dockerImage: string | undefined) => {
91
+ const dockerImageType =
92
+ dockerImage?.includes(seContainerRegistry) &&
93
+ dockerImage.split(`${seContainerRegistry}/`)[1]?.split(':')[0]
94
+
95
+ return dockerImageOptions.some((element) => element.type === dockerImageType)
96
+ }
97
+
98
+ export const getImageType = (imageUrl: string) => {
99
+ const postgresCustomImageType =
100
+ imageUrl.includes(seContainerRegistry) &&
101
+ imageUrl.split(`${seContainerRegistry}/`)[1]?.split(':')[0]
102
+
103
+ if (imageUrl.includes(genericImagePrefix)) {
104
+ return 'Generic Postgres'
105
+ } else if (postgresCustomImageType && isSeDockerImage(imageUrl)) {
106
+ return postgresCustomImageType
107
+ } else {
108
+ return 'custom'
109
+ }
110
+ }
111
+
112
+ export const getImageMajorVersion = (pgImage: string | undefined) => {
113
+ const pgImageVersion = pgImage?.split(':')[1]
114
+ const pgServerVersion = pgImageVersion?.split('-')[0]
115
+ return pgServerVersion?.includes('.')
116
+ ? pgServerVersion?.split('.')[0]
117
+ : pgServerVersion
118
+ }
119
+
120
+ export const formatDatabases = (databases: DatabaseType | null) => {
121
+ let formattedDatabases = ''
122
+
123
+ if (databases !== null) {
124
+ Object.keys(databases).forEach(function (key) {
125
+ formattedDatabases += key + ' '
126
+ })
127
+ }
128
+
129
+ return formattedDatabases
130
+ }
131
+
132
+ export const formatDumpCustomOptions = (options: string[] | null) => {
133
+ let formattedOptions = ''
134
+
135
+ if (options !== null) {
136
+ options.forEach(function (key) {
137
+ formattedOptions += key + ' '
138
+ })
139
+ }
140
+
141
+ return formattedOptions
142
+ }
143
+
144
+ export const postUniqueCustomOptions = (options: string) => {
145
+ const splitOptionsArray = options.split(/[,(\s)(\n)(\r)(\t)(\r\n)]/)
146
+ const uniqueOptions = splitOptionsArray.filter(
147
+ (item, index) => splitOptionsArray.indexOf(item) === index && item !== '',
148
+ )
149
+ return uniqueOptions
150
+ }
151
+
152
+ export const customOrGenericImage = (dockerImage: string | undefined) =>
153
+ dockerImage === 'Generic Postgres' || dockerImage === 'custom'