@pikku/cli 0.8.3 → 0.9.1

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 (159) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/bin/pikku-all.ts +47 -33
  3. package/bin/pikku-fetch.ts +1 -1
  4. package/bin/pikku-openapi.ts +2 -2
  5. package/bin/pikku-queue-service.ts +2 -2
  6. package/bin/pikku-websocket.ts +1 -1
  7. package/cli.schema.json +30 -30
  8. package/dist/bin/pikku-all.js +38 -33
  9. package/dist/bin/pikku-fetch.js +1 -1
  10. package/dist/bin/pikku-openapi.js +2 -2
  11. package/dist/bin/pikku-queue-service.js +2 -2
  12. package/dist/bin/pikku-websocket.js +1 -1
  13. package/dist/src/inspector-glob.js +2 -2
  14. package/dist/src/pikku-cli-config.d.ts +17 -17
  15. package/dist/src/pikku-cli-config.js +31 -31
  16. package/dist/src/runtimes/nextjs/pikku-command-nextjs.js +3 -3
  17. package/dist/src/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +29 -29
  18. package/dist/src/runtimes/nextjs/serialize-nextjs-http-wrapper.js +28 -28
  19. package/dist/src/schema-generator.d.ts +2 -2
  20. package/dist/src/schema-generator.js +2 -2
  21. package/dist/src/serialize-pikku-types.js +67 -67
  22. package/dist/src/utils.d.ts +5 -1
  23. package/dist/src/utils.js +17 -6
  24. package/dist/src/wirings/channels/pikku-channels.js +9 -0
  25. package/dist/src/wirings/channels/pikku-command-channels.js +9 -0
  26. package/dist/src/{events → wirings}/channels/serialize-typed-channel-map.js +3 -3
  27. package/dist/src/{events → wirings}/channels/serialize-websocket-wrapper.js +19 -5
  28. package/dist/src/{events → wirings}/fetch/index.js +2 -2
  29. package/dist/src/{events → wirings}/http/openapi-spec-generator.d.ts +2 -2
  30. package/dist/src/wirings/http/pikku-command-http-map.js +8 -0
  31. package/dist/src/{events → wirings}/http/pikku-command-http-routes.js +3 -3
  32. package/dist/src/{events → wirings}/http/pikku-http-routes.js +3 -3
  33. package/dist/src/wirings/http/serialize-fetch-wrapper.js +67 -0
  34. package/dist/src/wirings/http/serialize-typed-http-map.d.ts +4 -0
  35. package/dist/src/{events → wirings}/http/serialize-typed-http-map.js +13 -13
  36. package/dist/src/{events → wirings}/mcp/pikku-command-mcp.js +3 -3
  37. package/dist/src/wirings/queue/pikku-command-queue-service.js +15 -0
  38. package/dist/src/{events → wirings}/queue/pikku-command-queue.js +3 -3
  39. package/dist/src/{events → wirings}/queue/pikku-queue.js +3 -3
  40. package/dist/src/wirings/rpc/pikku-command-rpc-client.js +15 -0
  41. package/dist/src/wirings/rpc/pikku-command-rpc.js +6 -0
  42. package/dist/src/wirings/rpc/pikku-rpc.js +6 -0
  43. package/dist/src/wirings/rpc/serialize-rpc-wrapper.js +68 -0
  44. package/dist/src/{events → wirings}/scheduler/pikku-command-scheduler.js +3 -3
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +3 -3
  47. package/src/inspector-glob.ts +2 -2
  48. package/src/pikku-cli-config.ts +67 -52
  49. package/src/runtimes/nextjs/pikku-command-nextjs.ts +3 -3
  50. package/src/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +29 -29
  51. package/src/runtimes/nextjs/serialize-nextjs-http-wrapper.ts +28 -28
  52. package/src/schema-generator.ts +3 -3
  53. package/src/serialize-pikku-types.ts +67 -67
  54. package/src/utils.ts +26 -6
  55. package/src/{events → wirings}/channels/pikku-channels.ts +5 -4
  56. package/src/{events → wirings}/channels/pikku-command-channels.ts +5 -4
  57. package/src/{events → wirings}/channels/serialize-typed-channel-map.ts +3 -3
  58. package/src/{events → wirings}/channels/serialize-websocket-wrapper.ts +19 -5
  59. package/src/{events → wirings}/fetch/index.ts +2 -2
  60. package/src/{events → wirings}/http/openapi-spec-generator.ts +3 -3
  61. package/src/{events → wirings}/http/pikku-command-http-map.ts +5 -5
  62. package/src/{events → wirings}/http/pikku-command-http-routes.ts +5 -5
  63. package/src/{events → wirings}/http/pikku-http-routes.ts +5 -5
  64. package/src/wirings/http/serialize-fetch-wrapper.ts +67 -0
  65. package/src/{events → wirings}/http/serialize-typed-http-map.ts +17 -17
  66. package/src/{events → wirings}/mcp/pikku-command-mcp.ts +5 -5
  67. package/src/{events → wirings}/queue/pikku-command-queue-service.ts +9 -6
  68. package/src/{events → wirings}/queue/pikku-command-queue.ts +8 -5
  69. package/src/{events → wirings}/queue/pikku-queue.ts +8 -5
  70. package/src/{events → wirings}/rpc/pikku-command-rpc-client.ts +9 -6
  71. package/src/{events → wirings}/rpc/pikku-command-rpc.ts +2 -2
  72. package/src/{events → wirings}/rpc/pikku-rpc.ts +2 -2
  73. package/src/wirings/rpc/serialize-rpc-wrapper.ts +68 -0
  74. package/src/{events → wirings}/scheduler/pikku-command-scheduler.ts +8 -4
  75. package/dist/src/events/channels/pikku-channels.js +0 -9
  76. package/dist/src/events/channels/pikku-command-channels.js +0 -9
  77. package/dist/src/events/http/pikku-command-http-map.js +0 -8
  78. package/dist/src/events/http/serialize-fetch-wrapper.js +0 -67
  79. package/dist/src/events/http/serialize-typed-http-map.d.ts +0 -4
  80. package/dist/src/events/queue/pikku-command-queue-service.js +0 -12
  81. package/dist/src/events/rpc/pikku-command-rpc-client.js +0 -12
  82. package/dist/src/events/rpc/pikku-command-rpc.js +0 -6
  83. package/dist/src/events/rpc/pikku-rpc.js +0 -6
  84. package/dist/src/events/rpc/serialize-rpc-wrapper.js +0 -29
  85. package/src/events/http/serialize-fetch-wrapper.ts +0 -67
  86. package/src/events/rpc/serialize-rpc-wrapper.ts +0 -29
  87. /package/dist/src/{events → wirings}/channels/pikku-channels.d.ts +0 -0
  88. /package/dist/src/{events → wirings}/channels/pikku-command-channels-map.d.ts +0 -0
  89. /package/dist/src/{events → wirings}/channels/pikku-command-channels-map.js +0 -0
  90. /package/dist/src/{events → wirings}/channels/pikku-command-channels.d.ts +0 -0
  91. /package/dist/src/{events → wirings}/channels/pikku-command-websocket-typed.d.ts +0 -0
  92. /package/dist/src/{events → wirings}/channels/pikku-command-websocket-typed.js +0 -0
  93. /package/dist/src/{events → wirings}/channels/serialize-typed-channel-map.d.ts +0 -0
  94. /package/dist/src/{events → wirings}/channels/serialize-websocket-wrapper.d.ts +0 -0
  95. /package/dist/src/{events → wirings}/fetch/index.d.ts +0 -0
  96. /package/dist/src/{events → wirings}/functions/pikku-command-function-types.d.ts +0 -0
  97. /package/dist/src/{events → wirings}/functions/pikku-command-function-types.js +0 -0
  98. /package/dist/src/{events → wirings}/functions/pikku-command-functions.d.ts +0 -0
  99. /package/dist/src/{events → wirings}/functions/pikku-command-functions.js +0 -0
  100. /package/dist/src/{events → wirings}/functions/pikku-command-services.d.ts +0 -0
  101. /package/dist/src/{events → wirings}/functions/pikku-command-services.js +0 -0
  102. /package/dist/src/{events → wirings}/functions/pikku-function-types.d.ts +0 -0
  103. /package/dist/src/{events → wirings}/functions/pikku-function-types.js +0 -0
  104. /package/dist/src/{events → wirings}/functions/pikku-functions.d.ts +0 -0
  105. /package/dist/src/{events → wirings}/functions/pikku-functions.js +0 -0
  106. /package/dist/src/{events → wirings}/http/openapi-spec-generator.js +0 -0
  107. /package/dist/src/{events → wirings}/http/pikku-command-http-map.d.ts +0 -0
  108. /package/dist/src/{events → wirings}/http/pikku-command-http-routes.d.ts +0 -0
  109. /package/dist/src/{events → wirings}/http/pikku-command-openapi.d.ts +0 -0
  110. /package/dist/src/{events → wirings}/http/pikku-command-openapi.js +0 -0
  111. /package/dist/src/{events → wirings}/http/pikku-http-routes.d.ts +0 -0
  112. /package/dist/src/{events → wirings}/http/serialize-fetch-wrapper.d.ts +0 -0
  113. /package/dist/src/{events → wirings}/mcp/pikku-command-mcp-json.d.ts +0 -0
  114. /package/dist/src/{events → wirings}/mcp/pikku-command-mcp-json.js +0 -0
  115. /package/dist/src/{events → wirings}/mcp/pikku-command-mcp.d.ts +0 -0
  116. /package/dist/src/{events → wirings}/mcp/serialize-mcp-json.d.ts +0 -0
  117. /package/dist/src/{events → wirings}/mcp/serialize-mcp-json.js +0 -0
  118. /package/dist/src/{events → wirings}/queue/pikku-command-queue-map.d.ts +0 -0
  119. /package/dist/src/{events → wirings}/queue/pikku-command-queue-map.js +0 -0
  120. /package/dist/src/{events → wirings}/queue/pikku-command-queue-service.d.ts +0 -0
  121. /package/dist/src/{events → wirings}/queue/pikku-command-queue.d.ts +0 -0
  122. /package/dist/src/{events → wirings}/queue/pikku-queue-map.d.ts +0 -0
  123. /package/dist/src/{events → wirings}/queue/pikku-queue-map.js +0 -0
  124. /package/dist/src/{events → wirings}/queue/pikku-queue.d.ts +0 -0
  125. /package/dist/src/{events → wirings}/queue/serialize-queue-map.d.ts +0 -0
  126. /package/dist/src/{events → wirings}/queue/serialize-queue-map.js +0 -0
  127. /package/dist/src/{events → wirings}/queue/serialize-queue-meta.d.ts +0 -0
  128. /package/dist/src/{events → wirings}/queue/serialize-queue-meta.js +0 -0
  129. /package/dist/src/{events → wirings}/queue/serialize-queue-wrapper.d.ts +0 -0
  130. /package/dist/src/{events → wirings}/queue/serialize-queue-wrapper.js +0 -0
  131. /package/dist/src/{events → wirings}/rpc/pikku-command-rpc-client.d.ts +0 -0
  132. /package/dist/src/{events → wirings}/rpc/pikku-command-rpc-map.d.ts +0 -0
  133. /package/dist/src/{events → wirings}/rpc/pikku-command-rpc-map.js +0 -0
  134. /package/dist/src/{events → wirings}/rpc/pikku-command-rpc.d.ts +0 -0
  135. /package/dist/src/{events → wirings}/rpc/pikku-rpc.d.ts +0 -0
  136. /package/dist/src/{events → wirings}/rpc/serialize-rpc-wrapper.d.ts +0 -0
  137. /package/dist/src/{events → wirings}/rpc/serialize-typed-rpc-map.d.ts +0 -0
  138. /package/dist/src/{events → wirings}/rpc/serialize-typed-rpc-map.js +0 -0
  139. /package/dist/src/{events → wirings}/scheduler/pikku-command-scheduler.d.ts +0 -0
  140. /package/dist/src/{events → wirings}/scheduler/serialize-scheduler-meta.d.ts +0 -0
  141. /package/dist/src/{events → wirings}/scheduler/serialize-scheduler-meta.js +0 -0
  142. /package/src/{events → wirings}/channels/pikku-command-channels-map.ts +0 -0
  143. /package/src/{events → wirings}/channels/pikku-command-websocket-typed.ts +0 -0
  144. /package/src/{events → wirings}/functions/pikku-command-function-types.ts +0 -0
  145. /package/src/{events → wirings}/functions/pikku-command-functions.ts +0 -0
  146. /package/src/{events → wirings}/functions/pikku-command-services.ts +0 -0
  147. /package/src/{events → wirings}/functions/pikku-function-types.ts +0 -0
  148. /package/src/{events → wirings}/functions/pikku-functions.ts +0 -0
  149. /package/src/{events → wirings}/http/pikku-command-openapi.ts +0 -0
  150. /package/src/{events → wirings}/mcp/pikku-command-mcp-json.ts +0 -0
  151. /package/src/{events → wirings}/mcp/serialize-mcp-json.ts +0 -0
  152. /package/src/{events → wirings}/queue/pikku-command-queue-map.ts +0 -0
  153. /package/src/{events → wirings}/queue/pikku-queue-map.ts +0 -0
  154. /package/src/{events → wirings}/queue/serialize-queue-map.ts +0 -0
  155. /package/src/{events → wirings}/queue/serialize-queue-meta.ts +0 -0
  156. /package/src/{events → wirings}/queue/serialize-queue-wrapper.ts +0 -0
  157. /package/src/{events → wirings}/rpc/pikku-command-rpc-map.ts +0 -0
  158. /package/src/{events → wirings}/rpc/serialize-typed-rpc-map.ts +0 -0
  159. /package/src/{events → wirings}/scheduler/serialize-scheduler-meta.ts +0 -0
@@ -3,7 +3,7 @@ import { PikkuCommand } from '../../types.js'
3
3
 
4
4
  export const pikkuRPC: PikkuCommand = async (
5
5
  logger,
6
- { rpcMetaFile },
6
+ { rpcWiringMetaFile },
7
7
  { rpc }
8
8
  ) => {
9
9
  return await logCommandInfoAndTime(
@@ -14,7 +14,7 @@ export const pikkuRPC: PikkuCommand = async (
14
14
  async () => {
15
15
  await writeFileInDir(
16
16
  logger,
17
- rpcMetaFile,
17
+ rpcWiringMetaFile,
18
18
  `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`
19
19
  )
20
20
  }
@@ -3,7 +3,7 @@ import { PikkuCommand } from '../../types.js'
3
3
 
4
4
  export const pikkuRPC: PikkuCommand = async (
5
5
  logger,
6
- { rpcMetaFile },
6
+ { rpcWiringMetaFile },
7
7
  { rpc }
8
8
  ) => {
9
9
  return await logCommandInfoAndTime(
@@ -14,7 +14,7 @@ export const pikkuRPC: PikkuCommand = async (
14
14
  async () => {
15
15
  await writeFileInDir(
16
16
  logger,
17
- rpcMetaFile,
17
+ rpcWiringMetaFile,
18
18
  `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`
19
19
  )
20
20
  }
@@ -0,0 +1,68 @@
1
+ export const serializeRPCWrapper = (rpcMapPath: string) => {
2
+ return `
3
+ import { PikkuFetch } from "./pikku-fetch.gen.js"
4
+ import type { RPCInvoke } from '${rpcMapPath}'
5
+
6
+ /**
7
+ * PikkuRPC provides a type-safe client for making Remote Procedure Calls (RPC)
8
+ * to your Pikku server. It wraps the underlying HTTP client and provides a
9
+ * simple interface for invoking server-side functions.
10
+ */
11
+ export class PikkuRPC {
12
+ /** The underlying HTTP client used for making RPC calls */
13
+ pikkuFetch = new PikkuFetch()
14
+
15
+ /**
16
+ * Sets a custom PikkuFetch instance to use for RPC calls.
17
+ * This allows you to configure custom settings or use a shared client instance.
18
+ *
19
+ * @param pikkuFetch - The PikkuFetch instance to use
20
+ */
21
+ setPikkuFetch(pikkuFetch: PikkuFetch): void {
22
+ this.pikkuFetch = pikkuFetch
23
+ }
24
+
25
+ /**
26
+ * Sets the base server URL for all RPC calls.
27
+ *
28
+ * @param serverUrl - The base URL of your Pikku server (e.g., 'https://api.example.com')
29
+ */
30
+ setServerUrl(serverUrl: string): void {
31
+ this.pikkuFetch.setServerUrl(serverUrl)
32
+ }
33
+
34
+ /**
35
+ * Sets the JWT token for authorization on all RPC calls.
36
+ *
37
+ * @param jwt - The JWT token to use for authorization, or null to remove authorization
38
+ */
39
+ setAuthorizationJWT(jwt: string | null): void {
40
+ this.pikkuFetch.setAuthorizationJWT(jwt)
41
+ }
42
+
43
+ /**
44
+ * Sets the API key for authorization on all RPC calls.
45
+ *
46
+ * @param apiKey - The API key to use for authorization, or null to remove the API key
47
+ */
48
+ setAPIKey(apiKey: string | null): void {
49
+ this.pikkuFetch.setAPIKey(apiKey)
50
+ }
51
+
52
+ /**
53
+ * Invokes a remote procedure call on the server.
54
+ * This is a generic method that routes to the appropriate server function
55
+ * based on the function name and passes the provided data.
56
+ *
57
+ * @param name - The name of the server function to invoke
58
+ * @param data - The data to pass to the server function
59
+ * @returns A promise that resolves with the function's return value
60
+ */
61
+ invoke: RPCInvoke = async (name, data) => {
62
+ return await this.pikkuFetch.post('/rpc', { name, data })
63
+ }
64
+ }
65
+
66
+ export const pikkuRPC = new PikkuRPC();
67
+ `
68
+ }
@@ -17,19 +17,23 @@ export const pikkuScheduler: PikkuCommand = async (
17
17
  'Found scheduled tasks',
18
18
  [visitState.scheduledTasks.files.size === 0],
19
19
  async () => {
20
- const { schedulersFile, schedulersMetaFile, packageMappings } = cliConfig
20
+ const {
21
+ schedulersWiringFile,
22
+ schedulersWiringMetaFile,
23
+ packageMappings,
24
+ } = cliConfig
21
25
  const { scheduledTasks } = visitState
22
26
  await writeFileInDir(
23
27
  logger,
24
- schedulersMetaFile,
28
+ schedulersWiringMetaFile,
25
29
  serializeSchedulerMeta(scheduledTasks.meta)
26
30
  )
27
31
  await writeFileInDir(
28
32
  logger,
29
- schedulersFile,
33
+ schedulersWiringFile,
30
34
  serializeFileImports(
31
35
  'addScheduledTasks',
32
- schedulersFile,
36
+ schedulersWiringFile,
33
37
  scheduledTasks.files,
34
38
  packageMappings
35
39
  )
@@ -1,9 +0,0 @@
1
- import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
2
- export const pikkuChannels = async (logger, cliConfig, visitState) => {
3
- return await logCommandInfoAndTime(logger, 'Finding Channels', 'Found channels', [visitState.channels.files.size === 0], async () => {
4
- const { channelsFile, channelsMetaFile, packageMappings } = cliConfig;
5
- const { channels } = visitState;
6
- await writeFileInDir(logger, channelsFile, serializeFileImports('addChannel', channelsFile, channels.files, packageMappings));
7
- await writeFileInDir(logger, channelsMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`);
8
- });
9
- };
@@ -1,9 +0,0 @@
1
- import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
2
- export const pikkuChannels = async (logger, cliConfig, visitState) => {
3
- return await logCommandInfoAndTime(logger, 'Finding Channels', 'Found channels', [visitState.channels.files.size === 0], async () => {
4
- const { channelsFile, channelsMetaFile, packageMappings } = cliConfig;
5
- const { channels } = visitState;
6
- await writeFileInDir(logger, channelsFile, serializeFileImports('addChannel', channelsFile, channels.files, packageMappings));
7
- await writeFileInDir(logger, channelsMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`);
8
- });
9
- };
@@ -1,8 +0,0 @@
1
- import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
- import { serializeTypedRoutesMap } from './serialize-typed-http-map.js';
3
- export const pikkuHTTPMap = async (logger, { httpRoutesMapDeclarationFile, packageMappings }, { http, functions }) => {
4
- return await logCommandInfoAndTime(logger, 'Creating HTTP map', 'Created HTTP map', [http.files.size === 0], async () => {
5
- const content = serializeTypedRoutesMap(httpRoutesMapDeclarationFile, packageMappings, functions.typesMap, functions.meta, http.meta, http.metaInputTypes);
6
- await writeFileInDir(logger, httpRoutesMapDeclarationFile, content);
7
- });
8
- };
@@ -1,67 +0,0 @@
1
- export const serializeFetchWrapper = (routesMapPath) => {
2
- return `
3
- import { CorePikkuFetch, HTTPMethod } from '@pikku/fetch'
4
- import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
5
-
6
- export class PikkuFetch extends CorePikkuFetch {
7
- public async post<Route extends RoutesWithMethod<'POST'>>(
8
- route: Route,
9
- ...args: null extends RouteHandlerOf<Route, 'POST'>['input']
10
- ? [data?: Exclude<RouteHandlerOf<Route, 'POST'>['input'], null>, options?: Omit<RequestInit, 'body'>]
11
- : [data: RouteHandlerOf<Route, 'POST'>['input'], options?: Omit<RequestInit, 'body'>]
12
- ): Promise<RouteHandlerOf<Route, 'POST'>['output']> {
13
- const [data, options] = args;
14
- return super.api(route, 'POST', data, options);
15
- }
16
-
17
- public async get<Route extends RoutesWithMethod<'GET'>>(
18
- route: Route,
19
- ...args: null extends RouteHandlerOf<Route, 'GET'>['input']
20
- ? [data?: Exclude<RouteHandlerOf<Route, 'GET'>['input'], null>, options?: Omit<RequestInit, 'body'>]
21
- : [data: RouteHandlerOf<Route, 'GET'>['input'], options?: Omit<RequestInit, 'body'>]
22
- ): Promise<RouteHandlerOf<Route, 'GET'>['output']> {
23
- const [data, options] = args;
24
- return super.api(route, 'GET', data, options);
25
- }
26
-
27
- public async patch<Route extends RoutesWithMethod<'PATCH'>>(
28
- route: Route,
29
- ...args: null extends RouteHandlerOf<Route, 'PATCH'>['input']
30
- ? [data?: Exclude<RouteHandlerOf<Route, 'PATCH'>['input'], null>, options?: Omit<RequestInit, 'body'>]
31
- : [data: RouteHandlerOf<Route, 'PATCH'>['input'], options?: Omit<RequestInit, 'body'>]
32
- ): Promise<RouteHandlerOf<Route, 'PATCH'>['output']> {
33
- const [data, options] = args;
34
- return super.api(route, 'PATCH', data, options);
35
- }
36
-
37
- public async head<Route extends RoutesWithMethod<'HEAD'>>(
38
- route: Route,
39
- ...args: null extends RouteHandlerOf<Route, 'HEAD'>['input']
40
- ? [data?: Exclude<RouteHandlerOf<Route, 'HEAD'>['input'], null>, options?: Omit<RequestInit, 'body'>]
41
- : [data: RouteHandlerOf<Route, 'HEAD'>['input'], options?: Omit<RequestInit, 'body'>]
42
- ): Promise<RouteHandlerOf<Route, 'HEAD'>['output']> {
43
- const [data, options] = args;
44
- return super.api(route, 'HEAD', data, options);
45
- }
46
-
47
- public async delete<Route extends RoutesWithMethod<'DELETE'>>(
48
- route: Route,
49
- ...args: null extends RouteHandlerOf<Route, 'DELETE'>['input']
50
- ? [data?: Exclude<RouteHandlerOf<Route, 'DELETE'>['input'], null>, options?: Omit<RequestInit, 'body'>]
51
- : [data: RouteHandlerOf<Route, 'DELETE'>['input'], options?: Omit<RequestInit, 'body'>]
52
- ): Promise<RouteHandlerOf<Route, 'DELETE'>['output']> {
53
- const [data, options] = args;
54
- return super.api(route, 'DELETE', data, options);
55
- }
56
-
57
- public async fetch<
58
- Route extends keyof RoutesMap,
59
- Method extends keyof RoutesMap[Route]
60
- >(route: Route, method: Method, data: RouteHandlerOf<Route, Method>['input'], options?: Omit<RequestInit, 'body'>): Promise<Response> {
61
- return await super.fetch(route, method as HTTPMethod, data, options);
62
- }
63
- }
64
-
65
- export const pikkuFetch = new PikkuFetch();
66
- `;
67
- };
@@ -1,4 +0,0 @@
1
- import { HTTPRoutesMeta } from '@pikku/core/http';
2
- import { MetaInputTypes, TypesMap } from '@pikku/inspector';
3
- import { FunctionsMeta } from '@pikku/core';
4
- export declare const serializeTypedRoutesMap: (relativeToPath: string, packageMappings: Record<string, string>, typesMap: TypesMap, functionsMeta: FunctionsMeta, routesMeta: HTTPRoutesMeta, metaTypes: MetaInputTypes) => string;
@@ -1,12 +0,0 @@
1
- import { serializeQueueWrapper } from './serialize-queue-wrapper.js';
2
- import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
3
- export const pikkuQueueService = async (logger, { queueFile, queueMapDeclarationFile, packageMappings }) => {
4
- return await logCommandInfoAndTime(logger, 'Generating queue service wrapper', 'Generated queue service wrapper', [queueFile === undefined, "queueFile isn't set in the pikku config"], async () => {
5
- if (!queueFile) {
6
- throw new Error("queueFile is isn't set in the pikku config");
7
- }
8
- const queueMapDeclarationPath = getFileImportRelativePath(queueFile, queueMapDeclarationFile, packageMappings);
9
- const content = [serializeQueueWrapper(queueMapDeclarationPath)];
10
- await writeFileInDir(logger, queueFile, content.join('\n'));
11
- });
12
- };
@@ -1,12 +0,0 @@
1
- import { serializeRPCWrapper } from './serialize-rpc-wrapper.js';
2
- import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
3
- export const pikkuRPCClient = async (logger, { rpcFile, rpcMapDeclarationFile, packageMappings }) => {
4
- return await logCommandInfoAndTime(logger, 'Generating RPC wrapper', 'Generated RPC wrapper', [rpcFile === undefined, "rpcFile isn't set in the pikku config"], async () => {
5
- if (!rpcFile) {
6
- throw new Error("rpcFile isn't set in the pikku config");
7
- }
8
- const rpcMapDeclarationPath = getFileImportRelativePath(rpcFile, rpcMapDeclarationFile, packageMappings);
9
- const content = [serializeRPCWrapper(rpcMapDeclarationPath)];
10
- await writeFileInDir(logger, rpcFile, content.join('\n'));
11
- });
12
- };
@@ -1,6 +0,0 @@
1
- import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
- export const pikkuRPC = async (logger, { rpcMetaFile }, { rpc }) => {
3
- return await logCommandInfoAndTime(logger, 'Finding RPCs tasks', 'Found RPCs', [false], async () => {
4
- await writeFileInDir(logger, rpcMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`);
5
- });
6
- };
@@ -1,6 +0,0 @@
1
- import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
- export const pikkuRPC = async (logger, { rpcMetaFile }, { rpc }) => {
3
- return await logCommandInfoAndTime(logger, 'Finding RPCs tasks', 'Found RPCs', [false], async () => {
4
- await writeFileInDir(logger, rpcMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`);
5
- });
6
- };
@@ -1,29 +0,0 @@
1
- export const serializeRPCWrapper = (rpcMapPath) => {
2
- return `
3
- import { PikkuFetch } from "./pikku-fetch.gen.js"
4
- import type { RPCInvoke } from '${rpcMapPath}'
5
-
6
- export class PikkuRPC {
7
- pikkuFetch = new PikkuFetch()
8
-
9
- setPikkuFetch(pikkuFetch: PikkuFetch): void {
10
- this.pikkuFetch = pikkuFetch
11
- }
12
-
13
- setServerUrl(serverUrl: string): void {
14
- this.pikkuFetch.setServerUrl(serverUrl)
15
- }
16
-
17
- setAuthorizationJWT(jwt: string | null): void {
18
- this.pikkuFetch.setAuthorizationJWT(jwt)
19
- }
20
-
21
- // Generic RPC invoke method
22
- invoke: RPCInvoke = async (name, data) => {
23
- return await this.pikkuFetch.post('/rpc', { name, data })
24
- }
25
- }
26
-
27
- export const pikkuRPC = new PikkuRPC();
28
- `;
29
- };
@@ -1,67 +0,0 @@
1
- export const serializeFetchWrapper = (routesMapPath: string) => {
2
- return `
3
- import { CorePikkuFetch, HTTPMethod } from '@pikku/fetch'
4
- import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
5
-
6
- export class PikkuFetch extends CorePikkuFetch {
7
- public async post<Route extends RoutesWithMethod<'POST'>>(
8
- route: Route,
9
- ...args: null extends RouteHandlerOf<Route, 'POST'>['input']
10
- ? [data?: Exclude<RouteHandlerOf<Route, 'POST'>['input'], null>, options?: Omit<RequestInit, 'body'>]
11
- : [data: RouteHandlerOf<Route, 'POST'>['input'], options?: Omit<RequestInit, 'body'>]
12
- ): Promise<RouteHandlerOf<Route, 'POST'>['output']> {
13
- const [data, options] = args;
14
- return super.api(route, 'POST', data, options);
15
- }
16
-
17
- public async get<Route extends RoutesWithMethod<'GET'>>(
18
- route: Route,
19
- ...args: null extends RouteHandlerOf<Route, 'GET'>['input']
20
- ? [data?: Exclude<RouteHandlerOf<Route, 'GET'>['input'], null>, options?: Omit<RequestInit, 'body'>]
21
- : [data: RouteHandlerOf<Route, 'GET'>['input'], options?: Omit<RequestInit, 'body'>]
22
- ): Promise<RouteHandlerOf<Route, 'GET'>['output']> {
23
- const [data, options] = args;
24
- return super.api(route, 'GET', data, options);
25
- }
26
-
27
- public async patch<Route extends RoutesWithMethod<'PATCH'>>(
28
- route: Route,
29
- ...args: null extends RouteHandlerOf<Route, 'PATCH'>['input']
30
- ? [data?: Exclude<RouteHandlerOf<Route, 'PATCH'>['input'], null>, options?: Omit<RequestInit, 'body'>]
31
- : [data: RouteHandlerOf<Route, 'PATCH'>['input'], options?: Omit<RequestInit, 'body'>]
32
- ): Promise<RouteHandlerOf<Route, 'PATCH'>['output']> {
33
- const [data, options] = args;
34
- return super.api(route, 'PATCH', data, options);
35
- }
36
-
37
- public async head<Route extends RoutesWithMethod<'HEAD'>>(
38
- route: Route,
39
- ...args: null extends RouteHandlerOf<Route, 'HEAD'>['input']
40
- ? [data?: Exclude<RouteHandlerOf<Route, 'HEAD'>['input'], null>, options?: Omit<RequestInit, 'body'>]
41
- : [data: RouteHandlerOf<Route, 'HEAD'>['input'], options?: Omit<RequestInit, 'body'>]
42
- ): Promise<RouteHandlerOf<Route, 'HEAD'>['output']> {
43
- const [data, options] = args;
44
- return super.api(route, 'HEAD', data, options);
45
- }
46
-
47
- public async delete<Route extends RoutesWithMethod<'DELETE'>>(
48
- route: Route,
49
- ...args: null extends RouteHandlerOf<Route, 'DELETE'>['input']
50
- ? [data?: Exclude<RouteHandlerOf<Route, 'DELETE'>['input'], null>, options?: Omit<RequestInit, 'body'>]
51
- : [data: RouteHandlerOf<Route, 'DELETE'>['input'], options?: Omit<RequestInit, 'body'>]
52
- ): Promise<RouteHandlerOf<Route, 'DELETE'>['output']> {
53
- const [data, options] = args;
54
- return super.api(route, 'DELETE', data, options);
55
- }
56
-
57
- public async fetch<
58
- Route extends keyof RoutesMap,
59
- Method extends keyof RoutesMap[Route]
60
- >(route: Route, method: Method, data: RouteHandlerOf<Route, Method>['input'], options?: Omit<RequestInit, 'body'>): Promise<Response> {
61
- return await super.fetch(route, method as HTTPMethod, data, options);
62
- }
63
- }
64
-
65
- export const pikkuFetch = new PikkuFetch();
66
- `
67
- }
@@ -1,29 +0,0 @@
1
- export const serializeRPCWrapper = (rpcMapPath: string) => {
2
- return `
3
- import { PikkuFetch } from "./pikku-fetch.gen.js"
4
- import type { RPCInvoke } from '${rpcMapPath}'
5
-
6
- export class PikkuRPC {
7
- pikkuFetch = new PikkuFetch()
8
-
9
- setPikkuFetch(pikkuFetch: PikkuFetch): void {
10
- this.pikkuFetch = pikkuFetch
11
- }
12
-
13
- setServerUrl(serverUrl: string): void {
14
- this.pikkuFetch.setServerUrl(serverUrl)
15
- }
16
-
17
- setAuthorizationJWT(jwt: string | null): void {
18
- this.pikkuFetch.setAuthorizationJWT(jwt)
19
- }
20
-
21
- // Generic RPC invoke method
22
- invoke: RPCInvoke = async (name, data) => {
23
- return await this.pikkuFetch.post('/rpc', { name, data })
24
- }
25
- }
26
-
27
- export const pikkuRPC = new PikkuRPC();
28
- `
29
- }
File without changes
File without changes