npm package diff

Package: @forge/kvs

Versions: 1.0.9-next.0 - 1.1.0-next.1

File: package/out/__test__/index.test.js

Index: package/out/__test__/index.test.js
===================================================================
--- package/out/__test__/index.test.js
+++ package/out/__test__/index.test.js
@@ -29,8 +29,28 @@
         expect(apiClient).toHaveBeenCalledWith('/api/v1/get', expect.objectContaining({
             body: JSON.stringify({ key: 'foo' })
         }));
     });
+    it('should get with metadata fields correctly', async () => {
+        const response = new Response(JSON.stringify({ key: 'foo', value: 'bar', createdAt: 1718236800, updatedAt: 1718236800 }), {
+            status: 200,
+            headers: { 'x-trace-id': traceId }
+        });
+        const { sut, apiClient } = prepare(response);
+        const rs = await sut.get('foo', { metadataFields: [types_1.MetadataField.CREATED_AT, types_1.MetadataField.UPDATED_AT] });
+        expect(rs).toEqual({
+            key: 'foo',
+            value: 'bar',
+            createdAt: 1718236800,
+            updatedAt: 1718236800
+        });
+        expect(apiClient).toHaveBeenCalledWith('/api/v1/get', expect.objectContaining({
+            body: JSON.stringify({
+                key: 'foo',
+                options: { metadataFields: [types_1.MetadataField.CREATED_AT, types_1.MetadataField.UPDATED_AT] }
+            })
+        }));
+    });
     it('should return undefined when get receives 404', async () => {
         const response = new Response(JSON.stringify({ code: 'KEY_NOT_FOUND', message: 'Provided key does not exist' }), {
             status: 404,
             headers: { 'x-trace-id': traceId }
@@ -41,8 +61,20 @@
         expect(apiClient).toHaveBeenCalledWith('/api/v1/get', expect.objectContaining({
             body: JSON.stringify({ key: 'foo' })
         }));
     });
+    it('should handle unexpected metadata fields', async () => {
+        const response = new Response(JSON.stringify({
+            code: 'BAD_REQUEST',
+            message: 'Provided request body is invalid'
+        }), {
+            status: 400,
+            statusText: 'Bad Request',
+            headers: { 'x-trace-id': traceId }
+        });
+        const { sut } = prepare(response);
+        await expect(sut.get('foo', { metadataFields: ['INVALID_METADATA_FIELD'] })).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 400, statusText: 'Bad Request', traceId }, { code: 'BAD_REQUEST', message: 'Provided request body is invalid' }));
+    });
     it('should handle unexpected response', async () => {
         const response = new Response(JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }), {
             status: 500,
             statusText: 'Internal Server Error',
@@ -70,8 +102,28 @@
         expect(apiClient).toHaveBeenCalledWith('/api/v1/secret/get', expect.objectContaining({
             body: JSON.stringify({ key: 'foo' })
         }));
     });
+    it('should getSecret with metadata fields correctly', async () => {
+        const response = new Response(JSON.stringify({ key: 'foo', value: 'bar', createdAt: 1718236800, updatedAt: 1718236800 }), {
+            status: 200,
+            headers: { 'x-trace-id': traceId }
+        });
+        const { sut, apiClient } = prepare(response);
+        const rs = await sut.getSecret('foo', { metadataFields: [types_1.MetadataField.CREATED_AT, types_1.MetadataField.UPDATED_AT] });
+        expect(rs).toEqual({
+            key: 'foo',
+            value: 'bar',
+            createdAt: 1718236800,
+            updatedAt: 1718236800
+        });
+        expect(apiClient).toHaveBeenCalledWith('/api/v1/secret/get', expect.objectContaining({
+            body: JSON.stringify({
+                key: 'foo',
+                options: { metadataFields: [types_1.MetadataField.CREATED_AT, types_1.MetadataField.UPDATED_AT] }
+            })
+        }));
+    });
     it('should return undefined when getSecret receives 404', async () => {
         const response = new Response(JSON.stringify({ code: 'KEY_NOT_FOUND', message: 'Provided key does not exist' }), {
             status: 404,
             headers: { 'x-trace-id': traceId }
@@ -94,8 +146,31 @@
         expect(apiClient).toHaveBeenCalledWith('/api/v1/entity/get', expect.objectContaining({
             body: JSON.stringify({ entityName: 'employees', key: 'foo' })
         }));
     });
+    it('should getEntity with metadata fields correctly', async () => {
+        const response = new Response(JSON.stringify({ key: 'foo', value: { name: 'Jane Doe' }, createdAt: 1718236800, updatedAt: 1718236800 }), {
+            status: 200,
+            headers: { 'x-trace-id': traceId }
+        });
+        const { sut, apiClient } = prepare(response);
+        const rs = await sut
+            .entity('employees')
+            .get('foo', { metadataFields: [types_1.MetadataField.CREATED_AT, types_1.MetadataField.UPDATED_AT] });
+        expect(rs).toEqual({
+            key: 'foo',
+            value: { name: 'Jane Doe' },
+            createdAt: 1718236800,
+            updatedAt: 1718236800
+        });
+        expect(apiClient).toHaveBeenCalledWith('/api/v1/entity/get', expect.objectContaining({
+            body: JSON.stringify({
+                entityName: 'employees',
+                key: 'foo',
+                options: { metadataFields: [types_1.MetadataField.CREATED_AT, types_1.MetadataField.UPDATED_AT] }
+            })
+        }));
+    });
     it('should return undefined when getEntity receives 404', async () => {
         const response = new Response(JSON.stringify({ code: 'KEY_NOT_FOUND', message: 'Provided key does not exist' }), {
             status: 404,
             headers: { 'x-trace-id': traceId }