-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstants.ts
More file actions
1692 lines (1598 loc) · 45.1 KB
/
Copy pathconstants.ts
File metadata and controls
1692 lines (1598 loc) · 45.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Contains a bunch of constants that are used through the itemize app
* while they can be changed it's not truly recommended, this is mainly for
* internal usage and to keep configuration and have an idea
*
* @module
*/
import { IElasticIndexDefinitionType, ISQLTableDefinitionType } from "./base/Root/sql";
import path from "path";
import type { RQArg, RQField } from "./base/Root/rq";
export interface IItemizeConstantsConfig {
/**
* The maximum supported year
*/
MAX_SUPPORTED_YEAR?: number;
/**
* Defines how many characters a string type might have
*/
MAX_STRING_LENGTH?: number;
/**
* Defines how many characters (yes characters) a text type might have max
* please define maxLenght in the property itself for specific checking
* this check is expensive so checking twice is not good
*/
MAX_RAW_TEXT_LENGTH?: number;
/**
* The MAX file size of each given independent file, remember to ensure that
* your nginx config is in line with this number, this should be a byte number
*/
MAX_FILE_SIZE?: number;
/**
* Each files property can have a number of files, this number specifies the
* top amount of files in a property
*/
MAX_FILES_PER_PROPERTY?: number;
/**
* The total amount of files that exist in a single request, this is the total
* sum of files; this number is used for a max theorethical, as in it combines
* the max file size and this number to specify a size limit
*/
MAX_FILES_PER_REQUEST?: number;
/**
* The maximum size of a given rq query in bytes
*/
MAX_FIELD_SIZE?: number;
/**
* The maximum amount of search results that a module and its item
* children can retrieve at once in a given search query
* this also affects the get list command
*/
MAX_SEARCH_RESULTS_DEFAULT?: number;
/**
* The maximum amount of search records that a module and its item
* children can retrieve at once in a given search query
*/
MAX_SEARCH_RECORDS_DEFAULT?: number;
/**
* The maximum number of characters the search field can
* have that is build for the search mode
*/
MAX_SEARCH_FIELD_LENGTH?: number;
/**
* The supported mime types for images
*/
FILE_SUPPORTED_IMAGE_TYPES?: string[];
/**
* The minimum update time for the server data to be changed
* basically runs mantenience functions, mainly it's about
* updating the currency information
*
* this is a millisecond amount
*/
SERVER_DATA_MIN_UPDATE_TIME?: number;
/**
* The time it takes for block_until to be refreshed
* and blockage to be cleared
*
* this is a millisecond amount
*/
SERVER_BLOCK_UNTIL_REFRESH_TIME?: number;
/**
* The time it takes for elasticsearch (if available)
* to be cleaned the old records that are not expected to be retrieved
* this has to do with the since limiter that may exist within
* indexes
*/
SERVER_ELASTIC_CONSISTENCY_CHECK_TIME?: number;
/**
* The time it takes for elasticsearch (if available)
* to run the pings that send information about the state of the server
* by default this sends the status of the machine, CPU, memory usage, every
* 10 seconds, aka 10000ms
*/
SERVER_ELASTIC_PING_INTERVAL_TIME?: number;
/**
* The maximum amount of remote listeners a socket can
* have at once before the server denies adding more
* these are used for realtime updates
*/
MAX_REMOTE_LISTENERS_PER_SOCKET?: number;
/**
* Usernames that are not allowed to be taken
* by users, defaults to admin and unsubscribe
* it will prevent new users to creating accounts
* with those names via the standard signup method
* note that unsubscribe will remain being a protected
* username no matter what, even if you fail
* to specify it
*/
PROTECTED_USERNAMES?: string[];
/**
* Establishes the maximum possible value for the searchengine_full_highlights
* search filed, default is 100
*/
SEARCHENGINE_MAX_HIGHLIGHT_FRAMENT_SIZE?: number;
/**
* Specifies the admin role for the user
*/
ADMIN_ROLE?: string;
}
// in the client side it gets injected via esbuild in the server side
// it has to be required
declare var ITEMIZE_CONSTANTS_CONFIG: IItemizeConstantsConfig;
let R_ITEMIZE_CONSTANTS_CONFIG: IItemizeConstantsConfig = typeof ITEMIZE_CONSTANTS_CONFIG !== "undefined" ?
ITEMIZE_CONSTANTS_CONFIG : null;
if (!R_ITEMIZE_CONSTANTS_CONFIG) {
try {
const itemizeConfig = require(path.join(path.resolve("."), "itemize.config"));
R_ITEMIZE_CONSTANTS_CONFIG = itemizeConfig.constants;
} catch {
R_ITEMIZE_CONSTANTS_CONFIG = {};
}
}
// DATA ATTRIBUTES
/**
* Defines the max supported integer, it should match up the database
*/
export const MAX_SUPPORTED_INTEGER = 2147483647;
/**
* Defines the min supported integer, it should match up the database too
*/
export const MIN_SUPPORTED_INTEGER = -MAX_SUPPORTED_INTEGER;
/**
* Defines how many decimal points are supported, for the sake of usability
* the number is set to a precision of 6
*/
export const MAX_DECIMAL_COUNT = 6;
/**
* Defines how big can decimal numbers get
*/
export const MAX_SUPPORTED_REAL = 999999999;
/**
* Defines how small can decimal numbers get
*/
export const MIN_SUPPORTED_REAL = -999999999;
/**
* Years max
*/
export const MAX_SUPPORTED_YEAR = R_ITEMIZE_CONSTANTS_CONFIG.MAX_SUPPORTED_YEAR || 3000;
/**
* Years min
*/
export const MIN_SUPPORTED_YEAR = 0;
/**
* Defines how many characters a string might have
*/
export const MAX_STRING_LENGTH = R_ITEMIZE_CONSTANTS_CONFIG.MAX_STRING_LENGTH || 10000;
/**
* Defines how many characters (yes characters) a text might have max
* please define maxLenght in the property itself for specific checking
* this check is expensive so checking twice is not good
*/
export const MAX_RAW_TEXT_LENGTH = R_ITEMIZE_CONSTANTS_CONFIG.MAX_RAW_TEXT_LENGTH || 100000;
/**
* The max file size (for either images and binary files)
*/
export const MAX_FILE_SIZE = R_ITEMIZE_CONSTANTS_CONFIG.MAX_FILE_SIZE || 5000000; // equivalent to 5MB
/**
* how many files can be used in one item field at once
*/
export const MAX_FILES_PER_PROPERTY = R_ITEMIZE_CONSTANTS_CONFIG.MAX_FILES_PER_PROPERTY || 25;
/**
* how many files can there be total
* in a single request, this is more of a security concern
*/
export const MAX_FILES_PER_REQUEST =
R_ITEMIZE_CONSTANTS_CONFIG.MAX_FILES_PER_REQUEST ?
R_ITEMIZE_CONSTANTS_CONFIG.MAX_FILES_PER_REQUEST :
MAX_FILES_PER_PROPERTY * 10;
/**
* Another just a security concern, this
* is the size of the rq query, 1MB should be way more than enough for a rq query
*/
export const MAX_FIELD_SIZE = R_ITEMIZE_CONSTANTS_CONFIG.MAX_FIELD_SIZE || 1000000; // equivalent to 1MB
/**
* how many search results can be retrieved at once these are
* used for the actual search results
*/
export const MAX_SEARCH_RESULTS_DEFAULT = R_ITEMIZE_CONSTANTS_CONFIG.MAX_SEARCH_RECORDS_DEFAULT || 50;
/**
* how many search results can be retrieved at once these are
* used for the actual search results
*/
export const MAX_SEARCH_RECORDS_DEFAULT = R_ITEMIZE_CONSTANTS_CONFIG.MAX_SEARCH_RECORDS_DEFAULT || 500;
/**
* Size in characters of the search field
*/
export const MAX_SEARCH_FIELD_LENGTH = R_ITEMIZE_CONSTANTS_CONFIG.MAX_SEARCH_FIELD_LENGTH || 1024;
/**
* The minimum update time for the server data to be changed
* basically runs mantenience functions, mainly it's about
* updating the currency information
*/
export const SERVER_DATA_MIN_UPDATE_TIME = R_ITEMIZE_CONSTANTS_CONFIG.SERVER_DATA_MIN_UPDATE_TIME || 259200000; // 3 days
/**
* The time it takes for blocks to be refreshed, the blocks represent the blocked_at and blocked_until functionality
* that automatically gets removed
*/
export const SERVER_BLOCK_UNTIL_REFRESH_TIME = R_ITEMIZE_CONSTANTS_CONFIG.SERVER_BLOCK_UNTIL_REFRESH_TIME || 86400000; // 1 day
/**
* The time it takes to run a cleanup process into the elastic instance
*/
export const SERVER_ELASTIC_CONSISTENCY_CHECK_TIME = R_ITEMIZE_CONSTANTS_CONFIG.SERVER_ELASTIC_CONSISTENCY_CHECK_TIME || 60000; // every minute
/**
* The time to inform ping information
*/
export const SERVER_ELASTIC_PING_INTERVAL_TIME = R_ITEMIZE_CONSTANTS_CONFIG.SERVER_ELASTIC_PING_INTERVAL_TIME || 10000; // every 10 seconds
/**
* The maximum amount of remote listeners a socket supports
*/
export const MAX_REMOTE_LISTENERS_PER_SOCKET = R_ITEMIZE_CONSTANTS_CONFIG.MAX_REMOTE_LISTENERS_PER_SOCKET || 100;
/**
* The protected usernames that cannot be taken by the users
*/
export const PROTECTED_USERNAMES = R_ITEMIZE_CONSTANTS_CONFIG.PROTECTED_USERNAMES ?
R_ITEMIZE_CONSTANTS_CONFIG.PROTECTED_USERNAMES.concat(["unsubscribe"]) :
[
"admin",
"unsubscribe",
"postmaster",
"notifications",
"info",
"warning",
"payment",
"payments",
"moderator",
"password",
];
/**
* Supported image types
*/
export const FILE_SUPPORTED_IMAGE_TYPES = [
"image/png",
"image/jpeg",
"image/svg+xml",
"image/png",
"image/webp",
];
/**
* The properties for i18n a module should have
*/
export const MODULE_AND_ITEM_DEF_I18N = [
"name",
];
/**
* The properties for i18n a searchable module and item definition should have
*/
export const MODULE_AND_ITEM_DEF_I18N_SEARCHABLE = [
"search_field_label",
"search_field_placeholder",
"search_keywords",
"search_value_too_large",
]
/**
* The custom key as it is stored in the built file, the custom key
* is always custom in the properties
*/
export const MODULE_AND_ITEM_DEF_CUSTOM_I18N_KEY = "custom";
/**
* The properties for i18n an item that can be excluded should have
*/
export const ITEM_CAN_BE_EXCLUDED_I18N = [
"exclusion_selector_label",
"exclusion_ternary_selector_label",
"excluded_label",
"included_label",
"any_label",
];
/**
* The item optional data
*/
export const ITEM_OPTIONAL_I18N = [
"name",
];
/**
* The properties for i18n a callout excluded item should have
*/
export const ITEM_CALLOUT_EXCLUDED_I18N = [
"callout_excluded_label",
];
/**
* Where the destruction markers are located
*/
export const DESTRUCTION_MARKERS_LOCATION = "DESTRUCTION_MARKERS";
/**
* Where the destruction markers are located
*/
export const UNMOUNT_DESTRUCTION_MARKERS_LOCATION = "UNMOUNT_DESTRUCTION_MARKERS";
/**
* Where the destruction markers are located
*/
export const SEARCH_DESTRUCTION_MARKERS_LOCATION = "SEARCH_DESTRUCTION_MARKERS";
/**
* Where the destruction markers are located
*/
export const UNMOUNT_SEARCH_DESTRUCTION_MARKERS_LOCATION = "UNMOUNT_SEARCH_DESTRUCTION_MARKERS";
/**
* Where destruction markers get memory cached
*/
export const MEMCACHED_DESTRUCTION_MARKERS_LOCATION = "MEMCACHED_" + DESTRUCTION_MARKERS_LOCATION;
/**
* Where destruction markers get memory cached
*/
export const MEMCACHED_UNMOUNT_DESTRUCTION_MARKERS_LOCATION = "MEMCACHED_" + UNMOUNT_DESTRUCTION_MARKERS_LOCATION;
/**
* Where destruction markers get memory cached
*/
export const MEMCACHED_SEARCH_DESTRUCTION_MARKERS_LOCATION = "MEMCACHED_" + SEARCH_DESTRUCTION_MARKERS_LOCATION;
/**
* Where the destruction markers are located
*/
export const MEMCACHED_UNMOUNT_SEARCH_DESTRUCTION_MARKERS_LOCATION = "MEMCACHED_" + UNMOUNT_SEARCH_DESTRUCTION_MARKERS_LOCATION;
/**
* Awaiting websocket events
* that also get destroyed with the destruction markers
*/
export const AWAITING_WEBSOCKET_EVENTS = "AWAITING_WEBSOCKET_EVENTS"
/**
* Store a last rich text change size global to use to save memory for lenght calculation
*/
export const LAST_RICH_TEXT_CHANGE_LENGTH = "LAST_RICH_TEXT_CHANGE_LENGTH";
/**
* Rq endpoint errors codes that can be thrown
*/
export const ENDPOINT_ERRORS = {
UNSPECIFIED: "UNSPECIFIED",
INVALID_PROPERTY: "INVALID_PROPERTY", // should include a pcode
INVALID_POLICY: "INVALID_POLICY",
INVALID_INCLUDE: "INVALID_INCLUDE",
INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
TOKEN_EXPIRED: "TOKEN_EXPIRED",
BLOCKED: "BLOCKED",
CANT_CONNECT: "CANT_CONNECT",
INVALID_DATA_SUBMIT_REFUSED: "INVALID_DATA_SUBMIT_REFUSED",
INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR",
NOTHING_TO_UPDATE: "NOTHING_TO_UPDATE",
MUST_BE_LOGGED_IN: "MUST_BE_LOGGED_IN",
FORBIDDEN: "FORBIDDEN",
USER_BLOCKED: "USER_BLOCKED",
USER_REMOVED: "USER_REMOVED",
USER_EMAIL_TAKEN: "USER_EMAIL_TAKEN",
USER_PHONE_TAKEN: "USER_PHONE_TAKEN",
NOT_FOUND: "NOT_FOUND",
CONFLICT: "CONFLICT",
};
/**
* Extra i18n properties that are used for the generation
* of the validation email and the recovery email
*/
export const USER_EXTRA_CUSTOM_I18N = [
"validate_account_email_fragment_id",
"validate_account_phone_fragment_id",
"validate_account",
"validate_account_user",
"validate_account_email_user",
"forgot_password_link_target",
"forgot_password_fragment_id",
"forgot_password_title",
];
/**
* This is for small use anywhere language data
*/
export const LOCALE_I18N = [
// language name
"name",
// decimal separator that is used, comma or dot
"number_decimal_separator",
// word separator, comma, usually
"word_separator",
// N$ or $N depending if currency symbol goes before or after
"currency_format",
// For the given text editor
"format_bold",
"format_italic",
"format_underline",
"format_title",
"format_quote",
"format_link",
"format_list_numbered",
"format_list_bulleted",
"format_add_image",
"format_add_file",
"format_add_video",
"format_add_container",
"format_add_custom",
"format_set_style",
"format_set_hover_style",
"format_set_active_style",
"format_set_class",
"format_set_event_handlers",
"format_set_context",
"format_set_render_condition",
"format_make_loop",
"format_set_ui_handler",
"format_set_ui_handler_arg",
"format_set_ui_handler_arg_name",
"format_set_ui_handler_arg_value",
"format_add_template_text",
"format_add_template_html",
"format_delete_element",
"format_more",
"format_add_table",
"format_add_thead",
"format_add_tbody",
"format_add_tr",
"format_add_td",
"format_add_th",
"format_del_tr",
"format_del_td",
"format_del_th",
"format_add_tfoot",
// extra rich element information
"rich_name",
"rich_alt",
"rich_sizes",
"rich_container",
"rich_inline",
"rich_text",
"rich_custom",
"rich_file",
"rich_image",
"rich_link",
"rich_list",
"rich_list_item",
"rich_paragraph",
"rich_quote",
"rich_title",
"rich_video",
"rich_styled_component",
"rich_template_component",
"rich_interactive_component",
"rich_style",
"rich_style_active",
"rich_style_hover",
"rich_classes",
"rich_settings",
"rich_styles",
"rich_templating",
"rich_actions",
"rich_each",
"rich_context",
"rich_render_condition",
"rich_ui_handler",
"rich_type",
"rich_standalone",
"rich_table",
"rich_thead",
"rich_tbody",
"rich_tr",
"rich_td",
"rich_th",
"rich_tfoot",
// for filling the booleans and other things
"yes",
"no",
"unspecified",
"any",
// for the datetime and other things
"cancel",
"ok",
// for mostly the aria label of closing dialogs
"close",
// some extras for fast prototyping
"menu",
"reload",
"home",
// for file uploader
"file_uploader_placeholder_active",
"image_uploader_placeholder_active",
"file_uploader_placeholder_active_single",
"image_uploader_placeholder_active_single",
"file_uploader_invalid_type",
"image_uploader_invalid_type",
"file_uploader_file_too_big",
"image_uploader_file_too_big",
"file_uploader_byte_limit_exceed",
"file_uploader_select_file",
"image_uploader_select_file",
"file_uploader_delete_file",
"image_uploader_delete_file",
// for video
"video_loader_title",
"video_loader_label",
"video_loader_placeholder",
"video_loader_invalid",
"video_loader_submit",
// for links
"link_setter_title",
"link_setter_label",
"link_setter_placeholder",
"link_setter_placeholder_local_only",
"link_setter_templated",
"link_setter_templated_label",
"link_setter_templated_placeholder",
"link_setter_templated_unspecified",
"link_setter_invalid",
"link_setter_submit",
// for template text
"add_template_text_title",
"add_template_text_label",
"add_template_text_placeholder",
"add_template_text_submit",
// for template html
"add_template_html_title",
"add_template_html_label",
"add_template_html_placeholder",
"add_template_html_submit",
// for search utilites
"no_results",
"result_out_of",
"results",
"results_singular",
// for item definition too
"callout_exclude_warning",
// for showing the dialog message when selecting units
"unit_dialog_title",
"unit_dialog_others",
"unit_dialog_metric",
"unit_dialog_imperial",
// for showing the currency selection dialog when selecting a currency
"currency_dialog_title",
// when the app cannot be updated
"blocked_update",
"needs_update_navigation",
"needs_update_title",
"needs_update_action",
"needs_update_content",
// errors
"generic_error",
"generic_warning",
"generic_info",
// unsaved changes
"unsaved_changes",
"save",
"discard",
// payments, based on paymentStatusesArr and paymentTypesArr but not imported to prevent
// giving dependencies to constants.ts
"payment.type",
"payment.status",
"payment.amount",
"payment.currency",
"payment.metadata",
"payment.create",
"payment.destroy",
"payment.pending",
"payment.paid",
"payment.disputed",
"payment.reversed",
"payment.inactive",
"payment.active",
"payment.invoice",
"payment.refund",
"payment.subscription_monthly",
"payment.subscription_daily",
"payment.subscription_yearly",
].concat(
// we add all the endpoint errors
Object.keys(ENDPOINT_ERRORS).map(((ee) => `error.${ee}`)),
);
/**
* Root required i18n properties
*/
export const ROOT_REQUIRED_LOCALE_I18N = [
"app_name",
"app_short_name",
"app_description",
];
/**
* Standard i18n fields required for properties
*/
export const CLASSIC_BASE_I18N = [
"label",
"placeholder",
];
/**
* Standard i18n fields required for properties when
* they are searchable
*/
export const CLASSIC_SEARCH_BASE_I18N = [
"search.label",
"search.placeholder",
];
/**
* Reduced i18n required for properties
*/
export const REDUCED_BASE_I18N = [
"label",
];
/**
* Reduced i18n required for properties when
* they are searchable
*/
export const REDUCED_SEARCH_BASE_I18N = [
"search.label",
];
/**
* Optional i18n fields in properties
*/
export const CLASSIC_OPTIONAL_I18N = [
"description",
];
/**
* Optional i18n fields in properties when they are
* searchable
*/
export const CLASSIC_SEARCH_OPTIONAL_I18N = [
"search.description",
];
/**
* Extended required i18n fields required in properties
* when they use a ranged search
*/
export const CLASSIC_SEARCH_RANGED_I18N = [
"search.range.from.label",
"search.range.to.label",
"search.range.from.placeholder",
"search.range.to.placeholder",
];
/**
* Extended optional i18n fields required in properties
* when they use a ranged search
*/
export const CLASSIC_SEARCH_RANGED_OPTIONAL_I18N = [
"search.range.from.description",
"search.range.to.description",
];
/**
* Extended i18n fields required in properties
* when they use a location search
*/
export const LOCATION_SEARCH_I18N = [
"search.label",
"search.placeholder",
"search.radius.label",
"search.radius.placeholder",
];
/**
* Rq values come in a DATA form, because they can be blocked
* however some attributes are meant to leak and be externally accessible
* these atrributes can only be accessed outside of it
*/
export const EXTERNALLY_ACCESSIBLE_RESERVED_BASE_PROPERTIES = [
"id",
"version",
"type",
"blocked_at",
"blocked_by",
"blocked_until",
"blocked_reason",
"last_modified",
] as const;
/**
* These attributes are however protected, they exist only within
* the DATA field
*/
export const STANDARD_ACCESSIBLE_RESERVED_BASE_PROPERTIES = [
"created_at",
"created_by",
"edited_at",
"edited_by",
"reviewed_at",
"reviewed_by",
"parent_id",
"parent_version",
"parent_type",
] as const;
/**
* The format that dates are expected to have in order to be exchanged
* these represent the SQL form, does not support nano date
*/
export const DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss.SSSSSSZ";
/**
* The format with the nano information included, used mainly for elastic
* parsing
*/
export const DATETIME_FORMAT_ELASTIC_NANO = "yyyy-MM-dd HH:mm:ss.SSSSSSZZZZZ";
/**
* The format that time is expected to have in order to be exchanged
* this is the SQL form
*/
export const TIME_FORMAT = "HH:mm:ss";
/**
* The format date has in order to be exchanged, this is
* the SQL form
*/
export const DATE_FORMAT = "YYYY-MM-DD";
/**
* The reserved base properties that are exists within every rq query
* and should mirror the database
*/
export const RESERVED_BASE_PROPERTIES_RQ: {
[id: string]: RQArg;
} = {
id: {
type: "string",
required: true,
description: "The id of the item",
},
version: {
type: "string",
description: "An optional version of the item, the item must have versioning enabled",
},
type: {
type: "string",
required: true,
description: "The type (qualified name) of the item",
},
parent_id: {
type: "string",
description: "If exists, a parent id of this item",
},
parent_version: {
type: "string",
description: "If exists, the parent version of this item",
},
parent_type: {
type: "string",
description: "If exists, a parent type of this item",
},
created_at: {
type: "string",
description: "When the item was created",
},
created_by: {
type: "string",
description: "The id of the user who created this item",
},
edited_at: {
type: "string",
description: "Whenever the item was modified, otherwise null",
},
edited_by: {
type: "string",
description: "Whoever modified this item, otherwise null",
},
reviewed_at: {
type: "string",
description: "When a moderator or admin reviewed this item",
},
reviewed_by: {
type: "string",
description: "The user id who reviewed it",
},
last_modified: {
type: "string",
description: "An internal variable that represents when the whole item, as a whole " +
" was last modified, by any factor, edited_at servers a UI purpose when things were " +
" modified by normal means whereas last_modified is a global factor, it could be the " +
" server that did the change, or a side effect, edited_at can be used in the UI " +
" last modified is for usage which checking if items updated",
},
blocked_at: {
type: "string",
description: "When the item was blocked, blocked items are not searchable or retrievable by normal means; " +
"if you as an user own this item, you will only see it blocked, unlike deleted items, blocked items remain " +
"in the database until they are manually removed by an admin or moderator, none can access the data of this " +
"item, the API will null all the fields, with the exception of blocked_at, blocked_by, blocked_until and blocked_reason",
},
blocked_until: {
type: "string",
description: "Basically makes the block be temporary and will be automatically lifted by the database",
},
blocked_by: {
type: "string",
description: "By whom it was blocked",
},
blocked_reason: {
type: "string",
description: "A written text of why it was blocked",
},
}
export const CREATED_AT_INDEX = "CREATED_AT_INDEX";
export const CREATED_BY_INDEX = "CREATED_BY_INDEX";
export const PARENT_INDEX = "PARENT_INDEX";
export const COMBINED_INDEX = "COMBINED_INDEX";
export const TRACKERS_INDEX = "TRACKERS_INDEX";
/**
* The reserved base properties but in SQL form
*/
export const RESERVED_BASE_PROPERTIES_SQL: (combinedIndexes: string[], addedIndexes: string[]) => ISQLTableDefinitionType = (
combinedIndexes: string[],
addedIndexes: string[],
) => ({
id: {
type: "ID",
notNull: true,
index: {
id: "PRIMARY_KEY",
type: "primary",
level: 0,
},
},
version: {
type: "TEXT",
notNull: true,
// make it default to the invalid version value empty string
// this means null only for versions, this trick is done because
// it makes sense for the client, at the cost of the server logic
defaultTo: "",
index: {
id: "PRIMARY_KEY",
type: "primary",
level: 1,
},
},
type: {
type: "TEXT",
notNull: true,
},
parent_id: {
type: "TEXT",
index: combinedIndexes.includes("parent_id") ? {
id: COMBINED_INDEX,
type: "btree",
level: combinedIndexes.indexOf("parent_id"),
} : {
id: PARENT_INDEX,
type: "btree",
level: 0,
},
},
parent_version: {
type: "TEXT",
index: combinedIndexes.includes("parent_version") ? {
id: COMBINED_INDEX,
type: "btree",
level: combinedIndexes.indexOf("parent_version"),
} : {
id: PARENT_INDEX,
type: "btree",
level: 1,
},
},
parent_type: {
type: "TEXT",
index: combinedIndexes.includes("parent_type") ? {
id: COMBINED_INDEX,
type: "btree",
level: combinedIndexes.indexOf("parent_type"),
} : {
id: PARENT_INDEX,
type: "btree",
level: 2,
},
},
created_at: {
type: "TIMESTAMPTZ",
notNull: true,
index: (combinedIndexes.includes("created_at") || addedIndexes.includes("created_at")) ? {
id: combinedIndexes.includes("created_at") ? COMBINED_INDEX : CREATED_AT_INDEX,
type: "btree",
level: combinedIndexes.includes("created_at") ? combinedIndexes.indexOf("created_at") : 0,
} : null,
},
created_by: {
type: "TEXT",
notNull: true,
index: combinedIndexes.includes("created_by") ? {
id: COMBINED_INDEX,
type: "btree",
level: combinedIndexes.indexOf("created_by"),
} : {
id: CREATED_BY_INDEX,
type: "btree",
level: 0,
},
},
edited_at: {
type: "TIMESTAMPTZ",
},
edited_by: {
type: "TEXT",
},
reviewed_at: {
type: "TIMESTAMPTZ",
},
reviewed_by: {
type: "TEXT",
},
last_modified: {
type: "TIMESTAMPTZ",
},
blocked_at: {
type: "TIMESTAMPTZ",
},
blocked_until: {
type: "TIMESTAMPTZ",
},
blocked_by: {
type: "TEXT",
},
blocked_reason: {
type: "TEXT",
},
});
export const RESERVED_BASE_PROPERTIES_ELASTIC: IElasticIndexDefinitionType = {
properties: {
id: {
type: "keyword",
},
version: {
type: "keyword",
// this is an invalid id in the itemize structure as the ? is not a valid
// character which allows us to use it as null
null_value: "?NULL",
},
type: {
type: "keyword",
},
parent_id: {
type: "keyword",
},
parent_version: {
type: "keyword",
// this is an invalid id in the itemize structure as the ? is not a valid
// character which allows us to use it as null
null_value: "?NULL",
},
parent_type: {
type: "keyword",
},
created_at: {
type: "date_nanos",
format: DATETIME_FORMAT_ELASTIC_NANO,