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
6 changes: 3 additions & 3 deletions scripts/clean/entity/unwrap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Unwrap, type WrappedValue, type IsEqual, type Transformer, type TransformerFunction, type SimplifyTopLevel, type DeepReadonly, type GetKindValue, type Kind, unwrap, isWrappedValue } from "@scripts/common";
import { type Unwrap, type WrappedValue, type IsEqual, type Transformer, type TransformerFunction, type SimplifyTopLevel, type DeepReadonly, type GetKindValue, type Kind, unwrap, isWrappedValue, isRuntimeKind } from "@scripts/common";
import { entityKind, type Entity } from ".";
import { flagKind } from "../flag";

Expand Down Expand Up @@ -54,7 +54,7 @@ export type UnwrapEntity<
GetKindValue<typeof flagKind, GenericEntity>
>
}
: {}
: { _flags?: Record<string, unknown> }
)
>
>;
Expand Down Expand Up @@ -124,7 +124,7 @@ export function unwrapEntity<
unwrapEntity._entityName = entity[prop];
} else if (prop === flagKind.runTimeKey) {
unwrapEntity._flags = entity[prop];
} else {
} else if (!isRuntimeKind(prop)) {
unwrapEntity[prop] = unwrapEntityProperty(entity[prop], params);
}
}
Expand Down
21 changes: 20 additions & 1 deletion tests/clean/entity/unwrap.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DClean, DDataParser, pipe, type ExpectType } from "@scripts";
import { newTypeKind } from "@scripts/clean";

describe("unwrapEntityProperty", () => {
it("unwraps wrapped values without transformer and supports pipe", () => {
Expand Down Expand Up @@ -172,7 +173,7 @@ describe("unwrapEntity", () => {

const result = pipe(
featuredEntity,
(value) => DClean.unwrapEntity(value),
DClean.unwrapEntity,
);

expect(result).toStrictEqual({
Expand Down Expand Up @@ -233,6 +234,8 @@ describe("unwrapEntity", () => {
},
});

newTypeKind.setTo(entity, "");

const result = DClean.unwrapEntity(
entity,
{
Expand All @@ -248,5 +251,21 @@ describe("unwrapEntity", () => {
},
_entityName: "User",
});

type check = ExpectType<
typeof result,
{
readonly name: "alice";
readonly role: "member";
readonly profile: {
readonly label: "member";
};
readonly _entityName: "User";
readonly _flags?: {
readonly [x: string]: unknown;
};
},
"strict"
>;
});
});
Loading