@objectstack/objectql 3.2.1 → 3.2.3
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +17 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +37 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/engine.test.ts +46 -46
- package/src/engine.ts +8 -10
- package/src/plugin.integration.test.ts +23 -24
- package/src/plugin.ts +17 -14
- package/src/protocol-data.test.ts +12 -12
- package/src/protocol.ts +17 -17
|
@@ -129,14 +129,14 @@ describe('ObjectStackProtocolImplementation - Data Operations', () => {
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
it('should return records and standard response shape', async () => {
|
|
132
|
-
mockEngine.find.mockResolvedValue([{
|
|
132
|
+
mockEngine.find.mockResolvedValue([{ id: 't1', name: 'Task 1' }]);
|
|
133
133
|
|
|
134
134
|
const result = await protocol.findData({ object: 'task', query: {} });
|
|
135
135
|
|
|
136
136
|
expect(result).toEqual(
|
|
137
137
|
expect.objectContaining({
|
|
138
138
|
object: 'task',
|
|
139
|
-
records: [{
|
|
139
|
+
records: [{ id: 't1', name: 'Task 1' }],
|
|
140
140
|
total: 1,
|
|
141
141
|
}),
|
|
142
142
|
);
|
|
@@ -149,21 +149,21 @@ describe('ObjectStackProtocolImplementation - Data Operations', () => {
|
|
|
149
149
|
|
|
150
150
|
describe('getData', () => {
|
|
151
151
|
it('should convert expand string to populate array', async () => {
|
|
152
|
-
mockEngine.findOne.mockResolvedValue({
|
|
152
|
+
mockEngine.findOne.mockResolvedValue({ id: 'oi_1', name: 'Item 1' });
|
|
153
153
|
|
|
154
154
|
await protocol.getData({ object: 'order_item', id: 'oi_1', expand: 'order,product' });
|
|
155
155
|
|
|
156
156
|
expect(mockEngine.findOne).toHaveBeenCalledWith(
|
|
157
157
|
'order_item',
|
|
158
158
|
expect.objectContaining({
|
|
159
|
-
filter: {
|
|
159
|
+
filter: { id: 'oi_1' },
|
|
160
160
|
populate: ['order', 'product'],
|
|
161
161
|
}),
|
|
162
162
|
);
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
it('should convert expand array to populate array', async () => {
|
|
166
|
-
mockEngine.findOne.mockResolvedValue({
|
|
166
|
+
mockEngine.findOne.mockResolvedValue({ id: 't1' });
|
|
167
167
|
|
|
168
168
|
await protocol.getData({ object: 'task', id: 't1', expand: ['assignee', 'project'] });
|
|
169
169
|
|
|
@@ -176,7 +176,7 @@ describe('ObjectStackProtocolImplementation - Data Operations', () => {
|
|
|
176
176
|
});
|
|
177
177
|
|
|
178
178
|
it('should convert select string to array', async () => {
|
|
179
|
-
mockEngine.findOne.mockResolvedValue({
|
|
179
|
+
mockEngine.findOne.mockResolvedValue({ id: 't1', name: 'Test' });
|
|
180
180
|
|
|
181
181
|
await protocol.getData({ object: 'task', id: 't1', select: 'name,status' });
|
|
182
182
|
|
|
@@ -189,7 +189,7 @@ describe('ObjectStackProtocolImplementation - Data Operations', () => {
|
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
it('should pass both expand and select together', async () => {
|
|
192
|
-
mockEngine.findOne.mockResolvedValue({
|
|
192
|
+
mockEngine.findOne.mockResolvedValue({ id: 'oi_1' });
|
|
193
193
|
|
|
194
194
|
await protocol.getData({
|
|
195
195
|
object: 'order_item',
|
|
@@ -201,7 +201,7 @@ describe('ObjectStackProtocolImplementation - Data Operations', () => {
|
|
|
201
201
|
expect(mockEngine.findOne).toHaveBeenCalledWith(
|
|
202
202
|
'order_item',
|
|
203
203
|
expect.objectContaining({
|
|
204
|
-
filter: {
|
|
204
|
+
filter: { id: 'oi_1' },
|
|
205
205
|
populate: ['order'],
|
|
206
206
|
select: ['name', 'total'],
|
|
207
207
|
}),
|
|
@@ -209,25 +209,25 @@ describe('ObjectStackProtocolImplementation - Data Operations', () => {
|
|
|
209
209
|
});
|
|
210
210
|
|
|
211
211
|
it('should work without expand or select', async () => {
|
|
212
|
-
mockEngine.findOne.mockResolvedValue({
|
|
212
|
+
mockEngine.findOne.mockResolvedValue({ id: 't1' });
|
|
213
213
|
|
|
214
214
|
await protocol.getData({ object: 'task', id: 't1' });
|
|
215
215
|
|
|
216
216
|
expect(mockEngine.findOne).toHaveBeenCalledWith(
|
|
217
217
|
'task',
|
|
218
|
-
{ filter: {
|
|
218
|
+
{ filter: { id: 't1' } },
|
|
219
219
|
);
|
|
220
220
|
});
|
|
221
221
|
|
|
222
222
|
it('should return standard GetDataResponse shape', async () => {
|
|
223
|
-
mockEngine.findOne.mockResolvedValue({
|
|
223
|
+
mockEngine.findOne.mockResolvedValue({ id: 'oi_1', name: 'Item 1' });
|
|
224
224
|
|
|
225
225
|
const result = await protocol.getData({ object: 'order_item', id: 'oi_1' });
|
|
226
226
|
|
|
227
227
|
expect(result).toEqual({
|
|
228
228
|
object: 'order_item',
|
|
229
229
|
id: 'oi_1',
|
|
230
|
-
record: {
|
|
230
|
+
record: { id: 'oi_1', name: 'Item 1' },
|
|
231
231
|
});
|
|
232
232
|
});
|
|
233
233
|
|
package/src/protocol.ts
CHANGED
|
@@ -246,7 +246,7 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
246
246
|
// Form View Generation
|
|
247
247
|
// Simple single-section layout for now
|
|
248
248
|
const formFields = fieldKeys
|
|
249
|
-
.filter(k => k !== 'id' && k !== 'created_at' && k !== '
|
|
249
|
+
.filter(k => k !== 'id' && k !== 'created_at' && k !== 'updated_at' && !fields[k].hidden)
|
|
250
250
|
.map(f => ({
|
|
251
251
|
field: f,
|
|
252
252
|
label: fields[f]?.label,
|
|
@@ -361,7 +361,7 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
361
361
|
|
|
362
362
|
async getData(request: { object: string, id: string, expand?: string | string[], select?: string | string[] }) {
|
|
363
363
|
const queryOptions: any = {
|
|
364
|
-
filter: {
|
|
364
|
+
filter: { id: request.id }
|
|
365
365
|
};
|
|
366
366
|
|
|
367
367
|
// Support select for single-record retrieval
|
|
@@ -393,14 +393,14 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
393
393
|
const result = await this.engine.insert(request.object, request.data);
|
|
394
394
|
return {
|
|
395
395
|
object: request.object,
|
|
396
|
-
id: result.
|
|
396
|
+
id: result.id,
|
|
397
397
|
record: result
|
|
398
398
|
};
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
async updateData(request: { object: string, id: string, data: any }) {
|
|
402
402
|
// Adapt: update(obj, id, data) -> update(obj, data, options)
|
|
403
|
-
const result = await this.engine.update(request.object, request.data, { filter: {
|
|
403
|
+
const result = await this.engine.update(request.object, request.data, { filter: { id: request.id } });
|
|
404
404
|
return {
|
|
405
405
|
object: request.object,
|
|
406
406
|
id: request.id,
|
|
@@ -410,7 +410,7 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
410
410
|
|
|
411
411
|
async deleteData(request: { object: string, id: string }) {
|
|
412
412
|
// Adapt: delete(obj, id) -> delete(obj, options)
|
|
413
|
-
await this.engine.delete(request.object, { filter: {
|
|
413
|
+
await this.engine.delete(request.object, { filter: { id: request.id } });
|
|
414
414
|
return {
|
|
415
415
|
object: request.object,
|
|
416
416
|
id: request.id,
|
|
@@ -478,13 +478,13 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
478
478
|
switch (operation) {
|
|
479
479
|
case 'create': {
|
|
480
480
|
const created = await this.engine.insert(object, record.data || record);
|
|
481
|
-
results.push({ id: created.
|
|
481
|
+
results.push({ id: created.id, success: true, record: created });
|
|
482
482
|
succeeded++;
|
|
483
483
|
break;
|
|
484
484
|
}
|
|
485
485
|
case 'update': {
|
|
486
486
|
if (!record.id) throw new Error('Record id is required for update');
|
|
487
|
-
const updated = await this.engine.update(object, record.data || {}, { filter: {
|
|
487
|
+
const updated = await this.engine.update(object, record.data || {}, { filter: { id: record.id } });
|
|
488
488
|
results.push({ id: record.id, success: true, record: updated });
|
|
489
489
|
succeeded++;
|
|
490
490
|
break;
|
|
@@ -493,28 +493,28 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
493
493
|
// Try update first, then create if not found
|
|
494
494
|
if (record.id) {
|
|
495
495
|
try {
|
|
496
|
-
const existing = await this.engine.findOne(object, { filter: {
|
|
496
|
+
const existing = await this.engine.findOne(object, { filter: { id: record.id } });
|
|
497
497
|
if (existing) {
|
|
498
|
-
const updated = await this.engine.update(object, record.data || {}, { filter: {
|
|
498
|
+
const updated = await this.engine.update(object, record.data || {}, { filter: { id: record.id } });
|
|
499
499
|
results.push({ id: record.id, success: true, record: updated });
|
|
500
500
|
} else {
|
|
501
|
-
const created = await this.engine.insert(object, {
|
|
502
|
-
results.push({ id: created.
|
|
501
|
+
const created = await this.engine.insert(object, { id: record.id, ...(record.data || {}) });
|
|
502
|
+
results.push({ id: created.id, success: true, record: created });
|
|
503
503
|
}
|
|
504
504
|
} catch {
|
|
505
|
-
const created = await this.engine.insert(object, {
|
|
506
|
-
results.push({ id: created.
|
|
505
|
+
const created = await this.engine.insert(object, { id: record.id, ...(record.data || {}) });
|
|
506
|
+
results.push({ id: created.id, success: true, record: created });
|
|
507
507
|
}
|
|
508
508
|
} else {
|
|
509
509
|
const created = await this.engine.insert(object, record.data || record);
|
|
510
|
-
results.push({ id: created.
|
|
510
|
+
results.push({ id: created.id, success: true, record: created });
|
|
511
511
|
}
|
|
512
512
|
succeeded++;
|
|
513
513
|
break;
|
|
514
514
|
}
|
|
515
515
|
case 'delete': {
|
|
516
516
|
if (!record.id) throw new Error('Record id is required for delete');
|
|
517
|
-
await this.engine.delete(object, { filter: {
|
|
517
|
+
await this.engine.delete(object, { filter: { id: record.id } });
|
|
518
518
|
results.push({ id: record.id, success: true });
|
|
519
519
|
succeeded++;
|
|
520
520
|
break;
|
|
@@ -563,7 +563,7 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
563
563
|
|
|
564
564
|
for (const record of records) {
|
|
565
565
|
try {
|
|
566
|
-
const updated = await this.engine.update(object, record.data, { filter: {
|
|
566
|
+
const updated = await this.engine.update(object, record.data, { filter: { id: record.id } });
|
|
567
567
|
results.push({ id: record.id, success: true, record: updated });
|
|
568
568
|
succeeded++;
|
|
569
569
|
} catch (err: any) {
|
|
@@ -765,7 +765,7 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
765
765
|
async deleteManyData(request: DeleteManyDataRequest): Promise<any> {
|
|
766
766
|
// This expects deleting by IDs.
|
|
767
767
|
return this.engine.delete(request.object, {
|
|
768
|
-
filter: {
|
|
768
|
+
filter: { id: { $in: request.ids } },
|
|
769
769
|
...request.options
|
|
770
770
|
});
|
|
771
771
|
}
|