Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runner/src/data-updating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export function normalizeAndDiff(
i++
) {
changes.push({
location: { ...link, path: [...link.path, i.toString()] },
location: { ...link, path: [...link.path.slice(0, -1), i.toString()] },
value: undefined,
});
}
Expand Down
8 changes: 7 additions & 1 deletion packages/runner/src/storage/transaction-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ class TransactionWriter extends TransactionReader
throw new Error(`Failed to get or create document: ${address.id}`);
}

// Rewrite creating new documents as setting the value
if (address.path.length === 0 && isObject(value) && "value" in value) {
address = { ...address, path: ["value"] };
value = value.value;
}

// Path-based logic
if (!address.path.length) {
const notFoundError: INotFoundError = new Error(
Expand Down Expand Up @@ -588,7 +594,7 @@ export class ExtendedStorageTransaction implements IExtendedStorageTransaction {
for (const key of remainingPath) {
nextValue =
nextValue[key] =
(typeof Number(key) === "number" ? [] : {}) as typeof nextValue;
(!Number.isNaN(Number(key)) ? [] : {}) as typeof nextValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, is this for clarity or did this misbehave?

if we change to Number., then let's use isInteger instead, since array indices have to be that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number(key) might return NaN, however, typeof NaN is "number", so therefore its always true and it will never create an object. i guess thats why I used NaN since its closer probably to the intended behaviour. still, isInteger is better.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number will also cast string|number, where isInteger will always fail for strings, not sure of key type here

}
nextValue[lastKey] = value;
const parentAddress = { ...address, path: lastValidPath ?? [] };
Expand Down