@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.
Files changed (65) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/function/functions.types.d.ts +1 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +2 -0
  5. package/dist/middleware/auth-apikey.d.ts +1 -0
  6. package/dist/middleware/auth-bearer.d.ts +1 -0
  7. package/dist/middleware/auth-cookie.d.ts +1 -0
  8. package/dist/middleware/timeout.d.ts +1 -0
  9. package/dist/middleware-runner.js +1 -0
  10. package/dist/permissions.js +1 -0
  11. package/dist/pikku-state.d.ts +7 -2
  12. package/dist/pikku-state.js +4 -0
  13. package/dist/services/index.d.ts +1 -0
  14. package/dist/services/index.js +1 -0
  15. package/dist/services/scheduler-service.d.ts +63 -0
  16. package/dist/services/scheduler-service.js +6 -0
  17. package/dist/time-utils.d.ts +14 -0
  18. package/dist/time-utils.js +62 -0
  19. package/dist/types/core.types.d.ts +24 -2
  20. package/dist/types/core.types.js +1 -0
  21. package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
  22. package/dist/wirings/cli/cli-runner.js +1 -1
  23. package/dist/wirings/queue/queue-runner.js +6 -3
  24. package/dist/wirings/queue/queue.types.d.ts +1 -3
  25. package/dist/wirings/rpc/index.d.ts +1 -1
  26. package/dist/wirings/rpc/index.js +1 -1
  27. package/dist/wirings/rpc/rpc-runner.d.ts +4 -0
  28. package/dist/wirings/rpc/rpc-runner.js +37 -2
  29. package/dist/wirings/rpc/rpc-types.d.ts +1 -0
  30. package/dist/wirings/workflow/index.d.ts +6 -0
  31. package/dist/wirings/workflow/index.js +6 -0
  32. package/dist/wirings/workflow/pikku-workflow-service.d.ts +152 -0
  33. package/dist/wirings/workflow/pikku-workflow-service.js +448 -0
  34. package/dist/wirings/workflow/workflow-runner.d.ts +35 -0
  35. package/dist/wirings/workflow/workflow-runner.js +68 -0
  36. package/dist/wirings/workflow/workflow.types.d.ts +247 -0
  37. package/dist/wirings/workflow/workflow.types.js +1 -0
  38. package/package.json +2 -3
  39. package/src/function/functions.types.ts +1 -0
  40. package/src/index.ts +2 -0
  41. package/src/middleware-runner.ts +1 -0
  42. package/src/permissions.ts +1 -0
  43. package/src/pikku-state.ts +14 -2
  44. package/src/services/index.ts +1 -0
  45. package/src/services/scheduler-service.ts +76 -0
  46. package/src/time-utils.ts +75 -0
  47. package/src/types/core.types.ts +30 -1
  48. package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
  49. package/src/wirings/cli/cli-runner.ts +1 -1
  50. package/src/wirings/queue/queue-runner.ts +14 -6
  51. package/src/wirings/queue/queue.types.ts +1 -4
  52. package/src/wirings/rpc/index.ts +1 -1
  53. package/src/wirings/rpc/rpc-runner.ts +56 -3
  54. package/src/wirings/rpc/rpc-types.ts +1 -0
  55. package/src/wirings/workflow/index.ts +22 -0
  56. package/src/wirings/workflow/pikku-workflow-service.ts +756 -0
  57. package/src/wirings/workflow/workflow-runner.ts +85 -0
  58. package/src/wirings/workflow/workflow.types.ts +332 -0
  59. package/tsconfig.tsbuildinfo +1 -1
  60. package/dist/services/file-channel-store.d.ts +0 -19
  61. package/dist/services/file-channel-store.js +0 -69
  62. package/dist/services/file-eventhub-store.d.ts +0 -17
  63. package/dist/services/file-eventhub-store.js +0 -71
  64. package/src/services/file-channel-store.ts +0 -86
  65. 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
- }