Skip to content

Commit

Permalink
update parser id to clarify the identifier liked-type
Browse files Browse the repository at this point in the history
  • Loading branch information
tofu-soya-p77u4n committed Apr 5, 2024
1 parent 9a2dda2 commit 3441968
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yl-ddd-ts",
"version": "1.0.4",
"version": "2.0.0",
"description": "Node typescript seedwork",
"main": "dist/src/index.js",
"author": "tuancaurao <tuancr.pt@gmail.com>",
Expand Down
2 changes: 1 addition & 1 deletion src/model/entity.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const construct: EntityParserFactory<WithEntityMetaInput<unknown>> =
}),
Either.flatMap((metaLike) => {
return structSummarizerParsing<Omit<EntityCommonProps, '_tag'>>({
id: parseId(options.autoGenId ? uuidv4() : metaLike.id),
id: parseId(options.autoGenId ? uuidv4() : metaLike.id || ''),
createdAt: Either.right(metaLike.createdAt),
updatedAt: Either.right(metaLike.updatedAt),
});
Expand Down
2 changes: 1 addition & 1 deletion src/model/entity.base.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type RecursiveWithArray<I> = I extends Entity
: Liken<I>;

export type WithEntityMetaInput<OriginInput> = OriginInput &
Liken<Omit<EntityCommonProps, '_tag' | 'id'>> & { id?: unknown };
Liken<Omit<EntityCommonProps, '_tag' | 'id'>> & { id?: string };

export type EntityInvariantParser<
T extends Entity,
Expand Down
4 changes: 2 additions & 2 deletions src/model/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export const structSummarizerParsing = <T>(struct: ParsingInput<T>) => {
};

export const arrayParser =
<T>(itemParser: Parser<T>) =>
(a: unknown[]) => {
<T, I>(itemParser: Parser<T, I>) =>
(a: I[]) => {
return pipe(
a,
A.reduceWithIndex({}, (i, acc, cur) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/typeclasses/obj-with-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { v4 as uuidv4 } from 'uuid';

export type Identifier = Brand<string, 'Identifier'>;

export const parseId: Parser<Identifier> = (v: unknown) => {
export const parseId: Parser<Identifier, string> = (v: string) => {
const isId = (v: unknown): v is Identifier =>
typeof v === 'string' && v.length > 0;
return Either.fromPredicate(isId, () =>
Expand Down

0 comments on commit 3441968

Please sign in to comment.