@pikku/core 0.7.6 → 0.7.8
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 +14 -0
- package/dist/channel/channel-runner.js +4 -4
- package/dist/channel/channel.types.d.ts +2 -6
- package/dist/channel/local/local-channel-runner.js +4 -4
- package/dist/channel/serverless/serverless-channel-runner.js +4 -4
- package/dist/http/http-runner.d.ts +1 -1
- package/dist/http/http-runner.js +22 -11
- package/dist/http/http.types.d.ts +1 -0
- package/dist/middleware-runner.js +2 -2
- package/dist/types/core.types.d.ts +6 -0
- package/dist/types/core.types.js +7 -1
- package/lcov.info +433 -417
- package/package.json +1 -1
- package/src/channel/channel-runner.ts +4 -4
- package/src/channel/channel.types.ts +2 -6
- package/src/channel/local/local-channel-runner.ts +4 -4
- package/src/channel/serverless/serverless-channel-runner.ts +4 -4
- package/src/http/http-runner.ts +30 -11
- package/src/http/http.types.ts +1 -0
- package/src/middleware-runner.ts +2 -2
- package/src/types/core.types.ts +7 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
## 0.7.0
|
|
2
2
|
|
|
3
|
+
## 0.7.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8b4f52e: fix: nextjs compatability with 0.7
|
|
8
|
+
- 8b4f52e: refactor: moving schemas in channels to functions
|
|
9
|
+
- 1d70184: feat: adding multiple bootstrap files for different transports
|
|
10
|
+
|
|
11
|
+
## 0.7.7
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 6af8a19: fix: always write functions meta data
|
|
16
|
+
|
|
3
17
|
## 0.7.6
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -16,14 +16,14 @@ export const addChannel = (channel) => {
|
|
|
16
16
|
}
|
|
17
17
|
pikkuState('channel', 'channels').set(channel.name, channel);
|
|
18
18
|
// Register onConnect function if provided
|
|
19
|
-
if (channel.onConnect && channelMeta.
|
|
20
|
-
addFunction(channelMeta.
|
|
19
|
+
if (channel.onConnect && channelMeta.connect) {
|
|
20
|
+
addFunction(channelMeta.connect.pikkuFuncName, {
|
|
21
21
|
func: channel.onConnect,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
// Register onDisconnect function if provided
|
|
25
|
-
if (channel.onDisconnect && channelMeta.
|
|
26
|
-
addFunction(channelMeta.
|
|
25
|
+
if (channel.onDisconnect && channelMeta.disconnect) {
|
|
26
|
+
addFunction(channelMeta.disconnect.pikkuFuncName, {
|
|
27
27
|
func: channel.onDisconnect,
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -18,8 +18,6 @@ export type RunChannelParams<ChannelData> = {
|
|
|
18
18
|
};
|
|
19
19
|
export interface ChannelMessageMeta {
|
|
20
20
|
pikkuFuncName: string;
|
|
21
|
-
inputs: string[] | null;
|
|
22
|
-
outputs: string[] | null;
|
|
23
21
|
docs?: APIDocs;
|
|
24
22
|
}
|
|
25
23
|
export interface ChannelMeta {
|
|
@@ -29,10 +27,8 @@ export interface ChannelMeta {
|
|
|
29
27
|
query?: string[];
|
|
30
28
|
input: string | null;
|
|
31
29
|
inputTypes?: HTTPFunctionMetaInputTypes;
|
|
32
|
-
connect:
|
|
33
|
-
|
|
34
|
-
disconnect: boolean;
|
|
35
|
-
disconnectPikkuFuncName: string | null;
|
|
30
|
+
connect: ChannelMessageMeta | null;
|
|
31
|
+
disconnect: ChannelMessageMeta | null;
|
|
36
32
|
message: ChannelMessageMeta | null;
|
|
37
33
|
messageRoutes: Record<string, Record<string, ChannelMessageMeta>>;
|
|
38
34
|
docs?: APIDocs;
|
|
@@ -43,13 +43,13 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
|
|
|
43
43
|
userSession: userSession,
|
|
44
44
|
});
|
|
45
45
|
channelHandler.registerOnOpen(() => {
|
|
46
|
-
if (channelConfig.onConnect && meta.
|
|
47
|
-
runPikkuFuncDirectly(meta.
|
|
46
|
+
if (channelConfig.onConnect && meta.connect) {
|
|
47
|
+
runPikkuFuncDirectly(meta.connect.pikkuFuncName, { ...allServices, channel }, openingData);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
channelHandler.registerOnClose(async () => {
|
|
51
|
-
if (channelConfig.onDisconnect && meta.
|
|
52
|
-
runPikkuFuncDirectly(meta.
|
|
51
|
+
if (channelConfig.onDisconnect && meta.disconnect) {
|
|
52
|
+
runPikkuFuncDirectly(meta.disconnect.pikkuFuncName, { ...allServices, channel }, openingData);
|
|
53
53
|
}
|
|
54
54
|
if (sessionServices) {
|
|
55
55
|
await closeSessionServices(singletonServices.logger, sessionServices);
|
|
@@ -59,8 +59,8 @@ export const runChannelConnect = async ({ singletonServices, channelId, channelO
|
|
|
59
59
|
if (createSessionServices) {
|
|
60
60
|
sessionServices = await createSessionServices(singletonServices, { http }, await userSession.get());
|
|
61
61
|
}
|
|
62
|
-
if (channelConfig.onConnect && meta.
|
|
63
|
-
await runPikkuFuncDirectly(meta.
|
|
62
|
+
if (channelConfig.onConnect && meta.connect) {
|
|
63
|
+
await runPikkuFuncDirectly(meta.connect.pikkuFuncName, { ...singletonServices, ...sessionServices, channel }, openingData);
|
|
64
64
|
}
|
|
65
65
|
http?.response?.status(101);
|
|
66
66
|
}
|
|
@@ -89,8 +89,8 @@ export const runChannelDisconnect = async ({ singletonServices, ...params }) =>
|
|
|
89
89
|
if (!sessionServices && params.createSessionServices) {
|
|
90
90
|
sessionServices = await params.createSessionServices(singletonServices, {}, session);
|
|
91
91
|
}
|
|
92
|
-
if (channelConfig.onDisconnect && meta.
|
|
93
|
-
await runPikkuFuncDirectly(meta.
|
|
92
|
+
if (channelConfig.onDisconnect && meta.disconnect) {
|
|
93
|
+
await runPikkuFuncDirectly(meta.disconnect.pikkuFuncName, { ...singletonServices, ...sessionServices, channel }, undefined);
|
|
94
94
|
}
|
|
95
95
|
await params.channelStore.removeChannels([channel.channelId]);
|
|
96
96
|
if (sessionServices) {
|
|
@@ -87,4 +87,4 @@ export declare const pikkuFetch: <In, Out>(request: Request | PikkuHTTPRequest,
|
|
|
87
87
|
* @param {RunRouteOptions & RunRouteParams} options - Options such as singleton services, session handling, and error configuration.
|
|
88
88
|
* @returns {Promise<Out | void>} The output from the route handler or void if an error occurred.
|
|
89
89
|
*/
|
|
90
|
-
export declare const fetchData: <In, Out>(request: Request | PikkuHTTPRequest, response: PikkuHTTPResponse, { singletonServices, createSessionServices, skipUserSession, respondWith404, logWarningsForStatusCodes, coerceDataFromSchema, bubbleErrors, generateRequestId, }: RunRouteOptions & RunRouteParams) => Promise<Out | void>;
|
|
90
|
+
export declare const fetchData: <In, Out>(request: Request | PikkuHTTPRequest, response: PikkuHTTPResponse, { singletonServices, createSessionServices, skipUserSession, respondWith404, logWarningsForStatusCodes, coerceDataFromSchema, bubbleErrors, generateRequestId, ignoreMiddleware, }: RunRouteOptions & RunRouteParams) => Promise<Out | void>;
|
package/dist/http/http-runner.js
CHANGED
|
@@ -21,14 +21,23 @@ import { rpcService } from '../rpc/rpc-runner.js';
|
|
|
21
21
|
* @param {APIMiddleware[]} [middleware] - The middleware array to apply when a route pattern is specified.
|
|
22
22
|
*/
|
|
23
23
|
export const addMiddleware = (routeOrMiddleware, middleware) => {
|
|
24
|
+
const middlewareStore = pikkuState('http', 'middleware');
|
|
24
25
|
if (typeof routeOrMiddleware === 'string' && middleware) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const route = routeOrMiddleware;
|
|
27
|
+
// Remove existing entry for this route if it exists
|
|
28
|
+
const existingIndex = middlewareStore.findIndex((item) => item.route === route);
|
|
29
|
+
if (existingIndex !== -1) {
|
|
30
|
+
middlewareStore.splice(existingIndex, 1);
|
|
31
|
+
}
|
|
32
|
+
middlewareStore.push({ route, middleware });
|
|
29
33
|
}
|
|
30
34
|
else {
|
|
31
|
-
|
|
35
|
+
// Handle global middleware
|
|
36
|
+
const existingIndex = middlewareStore.findIndex((item) => item.route === '*');
|
|
37
|
+
if (existingIndex !== -1) {
|
|
38
|
+
middlewareStore.splice(existingIndex, 1);
|
|
39
|
+
}
|
|
40
|
+
middlewareStore.push({
|
|
32
41
|
route: '*',
|
|
33
42
|
middleware: routeOrMiddleware,
|
|
34
43
|
});
|
|
@@ -57,8 +66,6 @@ export const addHTTPRoute = (httpRoute) => {
|
|
|
57
66
|
}
|
|
58
67
|
addFunction(routeMeta.pikkuFuncName, {
|
|
59
68
|
func: httpRoute.func,
|
|
60
|
-
auth: httpRoute.auth,
|
|
61
|
-
permissions: httpRoute.permissions,
|
|
62
69
|
});
|
|
63
70
|
const routes = pikkuState('http', 'routes');
|
|
64
71
|
if (!routes.has(httpRoute.method)) {
|
|
@@ -217,7 +224,7 @@ const executeRouteWithMiddleware = async (services, matchedRoute, http, options)
|
|
|
217
224
|
channel,
|
|
218
225
|
});
|
|
219
226
|
};
|
|
220
|
-
|
|
227
|
+
result = await runPikkuFunc(meta.pikkuFuncName, {
|
|
221
228
|
getAllServices,
|
|
222
229
|
session,
|
|
223
230
|
data,
|
|
@@ -234,7 +241,6 @@ const executeRouteWithMiddleware = async (services, matchedRoute, http, options)
|
|
|
234
241
|
http?.response?.status(200);
|
|
235
242
|
// TODO: Evaluate if the response stream should be explicitly ended.
|
|
236
243
|
// http?.response?.end()
|
|
237
|
-
return result;
|
|
238
244
|
};
|
|
239
245
|
// Execute middleware, then run the main logic
|
|
240
246
|
await runMiddleware({ ...singletonServices, userSession }, { http }, middleware, runMain);
|
|
@@ -295,7 +301,7 @@ export const pikkuFetch = async (request, params) => {
|
|
|
295
301
|
* @param {RunRouteOptions & RunRouteParams} options - Options such as singleton services, session handling, and error configuration.
|
|
296
302
|
* @returns {Promise<Out | void>} The output from the route handler or void if an error occurred.
|
|
297
303
|
*/
|
|
298
|
-
export const fetchData = async (request, response, { singletonServices, createSessionServices, skipUserSession = false, respondWith404 = true, logWarningsForStatusCodes = [], coerceDataFromSchema = true, bubbleErrors = false, generateRequestId, }) => {
|
|
304
|
+
export const fetchData = async (request, response, { singletonServices, createSessionServices, skipUserSession = false, respondWith404 = true, logWarningsForStatusCodes = [], coerceDataFromSchema = true, bubbleErrors = false, generateRequestId, ignoreMiddleware = false, }) => {
|
|
299
305
|
const requestId = request.getHeader?.('x-request-id') ||
|
|
300
306
|
generateRequestId?.() ||
|
|
301
307
|
createWeakUID();
|
|
@@ -326,7 +332,12 @@ export const fetchData = async (request, response, { singletonServices, createSe
|
|
|
326
332
|
createSessionServices,
|
|
327
333
|
skipUserSession,
|
|
328
334
|
requestId,
|
|
329
|
-
},
|
|
335
|
+
}, ignoreMiddleware
|
|
336
|
+
? {
|
|
337
|
+
...matchedRoute,
|
|
338
|
+
middleware: [],
|
|
339
|
+
}
|
|
340
|
+
: matchedRoute, http, { coerceDataFromSchema }));
|
|
330
341
|
return result;
|
|
331
342
|
}
|
|
332
343
|
catch (e) {
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
export const runMiddleware = async (services, interaction, middlewares, main) => {
|
|
19
19
|
const dispatch = async (index) => {
|
|
20
20
|
if (middlewares && index < middlewares.length) {
|
|
21
|
-
await middlewares[index](services, interaction, () => dispatch(index + 1));
|
|
21
|
+
return await middlewares[index](services, interaction, () => dispatch(index + 1));
|
|
22
22
|
}
|
|
23
23
|
else if (main) {
|
|
24
|
-
|
|
24
|
+
await main();
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
await dispatch(0);
|
|
@@ -8,6 +8,12 @@ import { JWTService } from '../services/jwt-service.js';
|
|
|
8
8
|
import { SecretService } from '../services/secret-service.js';
|
|
9
9
|
import { PikkuChannel } from '../channel/channel.types.js';
|
|
10
10
|
import { PikkuRPC } from '../rpc/rpc-types.js';
|
|
11
|
+
export declare enum PikkuEventTypes {
|
|
12
|
+
http = "http",
|
|
13
|
+
scheduled = "scheduled",
|
|
14
|
+
channel = "channel",
|
|
15
|
+
rpc = "rpc"
|
|
16
|
+
}
|
|
11
17
|
export interface FunctionServicesMeta {
|
|
12
18
|
optimized: boolean;
|
|
13
19
|
services: string[];
|
package/dist/types/core.types.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var PikkuEventTypes;
|
|
2
|
+
(function (PikkuEventTypes) {
|
|
3
|
+
PikkuEventTypes["http"] = "http";
|
|
4
|
+
PikkuEventTypes["scheduled"] = "scheduled";
|
|
5
|
+
PikkuEventTypes["channel"] = "channel";
|
|
6
|
+
PikkuEventTypes["rpc"] = "rpc";
|
|
7
|
+
})(PikkuEventTypes || (PikkuEventTypes = {}));
|