@pikku/addon-aws-sqs 0.0.2
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/README.md +12 -0
- package/dist/.pikku/addon/pikku-addon-types.gen.d.ts +67 -0
- package/dist/.pikku/addon/pikku-addon-types.gen.d.ts.map +1 -0
- package/dist/.pikku/addon/pikku-addon-types.gen.js +78 -0
- package/dist/.pikku/addon/pikku-addon-types.gen.js.map +1 -0
- package/dist/.pikku/addon/pikku-addon-types.gen.ts +106 -0
- package/dist/.pikku/addon/pikku-package.gen.d.ts +2 -0
- package/dist/.pikku/addon/pikku-package.gen.d.ts.map +1 -0
- package/dist/.pikku/addon/pikku-package.gen.js +10 -0
- package/dist/.pikku/addon/pikku-package.gen.js.map +1 -0
- package/dist/.pikku/addon/pikku-package.gen.ts +11 -0
- package/dist/.pikku/agent/pikku-agent-map.gen.d.ts +4 -0
- package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +47 -0
- package/dist/.pikku/agent/pikku-agent-types.gen.d.ts.map +1 -0
- package/dist/.pikku/agent/pikku-agent-types.gen.js +18 -0
- package/dist/.pikku/agent/pikku-agent-types.gen.js.map +1 -0
- package/dist/.pikku/agent/pikku-agent-types.gen.ts +82 -0
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +112 -0
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts.map +1 -0
- package/dist/.pikku/channel/pikku-channel-types.gen.js +60 -0
- package/dist/.pikku/channel/pikku-channel-types.gen.js.map +1 -0
- package/dist/.pikku/channel/pikku-channel-types.gen.ts +177 -0
- package/dist/.pikku/console/pikku-node-types.gen.d.ts +7 -0
- package/dist/.pikku/console/pikku-node-types.gen.d.ts.map +1 -0
- package/dist/.pikku/console/pikku-node-types.gen.js +2 -0
- package/dist/.pikku/console/pikku-node-types.gen.js.map +1 -0
- package/dist/.pikku/console/pikku-node-types.gen.ts +8 -0
- package/dist/.pikku/credentials/pikku-credentials-meta.gen.json +10 -0
- package/dist/.pikku/credentials/pikku-credentials.gen.d.ts +15 -0
- package/dist/.pikku/credentials/pikku-credentials.gen.d.ts.map +1 -0
- package/dist/.pikku/credentials/pikku-credentials.gen.js +13 -0
- package/dist/.pikku/credentials/pikku-credentials.gen.js.map +1 -0
- package/dist/.pikku/credentials/pikku-credentials.gen.ts +23 -0
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +490 -0
- package/dist/.pikku/function/pikku-function-types.gen.d.ts.map +1 -0
- package/dist/.pikku/function/pikku-function-types.gen.js +334 -0
- package/dist/.pikku/function/pikku-function-types.gen.js.map +1 -0
- package/dist/.pikku/function/pikku-function-types.gen.ts +754 -0
- package/dist/.pikku/function/pikku-functions-meta-verbose.gen.json +31 -0
- package/dist/.pikku/function/pikku-functions-meta.gen.d.ts +2 -0
- package/dist/.pikku/function/pikku-functions-meta.gen.d.ts.map +1 -0
- package/dist/.pikku/function/pikku-functions-meta.gen.js +7 -0
- package/dist/.pikku/function/pikku-functions-meta.gen.js.map +1 -0
- package/dist/.pikku/function/pikku-functions-meta.gen.json +21 -0
- package/dist/.pikku/function/pikku-functions-meta.gen.ts +7 -0
- package/dist/.pikku/function/pikku-functions.gen.d.ts +2 -0
- package/dist/.pikku/function/pikku-functions.gen.d.ts.map +1 -0
- package/dist/.pikku/function/pikku-functions.gen.js +8 -0
- package/dist/.pikku/function/pikku-functions.gen.js.map +1 -0
- package/dist/.pikku/function/pikku-functions.gen.ts +8 -0
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +120 -0
- package/dist/.pikku/http/pikku-http-types.gen.d.ts.map +1 -0
- package/dist/.pikku/http/pikku-http-types.gen.js +72 -0
- package/dist/.pikku/http/pikku-http-types.gen.js.map +1 -0
- package/dist/.pikku/http/pikku-http-types.gen.ts +147 -0
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +131 -0
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts.map +1 -0
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +38 -0
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js.map +1 -0
- package/dist/.pikku/mcp/pikku-mcp-types.gen.ts +183 -0
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +9 -0
- package/dist/.pikku/pikku-bootstrap.gen.d.ts.map +1 -0
- package/dist/.pikku/pikku-bootstrap.gen.js +9 -0
- package/dist/.pikku/pikku-bootstrap.gen.js.map +1 -0
- package/dist/.pikku/pikku-bootstrap.gen.ts +8 -0
- package/dist/.pikku/pikku-meta-service.gen.d.ts +8 -0
- package/dist/.pikku/pikku-meta-service.gen.d.ts.map +1 -0
- package/dist/.pikku/pikku-meta-service.gen.js +10 -0
- package/dist/.pikku/pikku-meta-service.gen.js.map +1 -0
- package/dist/.pikku/pikku-meta-service.gen.ts +10 -0
- package/dist/.pikku/pikku-services.gen.d.ts +35 -0
- package/dist/.pikku/pikku-services.gen.d.ts.map +1 -0
- package/dist/.pikku/pikku-services.gen.js +30 -0
- package/dist/.pikku/pikku-services.gen.js.map +1 -0
- package/dist/.pikku/pikku-services.gen.ts +42 -0
- package/dist/.pikku/pikku-types.gen.d.ts +12 -0
- package/dist/.pikku/pikku-types.gen.d.ts.map +1 -0
- package/dist/.pikku/pikku-types.gen.js +17 -0
- package/dist/.pikku/pikku-types.gen.js.map +1 -0
- package/dist/.pikku/pikku-types.gen.ts +21 -0
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +24 -0
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts.map +1 -0
- package/dist/.pikku/queue/pikku-queue-types.gen.js +17 -0
- package/dist/.pikku/queue/pikku-queue-types.gen.js.map +1 -0
- package/dist/.pikku/queue/pikku-queue-types.gen.ts +27 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +105 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +106 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.d.ts +2 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.d.ts.map +1 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +7 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js.map +1 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +3 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +6 -0
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +22 -0
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts.map +1 -0
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +17 -0
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js.map +1 -0
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.ts +25 -0
- package/dist/.pikku/schemas/register.gen.d.ts +2 -0
- package/dist/.pikku/schemas/register.gen.d.ts.map +1 -0
- package/dist/.pikku/schemas/register.gen.js +13 -0
- package/dist/.pikku/schemas/register.gen.js.map +1 -0
- package/dist/.pikku/schemas/register.gen.ts +19 -0
- package/dist/.pikku/schemas/schemas/CredentialSchema_awsSqs.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/SendMessageInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/SendMessageOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/VariableSchema_AWS_SQS_BASE_URL.schema.json +1 -0
- package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +6 -0
- package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts.map +1 -0
- package/dist/.pikku/secrets/pikku-secret-types.gen.js +5 -0
- package/dist/.pikku/secrets/pikku-secret-types.gen.js.map +1 -0
- package/dist/.pikku/secrets/pikku-secret-types.gen.ts +5 -0
- package/dist/.pikku/secrets/pikku-secrets-meta.gen.json +1 -0
- package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +12 -0
- package/dist/.pikku/secrets/pikku-secrets.gen.d.ts.map +1 -0
- package/dist/.pikku/secrets/pikku-secrets.gen.js +11 -0
- package/dist/.pikku/secrets/pikku-secrets.gen.js.map +1 -0
- package/dist/.pikku/secrets/pikku-secrets.gen.ts +21 -0
- package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +114 -0
- package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts.map +1 -0
- package/dist/.pikku/trigger/pikku-trigger-types.gen.js +34 -0
- package/dist/.pikku/trigger/pikku-trigger-types.gen.js.map +1 -0
- package/dist/.pikku/trigger/pikku-trigger-types.gen.ts +160 -0
- package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +6 -0
- package/dist/.pikku/variables/pikku-variable-types.gen.d.ts.map +1 -0
- package/dist/.pikku/variables/pikku-variable-types.gen.js +5 -0
- package/dist/.pikku/variables/pikku-variable-types.gen.js.map +1 -0
- package/dist/.pikku/variables/pikku-variable-types.gen.ts +5 -0
- package/dist/.pikku/variables/pikku-variables-meta.gen.json +10 -0
- package/dist/.pikku/variables/pikku-variables.gen.d.ts +15 -0
- package/dist/.pikku/variables/pikku-variables.gen.d.ts.map +1 -0
- package/dist/.pikku/variables/pikku-variables.gen.js +13 -0
- package/dist/.pikku/variables/pikku-variables.gen.js.map +1 -0
- package/dist/.pikku/variables/pikku-variables.gen.ts +23 -0
- package/dist/.pikku/workflow/pikku-workflow-map.gen.d.ts +38 -0
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +90 -0
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts.map +1 -0
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js +18 -0
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js.map +1 -0
- package/dist/.pikku/workflow/pikku-workflow-types.gen.ts +167 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.d.ts +2 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.d.ts.map +1 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +7 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js.map +1 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.ts +9 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.d.ts +5 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.d.ts.map +1 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +5 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js.map +1 -0
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.ts +3 -0
- package/dist/src/aws-sqs-api.service.d.ts +10 -0
- package/dist/src/aws-sqs-api.service.d.ts.map +1 -0
- package/dist/src/aws-sqs-api.service.js +80 -0
- package/dist/src/aws-sqs-api.service.js.map +1 -0
- package/dist/src/aws-sqs.credential.d.ts +5 -0
- package/dist/src/aws-sqs.credential.d.ts.map +1 -0
- package/dist/src/aws-sqs.credential.js +13 -0
- package/dist/src/aws-sqs.credential.js.map +1 -0
- package/dist/src/aws-sqs.types.d.ts +7 -0
- package/dist/src/aws-sqs.types.d.ts.map +1 -0
- package/dist/src/aws-sqs.types.js +8 -0
- package/dist/src/aws-sqs.types.js.map +1 -0
- package/dist/src/aws-sqs.variable.d.ts +5 -0
- package/dist/src/aws-sqs.variable.d.ts.map +1 -0
- package/dist/src/aws-sqs.variable.js +11 -0
- package/dist/src/aws-sqs.variable.js.map +1 -0
- package/dist/src/functions/sendMessage.function.d.ts +13 -0
- package/dist/src/functions/sendMessage.function.d.ts.map +1 -0
- package/dist/src/functions/sendMessage.function.js +15 -0
- package/dist/src/functions/sendMessage.function.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/services.d.ts +2 -0
- package/dist/src/services.d.ts.map +1 -0
- package/dist/src/services.js +14 -0
- package/dist/src/services.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was generated by @pikku/cli@0.12.54
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Core function, middleware, and permission types for all wirings
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CorePikkuMiddleware, CorePermissionGroup, ListInput, ListOutput, PikkuWire, PickRequired } from '@pikku/core'
|
|
9
|
+
import type { CorePikkuFunctionConfig, CorePikkuAuth, CorePikkuAuthConfig, CorePikkuPermission } from '@pikku/core/function'
|
|
10
|
+
import { pikkuAuth as pikkuAuthCore } from '@pikku/core/function'
|
|
11
|
+
import {
|
|
12
|
+
addTagMiddleware as addTagMiddlewareCore,
|
|
13
|
+
addGlobalMiddleware as addGlobalMiddlewareCore,
|
|
14
|
+
addTagPermission as addTagPermissionCore,
|
|
15
|
+
addGlobalPermission as addGlobalPermissionCore,
|
|
16
|
+
} from '@pikku/core/middleware'
|
|
17
|
+
import { pikkuState as __pikkuState, CreateWireServices } from '@pikku/core/internal'
|
|
18
|
+
import type { NodeType } from '@pikku/core/node'
|
|
19
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
20
|
+
import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
|
|
21
|
+
|
|
22
|
+
import type { UserSession } from '../../types/application-types.d.js'
|
|
23
|
+
import type { SingletonServices } from '../../types/application-types.d.js'
|
|
24
|
+
import type { Services } from '../../types/application-types.d.js'
|
|
25
|
+
import type { Config } from '../../types/application-types.d.js'
|
|
26
|
+
import type { TypedPikkuRPC, FlattenedRPCMap } from '../rpc/pikku-rpc-wirings-map.internal.gen.d.js'
|
|
27
|
+
import type { RequiredSingletonServices, RequiredWireServices } from '../pikku-services.gen.js'
|
|
28
|
+
import type { TypedWorkflow } from '../workflow/pikku-workflow-types.gen.js'
|
|
29
|
+
|
|
30
|
+
export type { SingletonServices as SingletonServices }
|
|
31
|
+
export type { Services as Services }
|
|
32
|
+
export type Session = UserSession
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Inline node configuration for function definitions.
|
|
37
|
+
*/
|
|
38
|
+
export type NodeConfig = {
|
|
39
|
+
displayName: string
|
|
40
|
+
category: string
|
|
41
|
+
type: NodeType
|
|
42
|
+
errorOutput?: boolean
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Type-safe API permission definition that integrates with your application's session type.
|
|
47
|
+
* Use this to define authorization logic for your API endpoints.
|
|
48
|
+
*
|
|
49
|
+
* @template In - The input type that the permission check will receive
|
|
50
|
+
* @template RequiredServices - The services required for this permission check
|
|
51
|
+
*/
|
|
52
|
+
export type PikkuPermission<In = unknown, RequiredServices extends Services = Services> = CorePikkuPermission<In, RequiredServices, PikkuWire<In, never, false, Session>>
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Type-safe middleware definition that can access your application's services and session.
|
|
56
|
+
* Use this to define reusable middleware that can be applied to multiple wirings.
|
|
57
|
+
*
|
|
58
|
+
* @template RequiredServices - The services required for this middleware
|
|
59
|
+
*/
|
|
60
|
+
export type PikkuMiddleware<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuMiddleware<RequiredServices>
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Configuration object for creating a permission with metadata
|
|
64
|
+
*/
|
|
65
|
+
export type PikkuPermissionConfig<In = unknown, RequiredServices extends Services = Services> = {
|
|
66
|
+
/** The permission function */
|
|
67
|
+
func: PikkuPermission<In, RequiredServices>
|
|
68
|
+
/** Optional human-readable name for the permission */
|
|
69
|
+
name?: string
|
|
70
|
+
/** Optional description of what the permission checks */
|
|
71
|
+
description?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Factory function for creating permissions with tree-shaking support.
|
|
76
|
+
* Supports both direct function and configuration object syntax.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Direct function syntax
|
|
81
|
+
* const permission = pikkuPermission(async ({ logger }, data, { session }) => {
|
|
82
|
+
* const session = await session?.get()
|
|
83
|
+
* return session?.role === 'admin'
|
|
84
|
+
* })
|
|
85
|
+
*
|
|
86
|
+
* // Configuration object syntax with metadata
|
|
87
|
+
* const adminPermission = pikkuPermission({
|
|
88
|
+
* name: 'Admin Permission',
|
|
89
|
+
* description: 'Checks if user has admin role',
|
|
90
|
+
* func: async ({ logger }, data, { session }) => {
|
|
91
|
+
* const session = await session?.get()
|
|
92
|
+
* return session?.role === 'admin'
|
|
93
|
+
* }
|
|
94
|
+
* })
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export const pikkuPermission = <In>(
|
|
98
|
+
permission: PikkuPermission<In> | PikkuPermissionConfig<In>
|
|
99
|
+
): PikkuPermission<In> => {
|
|
100
|
+
return typeof permission === 'function' ? permission : permission.func
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Type-safe auth-only permission that only needs services and session.
|
|
105
|
+
* Use this for upfront authorization gates (MCP tools, AI agents, workflows)
|
|
106
|
+
* where request data isn't available yet.
|
|
107
|
+
*
|
|
108
|
+
* @template RequiredServices - The services required for this auth check
|
|
109
|
+
*/
|
|
110
|
+
export type PikkuAuth<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuAuth<RequiredServices, Session>
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Configuration object for creating an auth permission with metadata
|
|
114
|
+
*/
|
|
115
|
+
export type PikkuAuthConfig<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuAuthConfig<RequiredServices, Session>
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Factory function for creating auth-only permissions with tree-shaking support.
|
|
119
|
+
* Auth permissions only receive services and session (no request data),
|
|
120
|
+
* making them evaluable before request data is available.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* \`\`\`typescript
|
|
124
|
+
* const isAuthenticated = pikkuAuth(async ({ logger }, session) => {
|
|
125
|
+
* return !!session
|
|
126
|
+
* })
|
|
127
|
+
*
|
|
128
|
+
* const isAdmin = pikkuAuth({
|
|
129
|
+
* name: 'Admin Auth',
|
|
130
|
+
* description: 'Checks if user is an admin',
|
|
131
|
+
* func: async ({ logger }, session) => {
|
|
132
|
+
* return session?.role === 'admin'
|
|
133
|
+
* }
|
|
134
|
+
* })
|
|
135
|
+
* \`\`\`
|
|
136
|
+
*/
|
|
137
|
+
export const pikkuAuth = <RequiredServices extends SingletonServices = SingletonServices>(
|
|
138
|
+
auth: PikkuAuth<RequiredServices> | PikkuAuthConfig<RequiredServices>
|
|
139
|
+
): PikkuPermission<any, any> => {
|
|
140
|
+
return pikkuAuthCore(auth as any) as any
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Configuration object for creating middleware with metadata
|
|
145
|
+
*/
|
|
146
|
+
export type PikkuMiddlewareConfig<RequiredServices extends SingletonServices = SingletonServices> = {
|
|
147
|
+
/** The middleware function */
|
|
148
|
+
func: PikkuMiddleware<RequiredServices>
|
|
149
|
+
/** Optional human-readable name for the middleware */
|
|
150
|
+
name?: string
|
|
151
|
+
/** Optional description of what the middleware does */
|
|
152
|
+
description?: string
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Factory function for creating middleware with tree-shaking support.
|
|
157
|
+
* Supports both direct function and configuration object syntax.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* // Direct function syntax
|
|
162
|
+
* const middleware = pikkuMiddleware(({ logger }, wires, next) => {
|
|
163
|
+
* logger.info('Middleware executed')
|
|
164
|
+
* await next()
|
|
165
|
+
* })
|
|
166
|
+
*
|
|
167
|
+
* // Configuration object syntax with metadata
|
|
168
|
+
* const logMiddleware = pikkuMiddleware({
|
|
169
|
+
* name: 'Request Logger',
|
|
170
|
+
* description: 'Logs all incoming requests',
|
|
171
|
+
* func: async ({ logger }, wires, next) => {
|
|
172
|
+
* logger.info('Request started')
|
|
173
|
+
* await next()
|
|
174
|
+
* }
|
|
175
|
+
* })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export const pikkuMiddleware = <RequiredServices extends SingletonServices = SingletonServices>(
|
|
179
|
+
middleware: PikkuMiddleware<RequiredServices> | PikkuMiddlewareConfig<RequiredServices>
|
|
180
|
+
): PikkuMiddleware<RequiredServices> => {
|
|
181
|
+
return typeof middleware === 'function' ? middleware : middleware.func
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Factory function for creating middleware factories
|
|
186
|
+
* Use this when your middleware needs configuration/input parameters
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* export const logMiddleware = pikkuMiddlewareFactory<LogOptions>(({
|
|
191
|
+
* message,
|
|
192
|
+
* level = 'info'
|
|
193
|
+
* }) => {
|
|
194
|
+
* return pikkuMiddleware(async ({ logger }, next) => {
|
|
195
|
+
* logger[level](message)
|
|
196
|
+
* await next()
|
|
197
|
+
* })
|
|
198
|
+
* })
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export const pikkuMiddlewareFactory = <In = any>(
|
|
202
|
+
factory: (input: In) => PikkuMiddleware
|
|
203
|
+
): ((input: In) => PikkuMiddleware) => {
|
|
204
|
+
return factory
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Factory function for creating permission factories
|
|
209
|
+
* Use this when your permission needs configuration/input parameters
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* export const requireRole = pikkuPermissionFactory<{ role: string }>(({
|
|
214
|
+
* role
|
|
215
|
+
* }) => {
|
|
216
|
+
* return pikkuPermission(async ({ logger }, data, { session }) => {
|
|
217
|
+
* if (!session || session.role !== role) {
|
|
218
|
+
* logger.warn(`Permission denied: required role '${role}'`)
|
|
219
|
+
* return false
|
|
220
|
+
* }
|
|
221
|
+
* return true
|
|
222
|
+
* })
|
|
223
|
+
* })
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export const pikkuPermissionFactory = <In = any>(
|
|
227
|
+
factory: (input: In) => PikkuPermission<any>
|
|
228
|
+
): ((input: In) => PikkuPermission<any>) => {
|
|
229
|
+
return factory
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A function that generates a human-readable description of a pending approval action.
|
|
234
|
+
* Used by AI agents to show meaningful approval prompts instead of raw tool arguments.
|
|
235
|
+
*
|
|
236
|
+
* @template In - The input type (same as the function it describes)
|
|
237
|
+
* @template RequiredServices - The services required for this description function
|
|
238
|
+
*/
|
|
239
|
+
export type PikkuApprovalDescription<In = unknown, RequiredServices extends Services = Services> = (
|
|
240
|
+
services: RequiredServices,
|
|
241
|
+
data: In
|
|
242
|
+
) => Promise<string>
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Factory function for creating approval description functions with tree-shaking support.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* export const deleteTodoApproval = pikkuApprovalDescription(
|
|
250
|
+
* async ({ todoStore }, { id }) => {
|
|
251
|
+
* const todo = await todoStore.get(id)
|
|
252
|
+
* return \`Delete todo: "${todo.title}"\`
|
|
253
|
+
* }
|
|
254
|
+
* )
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export const pikkuApprovalDescription = <In = unknown, RequiredServices extends Services = Services>(
|
|
258
|
+
fn: PikkuApprovalDescription<In, RequiredServices>
|
|
259
|
+
): PikkuApprovalDescription<In, RequiredServices> => {
|
|
260
|
+
return fn
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* A sessionless API function that doesn't require user authentication.
|
|
265
|
+
* Use this for public endpoints, health checks, or operations that don't need user context.
|
|
266
|
+
*
|
|
267
|
+
* @template In - The input type
|
|
268
|
+
* @template Out - The output type that the function returns
|
|
269
|
+
* @template RequiredServices - Services required by this function
|
|
270
|
+
*/
|
|
271
|
+
export type PikkuFunctionSessionless<
|
|
272
|
+
In = unknown,
|
|
273
|
+
Out = never,
|
|
274
|
+
RequiredWires extends keyof PikkuWire = never,
|
|
275
|
+
RequiredServices extends Services = Services
|
|
276
|
+
> = CorePikkuFunctionSessionless<
|
|
277
|
+
In,
|
|
278
|
+
Out,
|
|
279
|
+
RequiredServices,
|
|
280
|
+
Session,
|
|
281
|
+
PickRequired<PikkuWire<In, Out, false, Session, TypedPikkuRPC, null, any, TypedWorkflow>, RequiredWires>
|
|
282
|
+
>
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* A session-aware API function that requires user authentication.
|
|
286
|
+
* Use this for protected endpoints that need access to user session data.
|
|
287
|
+
*
|
|
288
|
+
* @template In - The input type
|
|
289
|
+
* @template Out - The output type that the function returns
|
|
290
|
+
* @template RequiredServices - Services required by this function
|
|
291
|
+
*/
|
|
292
|
+
export type PikkuFunction<
|
|
293
|
+
In = unknown,
|
|
294
|
+
Out = never,
|
|
295
|
+
RequiredWires extends keyof PikkuWire = 'session',
|
|
296
|
+
RequiredServices extends Services = Services
|
|
297
|
+
> = CorePikkuFunction<
|
|
298
|
+
In,
|
|
299
|
+
Out,
|
|
300
|
+
RequiredServices,
|
|
301
|
+
Session,
|
|
302
|
+
PickRequired<PikkuWire<In, Out, true, Session, TypedPikkuRPC, null, any, TypedWorkflow>, RequiredWires>
|
|
303
|
+
>
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Helper type to infer the output type from a Standard Schema
|
|
307
|
+
*/
|
|
308
|
+
export type InferSchemaOutput<T> = T extends StandardSchemaV1<any, infer Output> ? Output : never
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Configuration object for Pikku functions with optional middleware, permissions, tags, and documentation.
|
|
312
|
+
* This type wraps CorePikkuFunctionConfig with the user's custom types.
|
|
313
|
+
*
|
|
314
|
+
* @template In - The input type
|
|
315
|
+
* @template Out - The output type
|
|
316
|
+
* @template PikkuFunc - The function type (can be narrowed to PikkuFunction or PikkuFunctionSessionless)
|
|
317
|
+
*/
|
|
318
|
+
export type PikkuFunctionConfig<
|
|
319
|
+
In = unknown,
|
|
320
|
+
Out = unknown,
|
|
321
|
+
RequiredWires extends keyof PikkuWire = never,
|
|
322
|
+
PikkuFunc extends PikkuFunction<In, Out, RequiredWires> | PikkuFunctionSessionless<In, Out, RequiredWires> = PikkuFunction<In, Out, RequiredWires> | PikkuFunctionSessionless<In, Out, RequiredWires>,
|
|
323
|
+
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
324
|
+
OutputSchema extends StandardSchemaV1 | undefined = undefined
|
|
325
|
+
> = CorePikkuFunctionConfig<PikkuFunc, PikkuPermission<In>, PikkuMiddleware, InputSchema, OutputSchema>
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Configuration object for Pikku functions with Zod schema validation.
|
|
329
|
+
* Use this when you want to define input/output schemas using Zod.
|
|
330
|
+
* Types are automatically inferred from the schemas.
|
|
331
|
+
*/
|
|
332
|
+
type SchemaInferred<S, Fallback = unknown> = S extends StandardSchemaV1
|
|
333
|
+
? InferSchemaOutput<S>
|
|
334
|
+
: Fallback
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Schema-overload variant for pikkuFunc. Derived from CorePikkuFunctionConfig
|
|
338
|
+
* so adding a field on the core type automatically propagates here.
|
|
339
|
+
*/
|
|
340
|
+
export type PikkuFunctionConfigWithSchema<
|
|
341
|
+
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
342
|
+
OutputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
343
|
+
RequiredWires extends keyof PikkuWire = never
|
|
344
|
+
> = Omit<
|
|
345
|
+
CorePikkuFunctionConfig<
|
|
346
|
+
| PikkuFunction<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires>
|
|
347
|
+
| PikkuFunctionSessionless<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires>
|
|
348
|
+
>,
|
|
349
|
+
'func' | 'input' | 'output' | 'permissions' | 'approvalDescription'
|
|
350
|
+
> & {
|
|
351
|
+
func:
|
|
352
|
+
| PikkuFunction<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires>
|
|
353
|
+
| PikkuFunctionSessionless<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires>
|
|
354
|
+
input?: InputSchema
|
|
355
|
+
output?: OutputSchema
|
|
356
|
+
permissions?: InputSchema extends StandardSchemaV1
|
|
357
|
+
? CorePermissionGroup<PikkuPermission<InferSchemaOutput<InputSchema>>>
|
|
358
|
+
: undefined
|
|
359
|
+
approvalDescription?: InputSchema extends StandardSchemaV1
|
|
360
|
+
? PikkuApprovalDescription<InferSchemaOutput<InputSchema>>
|
|
361
|
+
: never
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Creates a Pikku function that can be either session-aware or sessionless.
|
|
366
|
+
* This is the main function wrapper for creating API endpoints.
|
|
367
|
+
*
|
|
368
|
+
* Supports two patterns:
|
|
369
|
+
* 1. Generic types: `pikkuFunc<Input, Output>({ func: ... })`
|
|
370
|
+
* 2. Zod schemas: `pikkuFunc({ input: z.object(...), output: z.object(...), func: ... })`
|
|
371
|
+
*
|
|
372
|
+
* @template In - Input type for the function (inferred from schema if provided)
|
|
373
|
+
* @template Out - Output type for the function (inferred from schema if provided)
|
|
374
|
+
* @param func - Function definition, either direct function or configuration object
|
|
375
|
+
* @returns The normalized configuration object
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* // Pattern 1: Using generic types
|
|
380
|
+
* const createUser = pikkuFunc<{name: string, email: string}, {id: number}>({
|
|
381
|
+
* func: async ({db}, input) => {
|
|
382
|
+
* const user = await db.users.create(input)
|
|
383
|
+
* return { id: user.id }
|
|
384
|
+
* }
|
|
385
|
+
* })
|
|
386
|
+
*
|
|
387
|
+
* // Pattern 2: Using Zod schemas (types inferred automatically)
|
|
388
|
+
* const createUserInput = z.object({ name: z.string(), email: z.string() })
|
|
389
|
+
* const createUserOutput = z.object({ id: z.number() })
|
|
390
|
+
*
|
|
391
|
+
* const createUser = pikkuFunc({
|
|
392
|
+
* input: createUserInput,
|
|
393
|
+
* output: createUserOutput,
|
|
394
|
+
* func: async ({db}, input) => {
|
|
395
|
+
* // input is typed as { name: string, email: string }
|
|
396
|
+
* const user = await db.users.create(input)
|
|
397
|
+
* return { id: user.id } // must match output schema
|
|
398
|
+
* }
|
|
399
|
+
* })
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
export function pikkuFunc<
|
|
403
|
+
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
404
|
+
OutputSchema extends StandardSchemaV1 | undefined = undefined
|
|
405
|
+
>(
|
|
406
|
+
config: PikkuFunctionConfigWithSchema<InputSchema, OutputSchema, 'session' | 'rpc'>
|
|
407
|
+
): PikkuFunctionConfig<InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown, 'session' | 'rpc'>
|
|
408
|
+
export function pikkuFunc<In, Out = unknown>(
|
|
409
|
+
func:
|
|
410
|
+
| PikkuFunction<In, Out, 'session' | 'rpc'>
|
|
411
|
+
| PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
|
|
412
|
+
): PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
|
|
413
|
+
export function pikkuFunc(func: any) {
|
|
414
|
+
return typeof func === 'function' ? { func } : func
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export type PikkuListFunction<
|
|
418
|
+
F extends Record<string, unknown> = {},
|
|
419
|
+
Row = unknown,
|
|
420
|
+
S extends string = never
|
|
421
|
+
> =
|
|
422
|
+
| PikkuFunction<ListInput<F, S>, ListOutput<Row>, 'session' | 'rpc'>
|
|
423
|
+
| PikkuFunctionSessionless<
|
|
424
|
+
ListInput<F, S>,
|
|
425
|
+
ListOutput<Row>,
|
|
426
|
+
'session' | 'rpc'
|
|
427
|
+
>
|
|
428
|
+
|
|
429
|
+
export const pikkuListFunc = <
|
|
430
|
+
F extends Record<string, unknown> = {},
|
|
431
|
+
Row = unknown,
|
|
432
|
+
S extends string = never
|
|
433
|
+
>(
|
|
434
|
+
config: PikkuFunctionConfig<
|
|
435
|
+
ListInput<F, S>,
|
|
436
|
+
ListOutput<Row>,
|
|
437
|
+
'session' | 'rpc'
|
|
438
|
+
>
|
|
439
|
+
): PikkuFunctionConfig<ListInput<F, S>, ListOutput<Row>, 'session' | 'rpc'> => {
|
|
440
|
+
return pikkuFunc(config)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Configuration object for sessionless Pikku functions with Zod schema validation.
|
|
445
|
+
*/
|
|
446
|
+
/**
|
|
447
|
+
* Schema-overload variant for pikkuSessionlessFunc. Derived from
|
|
448
|
+
* CorePikkuFunctionConfig to stay in sync with the generic-typed config.
|
|
449
|
+
*/
|
|
450
|
+
export type PikkuFunctionSessionlessConfigWithSchema<
|
|
451
|
+
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
452
|
+
OutputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
453
|
+
RequiredWires extends keyof PikkuWire = never
|
|
454
|
+
> = Omit<
|
|
455
|
+
CorePikkuFunctionConfig<
|
|
456
|
+
PikkuFunctionSessionless<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires>
|
|
457
|
+
>,
|
|
458
|
+
'func' | 'input' | 'output' | 'permissions' | 'approvalDescription'
|
|
459
|
+
> & {
|
|
460
|
+
func: PikkuFunctionSessionless<
|
|
461
|
+
SchemaInferred<InputSchema>,
|
|
462
|
+
SchemaInferred<OutputSchema>,
|
|
463
|
+
RequiredWires
|
|
464
|
+
>
|
|
465
|
+
input?: InputSchema
|
|
466
|
+
output?: OutputSchema
|
|
467
|
+
permissions?: InputSchema extends StandardSchemaV1
|
|
468
|
+
? CorePermissionGroup<PikkuPermission<InferSchemaOutput<InputSchema>>>
|
|
469
|
+
: undefined
|
|
470
|
+
approvalDescription?: InputSchema extends StandardSchemaV1
|
|
471
|
+
? PikkuApprovalDescription<InferSchemaOutput<InputSchema>>
|
|
472
|
+
: never
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Creates a sessionless Pikku function that doesn't require user authentication.
|
|
477
|
+
* Use this for public endpoints, webhooks, or background tasks.
|
|
478
|
+
*
|
|
479
|
+
* Supports two patterns:
|
|
480
|
+
* 1. Generic types: `pikkuSessionlessFunc<Input, Output>({ func: ... })`
|
|
481
|
+
* 2. Zod schemas: `pikkuSessionlessFunc({ input: z.object(...), func: ... })`
|
|
482
|
+
*
|
|
483
|
+
* @template In - Input type for the function (inferred from schema if provided)
|
|
484
|
+
* @template Out - Output type for the function (inferred from schema if provided)
|
|
485
|
+
* @param func - Function definition, either direct function or configuration object
|
|
486
|
+
* @returns The normalized configuration object
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* // Pattern 1: Using generic types
|
|
491
|
+
* const healthCheck = pikkuSessionlessFunc<void, {status: string}>({
|
|
492
|
+
* func: async ({logger}) => {
|
|
493
|
+
* return { status: 'healthy' }
|
|
494
|
+
* }
|
|
495
|
+
* })
|
|
496
|
+
*
|
|
497
|
+
* // Pattern 2: Using Zod schemas
|
|
498
|
+
* const greetInput = z.object({ name: z.string() })
|
|
499
|
+
* const greetOutput = z.object({ message: z.string() })
|
|
500
|
+
*
|
|
501
|
+
* const greet = pikkuSessionlessFunc({
|
|
502
|
+
* input: greetInput,
|
|
503
|
+
* output: greetOutput,
|
|
504
|
+
* func: async (_services, { name }) => {
|
|
505
|
+
* return { message: `Hello, ${name}!` }
|
|
506
|
+
* }
|
|
507
|
+
* })
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
export function pikkuSessionlessFunc<
|
|
511
|
+
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
512
|
+
OutputSchema extends StandardSchemaV1 | undefined = undefined
|
|
513
|
+
>(
|
|
514
|
+
config: PikkuFunctionSessionlessConfigWithSchema<InputSchema, OutputSchema, 'session' | 'rpc'>
|
|
515
|
+
): PikkuFunctionConfig<InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown, 'session' | 'rpc'>
|
|
516
|
+
export function pikkuSessionlessFunc<In, Out = unknown>(
|
|
517
|
+
func:
|
|
518
|
+
| PikkuFunctionSessionless<In, Out, 'session' | 'rpc'>
|
|
519
|
+
| PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
|
|
520
|
+
): PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
|
|
521
|
+
export function pikkuSessionlessFunc(func: any) {
|
|
522
|
+
return typeof func === 'function' ? { func } : func
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Creates a function that takes no input and returns no output.
|
|
527
|
+
* Useful for health checks, triggers, or cleanup operations.
|
|
528
|
+
*
|
|
529
|
+
* @param func - Function definition, either direct function or configuration object
|
|
530
|
+
* @returns The normalized configuration object
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```typescript
|
|
534
|
+
* const cleanupTempFiles = pikkuVoidFunc(async ({fileSystem, logger}) => {
|
|
535
|
+
* logger.info('Starting cleanup of temporary files')
|
|
536
|
+
* await fileSystem.deleteDirectory('/tmp/uploads')
|
|
537
|
+
* logger.info('Cleanup completed')
|
|
538
|
+
* })
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
export const pikkuVoidFunc = (
|
|
542
|
+
func:
|
|
543
|
+
| PikkuFunctionSessionless<void, void, 'session' | 'rpc'>
|
|
544
|
+
| PikkuFunctionConfig<void, void, 'session' | 'rpc'>
|
|
545
|
+
) => {
|
|
546
|
+
return typeof func === 'function' ? { func } : func
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* References a registered function by name for use in any wiring.
|
|
551
|
+
* Works for both local and addon functions — resolves via RPC at runtime.
|
|
552
|
+
*
|
|
553
|
+
* @template Name - The function name (must be a key in FlattenedRPCMap)
|
|
554
|
+
* @param rpcName - The name of the function to reference
|
|
555
|
+
* @returns A Pikku function config that proxies calls via RPC
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```typescript
|
|
559
|
+
* // Use in agent tools
|
|
560
|
+
* tools: [ref('todos:listTodos'), ref('myLocalFunc')]
|
|
561
|
+
*
|
|
562
|
+
* // Use in HTTP wiring
|
|
563
|
+
* wireHTTP({ route: '/greet', method: 'post', func: ref('greet') })
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
export const ref = <Name extends keyof FlattenedRPCMap>(
|
|
567
|
+
rpcName: Name
|
|
568
|
+
): PikkuFunctionConfig<
|
|
569
|
+
FlattenedRPCMap[Name]['input'],
|
|
570
|
+
FlattenedRPCMap[Name]['output'],
|
|
571
|
+
'session' | 'rpc'
|
|
572
|
+
> => {
|
|
573
|
+
return {
|
|
574
|
+
func: async (_services: any, data: FlattenedRPCMap[Name]['input'], { rpc }: any) => {
|
|
575
|
+
return rpc.invoke(rpcName, data)
|
|
576
|
+
}
|
|
577
|
+
} as PikkuFunctionConfig<
|
|
578
|
+
FlattenedRPCMap[Name]['input'],
|
|
579
|
+
FlattenedRPCMap[Name]['output'],
|
|
580
|
+
'session' | 'rpc'
|
|
581
|
+
>
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Creates a Pikku config factory.
|
|
586
|
+
* Use this to define your application's configuration factory.
|
|
587
|
+
*
|
|
588
|
+
* @param func - Config factory function that returns your application's config
|
|
589
|
+
* @returns The config factory function
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```typescript
|
|
593
|
+
* export const createConfig = pikkuConfig(async () => {
|
|
594
|
+
* return {
|
|
595
|
+
* apiUrl: process.env.API_URL || 'http://localhost:3000',
|
|
596
|
+
* dbUrl: process.env.DATABASE_URL
|
|
597
|
+
* }
|
|
598
|
+
* })
|
|
599
|
+
* ```
|
|
600
|
+
*/
|
|
601
|
+
export const pikkuConfig = (
|
|
602
|
+
func: (variables?: any, ...args: any[]) => Promise<Config>
|
|
603
|
+
) => func
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Creates a Pikku singleton services factory.
|
|
608
|
+
* Use this to define services that are created once and shared across all requests.
|
|
609
|
+
*
|
|
610
|
+
* @param func - Singleton services factory function
|
|
611
|
+
* @returns The singleton services factory function
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* export const createSingletonServices = pikkuServices(async (config, existingServices) => {
|
|
616
|
+
* return {
|
|
617
|
+
* config,
|
|
618
|
+
* logger: new CustomLogger(),
|
|
619
|
+
* db: await createDatabaseConnection(config.dbUrl)
|
|
620
|
+
* }
|
|
621
|
+
* })
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
export const pikkuServices = (
|
|
625
|
+
func: (config: Config, existingServices: Partial<SingletonServices>) => Promise<Partial<Omit<RequiredSingletonServices, 'auth'>>>
|
|
626
|
+
) => {
|
|
627
|
+
return async (config: Config, existingServices: Partial<SingletonServices> = {}) => {
|
|
628
|
+
const createdServices = await func(config, existingServices)
|
|
629
|
+
const services = { ...existingServices, ...createdServices }
|
|
630
|
+
const authFactory = __pikkuState(null, 'package', 'authFactory')
|
|
631
|
+
if (authFactory) {
|
|
632
|
+
let authInstance: Promise<unknown> | undefined
|
|
633
|
+
;(services as any).auth = () => {
|
|
634
|
+
authInstance ??= Promise.resolve()
|
|
635
|
+
.then(() => authFactory(services as any))
|
|
636
|
+
.catch((error) => {
|
|
637
|
+
authInstance = undefined
|
|
638
|
+
throw error
|
|
639
|
+
})
|
|
640
|
+
return authInstance
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const resolved = services as RequiredSingletonServices
|
|
644
|
+
__pikkuState(null, 'package', 'singletonServices', resolved as any)
|
|
645
|
+
return resolved
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Creates a Pikku wire services factory.
|
|
651
|
+
* Use this to define services that are created per-request/session.
|
|
652
|
+
*
|
|
653
|
+
* @param func - Wire services factory function
|
|
654
|
+
* @returns The wire services factory function
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* export const createWireServices = pikkuWireServices(async (services, wire) => {
|
|
659
|
+
* const session = await wire.session?.get()
|
|
660
|
+
* return {
|
|
661
|
+
* userCache: new UserCache(session?.userId)
|
|
662
|
+
* }
|
|
663
|
+
* })
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
export const pikkuWireServices = (
|
|
667
|
+
func: (
|
|
668
|
+
services: SingletonServices,
|
|
669
|
+
wire: any
|
|
670
|
+
) => Promise<RequiredWireServices>
|
|
671
|
+
): CreateWireServices => {
|
|
672
|
+
const factories = __pikkuState(null, 'package', 'factories')
|
|
673
|
+
__pikkuState(null, 'package', 'factories', { ...factories, createWireServices: func as any })
|
|
674
|
+
return func as unknown as CreateWireServices
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Tag-scoped middleware. Applies to any wiring that carries the matching tag.
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* addTagMiddleware('admin', [adminMiddleware])
|
|
682
|
+
*/
|
|
683
|
+
export const addTagMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
|
|
684
|
+
addTagMiddlewareCore(tag, middleware as any, '@pikku/addon-aws-sqs')
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Wire-agnostic global middleware. Runs at the top of every wiring's
|
|
689
|
+
* middleware chain — before wire-, tag-, and function-level entries.
|
|
690
|
+
*
|
|
691
|
+
* Resolution order: global -> wire -> tag -> function.
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* addGlobalMiddleware([telemetryMiddleware])
|
|
695
|
+
*/
|
|
696
|
+
export const addGlobalMiddleware = (middleware: PikkuMiddleware[]) => {
|
|
697
|
+
addGlobalMiddlewareCore(middleware as any, '@pikku/addon-aws-sqs')
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Tag-scoped permissions. Applies to any wiring that carries the matching tag.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* addTagPermission('admin', [adminPermission])
|
|
705
|
+
*/
|
|
706
|
+
export const addTagPermission = <In = unknown>(tag: string, permissions: CorePermissionGroup<PikkuPermission<In>> | PikkuPermission<In>[]) => {
|
|
707
|
+
addTagPermissionCore(tag, permissions as any, '@pikku/addon-aws-sqs')
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Wire-agnostic global permissions. Runs at the top of every wiring's
|
|
712
|
+
* permission resolution — before wire-, tag-, and function-level entries.
|
|
713
|
+
*
|
|
714
|
+
* Resolution order: global -> wire -> tag -> function.
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* addGlobalPermission([signedInUser])
|
|
718
|
+
*/
|
|
719
|
+
export const addGlobalPermission = <In = unknown>(permissions: CorePermissionGroup<PikkuPermission<In>> | PikkuPermission<In>[]) => {
|
|
720
|
+
addGlobalPermissionCore(permissions as any, '@pikku/addon-aws-sqs')
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
export { wireAddon } from '@pikku/core/rpc'
|
|
724
|
+
export type { WireAddonConfig } from '@pikku/core/rpc'
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Addon contract references. Generated from each wired addon's published
|
|
729
|
+
* contract metadata — no addon source is imported. Functions are proxied via
|
|
730
|
+
* ref() (RPC) exactly like ref('namespace:fn').
|
|
731
|
+
*/
|
|
732
|
+
const __addonHttp = {} as const
|
|
733
|
+
const __addonChannel = {} as const
|
|
734
|
+
const __addonCli = {} as const
|
|
735
|
+
|
|
736
|
+
export const refHTTP = <Name extends keyof typeof __addonHttp>(
|
|
737
|
+
name: Name,
|
|
738
|
+
options?: { basePath?: string }
|
|
739
|
+
): (typeof __addonHttp)[Name] => {
|
|
740
|
+
const contract = __addonHttp[name] as any
|
|
741
|
+
return (
|
|
742
|
+
options?.basePath !== undefined
|
|
743
|
+
? { ...contract, basePath: options.basePath }
|
|
744
|
+
: contract
|
|
745
|
+
) as (typeof __addonHttp)[Name]
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
export const refChannel = <Name extends keyof typeof __addonChannel>(
|
|
749
|
+
name: Name
|
|
750
|
+
): (typeof __addonChannel)[Name] => __addonChannel[name]
|
|
751
|
+
|
|
752
|
+
export const refCLI = <Name extends keyof typeof __addonCli>(
|
|
753
|
+
name: Name
|
|
754
|
+
): (typeof __addonCli)[Name] => __addonCli[name]
|