@object-ui/data-objectstack 3.1.2 → 3.1.4
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.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/src/expand.test.ts +15 -15
- package/src/index.ts +2 -2
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/data-objectstack",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "ObjectStack Data Adapter for Object UI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"README.md"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@objectstack/client": "^3.2.
|
|
24
|
-
"@object-ui/core": "3.1.
|
|
25
|
-
"@object-ui/types": "3.1.
|
|
23
|
+
"@objectstack/client": "^3.2.9",
|
|
24
|
+
"@object-ui/core": "3.1.4",
|
|
25
|
+
"@object-ui/types": "3.1.4"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"tsup": "^8.5.1",
|
|
29
29
|
"typescript": "^5.9.3",
|
|
30
|
-
"vitest": "^4.0
|
|
30
|
+
"vitest": "^4.1.0"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
package/src/expand.test.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { ObjectStackAdapter } from './index';
|
|
|
16
16
|
// The key scenarios:
|
|
17
17
|
// 1. find() with $expand → raw GET /api/v1/data/:object?populate=...
|
|
18
18
|
// 2. find() without $expand → client.data.find() (GET) as before
|
|
19
|
-
// 3. findOne() with $expand → raw GET /api/v1/data/:object?filter={
|
|
19
|
+
// 3. findOne() with $expand → raw GET /api/v1/data/:object?filter={id:...}&populate=...
|
|
20
20
|
// 4. findOne() without $expand → client.data.get() as before
|
|
21
21
|
|
|
22
22
|
describe('ObjectStackAdapter $expand support', () => {
|
|
@@ -42,7 +42,7 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
42
42
|
data: {
|
|
43
43
|
find: vi.fn().mockResolvedValue({ records: [], total: 0 }),
|
|
44
44
|
query: vi.fn().mockResolvedValue({ records: [], total: 0 }),
|
|
45
|
-
get: vi.fn().mockResolvedValue({ record: {
|
|
45
|
+
get: vi.fn().mockResolvedValue({ record: { id: '1', name: 'Test' } }),
|
|
46
46
|
},
|
|
47
47
|
connect: vi.fn().mockResolvedValue(undefined),
|
|
48
48
|
discover: vi.fn().mockResolvedValue({ status: 'ok' }),
|
|
@@ -58,7 +58,7 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
58
58
|
mockFetch.mockResolvedValue({
|
|
59
59
|
ok: true,
|
|
60
60
|
json: () => Promise.resolve({
|
|
61
|
-
records: [{
|
|
61
|
+
records: [{ id: '1', name: 'Order 1', customer: { id: '2', name: 'Alice' } }],
|
|
62
62
|
total: 1,
|
|
63
63
|
}),
|
|
64
64
|
});
|
|
@@ -76,7 +76,7 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
76
76
|
expect(fetchUrl).toContain('top=10');
|
|
77
77
|
expect(mockClient.data.find).not.toHaveBeenCalled();
|
|
78
78
|
expect(result.data).toHaveLength(1);
|
|
79
|
-
expect(result.data[0].customer).toEqual({
|
|
79
|
+
expect(result.data[0].customer).toEqual({ id: '2', name: 'Alice' });
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it('should pass filters and sort as query params', async () => {
|
|
@@ -103,7 +103,7 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
it('should use data.find() when $expand is not present', async () => {
|
|
106
|
-
mockClient.data.find.mockResolvedValue({ records: [{
|
|
106
|
+
mockClient.data.find.mockResolvedValue({ records: [{ id: '1', name: 'Test' }], total: 1 });
|
|
107
107
|
|
|
108
108
|
const result = await adapter.find('order', { $top: 10 });
|
|
109
109
|
|
|
@@ -121,11 +121,11 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
describe('findOne() with $expand', () => {
|
|
124
|
-
it('should make a raw GET request with
|
|
124
|
+
it('should make a raw GET request with id filter and populate when $expand is present', async () => {
|
|
125
125
|
mockFetch.mockResolvedValue({
|
|
126
126
|
ok: true,
|
|
127
127
|
json: () => Promise.resolve({
|
|
128
|
-
records: [{
|
|
128
|
+
records: [{ id: 'order-1', name: 'Order 1', customer: { id: '2', name: 'Alice' } }],
|
|
129
129
|
}),
|
|
130
130
|
});
|
|
131
131
|
|
|
@@ -139,13 +139,13 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
139
139
|
expect(fetchUrl).toContain('populate=customer%2Caccount');
|
|
140
140
|
expect(fetchUrl).toContain('top=1');
|
|
141
141
|
expect(fetchUrl).toContain('filter=');
|
|
142
|
-
// Verify the filter contains
|
|
142
|
+
// Verify the filter contains id
|
|
143
143
|
const filterParam = new URL(fetchUrl).searchParams.get('filter');
|
|
144
144
|
expect(filterParam).toBeTruthy();
|
|
145
145
|
const parsedFilter = JSON.parse(filterParam!);
|
|
146
|
-
expect(parsedFilter).toEqual({
|
|
146
|
+
expect(parsedFilter).toEqual({ id: 'order-1' });
|
|
147
147
|
expect(mockClient.data.get).not.toHaveBeenCalled();
|
|
148
|
-
expect(result).toEqual({
|
|
148
|
+
expect(result).toEqual({ id: 'order-1', name: 'Order 1', customer: { id: '2', name: 'Alice' } });
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
it('should return null when raw request returns no records', async () => {
|
|
@@ -162,12 +162,12 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
it('should use data.get() when $expand is not present', async () => {
|
|
165
|
-
mockClient.data.get.mockResolvedValue({ record: {
|
|
165
|
+
mockClient.data.get.mockResolvedValue({ record: { id: '1', name: 'Test' } });
|
|
166
166
|
|
|
167
167
|
const result = await adapter.findOne('order', '1');
|
|
168
168
|
|
|
169
169
|
expect(mockClient.data.get).toHaveBeenCalledWith('order', '1');
|
|
170
|
-
expect(result).toEqual({
|
|
170
|
+
expect(result).toEqual({ id: '1', name: 'Test' });
|
|
171
171
|
});
|
|
172
172
|
|
|
173
173
|
it('should return null for 404 errors without $expand', async () => {
|
|
@@ -187,7 +187,7 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
187
187
|
json: () => Promise.resolve({ message: 'unsupported' }),
|
|
188
188
|
});
|
|
189
189
|
// But the direct data.get() call succeeds
|
|
190
|
-
mockClient.data.get.mockResolvedValue({ record: {
|
|
190
|
+
mockClient.data.get.mockResolvedValue({ record: { id: 'order-1', name: 'Order 1' } });
|
|
191
191
|
|
|
192
192
|
const result = await adapter.findOne('order', 'order-1', {
|
|
193
193
|
$expand: ['customer'],
|
|
@@ -197,7 +197,7 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
197
197
|
expect(mockFetch).toHaveBeenCalled();
|
|
198
198
|
// Then fell through to data.get()
|
|
199
199
|
expect(mockClient.data.get).toHaveBeenCalledWith('order', 'order-1');
|
|
200
|
-
expect(result).toEqual({
|
|
200
|
+
expect(result).toEqual({ id: 'order-1', name: 'Order 1' });
|
|
201
201
|
});
|
|
202
202
|
});
|
|
203
203
|
|
|
@@ -225,7 +225,7 @@ describe('ObjectStackAdapter $expand support', () => {
|
|
|
225
225
|
json: () => Promise.resolve({
|
|
226
226
|
success: true,
|
|
227
227
|
data: {
|
|
228
|
-
records: [{
|
|
228
|
+
records: [{ id: '1', name: 'Order' }],
|
|
229
229
|
total: 1,
|
|
230
230
|
},
|
|
231
231
|
}),
|
package/src/index.ts
CHANGED
|
@@ -278,14 +278,14 @@ export class ObjectStackAdapter<T = unknown> implements DataSource<T> {
|
|
|
278
278
|
async findOne(resource: string, id: string | number, params?: QueryParams): Promise<T | null> {
|
|
279
279
|
await this.connect();
|
|
280
280
|
|
|
281
|
-
// When $expand is requested, use a raw GET request with a filter by
|
|
281
|
+
// When $expand is requested, use a raw GET request with a filter by id
|
|
282
282
|
// and populate. The installed server v3.0.10's getData() does not support
|
|
283
283
|
// expand/populate, so we route through findData which does.
|
|
284
284
|
if (params?.$expand && params.$expand.length > 0) {
|
|
285
285
|
try {
|
|
286
286
|
const findParams: QueryParams = {
|
|
287
287
|
...params,
|
|
288
|
-
$filter: {
|
|
288
|
+
$filter: { id: String(id) },
|
|
289
289
|
$top: 1,
|
|
290
290
|
};
|
|
291
291
|
const result = await this.rawFindWithPopulate(resource, findParams);
|