Skip to content

Commit 5367bb3

Browse files
authored
fix: add check for nested empty JSON objects (#457)
1 parent 24d6ca9 commit 5367bb3

File tree

7 files changed

+734
-32
lines changed

7 files changed

+734
-32
lines changed

.github/workflows/deploy-subgraph.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ on:
55

66
jobs:
77
deploy:
8-
runs-on: ubuntu-latest
8+
runs-on:
9+
group: Azure_runners
10+
labels: [ self-hosted, Linux, X64 ]
911
strategy:
1012
matrix:
1113
include:

packages/sdk/src/utils/data.ts

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -263,32 +263,24 @@ export const createZipFromObject = (obj: unknown): Promise<Uint8Array> => {
263263
);
264264
};
265265

266-
export const reverseSafeSchema = function (
266+
export const reverseSafeSchema = (
267267
schema?: Array<Record<'id', string>>
268-
) {
269-
if (!schema) {
270-
return {};
271-
}
272-
return schema.reduce((propsAndTypes, { id: propPathColonType }) => {
273-
// { id: 'nested.something:string' }
274-
const [key, value] = propPathColonType.split(':');
275-
// key = 'nested.something'
276-
// value = 'string'
277-
if (key.includes('.')) {
278-
const firstKey = key.split('.')[0];
279-
// firstKey = 'nested'
280-
const restOfKey = key.split('.').slice(1).join('.');
281-
// restOfKey = 'something'
282-
const withValue = `${restOfKey}:${value}`;
283-
// withValue = 'something:string'
284-
propsAndTypes[firstKey] = reverseSafeSchema([
285-
{
286-
id: withValue,
287-
},
288-
]);
289-
} else {
290-
propsAndTypes[key] = value;
268+
): Record<string, any> => {
269+
if (!schema) return {};
270+
271+
return schema.reduce((acc, { id }) => {
272+
const [path, type] = id.split(':');
273+
const keys = path.split('.');
274+
275+
let current = acc;
276+
for (let i = 0; i < keys.length - 1; i++) {
277+
current[keys[i]] ??= {};
278+
current = current[keys[i]];
291279
}
292-
return propsAndTypes;
280+
281+
const finalKey = keys[keys.length - 1];
282+
current[finalKey] = type;
283+
284+
return acc;
293285
}, {});
294286
};

packages/sdk/tests/e2e/constructor.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { describe, it, expect } from '@jest/globals';
22
import { IExecDataProtector } from '../../src/index.js';
3+
import { getTestConfig } from '../test-utils.js';
34

45
describe('When instantiating SDK without a signer', () => {
56
describe('When calling a read method', () => {
67
it('should work as expected', async () => {
78
// --- GIVEN
8-
const dataProtector = new IExecDataProtector();
9+
const dataProtector = new IExecDataProtector(...getTestConfig());
910

1011
// --- WHEN/THEN
1112
await expect(

0 commit comments

Comments
 (0)