@codex-ts/core-lib 1.0.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 (76) hide show
  1. package/dist/core-lib/fesm2022/core-lib.mjs +2349 -0
  2. package/dist/core-lib/fesm2022/core-lib.mjs.map +1 -0
  3. package/dist/core-lib/index.d.ts +29 -0
  4. package/dist/core-lib/lib/components/base-form.component.d.ts +62 -0
  5. package/dist/core-lib/lib/components/base-list-page.component.d.ts +132 -0
  6. package/dist/core-lib/lib/components/base-page.component.d.ts +25 -0
  7. package/dist/core-lib/lib/components/base-tabbed-form.component.d.ts +54 -0
  8. package/dist/core-lib/lib/components/formly/core-formly.module.d.ts +7 -0
  9. package/dist/core-lib/lib/components/formly/form-field.wrapper.d.ts +21 -0
  10. package/dist/core-lib/lib/components/formly/formly.constants.d.ts +13 -0
  11. package/dist/core-lib/lib/components/formly/types/checkbox.type.d.ts +12 -0
  12. package/dist/core-lib/lib/components/formly/types/date.type.d.ts +20 -0
  13. package/dist/core-lib/lib/components/formly/types/multiselect.type.d.ts +26 -0
  14. package/dist/core-lib/lib/components/formly/types/numeric-input.type.d.ts +17 -0
  15. package/dist/core-lib/lib/components/formly/types/radio.type.d.ts +13 -0
  16. package/dist/core-lib/lib/components/formly/types/select.type.d.ts +25 -0
  17. package/dist/core-lib/lib/components/formly/types/text-input.type.d.ts +12 -0
  18. package/dist/core-lib/lib/components/formly/types/textarea.type.d.ts +14 -0
  19. package/dist/core-lib/lib/constants/app.constants.d.ts +13 -0
  20. package/dist/core-lib/lib/constants/app.messages.d.ts +36 -0
  21. package/dist/core-lib/lib/enums/component-context.enum.d.ts +6 -0
  22. package/dist/core-lib/lib/enums/tabbed-form-type.enum.d.ts +4 -0
  23. package/dist/core-lib/lib/models/pagination/filter-criteria.interface.d.ts +9 -0
  24. package/dist/core-lib/lib/models/pagination/page-request.interface.d.ts +10 -0
  25. package/dist/core-lib/lib/models/pagination/page.interface.d.ts +9 -0
  26. package/dist/core-lib/lib/models/pagination/sort-criteria.interface.d.ts +4 -0
  27. package/dist/core-lib/lib/pipes/indian-date.pipe.d.ts +12 -0
  28. package/dist/core-lib/lib/services/base-crud.service.d.ts +36 -0
  29. package/dist/core-lib/lib/services/entity-registry.service.d.ts +26 -0
  30. package/dist/core-lib/lib/services/entity.service.d.ts +9 -0
  31. package/dist/core-lib/lib/services/enum-registry.service.d.ts +41 -0
  32. package/dist/core-lib/lib/services/formly-config.service.d.ts +11 -0
  33. package/dist/core-lib/lib/services/http-utility.service.d.ts +130 -0
  34. package/dist/core-lib/lib/services/notification.service.d.ts +13 -0
  35. package/dist/core-lib/lib/services/reference-data-provider.service.d.ts +8 -0
  36. package/dist/core-lib/lib/services/utils.service.d.ts +72 -0
  37. package/ng-package.json +7 -0
  38. package/package.json +63 -0
  39. package/src/index.ts +44 -0
  40. package/src/lib/components/base-form.component.ts +328 -0
  41. package/src/lib/components/base-list-page.component.ts +327 -0
  42. package/src/lib/components/base-page.component.ts +33 -0
  43. package/src/lib/components/base-tabbed-form.component.ts +345 -0
  44. package/src/lib/components/formly/core-formly.module.ts +34 -0
  45. package/src/lib/components/formly/field.interface.ts +15 -0
  46. package/src/lib/components/formly/form-field.wrapper.ts +94 -0
  47. package/src/lib/components/formly/formly.constants.ts +14 -0
  48. package/src/lib/components/formly/primeng-formly.module.ts +77 -0
  49. package/src/lib/components/formly/types/checkbox.type.ts +43 -0
  50. package/src/lib/components/formly/types/date.type.ts +88 -0
  51. package/src/lib/components/formly/types/multiselect.type.ts +61 -0
  52. package/src/lib/components/formly/types/numeric-input.type.ts +45 -0
  53. package/src/lib/components/formly/types/radio.type.ts +47 -0
  54. package/src/lib/components/formly/types/select.type.ts +54 -0
  55. package/src/lib/components/formly/types/text-input.type.ts +33 -0
  56. package/src/lib/components/formly/types/textarea.type.ts +37 -0
  57. package/src/lib/constants/app.constants.ts +15 -0
  58. package/src/lib/constants/app.messages.ts +36 -0
  59. package/src/lib/enums/component-context.enum.ts +6 -0
  60. package/src/lib/enums/tabbed-form-type.enum.ts +4 -0
  61. package/src/lib/models/pagination/filter-criteria.interface.ts +19 -0
  62. package/src/lib/models/pagination/page-request.interface.ts +13 -0
  63. package/src/lib/models/pagination/page.interface.ts +9 -0
  64. package/src/lib/models/pagination/sort-criteria.interface.ts +4 -0
  65. package/src/lib/pipes/indian-date.pipe.ts +46 -0
  66. package/src/lib/services/base-crud.service.ts +81 -0
  67. package/src/lib/services/entity-registry.service.ts +51 -0
  68. package/src/lib/services/entity.service.ts +10 -0
  69. package/src/lib/services/enum-registry.service.ts +66 -0
  70. package/src/lib/services/formly-config.service.ts +50 -0
  71. package/src/lib/services/http-utility.service.example.ts +253 -0
  72. package/src/lib/services/http-utility.service.md +175 -0
  73. package/src/lib/services/http-utility.service.ts +389 -0
  74. package/src/lib/services/notification.service.ts +35 -0
  75. package/src/lib/services/reference-data-provider.service.ts +28 -0
  76. package/src/lib/services/utils.service.ts +154 -0
@@ -0,0 +1,154 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { MessageService } from 'primeng/api';
3
+
4
+ /**
5
+ * A utility service that provides common reusable functionality
6
+ * such as UUID validation and error message display
7
+ */
8
+ @Injectable({
9
+ providedIn: 'root'
10
+ })
11
+ export class UtilsService {
12
+ /**
13
+ * Validates if a string is a valid UUID
14
+ * @param uuid The string to validate
15
+ * @returns boolean indicating if the string is a valid UUID
16
+ */
17
+ isValidUUID(uuid: string): boolean {
18
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
19
+ return uuidRegex.test(uuid);
20
+ }
21
+
22
+ /**
23
+ * Shows an error message using PrimeNG's MessageService
24
+ * @param message The error message to display
25
+ * @param messageService The MessageService instance to use
26
+ */
27
+ showError(message: string, messageService?: MessageService) {
28
+ if (messageService) {
29
+ messageService.add({
30
+ severity: 'error',
31
+ summary: 'Error',
32
+ detail: message,
33
+ life: 3000
34
+ });
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Shows a success message using PrimeNG's MessageService
40
+ * @param message The success message to display
41
+ * @param messageService The MessageService instance to use
42
+ */
43
+ showSuccess(message: string, messageService?: MessageService) {
44
+ if (messageService) {
45
+ messageService.add({
46
+ severity: 'success',
47
+ summary: 'Success',
48
+ detail: message,
49
+ life: 3000
50
+ });
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Gets the display value for an enum key or array of enum keys
56
+ * @param enumType The enum type
57
+ * @param key The enum key or array of enum keys
58
+ * @returns The display value for the enum key or comma-separated list of display values for array of keys
59
+ */
60
+ getEnumValue<T>(enumType: T, key: string | string[]): string {
61
+ if (!key) return '';
62
+
63
+ if (Array.isArray(key)) {
64
+ // Handle array of keys - map each to its display value and join with comma
65
+ return key.map(k => (enumType as any)[k] || k).join(', ');
66
+ }
67
+
68
+ // Handle single key
69
+ return (enumType as any)[key] || key;
70
+ }
71
+
72
+ /**
73
+ * Gets all values from an enum type for use in formly select fields
74
+ * @param enumType The enum type to get values from
75
+ * @returns Array of {label, value} pairs for formly select options
76
+ */
77
+ getEnumValues<T extends { [key: string]: string | number }>(enumType: T): Array<{label: string, value: string}> {
78
+ return Object.entries(enumType)
79
+ .filter(([key]) => isNaN(Number(key))) // Filter out reverse mappings
80
+ .map(([key, value]) => ({
81
+ value: key, // enum key as the value
82
+ label: value as string // enum value as the label
83
+ }));
84
+ }
85
+
86
+ /**
87
+ * Converts a camelCase string to Title Case with spaces
88
+ * @param camelCase The camelCase string to convert
89
+ * @returns The Title Case string
90
+ */
91
+ camelCaseToTitleCase(camelCase: string): string {
92
+ if (!camelCase) return '';
93
+ const spacedString = camelCase.replace(/([a-z])([A-Z])/g, '$1 $2');
94
+ return spacedString.charAt(0).toUpperCase() + spacedString.slice(1);
95
+ }
96
+
97
+ /**
98
+ * Converts a string to kebab-case
99
+ * @param input The string to convert
100
+ * @returns The kebab-case string
101
+ */
102
+ toKebabCase(input: string): string {
103
+ return input
104
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
105
+ .replace(/([A-Z])([A-Z])(?=[a-z])/g, '$1-$2')
106
+ .toLowerCase();
107
+ }
108
+
109
+ /**
110
+ * Converts a string to camelCase.
111
+ * Example: "loan-application" becomes "loanApplication"
112
+ * @param input The string to convert
113
+ * @returns The camelCase string
114
+ */
115
+ toCamelCase(input: string): string {
116
+ if (!input) return '';
117
+
118
+ // Split by non-alphanumeric chars
119
+ const words = input.split(/[^a-zA-Z0-9]/);
120
+ const result = [words[0].toLowerCase()];
121
+
122
+ // Capitalize first letter of remaining words
123
+ for (let i = 1; i < words.length; i++) {
124
+ const word = words[i];
125
+ if (word) {
126
+ result.push(word.charAt(0).toUpperCase() + word.substring(1).toLowerCase());
127
+ }
128
+ }
129
+
130
+ return result.join('');
131
+ }
132
+
133
+ /**
134
+ * Removes double forward slashes from an endpoint string while preserving the protocol
135
+ * e.g. "http://localhost:8080//api//v1//users" -> "http://localhost:8080/api/v1/users"
136
+ * @param endpoint The endpoint string to clean
137
+ * @returns The cleaned endpoint string without double slashes
138
+ */
139
+ removeDoubleSlashes(endpoint: string): string {
140
+ if (!endpoint) return '';
141
+
142
+ // Split the URL into protocol and the rest to preserve protocol slashes
143
+ const [protocol, ...rest] = endpoint.split('://');
144
+
145
+ if (!rest.length) {
146
+ // If no protocol is present, just clean the entire string
147
+ return endpoint.replace(/\/+/g, '/');
148
+ }
149
+
150
+ // Clean the path part (after protocol) and reconstruct the URL
151
+ const cleanPath = rest.join('://').replace(/\/+/g, '/');
152
+ return `${protocol}://${cleanPath}`;
153
+ }
154
+ }