@privateaim/server-core-worker-kit 0.7.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +472 -0
- package/LICENSE +202 -0
- package/dist/components/builder/constants.d.ts +32 -0
- package/dist/components/builder/constants.d.ts.map +1 -0
- package/dist/components/builder/index.d.ts +4 -0
- package/dist/components/builder/index.d.ts.map +1 -0
- package/dist/components/builder/queue.d.ts +5 -0
- package/dist/components/builder/queue.d.ts.map +1 -0
- package/dist/components/builder/types.d.ts +35 -0
- package/dist/components/builder/types.d.ts.map +1 -0
- package/dist/components/core/constants.d.ts +24 -0
- package/dist/components/core/constants.d.ts.map +1 -0
- package/dist/components/core/index.d.ts +4 -0
- package/dist/components/core/index.d.ts.map +1 -0
- package/dist/components/core/queue.d.ts +5 -0
- package/dist/components/core/queue.d.ts.map +1 -0
- package/dist/components/core/types.d.ts +41 -0
- package/dist/components/core/types.d.ts.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/master-images/build/index.d.ts +2 -0
- package/dist/components/master-images/build/index.d.ts.map +1 -0
- package/dist/components/master-images/build/types.d.ts +18 -0
- package/dist/components/master-images/build/types.d.ts.map +1 -0
- package/dist/components/master-images/constants.d.ts +26 -0
- package/dist/components/master-images/constants.d.ts.map +1 -0
- package/dist/components/master-images/index.d.ts +7 -0
- package/dist/components/master-images/index.d.ts.map +1 -0
- package/dist/components/master-images/push/index.d.ts +2 -0
- package/dist/components/master-images/push/index.d.ts.map +1 -0
- package/dist/components/master-images/push/types.d.ts +17 -0
- package/dist/components/master-images/push/types.d.ts.map +1 -0
- package/dist/components/master-images/service/index.d.ts +3 -0
- package/dist/components/master-images/service/index.d.ts.map +1 -0
- package/dist/components/master-images/service/module.d.ts +16 -0
- package/dist/components/master-images/service/module.d.ts.map +1 -0
- package/dist/components/master-images/service/singleton.d.ts +3 -0
- package/dist/components/master-images/service/singleton.d.ts.map +1 -0
- package/dist/components/master-images/synchronize/index.d.ts +2 -0
- package/dist/components/master-images/synchronize/index.d.ts.map +1 -0
- package/dist/components/master-images/synchronize/types.d.ts +26 -0
- package/dist/components/master-images/synchronize/types.d.ts.map +1 -0
- package/dist/components/master-images/types.d.ts +40 -0
- package/dist/components/master-images/types.d.ts.map +1 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/index.cjs +287 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +265 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +41 -0
- package/rollup.config.mjs +14 -0
- package/src/components/builder/constants.ts +46 -0
- package/src/components/builder/index.ts +10 -0
- package/src/components/builder/queue.ts +39 -0
- package/src/components/builder/types.ts +57 -0
- package/src/components/core/constants.ts +38 -0
- package/src/components/core/index.ts +10 -0
- package/src/components/core/queue.ts +36 -0
- package/src/components/core/types.ts +66 -0
- package/src/components/index.ts +10 -0
- package/src/components/master-images/build/index.ts +8 -0
- package/src/components/master-images/build/types.ts +28 -0
- package/src/components/master-images/constants.ts +38 -0
- package/src/components/master-images/index.ts +14 -0
- package/src/components/master-images/push/index.ts +8 -0
- package/src/components/master-images/push/types.ts +25 -0
- package/src/components/master-images/service/index.ts +9 -0
- package/src/components/master-images/service/module.ts +125 -0
- package/src/components/master-images/service/singleton.ts +18 -0
- package/src/components/master-images/synchronize/index.ts +8 -0
- package/src/components/master-images/synchronize/types.ts +37 -0
- package/src/components/master-images/types.ts +67 -0
- package/src/constants.ts +19 -0
- package/src/index.ts +9 -0
- package/src/utils.ts +20 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Cache, QueueRouter, QueueRouterHandlers } from '@privateaim/server-kit';
|
|
9
|
+
import { buildQueueRouterPublishPayload, useCache, useQueueRouter } from '@privateaim/server-kit';
|
|
10
|
+
import { cleanupPayload } from '../../../utils';
|
|
11
|
+
import {
|
|
12
|
+
MasterImagesCommand,
|
|
13
|
+
MasterImagesEventQueueRouterRouting,
|
|
14
|
+
MasterImagesTaskQueueRouterRouting,
|
|
15
|
+
} from '../constants';
|
|
16
|
+
import type {
|
|
17
|
+
MasterImagesCommandContext,
|
|
18
|
+
MasterImagesCommandMap,
|
|
19
|
+
MasterImagesEventContext,
|
|
20
|
+
MasterImagesEventMap,
|
|
21
|
+
} from '../types';
|
|
22
|
+
|
|
23
|
+
export class MasterImageQueueService {
|
|
24
|
+
protected cache : Cache;
|
|
25
|
+
|
|
26
|
+
protected queueRouter : QueueRouter;
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
this.cache = useCache();
|
|
30
|
+
this.queueRouter = useQueueRouter();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// -------------------------------------------------
|
|
34
|
+
|
|
35
|
+
async publishCommand(ctx: MasterImagesCommandContext) {
|
|
36
|
+
const isLocked = await this.isCommandLocked(ctx.command);
|
|
37
|
+
if (isLocked) {
|
|
38
|
+
throw new Error('The command is locked and can therefore not be executed.');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const routerPayload = this.buildRouterPayloadForCommand(ctx);
|
|
42
|
+
await this.queueRouter.publish(routerPayload);
|
|
43
|
+
|
|
44
|
+
if (ctx.command === MasterImagesCommand.SYNCHRONIZE) {
|
|
45
|
+
await this.setCommandLock(ctx.command);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async consumeCommands(
|
|
50
|
+
handlers: QueueRouterHandlers<Partial<MasterImagesCommandMap>>,
|
|
51
|
+
) {
|
|
52
|
+
await this.queueRouter.consume(MasterImagesTaskQueueRouterRouting, {
|
|
53
|
+
$any: async (message) => {
|
|
54
|
+
if (handlers[message.type]) {
|
|
55
|
+
await handlers[message.type](message, this);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (handlers.$any) {
|
|
59
|
+
await handlers.$any(message);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// -------------------------------------------------
|
|
66
|
+
|
|
67
|
+
async publishEvent(ctx: MasterImagesEventContext) {
|
|
68
|
+
const routerPayload = this.buildRouterPayloadForEvent(ctx);
|
|
69
|
+
await this.queueRouter.publish(routerPayload);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async consumeEvents(
|
|
73
|
+
handlers: QueueRouterHandlers<Partial<MasterImagesEventMap>>,
|
|
74
|
+
) {
|
|
75
|
+
await this.queueRouter.consume(MasterImagesEventQueueRouterRouting, {
|
|
76
|
+
$any: async (message) => {
|
|
77
|
+
await this.setCommandLock(MasterImagesCommand.SYNCHRONIZE);
|
|
78
|
+
|
|
79
|
+
if (handlers[message.type]) {
|
|
80
|
+
await handlers[message.type](message);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (handlers.$any) {
|
|
84
|
+
await handlers.$any(message);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// -------------------------------------------------
|
|
91
|
+
|
|
92
|
+
protected async setCommandLock(command: string) {
|
|
93
|
+
await this.cache.set(`master-images-command:${command}`, true, {
|
|
94
|
+
ttl: 1000 * 60,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected async isCommandLocked(command: string) {
|
|
99
|
+
const isActive = await this.cache.get(`master-images-command:${command}`);
|
|
100
|
+
|
|
101
|
+
return !!isActive;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// -------------------------------------------------
|
|
105
|
+
|
|
106
|
+
protected buildRouterPayloadForEvent(context: MasterImagesEventContext) {
|
|
107
|
+
return buildQueueRouterPublishPayload({
|
|
108
|
+
type: context.event,
|
|
109
|
+
data: cleanupPayload(context.data),
|
|
110
|
+
metadata: {
|
|
111
|
+
routing: MasterImagesEventQueueRouterRouting,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
protected buildRouterPayloadForCommand(context: MasterImagesCommandContext) {
|
|
117
|
+
return buildQueueRouterPublishPayload({
|
|
118
|
+
type: context.command,
|
|
119
|
+
data: cleanupPayload(context.data),
|
|
120
|
+
metadata: {
|
|
121
|
+
routing: MasterImagesTaskQueueRouterRouting,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { singa } from 'singa';
|
|
9
|
+
import { MasterImageQueueService } from './module';
|
|
10
|
+
|
|
11
|
+
const instance = singa<MasterImageQueueService>({
|
|
12
|
+
name: 'masterImageQueue',
|
|
13
|
+
factory: () => new MasterImageQueueService(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export function useMasterImageQueueService() {
|
|
17
|
+
return instance.use();
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { MasterImageCommandArgument } from '@privateaim/core-kit';
|
|
9
|
+
|
|
10
|
+
export type MasterImageSyncData = {
|
|
11
|
+
name: string,
|
|
12
|
+
path: string,
|
|
13
|
+
virtualPath: string,
|
|
14
|
+
command: string,
|
|
15
|
+
commandArguments?: MasterImageCommandArgument[]
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type MasterImageGroupSyncData = {
|
|
19
|
+
name: string,
|
|
20
|
+
path: string,
|
|
21
|
+
virtualPath: string,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type MasterImagesSynchronizeCommandPayload = {
|
|
25
|
+
owner: string,
|
|
26
|
+
repository: string,
|
|
27
|
+
branch: string
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type MasterImagesSynchronizationFailedEventPayload = {
|
|
31
|
+
error: Error
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type MaterImagesSynchronizedEventPayload = {
|
|
35
|
+
images: MasterImageSyncData[],
|
|
36
|
+
groups: MasterImageGroupSyncData[]
|
|
37
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
MasterImagesBuildCommandPayload, MasterImagesBuildFailedEventPayload,
|
|
10
|
+
MasterImagesBuildingEventPayload,
|
|
11
|
+
MasterImagesBuiltEventPayload,
|
|
12
|
+
} from './build';
|
|
13
|
+
import type { MasterImagesCommand, MasterImagesEvent } from './constants';
|
|
14
|
+
import type {
|
|
15
|
+
MasterImagesPushCommandPayload,
|
|
16
|
+
MasterImagesPushEventPayload, MasterImagesPushFailedEventPayload,
|
|
17
|
+
} from './push';
|
|
18
|
+
import type {
|
|
19
|
+
MasterImagesSynchronizationFailedEventPayload, MasterImagesSynchronizeCommandPayload,
|
|
20
|
+
MaterImagesSynchronizedEventPayload,
|
|
21
|
+
} from './synchronize';
|
|
22
|
+
|
|
23
|
+
//-----------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
type MasterImagesCommandMapRaw = {
|
|
26
|
+
[MasterImagesCommand.BUILD]: MasterImagesBuildCommandPayload,
|
|
27
|
+
[MasterImagesCommand.PUSH]: MasterImagesPushCommandPayload,
|
|
28
|
+
[MasterImagesCommand.SYNCHRONIZE]: MasterImagesSynchronizeCommandPayload,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type MasterImagesCommandMap = {
|
|
32
|
+
[K in keyof MasterImagesCommandMapRaw as `${K}`]: MasterImagesCommandMapRaw[K]
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type MasterImagesCommandContext = {
|
|
36
|
+
[K in keyof MasterImagesCommandMap]: {
|
|
37
|
+
command: K,
|
|
38
|
+
data: MasterImagesCommandMap[K]
|
|
39
|
+
}
|
|
40
|
+
}[keyof MasterImagesCommandMap];
|
|
41
|
+
|
|
42
|
+
//-----------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
type MasterImagesEventMapRaw = {
|
|
45
|
+
[MasterImagesEvent.BUILDING]: MasterImagesBuildingEventPayload,
|
|
46
|
+
[MasterImagesEvent.BUILT]: MasterImagesBuiltEventPayload,
|
|
47
|
+
[MasterImagesEvent.BUILD_FAILED]: MasterImagesBuildFailedEventPayload,
|
|
48
|
+
|
|
49
|
+
[MasterImagesEvent.PUSHING]: MasterImagesPushEventPayload,
|
|
50
|
+
[MasterImagesEvent.PUSHED]: MasterImagesPushEventPayload,
|
|
51
|
+
[MasterImagesEvent.PUSH_FAILED]: MasterImagesPushFailedEventPayload,
|
|
52
|
+
|
|
53
|
+
[MasterImagesEvent.SYNCHRONIZING]: Record<string, any>,
|
|
54
|
+
[MasterImagesEvent.SYNCHRONIZED]: MaterImagesSynchronizedEventPayload,
|
|
55
|
+
[MasterImagesEvent.SYNCHRONIZATION_FAILED]: MasterImagesSynchronizationFailedEventPayload
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type MasterImagesEventMap = {
|
|
59
|
+
[K in keyof MasterImagesEventMapRaw as `${K}`]: MasterImagesEventMapRaw[K]
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type MasterImagesEventContext = {
|
|
63
|
+
[K in keyof MasterImagesEventMap]: {
|
|
64
|
+
event: K,
|
|
65
|
+
data: MasterImagesEventMap[K]
|
|
66
|
+
}
|
|
67
|
+
}[keyof MasterImagesEventMap];
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export enum ComponentName {
|
|
9
|
+
BUILDER = 'builder',
|
|
10
|
+
CORE = 'core',
|
|
11
|
+
MASTER_IMAGES = 'masterImages',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export enum ErrorCode {
|
|
15
|
+
NOT_FOUND = 'notFound',
|
|
16
|
+
REGISTRY_NOT_FOUND = 'registryNotFound',
|
|
17
|
+
REGISTRY_PROJECT_NOT_FOUND = 'registryProjectNotFound',
|
|
18
|
+
NONE = 'none',
|
|
19
|
+
}
|
package/src/index.ts
ADDED
package/src/utils.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { hasOwnProperty } from '@privateaim/kit';
|
|
9
|
+
|
|
10
|
+
export function cleanupPayload<T extends Record<string, any>>(payload: T): T {
|
|
11
|
+
if (hasOwnProperty(payload, 'entity')) {
|
|
12
|
+
delete payload.entity;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (hasOwnProperty(payload, 'registry')) {
|
|
16
|
+
delete payload.registry;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return payload;
|
|
20
|
+
}
|
package/tsconfig.json
ADDED