@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,418 +0,0 @@
1
- /**
2
- * ObjectUI — ApiDataSource Tests
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import { describe, it, expect, vi } from 'vitest';
10
- import { ApiDataSource } from '../ApiDataSource';
11
-
12
- // ---------------------------------------------------------------------------
13
- // Mock fetch helper
14
- // ---------------------------------------------------------------------------
15
-
16
- function createMockFetch(response: any, options?: { status?: number; contentType?: string }) {
17
- const status = options?.status ?? 200;
18
- const ok = status >= 200 && status < 300;
19
- const contentType = options?.contentType ?? 'application/json';
20
-
21
- return vi.fn().mockResolvedValue({
22
- ok,
23
- status,
24
- statusText: ok ? 'OK' : 'Error',
25
- headers: {
26
- get: (name: string) => (name.toLowerCase() === 'content-type' ? contentType : null),
27
- },
28
- json: () => Promise.resolve(response),
29
- text: () => Promise.resolve(typeof response === 'string' ? response : JSON.stringify(response)),
30
- } as unknown as Response);
31
- }
32
-
33
- // ---------------------------------------------------------------------------
34
- // find
35
- // ---------------------------------------------------------------------------
36
-
37
- describe('ApiDataSource — find', () => {
38
- it('should fetch from the read URL', async () => {
39
- const mockFetch = createMockFetch([{ id: '1', name: 'Alice' }]);
40
- const ds = new ApiDataSource({
41
- read: { url: 'https://api.example.com/users' },
42
- fetch: mockFetch,
43
- });
44
-
45
- const result = await ds.find('users');
46
- expect(mockFetch).toHaveBeenCalledOnce();
47
- expect(result.data).toHaveLength(1);
48
- expect(result.data[0].name).toBe('Alice');
49
- });
50
-
51
- it('should pass query params to the URL', async () => {
52
- const mockFetch = createMockFetch([]);
53
- const ds = new ApiDataSource({
54
- read: { url: 'https://api.example.com/users' },
55
- fetch: mockFetch,
56
- });
57
-
58
- await ds.find('users', { $top: 10, $skip: 20, $select: ['name', 'age'] });
59
-
60
- const calledUrl = mockFetch.mock.calls[0][0] as string;
61
- // URLSearchParams encodes $ as %24
62
- expect(calledUrl).toContain('top=10');
63
- expect(calledUrl).toContain('skip=20');
64
- expect(calledUrl).toContain('select=');
65
- });
66
-
67
- it('should normalize array response into QueryResult', async () => {
68
- const items = [{ id: '1' }, { id: '2' }, { id: '3' }];
69
- const mockFetch = createMockFetch(items);
70
- const ds = new ApiDataSource({
71
- read: { url: '/api/users' },
72
- fetch: mockFetch,
73
- });
74
-
75
- const result = await ds.find('users');
76
- expect(result.data).toEqual(items);
77
- expect(result.total).toBe(3);
78
- });
79
-
80
- it('should normalize { data, total } response', async () => {
81
- const mockFetch = createMockFetch({
82
- data: [{ id: '1' }],
83
- total: 42,
84
- });
85
- const ds = new ApiDataSource({
86
- read: { url: '/api/users' },
87
- fetch: mockFetch,
88
- });
89
-
90
- const result = await ds.find('users');
91
- expect(result.data).toHaveLength(1);
92
- expect(result.total).toBe(42);
93
- });
94
-
95
- it('should normalize { items } response', async () => {
96
- const mockFetch = createMockFetch({
97
- items: [{ id: '1' }, { id: '2' }],
98
- count: 10,
99
- });
100
- const ds = new ApiDataSource({
101
- read: { url: '/api/users' },
102
- fetch: mockFetch,
103
- });
104
-
105
- const result = await ds.find('users');
106
- expect(result.data).toHaveLength(2);
107
- expect(result.total).toBe(10);
108
- });
109
-
110
- it('should normalize { results } response', async () => {
111
- const mockFetch = createMockFetch({
112
- results: [{ id: '1' }],
113
- });
114
- const ds = new ApiDataSource({
115
- read: { url: '/api/users' },
116
- fetch: mockFetch,
117
- });
118
-
119
- const result = await ds.find('users');
120
- expect(result.data).toHaveLength(1);
121
- });
122
-
123
- it('should normalize { records } response (Salesforce-style)', async () => {
124
- const mockFetch = createMockFetch({
125
- records: [{ id: '1' }, { id: '2' }],
126
- totalCount: 50,
127
- });
128
- const ds = new ApiDataSource({
129
- read: { url: '/api/users' },
130
- fetch: mockFetch,
131
- });
132
-
133
- const result = await ds.find('users');
134
- expect(result.data).toHaveLength(2);
135
- expect(result.total).toBe(50);
136
- });
137
-
138
- it('should normalize { value } response (OData-style)', async () => {
139
- const mockFetch = createMockFetch({
140
- value: [{ id: '1' }],
141
- });
142
- const ds = new ApiDataSource({
143
- read: { url: '/api/users' },
144
- fetch: mockFetch,
145
- });
146
-
147
- const result = await ds.find('users');
148
- expect(result.data).toHaveLength(1);
149
- });
150
-
151
- it('should wrap single-object response as array', async () => {
152
- const mockFetch = createMockFetch({ id: '1', name: 'Single' });
153
- const ds = new ApiDataSource({
154
- read: { url: '/api/users' },
155
- fetch: mockFetch,
156
- });
157
-
158
- const result = await ds.find('users');
159
- expect(result.data).toHaveLength(1);
160
- expect(result.data[0].name).toBe('Single');
161
- });
162
-
163
- it('should merge base params with query params', async () => {
164
- const mockFetch = createMockFetch([]);
165
- const ds = new ApiDataSource({
166
- read: { url: '/api/users', params: { tenant: 'acme' } },
167
- fetch: mockFetch,
168
- });
169
-
170
- await ds.find('users', { $top: 5 });
171
- const calledUrl = mockFetch.mock.calls[0][0] as string;
172
- expect(calledUrl).toContain('tenant=acme');
173
- expect(calledUrl).toContain('top=5');
174
- });
175
-
176
- it('should merge default headers with request headers', async () => {
177
- const mockFetch = createMockFetch([]);
178
- const ds = new ApiDataSource({
179
- read: { url: '/api/users', headers: { 'X-Api-Key': 'key123' } },
180
- fetch: mockFetch,
181
- defaultHeaders: { Authorization: 'Bearer token' },
182
- });
183
-
184
- await ds.find('users');
185
- const init = mockFetch.mock.calls[0][1] as RequestInit;
186
- const headers = init.headers as Record<string, string>;
187
- expect(headers['Authorization']).toBe('Bearer token');
188
- expect(headers['X-Api-Key']).toBe('key123');
189
- });
190
- });
191
-
192
- // ---------------------------------------------------------------------------
193
- // findOne
194
- // ---------------------------------------------------------------------------
195
-
196
- describe('ApiDataSource — findOne', () => {
197
- it('should append id to the URL path', async () => {
198
- const mockFetch = createMockFetch({ id: '42', name: 'Alice' });
199
- const ds = new ApiDataSource({
200
- read: { url: 'https://api.example.com/users' },
201
- fetch: mockFetch,
202
- });
203
-
204
- const record = await ds.findOne('users', '42');
205
- const calledUrl = mockFetch.mock.calls[0][0] as string;
206
- expect(calledUrl).toBe('https://api.example.com/users/42');
207
- expect(record?.name).toBe('Alice');
208
- });
209
-
210
- it('should return null on 404', async () => {
211
- const mockFetch = createMockFetch('Not Found', { status: 404, contentType: 'text/plain' });
212
- const ds = new ApiDataSource({
213
- read: { url: '/api/users' },
214
- fetch: mockFetch,
215
- });
216
-
217
- const record = await ds.findOne('users', '999');
218
- expect(record).toBeNull();
219
- });
220
- });
221
-
222
- // ---------------------------------------------------------------------------
223
- // create
224
- // ---------------------------------------------------------------------------
225
-
226
- describe('ApiDataSource — create', () => {
227
- it('should POST to the write URL', async () => {
228
- const mockFetch = createMockFetch({ id: 'new', name: 'Bob' });
229
- const ds = new ApiDataSource({
230
- write: { url: '/api/users', method: 'POST' },
231
- fetch: mockFetch,
232
- });
233
-
234
- const created = await ds.create('users', { name: 'Bob' });
235
- const init = mockFetch.mock.calls[0][1] as RequestInit;
236
- expect(init.method).toBe('POST');
237
- expect(init.body).toBe(JSON.stringify({ name: 'Bob' }));
238
- expect(created.name).toBe('Bob');
239
- });
240
-
241
- it('should fall back to read URL when write is not defined', async () => {
242
- const mockFetch = createMockFetch({ id: 'new' });
243
- const ds = new ApiDataSource({
244
- read: { url: '/api/users' },
245
- fetch: mockFetch,
246
- });
247
-
248
- await ds.create('users', { name: 'Test' });
249
- const calledUrl = mockFetch.mock.calls[0][0] as string;
250
- expect(calledUrl).toBe('/api/users');
251
- });
252
-
253
- it('should set Content-Type to application/json', async () => {
254
- const mockFetch = createMockFetch({});
255
- const ds = new ApiDataSource({
256
- write: { url: '/api/users' },
257
- fetch: mockFetch,
258
- });
259
-
260
- await ds.create('users', { name: 'Test' });
261
- const headers = (mockFetch.mock.calls[0][1] as RequestInit).headers as Record<string, string>;
262
- expect(headers['Content-Type']).toBe('application/json');
263
- });
264
- });
265
-
266
- // ---------------------------------------------------------------------------
267
- // update
268
- // ---------------------------------------------------------------------------
269
-
270
- describe('ApiDataSource — update', () => {
271
- it('should PATCH to the write URL with id suffix', async () => {
272
- const mockFetch = createMockFetch({ id: '1', name: 'Updated' });
273
- const ds = new ApiDataSource({
274
- write: { url: '/api/users' },
275
- fetch: mockFetch,
276
- });
277
-
278
- const updated = await ds.update('users', '1', { name: 'Updated' });
279
- const calledUrl = mockFetch.mock.calls[0][0] as string;
280
- const init = mockFetch.mock.calls[0][1] as RequestInit;
281
- expect(calledUrl).toContain('/1');
282
- expect(init.method).toBe('PATCH');
283
- expect(updated.name).toBe('Updated');
284
- });
285
- });
286
-
287
- // ---------------------------------------------------------------------------
288
- // delete
289
- // ---------------------------------------------------------------------------
290
-
291
- describe('ApiDataSource — delete', () => {
292
- it('should DELETE at the write URL with id suffix', async () => {
293
- const mockFetch = createMockFetch('', { contentType: 'text/plain' });
294
- const ds = new ApiDataSource({
295
- write: { url: '/api/users' },
296
- fetch: mockFetch,
297
- });
298
-
299
- const result = await ds.delete('users', '1');
300
- const init = mockFetch.mock.calls[0][1] as RequestInit;
301
- expect(init.method).toBe('DELETE');
302
- expect(result).toBe(true);
303
- });
304
-
305
- it('should return false on failure', async () => {
306
- const mockFetch = createMockFetch('Server Error', { status: 500, contentType: 'text/plain' });
307
- const ds = new ApiDataSource({
308
- write: { url: '/api/users' },
309
- fetch: mockFetch,
310
- });
311
-
312
- const result = await ds.delete('users', '1');
313
- expect(result).toBe(false);
314
- });
315
- });
316
-
317
- // ---------------------------------------------------------------------------
318
- // getObjectSchema
319
- // ---------------------------------------------------------------------------
320
-
321
- describe('ApiDataSource — getObjectSchema', () => {
322
- it('should return a minimal stub', async () => {
323
- const ds = new ApiDataSource({
324
- read: { url: '/api/users' },
325
- fetch: createMockFetch({}),
326
- });
327
-
328
- const schema = await ds.getObjectSchema('users');
329
- expect(schema.name).toBe('users');
330
- expect(schema.fields).toEqual({});
331
- });
332
- });
333
-
334
- // ---------------------------------------------------------------------------
335
- // Error handling
336
- // ---------------------------------------------------------------------------
337
-
338
- describe('ApiDataSource — errors', () => {
339
- it('should throw on HTTP error response for find', async () => {
340
- const mockFetch = createMockFetch('Forbidden', { status: 403, contentType: 'text/plain' });
341
- const ds = new ApiDataSource({
342
- read: { url: '/api/users' },
343
- fetch: mockFetch,
344
- });
345
-
346
- await expect(ds.find('users')).rejects.toThrow();
347
- });
348
-
349
- it('should throw when no read config provided for find', async () => {
350
- const ds = new ApiDataSource({
351
- write: { url: '/api/users' },
352
- fetch: createMockFetch({}),
353
- });
354
-
355
- await expect(ds.find('users')).rejects.toThrow('No HTTP configuration');
356
- });
357
-
358
- it('should throw when no config provided at all for create', async () => {
359
- const ds = new ApiDataSource({
360
- fetch: createMockFetch({}),
361
- });
362
-
363
- await expect(ds.create('users', { name: 'X' })).rejects.toThrow('No HTTP configuration');
364
- });
365
- });
366
-
367
- // ---------------------------------------------------------------------------
368
- // URL building
369
- // ---------------------------------------------------------------------------
370
-
371
- describe('ApiDataSource — URL building', () => {
372
- it('should handle trailing slashes in base URL', async () => {
373
- const mockFetch = createMockFetch({ id: '1' });
374
- const ds = new ApiDataSource({
375
- read: { url: 'https://api.example.com/users/' },
376
- fetch: mockFetch,
377
- });
378
-
379
- await ds.findOne('users', '42');
380
- const calledUrl = mockFetch.mock.calls[0][0] as string;
381
- expect(calledUrl).toBe('https://api.example.com/users/42');
382
- });
383
-
384
- it('should serialize $filter as JSON string', async () => {
385
- const mockFetch = createMockFetch([]);
386
- const ds = new ApiDataSource({
387
- read: { url: 'http://localhost/api/users' },
388
- fetch: mockFetch,
389
- });
390
-
391
- await ds.find('users', { $filter: { status: 'active' } });
392
- const calledUrl = mockFetch.mock.calls[0][0] as string;
393
- // URLSearchParams encodes $ as %24
394
- expect(calledUrl).toContain('filter=');
395
- // The value should be URL-encoded JSON
396
- const url = new URL(calledUrl);
397
- const filterParam = url.searchParams.get('$filter');
398
- expect(JSON.parse(filterParam!)).toEqual({ status: 'active' });
399
- });
400
-
401
- it('should serialize $orderby from Record format', async () => {
402
- const mockFetch = createMockFetch([]);
403
- const ds = new ApiDataSource({
404
- read: { url: 'http://localhost/api/users' },
405
- fetch: mockFetch,
406
- });
407
-
408
- await ds.find('users', { $orderby: { name: 'asc', age: 'desc' } });
409
- const calledUrl = mockFetch.mock.calls[0][0] as string;
410
- // URLSearchParams encodes $ as %24
411
- expect(calledUrl).toContain('orderby=');
412
- // Should contain the formatted orderby string
413
- const url = new URL(calledUrl);
414
- const orderbyParam = url.searchParams.get('$orderby');
415
- expect(orderbyParam).toContain('name asc');
416
- expect(orderbyParam).toContain('age desc');
417
- });
418
- });