@pikku/core 0.6.26 → 0.7.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 (130) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/channel/channel-handler.js +16 -38
  3. package/dist/channel/channel-runner.d.ts +7 -8
  4. package/dist/channel/channel-runner.js +58 -7
  5. package/dist/channel/channel.types.d.ts +14 -27
  6. package/dist/channel/local/local-channel-runner.js +9 -4
  7. package/dist/channel/log-channels.js +4 -4
  8. package/dist/channel/serverless/serverless-channel-runner.js +17 -6
  9. package/dist/function/function-runner.d.ts +12 -0
  10. package/dist/function/function-runner.js +38 -0
  11. package/dist/function/functions.types.d.ts +37 -0
  12. package/dist/function/functions.types.js +1 -0
  13. package/dist/function/index.d.ts +2 -0
  14. package/dist/function/index.js +2 -0
  15. package/dist/handle-error.d.ts +1 -1
  16. package/dist/http/http-route-runner.d.ts +3 -3
  17. package/dist/http/http-route-runner.js +60 -35
  18. package/dist/http/http-routes.types.d.ts +38 -7
  19. package/dist/http/http-runner.d.ts +90 -0
  20. package/dist/http/http-runner.js +336 -0
  21. package/dist/http/http.types.d.ts +177 -0
  22. package/dist/http/http.types.js +1 -0
  23. package/dist/http/index.d.ts +2 -2
  24. package/dist/http/index.js +1 -1
  25. package/dist/http/log-http-routes.js +7 -5
  26. package/dist/http/pikku-fetch-http-request.d.ts +1 -1
  27. package/dist/http/pikku-fetch-http-response.d.ts +4 -2
  28. package/dist/http/pikku-fetch-http-response.js +64 -12
  29. package/dist/http/pikku-http-request.d.ts +56 -0
  30. package/dist/http/pikku-http-request.js +95 -0
  31. package/dist/http/pikku-http-response.d.ts +13 -0
  32. package/dist/http/pikku-http-response.js +60 -0
  33. package/dist/index.d.ts +3 -2
  34. package/dist/index.js +3 -2
  35. package/dist/middleware/auth-apikey.js +5 -4
  36. package/dist/middleware/auth-bearer.js +5 -4
  37. package/dist/middleware/auth-cookie.js +10 -9
  38. package/dist/parse-relative-time-offset.d.ts +12 -0
  39. package/dist/parse-relative-time-offset.js +20 -0
  40. package/dist/permissions.d.ts +2 -2
  41. package/dist/pikku-func.d.ts +12 -0
  42. package/dist/pikku-func.js +39 -0
  43. package/dist/pikku-function.d.ts +1 -0
  44. package/dist/pikku-function.js +1 -0
  45. package/dist/pikku-state.d.ts +10 -5
  46. package/dist/pikku-state.js +7 -3
  47. package/dist/scheduler/scheduler-runner.d.ts +1 -1
  48. package/dist/scheduler/scheduler-runner.js +24 -6
  49. package/dist/scheduler/scheduler.types.d.ts +3 -2
  50. package/dist/services/content-service.d.ts +34 -36
  51. package/dist/services/index.d.ts +1 -0
  52. package/dist/services/index.js +1 -0
  53. package/dist/services/local-content.d.ts +4 -2
  54. package/dist/services/local-content.js +19 -9
  55. package/dist/types/core.types.d.ts +15 -1
  56. package/dist/types/functions.types.d.ts +11 -6
  57. package/dist/utils.d.ts +2 -0
  58. package/dist/utils.js +15 -0
  59. package/package.json +2 -1
  60. package/lcov.info +0 -4310
  61. package/src/channel/channel-handler.ts +0 -227
  62. package/src/channel/channel-runner.ts +0 -98
  63. package/src/channel/channel-store.ts +0 -29
  64. package/src/channel/channel.types.ts +0 -171
  65. package/src/channel/eventhub-service.ts +0 -30
  66. package/src/channel/eventhub-store.ts +0 -8
  67. package/src/channel/index.ts +0 -8
  68. package/src/channel/local/index.ts +0 -3
  69. package/src/channel/local/local-channel-handler.ts +0 -50
  70. package/src/channel/local/local-channel-runner.test.ts +0 -158
  71. package/src/channel/local/local-channel-runner.ts +0 -126
  72. package/src/channel/local/local-eventhub-service.test.ts +0 -95
  73. package/src/channel/local/local-eventhub-service.ts +0 -95
  74. package/src/channel/log-channels.ts +0 -20
  75. package/src/channel/pikku-abstract-channel-handler.test.ts +0 -52
  76. package/src/channel/pikku-abstract-channel-handler.ts +0 -38
  77. package/src/channel/serverless/index.ts +0 -1
  78. package/src/channel/serverless/serverless-channel-runner.ts +0 -209
  79. package/src/errors/error-handler.ts +0 -61
  80. package/src/errors/error.test.ts +0 -54
  81. package/src/errors/errors.ts +0 -339
  82. package/src/errors/index.ts +0 -2
  83. package/src/handle-error.ts +0 -73
  84. package/src/http/http-route-runner.test.ts +0 -117
  85. package/src/http/http-route-runner.ts +0 -460
  86. package/src/http/http-routes.types.ts +0 -211
  87. package/src/http/incomingmessage-to-request-convertor.ts +0 -0
  88. package/src/http/index.ts +0 -8
  89. package/src/http/log-http-routes.ts +0 -20
  90. package/src/http/pikku-fetch-http-request.test.ts +0 -237
  91. package/src/http/pikku-fetch-http-request.ts +0 -167
  92. package/src/http/pikku-fetch-http-response.test.ts +0 -82
  93. package/src/http/pikku-fetch-http-response.ts +0 -84
  94. package/src/index.ts +0 -19
  95. package/src/middleware/auth-apikey.ts +0 -65
  96. package/src/middleware/auth-bearer.ts +0 -65
  97. package/src/middleware/auth-cookie.ts +0 -98
  98. package/src/middleware/index.ts +0 -3
  99. package/src/middleware/timeout.ts +0 -13
  100. package/src/middleware-runner.ts +0 -43
  101. package/src/permissions.test.ts +0 -58
  102. package/src/permissions.ts +0 -45
  103. package/src/pikku-request.ts +0 -23
  104. package/src/pikku-response.ts +0 -5
  105. package/src/pikku-state.ts +0 -71
  106. package/src/scheduler/index.ts +0 -5
  107. package/src/scheduler/log-schedulers.ts +0 -20
  108. package/src/scheduler/scheduler-runner.ts +0 -87
  109. package/src/scheduler/scheduler.types.ts +0 -29
  110. package/src/schema.test.ts +0 -57
  111. package/src/schema.ts +0 -99
  112. package/src/services/content-service.ts +0 -69
  113. package/src/services/index.ts +0 -17
  114. package/src/services/jwt-service.ts +0 -30
  115. package/src/services/local-content.ts +0 -91
  116. package/src/services/local-secrets.ts +0 -43
  117. package/src/services/local-variables.ts +0 -17
  118. package/src/services/logger-console.ts +0 -97
  119. package/src/services/logger.ts +0 -57
  120. package/src/services/schema-service.ts +0 -26
  121. package/src/services/secret-service.ts +0 -17
  122. package/src/services/user-session-service.ts +0 -53
  123. package/src/services/variables-service.ts +0 -6
  124. package/src/time-utils.test.ts +0 -56
  125. package/src/time-utils.ts +0 -32
  126. package/src/types/core.types.ts +0 -159
  127. package/src/types/functions.types.ts +0 -63
  128. package/src/utils.ts +0 -21
  129. package/tsconfig.json +0 -13
  130. package/tsconfig.tsbuildinfo +0 -1
@@ -1,7 +1,14 @@
1
1
  import { getErrorResponse } from '../errors/error-handler.js';
2
2
  import { closeSessionServices } from '../utils.js';
3
3
  import { pikkuState } from '../pikku-state.js';
4
+ import { addFunction, runPikkuFunc } from '../function/function-runner.js';
4
5
  export const addScheduledTask = (scheduledTask) => {
6
+ const meta = pikkuState('scheduler', 'meta');
7
+ const taskMeta = meta[scheduledTask.name];
8
+ if (!taskMeta) {
9
+ throw new Error('Task metadata not found');
10
+ }
11
+ addFunction(taskMeta.pikkuFuncName, scheduledTask.func);
5
12
  const tasks = pikkuState('scheduler', 'tasks');
6
13
  if (tasks.has(scheduledTask.name)) {
7
14
  throw new Error(`Scheduled task already exists: ${scheduledTask.name}`);
@@ -17,16 +24,27 @@ export async function runScheduledTask({ name, session, singletonServices, creat
17
24
  let sessionServices;
18
25
  try {
19
26
  const task = pikkuState('scheduler', 'tasks').get(name);
27
+ const meta = pikkuState('scheduler', 'meta')[name];
20
28
  if (!task) {
21
29
  throw new ScheduledTaskNotFoundError(`Scheduled task not found: ${name}`);
22
30
  }
23
- singletonServices.logger.info(`Running schedule task: ${name} | schedule: ${task.schedule}`);
24
- let allServices = singletonServices;
25
- if (createSessionServices) {
26
- const sessionServices = await createSessionServices(singletonServices, {}, session);
27
- allServices = { ...singletonServices, ...sessionServices };
31
+ if (!meta) {
32
+ throw new ScheduledTaskNotFoundError(`Scheduled task meta not found: ${name}`);
28
33
  }
29
- await task.func(allServices, undefined, session);
34
+ singletonServices.logger.info(`Running schedule task: ${name} | schedule: ${task.schedule}`);
35
+ const getAllServices = async () => {
36
+ if (createSessionServices) {
37
+ const sessionServices = await createSessionServices(singletonServices, {}, session);
38
+ return { ...singletonServices, ...sessionServices };
39
+ }
40
+ return singletonServices;
41
+ };
42
+ return await runPikkuFunc(meta.pikkuFuncName, {
43
+ singletonServices,
44
+ getAllServices,
45
+ session,
46
+ data: undefined,
47
+ });
30
48
  }
31
49
  catch (e) {
32
50
  const errorResponse = getErrorResponse(e);
@@ -1,9 +1,10 @@
1
1
  import { APIDocs, CoreUserSession } from '../types/core.types.js';
2
- import { CoreAPIFunctionSessionless } from '../types/functions.types.js';
2
+ import { CoreAPIFunctionSessionless } from '../function/functions.types.js';
3
3
  /**
4
4
  * Represents metadata for scheduled tasks, including title, schedule, and documentation.
5
5
  */
6
- export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> = Array<{
6
+ export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> = Record<string, {
7
+ pikkuFuncName: string;
7
8
  name: string;
8
9
  schedule: string;
9
10
  session?: UserSession;
@@ -1,55 +1,53 @@
1
- /**
2
- * Interface for handling content operations.
3
- */
1
+ import { ReadStream } from 'fs';
4
2
  export interface ContentService {
5
3
  /**
6
- * Signs a content key to provide secure access.
7
- * @param contentKey - The key of the content to sign.
8
- * @returns A promise that resolves to the signed content key URL.
4
+ * Signs a content key to generate a secure, time-limited access URL.
5
+ * @param contentKey - The key representing the content object.
6
+ * @param dateLessThan - The expiration time for the signed URL.
7
+ * @param dateGreaterThan - (Optional) Start time before which access is denied.
9
8
  */
10
- signContentKey: (contentKey: string, dateLessThan: Date, dateGreaterThan?: Date) => Promise<string>;
9
+ signContentKey(contentKey: string, dateLessThan: Date, dateGreaterThan?: Date): Promise<string>;
11
10
  /**
12
- * Signs a URL to provide secure access.
13
- * @param url - The URL to sign.
14
- * @returns A promise that resolves to the signed URL.
11
+ * Signs an arbitrary URL to generate a secure, time-limited access URL.
12
+ * @param url - The full URL that needs signing.
13
+ * @param dateLessThan - The expiration time for the signed URL.
14
+ * @param dateGreaterThan - (Optional) Start time before which access is denied.
15
15
  */
16
- signURL: (url: string, dateLessThan: Date, dateGreaterThan?: Date) => Promise<string>;
16
+ signURL(url: string, dateLessThan: Date, dateGreaterThan?: Date): Promise<string>;
17
17
  /**
18
- * Gets an upload URL for a file.
19
- * @param fileKey - The key of the file to upload.
20
- * @param contentType - The content type of the file.
21
- * @returns A promise that resolves to an object containing the upload URL and asset key.
22
- * This method generates an upload URL for the specified file key and content type, allowing the file to be uploaded.
18
+ * Generates a signed URL for uploading a file directly to storage.
19
+ * @param fileKey - The desired key/location of the uploaded file.
20
+ * @param contentType - The MIME type of the file.
21
+ * @returns A signed upload URL and the finalized asset key.
23
22
  */
24
- getUploadURL: (fileKey: string, contentType: string) => Promise<{
23
+ getUploadURL(fileKey: string, contentType: string): Promise<{
25
24
  uploadUrl: string;
26
25
  assetKey: string;
27
26
  }>;
28
27
  /**
29
- * Deletes a file.
30
- * @param fileName - The name of the file to delete.
31
- * @returns A promise that resolves to a boolean indicating success.
32
- * This method deletes the specified file and returns a boolean indicating whether the deletion was successful.
28
+ * Deletes a file from the storage backend.
29
+ * @param fileName - The name or key of the file to delete.
30
+ * @returns A boolean indicating success.
33
31
  */
34
- deleteFile?: (fileName: string) => Promise<boolean>;
32
+ deleteFile(fileName: string): Promise<boolean>;
35
33
  /**
36
- * Writes a file.
37
- * @param assetKey - The key of the asset to write.
38
- * @param buffer - The buffer containing the file data.
39
- * @returns A promise that resolves to a boolean indicating success.
34
+ * Uploads a file stream to storage under a specified asset key.
35
+ * @param assetKey - The key where the file will be saved.
36
+ * @param stream - A readable stream of the file contents.
37
+ * @returns A boolean indicating success.
40
38
  */
41
- writeFile?: (assetKey: string, buffer: Buffer) => Promise<boolean>;
39
+ writeFile(assetKey: string, stream: ReadStream): Promise<boolean>;
42
40
  /**
43
- * This method copies the file from the specified absolute path to the location identified by the asset key and returns a boolean indicating success.
44
- * @param assetKey - The key of the asset to copy.
45
- * @param fromAbsolutePath - The absolute path of the source file.
46
- * @returns A promise that resolves to a boolean indicating success.
41
+ * Copies a file from a local absolute path into storage under a new asset key.
42
+ * @param assetKey - The destination key.
43
+ * @param fromAbsolutePath - The local absolute file path.
44
+ * @returns A boolean indicating success.
47
45
  */
48
- copyFile?: (assetKey: string, fromAbsolutePath: string) => Promise<boolean>;
46
+ copyFile(assetKey: string, fromAbsolutePath: string): Promise<boolean>;
49
47
  /**
50
- * Reads a file.
51
- * @param assetKey - The key of the asset to read.
52
- * @returns A promise that resolves to a buffer containing the file data.
48
+ * Reads a file from storage as a readable stream.
49
+ * @param assetKey - The key of the file to read.
50
+ * @returns A readable file stream.
53
51
  */
54
- readFile?: (assetKey: string) => Promise<Buffer>;
52
+ readFile(assetKey: string): Promise<ReadStream>;
55
53
  }
@@ -9,5 +9,6 @@ export * from './secret-service.js';
9
9
  export * from './variables-service.js';
10
10
  export * from './schema-service.js';
11
11
  export * from './user-session-service.js';
12
+ export * from './local-content.js';
12
13
  export * from './local-secrets.js';
13
14
  export * from './local-variables.js';
@@ -10,6 +10,7 @@ export * from './secret-service.js';
10
10
  export * from './variables-service.js';
11
11
  export * from './schema-service.js';
12
12
  export * from './user-session-service.js';
13
+ export * from './local-content.js';
13
14
  // Local implementations
14
15
  export * from './local-secrets.js';
15
16
  export * from './local-variables.js';
@@ -1,4 +1,6 @@
1
+ import { ReadStream } from 'fs';
1
2
  import { ContentService, Logger } from '@pikku/core/services';
3
+ import { Readable } from 'stream';
2
4
  export interface LocalContentConfig {
3
5
  localFileUploadPath: string;
4
6
  uploadUrlPrefix: string;
@@ -16,9 +18,9 @@ export declare class LocalContent implements ContentService {
16
18
  uploadUrl: string;
17
19
  assetKey: string;
18
20
  }>;
19
- writeFile(assetKey: string, buffer: Buffer): Promise<boolean>;
21
+ writeFile(assetKey: string, stream: Readable): Promise<boolean>;
20
22
  copyFile(assetKey: string, fromAbsolutePath: string): Promise<boolean>;
21
- readFile(assetKey: string): Promise<Buffer>;
23
+ readFile(assetKey: string): Promise<ReadStream>;
22
24
  deleteFile(assetKey: string): Promise<boolean>;
23
25
  private createDirectoryForFile;
24
26
  }
@@ -1,5 +1,6 @@
1
- import { promises } from 'fs';
1
+ import { createReadStream, createWriteStream, promises } from 'fs';
2
2
  import { mkdir } from 'fs/promises';
3
+ import { pipeline } from 'stream/promises';
3
4
  export class LocalContent {
4
5
  config;
5
6
  logger;
@@ -21,18 +22,21 @@ export class LocalContent {
21
22
  assetKey,
22
23
  };
23
24
  }
24
- async writeFile(assetKey, buffer) {
25
+ async writeFile(assetKey, stream) {
25
26
  this.logger.debug(`Writing file: ${assetKey}`);
27
+ const path = `${this.config.localFileUploadPath}/${assetKey}`;
26
28
  try {
27
- const path = `${this.config.localFileUploadPath}/${assetKey}`;
28
29
  await this.createDirectoryForFile(path);
29
- await promises.writeFile(path, buffer);
30
+ const fileStream = createWriteStream(path);
31
+ // Use pipeline to properly manage stream piping and errors
32
+ await pipeline(stream, fileStream);
33
+ return true;
30
34
  }
31
35
  catch (e) {
32
36
  console.error(e);
33
- this.logger.error(`Error inserting content ${assetKey}`, e);
37
+ this.logger.error(`Error writing content ${assetKey}`, e);
38
+ return false;
34
39
  }
35
- return false;
36
40
  }
37
41
  async copyFile(assetKey, fromAbsolutePath) {
38
42
  this.logger.debug(`Writing file: ${assetKey}`);
@@ -48,12 +52,18 @@ export class LocalContent {
48
52
  return false;
49
53
  }
50
54
  async readFile(assetKey) {
51
- this.logger.debug(`getting key: ${assetKey}`);
55
+ this.logger.debug(`Getting key: ${assetKey}`);
56
+ const filePath = `${this.config.localFileUploadPath}/${assetKey}`;
52
57
  try {
53
- return await promises.readFile(`${this.config.localFileUploadPath}/${assetKey}`);
58
+ const stream = createReadStream(filePath);
59
+ // Handle early stream errors (like file not found, permission denied, etc.)
60
+ stream.on('error', (err) => {
61
+ this.logger.error(`Error getting content ${assetKey}`, err);
62
+ });
63
+ return stream;
54
64
  }
55
65
  catch (e) {
56
- this.logger.error(`Error get content ${assetKey}`);
66
+ this.logger.error(`Error setting up stream for ${assetKey}`, e);
57
67
  throw e;
58
68
  }
59
69
  }
@@ -2,10 +2,23 @@ import type { Logger, LogLevel } from '../services/logger.js';
2
2
  import { VariablesService } from '../services/variables-service.js';
3
3
  import { EventHubService } from '../channel/eventhub-service.js';
4
4
  import { SchemaService } from '../services/schema-service.js';
5
- import { PikkuHTTP } from '../http/http-routes.types.js';
5
+ import { PikkuHTTP } from '../http/http.types.js';
6
6
  import { UserSessionService } from '../services/user-session-service.js';
7
7
  import { JWTService } from '../services/jwt-service.js';
8
8
  import { SecretService } from '../services/secret-service.js';
9
+ import { PikkuChannel } from '../channel/channel.types.js';
10
+ export interface FunctionServicesMeta {
11
+ optimized: boolean;
12
+ services: string[];
13
+ }
14
+ export type FunctionsMeta = Record<string, {
15
+ pikkuFuncName: string;
16
+ name?: string;
17
+ services: FunctionServicesMeta;
18
+ schemaName: string | null;
19
+ inputs: string[] | null;
20
+ outputs: string[] | null;
21
+ }>;
9
22
  export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
10
23
  /**
11
24
  * Represents a JSON primitive type which can be a string, number, boolean, null, or undefined.
@@ -81,6 +94,7 @@ export type PikkuMiddleware<SingletonServices extends CoreSingletonServices = Co
81
94
  */
82
95
  export type CoreServices<SingletonServices = CoreSingletonServices, UserSession extends CoreUserSession = CoreUserSession, CoreServices extends Record<string, unknown> = {}> = SingletonServices & PikkuInteraction & {
83
96
  userSession?: UserSessionService<UserSession>;
97
+ channel?: PikkuChannel<unknown, unknown>;
84
98
  } & CoreServices;
85
99
  export type SessionServices<SingletonServices extends CoreSingletonServices = CoreSingletonServices, Services = CoreServices<SingletonServices>> = Omit<Services, keyof SingletonServices | keyof PikkuInteraction | 'session'>;
86
100
  /**
@@ -8,9 +8,11 @@ import type { CoreServices, CoreSingletonServices, CoreUserSession } from './cor
8
8
  * @template Services - The services type, defaults to `CoreServices`.
9
9
  * @template Session - The session type, defaults to `CoreUserSession`.
10
10
  */
11
- export type CoreAPIFunction<In, Out, Services extends CoreSingletonServices = CoreServices & {
12
- channel?: PikkuChannel<unknown, Out>;
13
- }, Session extends CoreUserSession = CoreUserSession, Channel extends boolean = false> = (services: Services, data: In, session: Session) => Channel extends true ? Promise<Out> | Promise<void> : Promise<Out>;
11
+ export type CoreAPIFunction<In, Out, Channel extends boolean = false, Services extends CoreSingletonServices = CoreServices & (Channel extends true ? {
12
+ channel: PikkuChannel<unknown, Out>;
13
+ } : {
14
+ channel?: PikkuChannel<unknown, Out> | undefined;
15
+ }), Session extends CoreUserSession = CoreUserSession> = (services: Services, data: In, session: Session) => Channel extends true ? Promise<Out> | Promise<void> : Promise<Out>;
14
16
  /**
15
17
  * Represents a core API function that can be used without a session.
16
18
  *
@@ -19,9 +21,11 @@ export type CoreAPIFunction<In, Out, Services extends CoreSingletonServices = Co
19
21
  * @template Services - The services type, defaults to `CoreServices`.
20
22
  * @template Session - The session type, defaults to `CoreUserSession`.
21
23
  */
22
- export type CoreAPIFunctionSessionless<In, Out, Services extends CoreSingletonServices = CoreServices & {
23
- channel?: PikkuChannel<unknown, Out>;
24
- }, Session extends CoreUserSession = CoreUserSession, Channel extends boolean = false> = (services: Services, data: In, session?: Session) => Channel extends true ? Promise<Out> | Promise<void> : Promise<Out>;
24
+ export type CoreAPIFunctionSessionless<In, Out, Channel extends boolean = false, Services extends CoreSingletonServices = CoreServices & (Channel extends true ? {
25
+ channel: PikkuChannel<unknown, Out>;
26
+ } : {
27
+ channel?: PikkuChannel<unknown, Out> | undefined;
28
+ }), Session extends CoreUserSession = CoreUserSession> = (services: Services, data: In, session?: Session) => Channel extends true ? Promise<Out> | Promise<void> : Promise<Out>;
25
29
  /**
26
30
  * Represents a function that checks permissions for a given API operation.
27
31
  *
@@ -30,3 +34,4 @@ export type CoreAPIFunctionSessionless<In, Out, Services extends CoreSingletonSe
30
34
  * @template Session - The session type, defaults to `CoreUserSession`.
31
35
  */
32
36
  export type CoreAPIPermission<In = any, Services extends CoreSingletonServices = CoreServices, Session extends CoreUserSession = CoreUserSession> = (services: Services, data: In, session?: Session) => Promise<boolean>;
37
+ export type CorePermissionGroup<APIPermission = CoreAPIPermission<any>> = Record<string, APIPermission | APIPermission[]> | undefined;
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  import { Logger } from './services/logger.js';
2
2
  export declare const closeSessionServices: (logger: Logger, sessionServices: Record<string, any>) => Promise<void>;
3
+ export declare const createWeakUID: () => string;
4
+ export declare const isSerializable: (data: any) => boolean;
package/dist/utils.js CHANGED
@@ -13,3 +13,18 @@ export const closeSessionServices = async (logger, sessionServices) => {
13
13
  }
14
14
  }));
15
15
  };
16
+ export const createWeakUID = () => {
17
+ return Date.now().toString(36) + Math.random().toString(36).substring(2, 10);
18
+ };
19
+ export const isSerializable = (data) => {
20
+ return !(typeof data === 'string' ||
21
+ data instanceof ArrayBuffer ||
22
+ data instanceof Uint8Array ||
23
+ data instanceof Int8Array ||
24
+ data instanceof Uint16Array ||
25
+ data instanceof Int16Array ||
26
+ data instanceof Uint32Array ||
27
+ data instanceof Int32Array ||
28
+ data instanceof Float32Array ||
29
+ data instanceof Float64Array);
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/core",
3
- "version": "0.6.26",
3
+ "version": "0.7.0",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -19,6 +19,7 @@
19
19
  "exports": {
20
20
  ".": "./dist/index.js",
21
21
  "./middleware": "./dist/middleware/index.js",
22
+ "./function": "./dist/function/index.js",
22
23
  "./channel": "./dist/channel/index.js",
23
24
  "./channel/local": "./dist/channel/local/index.js",
24
25
  "./channel/serverless": "./dist/channel/serverless/index.js",