-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs: - #282
- Loading branch information
Showing
25 changed files
with
856 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isoNow() { | ||
return new Date().toISOString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { HookEventType } from '../../common/enum/Hook'; | ||
|
||
export interface PublishChangePayload { | ||
'dist-tag'?: string; | ||
version: string; | ||
} | ||
|
||
export interface UnpublishChangePayload { | ||
'dist-tag'?: string; | ||
version?: string; | ||
} | ||
|
||
export interface DistTagChangePayload { | ||
'dist-tag': string; | ||
} | ||
|
||
export interface PackageOwnerPayload { | ||
maintainer: string; | ||
} | ||
|
||
export interface DeprecatedChangePayload { | ||
deprecated: string; | ||
} | ||
|
||
export class HookEvent<T = object> { | ||
readonly changeId: string; | ||
readonly event: HookEventType; | ||
readonly fullname: string; | ||
readonly type: 'package'; | ||
readonly version: '1.0.0'; | ||
readonly change: T; | ||
readonly time: number; | ||
|
||
constructor(event: HookEventType, changeId: string, fullname: string, change: T) { | ||
this.changeId = changeId; | ||
this.event = event; | ||
this.fullname = fullname; | ||
this.type = 'package'; | ||
this.version = '1.0.0'; | ||
this.change = change; | ||
this.time = Date.now(); | ||
} | ||
|
||
static createPublishEvent(fullname: string, changeId: string, version: string, distTag?: string): HookEvent<PublishChangePayload> { | ||
return new HookEvent(HookEventType.Publish, changeId, fullname, { | ||
'dist-tag': distTag, | ||
version, | ||
}); | ||
} | ||
|
||
static createUnpublishEvent(fullname: string, changeId: string, version?: string, distTag?: string): HookEvent<UnpublishChangePayload> { | ||
return new HookEvent(HookEventType.Unpublish, changeId, fullname, { | ||
'dist-tag': distTag, | ||
version, | ||
}); | ||
} | ||
|
||
static createOwnerEvent(fullname: string, changeId: string, maintainer: string): HookEvent<PackageOwnerPayload> { | ||
return new HookEvent(HookEventType.Owner, changeId, fullname, { | ||
maintainer, | ||
}); | ||
} | ||
|
||
static createOwnerRmEvent(fullname: string, changeId: string, maintainer: string): HookEvent<PackageOwnerPayload> { | ||
return new HookEvent(HookEventType.OwnerRm, changeId, fullname, { | ||
maintainer, | ||
}); | ||
} | ||
|
||
static createDistTagEvent(fullname: string, changeId: string, distTag: string): HookEvent<DistTagChangePayload> { | ||
return new HookEvent(HookEventType.DistTag, changeId, fullname, { | ||
'dist-tag': distTag, | ||
}); | ||
} | ||
|
||
static createDistTagRmEvent(fullname: string, changeId: string, distTag: string): HookEvent<DistTagChangePayload> { | ||
return new HookEvent(HookEventType.DistTagRm, changeId, fullname, { | ||
'dist-tag': distTag, | ||
}); | ||
} | ||
|
||
static createDeprecatedEvent(fullname: string, changeId: string, deprecated: string): HookEvent<DeprecatedChangePayload> { | ||
return new HookEvent(HookEventType.Deprecated, changeId, fullname, { | ||
deprecated, | ||
}); | ||
} | ||
|
||
static createUndeprecatedEvent(fullname: string, changeId: string, deprecated: string): HookEvent<DeprecatedChangePayload> { | ||
return new HookEvent(HookEventType.Undeprecated, changeId, fullname, { | ||
deprecated, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.