@object-ui/core 3.1.5 → 3.3.1

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 (110) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +20 -1
  3. package/dist/actions/ActionRunner.d.ts +9 -0
  4. package/dist/actions/ActionRunner.js +41 -4
  5. package/dist/adapters/ValueDataSource.d.ts +5 -1
  6. package/dist/adapters/ValueDataSource.js +30 -1
  7. package/dist/errors/index.js +2 -3
  8. package/dist/evaluator/ExpressionCache.d.ts +9 -10
  9. package/dist/evaluator/ExpressionCache.js +29 -8
  10. package/dist/evaluator/SafeExpressionParser.d.ts +131 -0
  11. package/dist/evaluator/SafeExpressionParser.js +851 -0
  12. package/dist/evaluator/index.d.ts +1 -0
  13. package/dist/evaluator/index.js +1 -0
  14. package/dist/protocols/DndProtocol.js +2 -14
  15. package/dist/protocols/KeyboardProtocol.js +1 -4
  16. package/dist/protocols/NotificationProtocol.js +3 -13
  17. package/dist/utils/debug.js +2 -1
  18. package/dist/utils/filter-converter.js +25 -5
  19. package/package.json +33 -9
  20. package/.turbo/turbo-build.log +0 -4
  21. package/src/__benchmarks__/core.bench.ts +0 -64
  22. package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
  23. package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
  24. package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
  25. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
  26. package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
  27. package/src/actions/ActionEngine.ts +0 -268
  28. package/src/actions/ActionRunner.ts +0 -717
  29. package/src/actions/TransactionManager.ts +0 -521
  30. package/src/actions/UndoManager.ts +0 -215
  31. package/src/actions/__tests__/ActionEngine.test.ts +0 -206
  32. package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
  33. package/src/actions/__tests__/ActionRunner.test.ts +0 -711
  34. package/src/actions/__tests__/TransactionManager.test.ts +0 -447
  35. package/src/actions/__tests__/UndoManager.test.ts +0 -320
  36. package/src/actions/index.ts +0 -12
  37. package/src/adapters/ApiDataSource.ts +0 -376
  38. package/src/adapters/README.md +0 -180
  39. package/src/adapters/ValueDataSource.ts +0 -438
  40. package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
  41. package/src/adapters/__tests__/ValueDataSource.test.ts +0 -472
  42. package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
  43. package/src/adapters/index.ts +0 -15
  44. package/src/adapters/resolveDataSource.ts +0 -79
  45. package/src/builder/__tests__/schema-builder.test.ts +0 -235
  46. package/src/builder/schema-builder.ts +0 -584
  47. package/src/data-scope/DataScopeManager.ts +0 -269
  48. package/src/data-scope/ViewDataProvider.ts +0 -282
  49. package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
  50. package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
  51. package/src/data-scope/index.ts +0 -24
  52. package/src/errors/__tests__/errors.test.ts +0 -292
  53. package/src/errors/index.ts +0 -270
  54. package/src/evaluator/ExpressionCache.ts +0 -192
  55. package/src/evaluator/ExpressionContext.ts +0 -118
  56. package/src/evaluator/ExpressionEvaluator.ts +0 -315
  57. package/src/evaluator/FormulaFunctions.ts +0 -398
  58. package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
  59. package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
  60. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -131
  61. package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
  62. package/src/evaluator/index.ts +0 -12
  63. package/src/index.ts +0 -38
  64. package/src/protocols/DndProtocol.ts +0 -184
  65. package/src/protocols/KeyboardProtocol.ts +0 -185
  66. package/src/protocols/NotificationProtocol.ts +0 -159
  67. package/src/protocols/ResponsiveProtocol.ts +0 -210
  68. package/src/protocols/SharingProtocol.ts +0 -185
  69. package/src/protocols/index.ts +0 -13
  70. package/src/query/__tests__/query-ast.test.ts +0 -211
  71. package/src/query/__tests__/window-functions.test.ts +0 -275
  72. package/src/query/index.ts +0 -7
  73. package/src/query/query-ast.ts +0 -341
  74. package/src/registry/PluginScopeImpl.ts +0 -259
  75. package/src/registry/PluginSystem.ts +0 -206
  76. package/src/registry/Registry.ts +0 -219
  77. package/src/registry/WidgetRegistry.ts +0 -316
  78. package/src/registry/__tests__/PluginSystem.test.ts +0 -309
  79. package/src/registry/__tests__/Registry.test.ts +0 -293
  80. package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
  81. package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
  82. package/src/theme/ThemeEngine.ts +0 -530
  83. package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
  84. package/src/theme/index.ts +0 -24
  85. package/src/types/index.ts +0 -21
  86. package/src/utils/__tests__/debug-collector.test.ts +0 -102
  87. package/src/utils/__tests__/debug.test.ts +0 -134
  88. package/src/utils/__tests__/expand-fields.test.ts +0 -120
  89. package/src/utils/__tests__/extract-records.test.ts +0 -50
  90. package/src/utils/__tests__/filter-converter.test.ts +0 -118
  91. package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
  92. package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
  93. package/src/utils/debug-collector.ts +0 -100
  94. package/src/utils/debug.ts +0 -147
  95. package/src/utils/expand-fields.ts +0 -76
  96. package/src/utils/extract-records.ts +0 -33
  97. package/src/utils/filter-converter.ts +0 -133
  98. package/src/utils/merge-views-into-objects.ts +0 -36
  99. package/src/utils/normalize-quick-filter.ts +0 -78
  100. package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
  101. package/src/validation/__tests__/schema-validator.test.ts +0 -118
  102. package/src/validation/__tests__/validation-engine.test.ts +0 -102
  103. package/src/validation/index.ts +0 -10
  104. package/src/validation/schema-validator.ts +0 -344
  105. package/src/validation/validation-engine.ts +0 -528
  106. package/src/validation/validators/index.ts +0 -25
  107. package/src/validation/validators/object-validation-engine.ts +0 -722
  108. package/tsconfig.json +0 -15
  109. package/tsconfig.tsbuildinfo +0 -1
  110. package/vitest.config.ts +0 -2
@@ -1,142 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type {
3
- Notification as SpecNotification,
4
- NotificationConfig,
5
- } from '@object-ui/types';
6
- import {
7
- specNotificationToToast,
8
- mapSeverityToVariant,
9
- mapPosition,
10
- resolveNotificationConfig,
11
- } from '../../protocols/NotificationProtocol';
12
-
13
- describe('NotificationProtocol', () => {
14
- // ==========================================================================
15
- // mapSeverityToVariant
16
- // ==========================================================================
17
- describe('mapSeverityToVariant', () => {
18
- it.each([
19
- ['info', 'default'],
20
- ['success', 'success'],
21
- ['warning', 'warning'],
22
- ['error', 'destructive'],
23
- ] as const)('should map "%s" to "%s"', (severity, expected) => {
24
- expect(mapSeverityToVariant(severity)).toBe(expected);
25
- });
26
-
27
- it('should fall back to "default" for unknown severity', () => {
28
- expect(mapSeverityToVariant('critical')).toBe('default');
29
- });
30
- });
31
-
32
- // ==========================================================================
33
- // mapPosition
34
- // ==========================================================================
35
- describe('mapPosition', () => {
36
- it.each([
37
- ['top_left', 'top-left'],
38
- ['top_center', 'top-center'],
39
- ['top_right', 'top-right'],
40
- ['bottom_left', 'bottom-left'],
41
- ['bottom_center', 'bottom-center'],
42
- ['bottom_right', 'bottom-right'],
43
- ] as const)('should map "%s" to "%s"', (spec, expected) => {
44
- expect(mapPosition(spec)).toBe(expected);
45
- });
46
-
47
- it('should fall back to "top-right" for unknown position', () => {
48
- expect(mapPosition('center')).toBe('top-right');
49
- });
50
- });
51
-
52
- // ==========================================================================
53
- // resolveNotificationConfig
54
- // ==========================================================================
55
- describe('resolveNotificationConfig', () => {
56
- it('should apply all defaults for empty config', () => {
57
- const config = {} as NotificationConfig;
58
- const resolved = resolveNotificationConfig(config);
59
-
60
- expect(resolved.defaultPosition).toBe('top_right');
61
- expect(resolved.defaultDuration).toBe(5000);
62
- expect(resolved.maxVisible).toBe(5);
63
- expect(resolved.stackDirection).toBe('down');
64
- expect(resolved.pauseOnHover).toBe(true);
65
- });
66
-
67
- it('should preserve explicit values', () => {
68
- const config = {
69
- defaultPosition: 'bottom_left',
70
- defaultDuration: 3000,
71
- maxVisible: 3,
72
- stackDirection: 'up',
73
- pauseOnHover: false,
74
- } as NotificationConfig;
75
- const resolved = resolveNotificationConfig(config);
76
-
77
- expect(resolved.defaultPosition).toBe('bottom_left');
78
- expect(resolved.defaultDuration).toBe(3000);
79
- expect(resolved.maxVisible).toBe(3);
80
- expect(resolved.stackDirection).toBe('up');
81
- expect(resolved.pauseOnHover).toBe(false);
82
- });
83
- });
84
-
85
- // ==========================================================================
86
- // specNotificationToToast
87
- // ==========================================================================
88
- describe('specNotificationToToast', () => {
89
- it('should convert a basic notification to toast', () => {
90
- const notification = {
91
- message: 'Record saved',
92
- severity: 'success',
93
- } as SpecNotification;
94
- const toast = specNotificationToToast(notification);
95
-
96
- expect(toast.description).toBe('Record saved');
97
- expect(toast.variant).toBe('success');
98
- expect(toast.position).toBe('top-right');
99
- expect(toast.duration).toBe(5000);
100
- expect(toast.dismissible).toBe(true);
101
- expect(toast.actions).toEqual([]);
102
- });
103
-
104
- it('should handle translation objects for title and message', () => {
105
- const notification = {
106
- title: { key: 'notify.title', defaultValue: 'Heads up' },
107
- message: { key: 'notify.msg', defaultValue: 'Something happened' },
108
- } as unknown as SpecNotification;
109
- const toast = specNotificationToToast(notification);
110
-
111
- expect(toast.title).toBe('Heads up');
112
- expect(toast.description).toBe('Something happened');
113
- });
114
-
115
- it('should map actions to toast actions', () => {
116
- const notification = {
117
- message: 'Error occurred',
118
- severity: 'error',
119
- actions: [
120
- { label: 'Retry', action: 'retry', variant: 'primary' },
121
- { label: 'Dismiss', action: 'dismiss', variant: 'secondary' },
122
- ],
123
- } as unknown as SpecNotification;
124
- const toast = specNotificationToToast(notification);
125
-
126
- expect(toast.actions).toHaveLength(2);
127
- expect(toast.actions[0]).toEqual({ label: 'Retry', action: 'retry', variant: 'primary' });
128
- expect(toast.actions[1]).toEqual({ label: 'Dismiss', action: 'dismiss', variant: 'secondary' });
129
- });
130
-
131
- it('should apply defaults for missing fields', () => {
132
- const notification = {} as SpecNotification;
133
- const toast = specNotificationToToast(notification);
134
-
135
- expect(toast.description).toBe('');
136
- expect(toast.variant).toBe('default');
137
- expect(toast.position).toBe('top-right');
138
- expect(toast.duration).toBe(5000);
139
- expect(toast.dismissible).toBe(true);
140
- });
141
- });
142
- });
@@ -1,176 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type { SpecResponsiveConfig } from '@object-ui/types';
3
- import {
4
- getVisibilityClasses,
5
- getColumnClasses,
6
- getOrderClasses,
7
- shouldHideAtBreakpoint,
8
- resolveResponsiveConfig,
9
- BREAKPOINT_VALUES,
10
- } from '../../protocols/ResponsiveProtocol';
11
-
12
- describe('ResponsiveProtocol', () => {
13
- // ==========================================================================
14
- // BREAKPOINT_VALUES
15
- // ==========================================================================
16
- describe('BREAKPOINT_VALUES', () => {
17
- it('should export correct pixel values for all breakpoints', () => {
18
- expect(BREAKPOINT_VALUES.xs).toBe(0);
19
- expect(BREAKPOINT_VALUES.sm).toBe(640);
20
- expect(BREAKPOINT_VALUES.md).toBe(768);
21
- expect(BREAKPOINT_VALUES.lg).toBe(1024);
22
- expect(BREAKPOINT_VALUES.xl).toBe(1280);
23
- expect(BREAKPOINT_VALUES['2xl']).toBe(1536);
24
- });
25
- });
26
-
27
- // ==========================================================================
28
- // resolveResponsiveConfig
29
- // ==========================================================================
30
- describe('resolveResponsiveConfig', () => {
31
- it('should apply defaults for empty config', () => {
32
- const config = {} as SpecResponsiveConfig;
33
- const resolved = resolveResponsiveConfig(config);
34
-
35
- expect(resolved.breakpoint).toBeUndefined();
36
- expect(resolved.hiddenOn).toEqual([]);
37
- expect(resolved.columns).toEqual({});
38
- expect(resolved.order).toEqual({});
39
- });
40
-
41
- it('should preserve explicit values', () => {
42
- const config = {
43
- breakpoint: 'md',
44
- hiddenOn: ['sm'],
45
- columns: { xs: 1, md: 2 },
46
- order: { xs: 2, md: 1 },
47
- } as SpecResponsiveConfig;
48
- const resolved = resolveResponsiveConfig(config);
49
-
50
- expect(resolved.breakpoint).toBe('md');
51
- expect(resolved.hiddenOn).toEqual(['sm']);
52
- expect(resolved.columns).toEqual({ xs: 1, md: 2 });
53
- expect(resolved.order).toEqual({ xs: 2, md: 1 });
54
- });
55
- });
56
-
57
- // ==========================================================================
58
- // getVisibilityClasses
59
- // ==========================================================================
60
- describe('getVisibilityClasses', () => {
61
- it('should return empty array for no visibility config', () => {
62
- const config = {} as SpecResponsiveConfig;
63
- expect(getVisibilityClasses(config)).toEqual([]);
64
- });
65
-
66
- it('should return hidden + breakpoint:block for minimum breakpoint', () => {
67
- const config = { breakpoint: 'md' } as SpecResponsiveConfig;
68
- const classes = getVisibilityClasses(config);
69
-
70
- expect(classes).toContain('hidden');
71
- expect(classes).toContain('md:block');
72
- });
73
-
74
- it('should not add hidden class for xs breakpoint', () => {
75
- const config = { breakpoint: 'xs' } as SpecResponsiveConfig;
76
- const classes = getVisibilityClasses(config);
77
-
78
- expect(classes).not.toContain('hidden');
79
- });
80
-
81
- it('should generate toggle classes for hiddenOn', () => {
82
- const config = { hiddenOn: ['sm'] } as SpecResponsiveConfig;
83
- const classes = getVisibilityClasses(config);
84
-
85
- expect(classes).toContain('sm:hidden');
86
- expect(classes).toContain('md:block');
87
- });
88
-
89
- it('should handle hiddenOn at xs breakpoint', () => {
90
- const config = { hiddenOn: ['xs'] } as SpecResponsiveConfig;
91
- const classes = getVisibilityClasses(config);
92
-
93
- expect(classes).toContain('hidden');
94
- expect(classes).toContain('sm:block');
95
- });
96
- });
97
-
98
- // ==========================================================================
99
- // getColumnClasses
100
- // ==========================================================================
101
- describe('getColumnClasses', () => {
102
- it('should return empty array when no columns set', () => {
103
- const config = {} as SpecResponsiveConfig;
104
- expect(getColumnClasses(config)).toEqual([]);
105
- });
106
-
107
- it('should return grid-cols classes for each breakpoint', () => {
108
- const config = {
109
- columns: { xs: 1, md: 2, xl: 4 },
110
- } as SpecResponsiveConfig;
111
- const classes = getColumnClasses(config);
112
-
113
- expect(classes).toContain('grid-cols-1');
114
- expect(classes).toContain('md:grid-cols-2');
115
- expect(classes).toContain('xl:grid-cols-4');
116
- });
117
-
118
- it('should omit prefix for xs breakpoint', () => {
119
- const config = { columns: { xs: 3 } } as SpecResponsiveConfig;
120
- const classes = getColumnClasses(config);
121
-
122
- expect(classes).toEqual(['grid-cols-3']);
123
- });
124
- });
125
-
126
- // ==========================================================================
127
- // getOrderClasses
128
- // ==========================================================================
129
- describe('getOrderClasses', () => {
130
- it('should return empty array when no order set', () => {
131
- const config = {} as SpecResponsiveConfig;
132
- expect(getOrderClasses(config)).toEqual([]);
133
- });
134
-
135
- it('should return order classes for each breakpoint', () => {
136
- const config = {
137
- order: { xs: 2, lg: 1 },
138
- } as SpecResponsiveConfig;
139
- const classes = getOrderClasses(config);
140
-
141
- expect(classes).toContain('order-2');
142
- expect(classes).toContain('lg:order-1');
143
- });
144
- });
145
-
146
- // ==========================================================================
147
- // shouldHideAtBreakpoint
148
- // ==========================================================================
149
- describe('shouldHideAtBreakpoint', () => {
150
- it('should hide below minimum breakpoint', () => {
151
- const config = { breakpoint: 'md' } as SpecResponsiveConfig;
152
-
153
- expect(shouldHideAtBreakpoint(config, 600)).toBe(true); // below 768
154
- expect(shouldHideAtBreakpoint(config, 768)).toBe(false); // at 768
155
- expect(shouldHideAtBreakpoint(config, 1024)).toBe(false); // above 768
156
- });
157
-
158
- it('should hide at breakpoints in hiddenOn list', () => {
159
- const config = { hiddenOn: ['sm', 'lg'] } as SpecResponsiveConfig;
160
-
161
- expect(shouldHideAtBreakpoint(config, 700)).toBe(true); // sm range
162
- expect(shouldHideAtBreakpoint(config, 800)).toBe(false); // md range
163
- expect(shouldHideAtBreakpoint(config, 1100)).toBe(true); // lg range
164
- });
165
-
166
- it('should return false when no config constraints', () => {
167
- const config = {} as SpecResponsiveConfig;
168
- expect(shouldHideAtBreakpoint(config, 500)).toBe(false);
169
- });
170
-
171
- it('should not hide at xs width when no constraints', () => {
172
- const config = {} as SpecResponsiveConfig;
173
- expect(shouldHideAtBreakpoint(config, 0)).toBe(false);
174
- });
175
- });
176
- });
@@ -1,188 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type { SharingConfig, EmbedConfig } from '@object-ui/types';
3
- import {
4
- resolveSharingConfig,
5
- resolveEmbedConfig,
6
- generateEmbedCode,
7
- validateSharingConfig,
8
- } from '../../protocols/SharingProtocol';
9
-
10
- describe('SharingProtocol', () => {
11
- // ==========================================================================
12
- // resolveSharingConfig
13
- // ==========================================================================
14
- describe('resolveSharingConfig', () => {
15
- it('should apply defaults for empty config', () => {
16
- const resolved = resolveSharingConfig({});
17
-
18
- expect(resolved.enabled).toBe(false);
19
- expect(resolved.allowedDomains).toEqual([]);
20
- expect(resolved.allowAnonymous).toBe(false);
21
- expect(resolved.publicLink).toBeUndefined();
22
- expect(resolved.password).toBeUndefined();
23
- expect(resolved.expiresAt).toBeUndefined();
24
- });
25
-
26
- it('should preserve explicit values', () => {
27
- const config: Partial<SharingConfig> = {
28
- enabled: true,
29
- publicLink: 'https://example.com/share/abc',
30
- password: 'secret',
31
- allowedDomains: ['example.com'],
32
- expiresAt: '2025-12-31T00:00:00Z',
33
- allowAnonymous: true,
34
- };
35
- const resolved = resolveSharingConfig(config);
36
-
37
- expect(resolved.enabled).toBe(true);
38
- expect(resolved.publicLink).toBe('https://example.com/share/abc');
39
- expect(resolved.password).toBe('secret');
40
- expect(resolved.allowedDomains).toEqual(['example.com']);
41
- expect(resolved.expiresAt).toBe('2025-12-31T00:00:00Z');
42
- expect(resolved.allowAnonymous).toBe(true);
43
- });
44
- });
45
-
46
- // ==========================================================================
47
- // resolveEmbedConfig
48
- // ==========================================================================
49
- describe('resolveEmbedConfig', () => {
50
- it('should apply defaults for empty config', () => {
51
- const resolved = resolveEmbedConfig({});
52
-
53
- expect(resolved.enabled).toBe(false);
54
- expect(resolved.allowedOrigins).toEqual([]);
55
- expect(resolved.width).toBe('100%');
56
- expect(resolved.height).toBe('600px');
57
- expect(resolved.showHeader).toBe(true);
58
- expect(resolved.showNavigation).toBe(false);
59
- expect(resolved.responsive).toBe(true);
60
- });
61
-
62
- it('should preserve explicit values', () => {
63
- const config: Partial<EmbedConfig> = {
64
- enabled: true,
65
- width: '800px',
66
- height: '400px',
67
- showHeader: false,
68
- responsive: false,
69
- };
70
- const resolved = resolveEmbedConfig(config);
71
-
72
- expect(resolved.enabled).toBe(true);
73
- expect(resolved.width).toBe('800px');
74
- expect(resolved.height).toBe('400px');
75
- expect(resolved.showHeader).toBe(false);
76
- expect(resolved.responsive).toBe(false);
77
- });
78
- });
79
-
80
- // ==========================================================================
81
- // generateEmbedCode
82
- // ==========================================================================
83
- describe('generateEmbedCode', () => {
84
- it('should return valid iframe HTML', () => {
85
- const config = {} as EmbedConfig;
86
- const html = generateEmbedCode(config, 'https://app.example.com/view/123');
87
-
88
- expect(html).toContain('<iframe');
89
- expect(html).toContain('</iframe>');
90
- expect(html).toContain('src="https://app.example.com/view/123"');
91
- expect(html).toContain('width="100%"');
92
- expect(html).toContain('height="600px"');
93
- expect(html).toContain('allowfullscreen');
94
- });
95
-
96
- it('should include responsive style when responsive is true', () => {
97
- const config = { responsive: true } as EmbedConfig;
98
- const html = generateEmbedCode(config, 'https://example.com');
99
-
100
- expect(html).toContain('max-width: 100%');
101
- });
102
-
103
- it('should not include max-width when responsive is false', () => {
104
- const config = { responsive: false } as EmbedConfig;
105
- const html = generateEmbedCode(config, 'https://example.com');
106
-
107
- expect(html).not.toContain('max-width');
108
- });
109
-
110
- it('should HTML-escape URLs to prevent XSS', () => {
111
- const config = {} as EmbedConfig;
112
- const maliciousUrl = 'https://example.com/"><script>alert("xss")</script>';
113
- const html = generateEmbedCode(config, maliciousUrl);
114
-
115
- expect(html).not.toContain('<script>');
116
- expect(html).toContain('&lt;script&gt;');
117
- expect(html).toContain('&quot;');
118
- });
119
- });
120
-
121
- // ==========================================================================
122
- // validateSharingConfig
123
- // ==========================================================================
124
- describe('validateSharingConfig', () => {
125
- it('should return valid for a well-formed config', () => {
126
- const config = {
127
- enabled: true,
128
- publicLink: 'https://example.com/share/abc',
129
- allowedDomains: ['example.com'],
130
- } as SharingConfig;
131
- const result = validateSharingConfig(config);
132
-
133
- expect(result.valid).toBe(true);
134
- expect(result.errors).toEqual([]);
135
- });
136
-
137
- it('should error when enabled without publicLink', () => {
138
- const config = { enabled: true } as SharingConfig;
139
- const result = validateSharingConfig(config);
140
-
141
- expect(result.valid).toBe(false);
142
- expect(result.errors).toContain('A public link is required when sharing is enabled.');
143
- });
144
-
145
- it('should error for invalid expiresAt date', () => {
146
- const config = {
147
- enabled: false,
148
- expiresAt: 'not-a-date',
149
- } as SharingConfig;
150
- const result = validateSharingConfig(config);
151
-
152
- expect(result.valid).toBe(false);
153
- expect(result.errors).toContain('expiresAt must be a valid ISO 8601 date string.');
154
- });
155
-
156
- it('should error for empty password string', () => {
157
- const config = {
158
- enabled: false,
159
- password: '',
160
- } as SharingConfig;
161
- const result = validateSharingConfig(config);
162
-
163
- expect(result.valid).toBe(false);
164
- expect(result.errors).toContain('Password must not be an empty string when provided.');
165
- });
166
-
167
- it('should error for empty domain entries', () => {
168
- const config = {
169
- enabled: false,
170
- allowedDomains: ['example.com', ' '],
171
- } as SharingConfig;
172
- const result = validateSharingConfig(config);
173
-
174
- expect(result.valid).toBe(false);
175
- expect(result.errors).toContain(
176
- 'allowedDomains contains an empty or whitespace-only entry.'
177
- );
178
- });
179
-
180
- it('should return valid for disabled config with no issues', () => {
181
- const config = { enabled: false } as SharingConfig;
182
- const result = validateSharingConfig(config);
183
-
184
- expect(result.valid).toBe(true);
185
- expect(result.errors).toEqual([]);
186
- });
187
- });
188
- });