@object-ui/data-objectstack 17.5.0 → 17.7.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 (53) hide show
  1. package/CHANGELOG.md +2311 -0
  2. package/README.md +557 -11
  3. package/dist/index.cjs +1663 -463
  4. package/dist/index.d.cts +1780 -518
  5. package/dist/index.d.ts +1780 -518
  6. package/dist/index.js +1648 -457
  7. package/package.json +9 -9
  8. package/dist/tsconfig.tsbuildinfo +0 -1
  9. package/src/aggregate-capability.test.ts +0 -177
  10. package/src/apiAccessDenied.test.ts +0 -233
  11. package/src/appAccessProbe.test.ts +0 -147
  12. package/src/bulkDelete.test.ts +0 -75
  13. package/src/bulkUpdate.test.ts +0 -93
  14. package/src/cache/MetadataCache.test.ts +0 -477
  15. package/src/cache/MetadataCache.ts +0 -289
  16. package/src/cloud-surface-retired-4152.pin.test.ts +0 -171
  17. package/src/connection.test.ts +0 -188
  18. package/src/contracts.ts +0 -115
  19. package/src/deleteView.homes.test.ts +0 -389
  20. package/src/deleteViewContract.types.test.ts +0 -246
  21. package/src/errors.test.ts +0 -426
  22. package/src/errors.ts +0 -293
  23. package/src/exportDownload.test.ts +0 -141
  24. package/src/filter-entry-translation.test.ts +0 -360
  25. package/src/filter-operator-ast-parity.test.ts +0 -135
  26. package/src/getObjectSchema.test.ts +0 -145
  27. package/src/httpFailureLogging.test.ts +0 -109
  28. package/src/importJob.test.ts +0 -71
  29. package/src/index.ts +0 -4442
  30. package/src/integration.ts +0 -200
  31. package/src/listViewOverrides.test.ts +0 -241
  32. package/src/listViews.test.ts +0 -175
  33. package/src/metadata-client.get-envelope.test.ts +0 -171
  34. package/src/metadata-client.saveAdvisories.test.ts +0 -226
  35. package/src/metadata-client.test.ts +0 -303
  36. package/src/metadata-client.ts +0 -1046
  37. package/src/occ.test.ts +0 -101
  38. package/src/onMutation.test.ts +0 -589
  39. package/src/onSaveAdvisory.test.ts +0 -311
  40. package/src/onWriteWarning.test.ts +0 -273
  41. package/src/orderby-serialization.test.ts +0 -115
  42. package/src/queryDataset.test.ts +0 -543
  43. package/src/searchAll.test.ts +0 -120
  44. package/src/security.ts +0 -243
  45. package/src/spec-symbol-batch6.test.ts +0 -326
  46. package/src/studio.ts +0 -152
  47. package/src/updateView.draft.test.ts +0 -242
  48. package/src/userState.test.ts +0 -315
  49. package/src/userState.ts +0 -238
  50. package/src/v3-compat.test.ts +0 -229
  51. package/src/validation-error.test.ts +0 -94
  52. package/src/viewCacheInvalidation.pin.test.ts +0 -260
  53. package/src/viewInvalidationSeam.pin.test.ts +0 -162
@@ -1,303 +0,0 @@
1
- /**
2
- * ObjectUI
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, beforeEach } from 'vitest';
10
- import { MetadataClient } from './metadata-client';
11
-
12
- function mockFetch(handler: (url: string, init?: RequestInit) => Promise<Response>): typeof fetch {
13
- return vi.fn(handler) as unknown as typeof fetch;
14
- }
15
-
16
- function jsonResponse(body: unknown, init?: ResponseInit): Response {
17
- return new Response(JSON.stringify(body), {
18
- status: 200,
19
- headers: { 'content-type': 'application/json' },
20
- ...init,
21
- });
22
- }
23
-
24
- describe('MetadataClient', () => {
25
- let urls: string[];
26
- let inits: (RequestInit | undefined)[];
27
-
28
- beforeEach(() => {
29
- urls = [];
30
- inits = [];
31
- });
32
-
33
- function client(baseUrl: string, environmentId?: string) {
34
- return new MetadataClient({
35
- baseUrl,
36
- environmentId,
37
- fetch: mockFetch(async (url, init) => {
38
- urls.push(url);
39
- inits.push(init);
40
- if (init?.method === 'PUT' || init?.method === 'DELETE') {
41
- return jsonResponse({ ok: true });
42
- }
43
- if (url.endsWith('/meta')) return jsonResponse([{ type: 'object' }]);
44
- if (url.match(/\/meta\/object$/)) return jsonResponse([{ name: 'account' }]);
45
- if (url.match(/\/meta\/object\/account$/)) {
46
- return jsonResponse({ name: 'account', label: 'Account' });
47
- }
48
- if (url.match(/\/meta\/object\/missing$/)) {
49
- return new Response('not found', { status: 404 });
50
- }
51
- if (url.match(/history$/)) return jsonResponse({ events: [] });
52
- return jsonResponse({ items: [{ name: 'fallback' }] });
53
- }),
54
- });
55
- }
56
-
57
- it('builds unscoped URLs against the bare baseUrl', async () => {
58
- await client('http://localhost:3000').list('object');
59
- expect(urls[0]).toBe('http://localhost:3000/api/v1/meta/object');
60
- });
61
-
62
- it('save() rejects an empty name before any request (#2767 empty-name 405)', async () => {
63
- const c = client('http://localhost:3000');
64
- await expect(c.save('view', '', { columns: [] })).rejects.toThrow(/name must be non-empty/);
65
- await expect(c.save('view', ' ', { columns: [] })).rejects.toThrow(/name must be non-empty/);
66
- // No malformed `PUT /meta/view/` ever reached the transport.
67
- expect(urls).toEqual([]);
68
- });
69
-
70
- it('builds scoped URLs when environmentId is set', async () => {
71
- await client('http://localhost:3000', 'env_42').list('object');
72
- expect(urls[0]).toBe('http://localhost:3000/api/v1/environments/env_42/meta/object');
73
- });
74
-
75
- it('collapses /api/v1 suffix on baseUrl to avoid duplication', async () => {
76
- await client('http://localhost:3000/api/v1').list('object');
77
- expect(urls[0]).toBe('http://localhost:3000/api/v1/meta/object');
78
- });
79
-
80
- it('returns null on 404 from get()', async () => {
81
- const result = await client('http://localhost:3000').get('object', 'missing');
82
- expect(result).toBeNull();
83
- });
84
-
85
- it('unwraps `items` envelope on list when the server returns one', async () => {
86
- const c = new MetadataClient({
87
- baseUrl: 'http://localhost:3000',
88
- fetch: mockFetch(async () => jsonResponse({ items: [{ name: 'wrapped' }] })),
89
- });
90
- const items = await c.list<{ name: string }>('field');
91
- expect(items).toEqual([{ name: 'wrapped' }]);
92
- });
93
-
94
- it('sends If-Match and X-Actor headers on save when provided', async () => {
95
- await client('http://localhost:3000').save('object', 'account', { foo: 1 }, {
96
- ifMatch: 'sha256:abc',
97
- actor: 'user_1',
98
- });
99
- expect(inits[0]?.method).toBe('PUT');
100
- const headers = inits[0]?.headers as Record<string, string>;
101
- expect(headers['If-Match']).toBe('sha256:abc');
102
- expect(headers['X-Actor']).toBe('user_1');
103
- expect(headers['Content-Type']).toBe('application/json');
104
- expect(inits[0]?.body).toBe(JSON.stringify({ foo: 1 }));
105
- });
106
-
107
- it('encodes type and name path segments', async () => {
108
- await client('http://localhost:3000').get('object', 'has spaces');
109
- expect(urls[0]).toBe('http://localhost:3000/api/v1/meta/object/has%20spaces');
110
- });
111
-
112
- it('builds history URL with query params', async () => {
113
- await client('http://localhost:3000').history('view', 'all', { sinceSeq: 10, limit: 5 });
114
- expect(urls[0]).toBe('http://localhost:3000/api/v1/meta/view/all/history?sinceSeq=10&limit=5');
115
- });
116
-
117
- it('throws MetadataError with status and body on failure', async () => {
118
- const c = new MetadataClient({
119
- baseUrl: 'http://localhost:3000',
120
- fetch: mockFetch(async () =>
121
- new Response(JSON.stringify({ error: 'metadata_conflict', code: 'metadata_conflict' }), {
122
- status: 409,
123
- headers: { 'content-type': 'application/json' },
124
- })),
125
- });
126
- await expect(c.save('object', 'account', {})).rejects.toMatchObject({
127
- status: 409,
128
- code: 'metadata_conflict',
129
- message: 'metadata_conflict',
130
- });
131
- });
132
-
133
- it('extracts message, code + field-anchored issues from the dispatcher error shape', async () => {
134
- // The dispatcher sends `error` as an OBJECT { message, code, details:{ code, issues } }.
135
- // Reading `.message` (not String(object) → "[object Object]") and surfacing
136
- // `details.issues` is what lets the Studio point at the offending field.
137
- const c = new MetadataClient({
138
- baseUrl: 'http://localhost:3000',
139
- fetch: mockFetch(async () =>
140
- new Response(
141
- JSON.stringify({
142
- success: false,
143
- error: {
144
- message: '[invalid_metadata] object/bad failed spec validation: label: Required',
145
- code: 422,
146
- details: {
147
- code: 'invalid_metadata',
148
- issues: [{ path: 'label', message: 'Required', code: 'invalid_type' }],
149
- },
150
- },
151
- }),
152
- { status: 422, headers: { 'content-type': 'application/json' } },
153
- )),
154
- });
155
- await expect(c.save('object', 'bad', {})).rejects.toMatchObject({
156
- status: 422,
157
- code: 'invalid_metadata',
158
- message: '[invalid_metadata] object/bad failed spec validation: label: Required',
159
- issues: [{ path: 'label', message: 'Required', code: 'invalid_type' }],
160
- });
161
- });
162
-
163
- it('listDrafts requests /meta/_drafts with packageId + type and parses {drafts}', async () => {
164
- const seen: string[] = [];
165
- const c = new MetadataClient({
166
- baseUrl: 'http://localhost:3000',
167
- fetch: mockFetch(async (url) => {
168
- seen.push(url);
169
- return jsonResponse({
170
- drafts: [{ type: 'object', name: 'course', packageId: 'app.edu', updatedAt: 't', updatedBy: 'ai' }],
171
- });
172
- }),
173
- });
174
- const out = await c.listDrafts({ packageId: 'app.edu', type: 'object' });
175
- expect(seen[0]).toBe('http://localhost:3000/api/v1/meta/_drafts?packageId=app.edu&type=object');
176
- expect(out).toEqual([
177
- { type: 'object', name: 'course', packageId: 'app.edu', updatedAt: 't', updatedBy: 'ai' },
178
- ]);
179
- });
180
-
181
- it('listDrafts tolerates the {data:{drafts}} envelope and a bare array', async () => {
182
- const enveloped = new MetadataClient({
183
- baseUrl: '',
184
- fetch: mockFetch(async () =>
185
- jsonResponse({ data: { drafts: [{ type: 'view', name: 'v', packageId: null, updatedAt: null, updatedBy: null }] } })),
186
- });
187
- expect((await enveloped.listDrafts()).map((d) => d.name)).toEqual(['v']);
188
-
189
- const bare = new MetadataClient({
190
- baseUrl: '',
191
- fetch: mockFetch(async () =>
192
- jsonResponse([{ type: 'object', name: 'b', packageId: null, updatedAt: null, updatedBy: null }])),
193
- });
194
- expect((await bare.listDrafts()).map((d) => d.name)).toEqual(['b']);
195
- });
196
-
197
- it('publishDraft POSTs /meta/:type/:name/publish (promotes a draft by ref, no package needed)', async () => {
198
- const seen: { url: string; method?: string }[] = [];
199
- const c = new MetadataClient({
200
- baseUrl: 'http://localhost:3000',
201
- fetch: mockFetch(async (url, init) => {
202
- seen.push({ url, method: init?.method });
203
- return jsonResponse({ success: true });
204
- }),
205
- });
206
- await c.publishDraft('dashboard', 'sales_dashboard');
207
- expect(seen[0]?.method).toBe('POST');
208
- expect(seen[0]?.url).toBe('http://localhost:3000/api/v1/meta/dashboard/sales_dashboard/publish');
209
- });
210
-
211
- it('publishDraft throws on a non-ok response', async () => {
212
- const c = new MetadataClient({
213
- baseUrl: '',
214
- fetch: mockFetch(async () => new Response('nope', { status: 500 })),
215
- });
216
- await expect(c.publishDraft('view', 'x')).rejects.toBeTruthy();
217
- });
218
-
219
- it('publishDraft returns the result (incl. seedApplied) and unwraps the {data} envelope', async () => {
220
- // Flat shape (rest-server passes protocol result through).
221
- const flat = new MetadataClient({
222
- baseUrl: '',
223
- fetch: mockFetch(async () =>
224
- jsonResponse({ success: true, seedApplied: { success: false, error: 'no readable seed bodies' } })),
225
- });
226
- const r1 = await flat.publishDraft('seed', 'job_sample');
227
- expect(r1.seedApplied).toEqual({ success: false, error: 'no readable seed bodies' });
228
-
229
- // Dispatcher `{ success, data: {...} }` envelope.
230
- const enveloped = new MetadataClient({
231
- baseUrl: '',
232
- fetch: mockFetch(async () =>
233
- jsonResponse({ success: true, data: { success: true, seedApplied: { success: true, inserted: 6, updated: 0 } } })),
234
- });
235
- const r2 = await enveloped.publishDraft('seed', 'candidate_sample');
236
- expect(r2.seedApplied).toEqual({ success: true, inserted: 6, updated: 0 });
237
- });
238
- });
239
-
240
- describe('MetadataClient — ADR-0037 previewDrafts', () => {
241
- function previewClient(opts: { previewDrafts?: boolean; environmentId?: string } = {}) {
242
- const urls: string[] = [];
243
- const c = new MetadataClient({
244
- baseUrl: 'http://localhost:3000',
245
- ...opts,
246
- fetch: mockFetch(async (url) => {
247
- urls.push(url);
248
- return jsonResponse([{ name: 'account' }]);
249
- }),
250
- });
251
- return { c, urls };
252
- }
253
-
254
- it('list() and get() append ?preview=draft when enabled', async () => {
255
- const { c, urls } = previewClient({ previewDrafts: true });
256
- await c.list('object');
257
- await c.get('object', 'account');
258
- expect(urls[0]).toBe('http://localhost:3000/api/v1/meta/object?preview=draft');
259
- expect(urls[1]).toBe('http://localhost:3000/api/v1/meta/object/account?preview=draft');
260
- });
261
-
262
- it('combines preview with the package filter on list()', async () => {
263
- const { c, urls } = previewClient({ previewDrafts: true });
264
- await c.list('object', { packageId: 'app.crm' });
265
- expect(urls[0]).toBe('http://localhost:3000/api/v1/meta/object?package=app.crm&preview=draft');
266
- });
267
-
268
- it('an explicit state=draft read wins over the overlay flag', async () => {
269
- const { c, urls } = previewClient({ previewDrafts: true });
270
- await c.get('object', 'account', { state: 'draft' });
271
- expect(urls[0]).toBe('http://localhost:3000/api/v1/meta/object/account?state=draft');
272
- });
273
-
274
- it('default client never sends the flag', async () => {
275
- const { c, urls } = previewClient();
276
- await c.list('object');
277
- await c.get('object', 'account');
278
- expect(urls[0]).not.toContain('preview');
279
- expect(urls[1]).not.toContain('preview');
280
- });
281
-
282
- it('withPreviewDrafts derives a preview client and PRESERVES the environment scope', async () => {
283
- const { c } = previewClient({ environmentId: 'env_1' });
284
- const p = c.withPreviewDrafts(true);
285
- expect(p.previewDrafts).toBe(true);
286
- // Same instance back when the flag already matches.
287
- expect(p.withPreviewDrafts(true)).toBe(p);
288
- // Environment-scoped path survives the derivation (regression guard:
289
- // a naive rebuild dropped /environments/:id from the base).
290
- const urls: string[] = [];
291
- const scoped = new MetadataClient({
292
- baseUrl: 'http://localhost:3000',
293
- environmentId: 'env_1',
294
- previewDrafts: false,
295
- fetch: mockFetch(async (url) => {
296
- urls.push(url);
297
- return jsonResponse([]);
298
- }),
299
- }).withPreviewDrafts(true);
300
- await scoped.list('object');
301
- expect(urls[0]).toBe('http://localhost:3000/api/v1/environments/env_1/meta/object?preview=draft');
302
- });
303
- });