@pikku/core 0.10.2 → 0.11.0
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 +9 -0
- package/dist/function/functions.types.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/middleware/auth-apikey.d.ts +1 -0
- package/dist/middleware/auth-bearer.d.ts +1 -0
- package/dist/middleware/auth-cookie.d.ts +1 -0
- package/dist/middleware/timeout.d.ts +1 -0
- package/dist/middleware-runner.js +1 -0
- package/dist/permissions.js +1 -0
- package/dist/pikku-state.d.ts +7 -2
- package/dist/pikku-state.js +4 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/scheduler-service.d.ts +63 -0
- package/dist/services/scheduler-service.js +6 -0
- package/dist/time-utils.d.ts +14 -0
- package/dist/time-utils.js +62 -0
- package/dist/types/core.types.d.ts +24 -2
- package/dist/types/core.types.js +1 -0
- package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
- package/dist/wirings/cli/cli-runner.js +1 -1
- package/dist/wirings/queue/queue-runner.js +6 -3
- package/dist/wirings/queue/queue.types.d.ts +1 -3
- package/dist/wirings/rpc/index.d.ts +1 -1
- package/dist/wirings/rpc/index.js +1 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +4 -0
- package/dist/wirings/rpc/rpc-runner.js +37 -2
- package/dist/wirings/rpc/rpc-types.d.ts +1 -0
- package/dist/wirings/workflow/index.d.ts +6 -0
- package/dist/wirings/workflow/index.js +6 -0
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +152 -0
- package/dist/wirings/workflow/pikku-workflow-service.js +448 -0
- package/dist/wirings/workflow/workflow-runner.d.ts +35 -0
- package/dist/wirings/workflow/workflow-runner.js +68 -0
- package/dist/wirings/workflow/workflow.types.d.ts +247 -0
- package/dist/wirings/workflow/workflow.types.js +1 -0
- package/package.json +2 -3
- package/src/function/functions.types.ts +1 -0
- package/src/index.ts +2 -0
- package/src/middleware-runner.ts +1 -0
- package/src/permissions.ts +1 -0
- package/src/pikku-state.ts +14 -2
- package/src/services/index.ts +1 -0
- package/src/services/scheduler-service.ts +76 -0
- package/src/time-utils.ts +75 -0
- package/src/types/core.types.ts +30 -1
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/cli-runner.ts +1 -1
- package/src/wirings/queue/queue-runner.ts +14 -6
- package/src/wirings/queue/queue.types.ts +1 -4
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +56 -3
- package/src/wirings/rpc/rpc-types.ts +1 -0
- package/src/wirings/workflow/index.ts +22 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +756 -0
- package/src/wirings/workflow/workflow-runner.ts +85 -0
- package/src/wirings/workflow/workflow.types.ts +332 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/services/file-channel-store.d.ts +0 -19
- package/dist/services/file-channel-store.js +0 -69
- package/dist/services/file-eventhub-store.d.ts +0 -17
- package/dist/services/file-eventhub-store.js +0 -71
- package/src/services/file-channel-store.ts +0 -86
- package/src/services/file-eventhub-store.ts +0 -90
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs'
|
|
2
|
-
import { join } from 'path'
|
|
3
|
-
import { EventHubStore } from '../wirings/channel/eventhub-store.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* File-based implementation of EventHubStore for serverless/multi-process environments.
|
|
7
|
-
* Stores subscriptions as JSON files in a directory. Suitable for AWS Lambda /tmp storage
|
|
8
|
-
* or other shared filesystem scenarios.
|
|
9
|
-
*/
|
|
10
|
-
export class FileEventHubStore<
|
|
11
|
-
EventTopics extends Record<string, any> = {},
|
|
12
|
-
> extends EventHubStore<EventTopics> {
|
|
13
|
-
private storageDir: string
|
|
14
|
-
|
|
15
|
-
constructor(storageDir: string = '/tmp/pikku-eventhub') {
|
|
16
|
-
super()
|
|
17
|
-
this.storageDir = storageDir
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private async ensureDir(): Promise<void> {
|
|
21
|
-
try {
|
|
22
|
-
await fs.mkdir(this.storageDir, { recursive: true })
|
|
23
|
-
} catch (err) {
|
|
24
|
-
// Directory might already exist, ignore error
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private getTopicPath(topic: string): string {
|
|
29
|
-
// Sanitize topic name for filesystem
|
|
30
|
-
const safeTopic = topic.replace(/[^a-zA-Z0-9-_]/g, '_')
|
|
31
|
-
return join(this.storageDir, `${safeTopic}.json`)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private async readSubscriptions(topic: string): Promise<Set<string>> {
|
|
35
|
-
try {
|
|
36
|
-
const content = await fs.readFile(this.getTopicPath(topic), 'utf-8')
|
|
37
|
-
const channelIds = JSON.parse(content) as string[]
|
|
38
|
-
return new Set(channelIds)
|
|
39
|
-
} catch (err) {
|
|
40
|
-
return new Set()
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private async writeSubscriptions(
|
|
45
|
-
topic: string,
|
|
46
|
-
channelIds: Set<string>
|
|
47
|
-
): Promise<void> {
|
|
48
|
-
await this.ensureDir()
|
|
49
|
-
await fs.writeFile(
|
|
50
|
-
this.getTopicPath(topic),
|
|
51
|
-
JSON.stringify(Array.from(channelIds))
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public async getChannelIdsForTopic(topic: string): Promise<string[]> {
|
|
56
|
-
const channelIds = await this.readSubscriptions(topic)
|
|
57
|
-
return Array.from(channelIds)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public async subscribe<T extends keyof EventTopics>(
|
|
61
|
-
topic: T,
|
|
62
|
-
channelId: string
|
|
63
|
-
): Promise<boolean> {
|
|
64
|
-
const topicKey = topic as string
|
|
65
|
-
const channelIds = await this.readSubscriptions(topicKey)
|
|
66
|
-
channelIds.add(channelId)
|
|
67
|
-
await this.writeSubscriptions(topicKey, channelIds)
|
|
68
|
-
return true
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public async unsubscribe<T extends keyof EventTopics>(
|
|
72
|
-
topic: T,
|
|
73
|
-
channelId: string
|
|
74
|
-
): Promise<boolean> {
|
|
75
|
-
const topicKey = topic as string
|
|
76
|
-
const channelIds = await this.readSubscriptions(topicKey)
|
|
77
|
-
channelIds.delete(channelId)
|
|
78
|
-
if (channelIds.size === 0) {
|
|
79
|
-
// Remove the file if no subscriptions left
|
|
80
|
-
try {
|
|
81
|
-
await fs.unlink(this.getTopicPath(topicKey))
|
|
82
|
-
} catch (err) {
|
|
83
|
-
// File might not exist, ignore error
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
await this.writeSubscriptions(topicKey, channelIds)
|
|
87
|
-
}
|
|
88
|
-
return true
|
|
89
|
-
}
|
|
90
|
-
}
|