@pikku/core 0.6.9 → 0.6.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/core",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -10,7 +10,7 @@
10
10
  "tsc": "tsc",
11
11
  "build:esm": "tsc -b",
12
12
  "build": "yarn build:esm",
13
- "ncu": "ncu",
13
+ "ncu": "npx npm-check-updates",
14
14
  "release": "npm run build && npm test",
15
15
  "test": "bash run-tests.sh",
16
16
  "test:watch": "bash run-tests.sh --watch",
@@ -1,4 +1,4 @@
1
- import { EError } from '../errors/error-handler.js'
1
+ import { PikkuError } from '../errors/error-handler.js'
2
2
  import {
3
3
  HTTPFunctionMetaInputTypes,
4
4
  PikkuHTTP,
@@ -11,7 +11,6 @@ import {
11
11
  CoreSingletonServices,
12
12
  CoreUserSession,
13
13
  CreateSessionServices,
14
- MakeRequired,
15
14
  } from '../types/core.types.js'
16
15
  import { CoreAPIPermission } from '../types/functions.types.js'
17
16
  import { PikkuRequest } from '../pikku-request.js'
@@ -27,7 +26,7 @@ export type RunChannelOptions = Partial<{
27
26
 
28
27
  export type RunChannelParams<ChannelData> = {
29
28
  channelId: string
30
- singletonServices: MakeRequired<CoreSingletonServices, 'eventHub'>
29
+ singletonServices: CoreSingletonServices
31
30
  request?: PikkuRequest<ChannelData> | PikkuHTTPAbstractRequest<ChannelData>
32
31
  response?: PikkuResponse | PikkuHTTPAbstractResponse
33
32
  http?: PikkuHTTP
@@ -67,7 +66,7 @@ export type CoreChannelConnection<
67
66
  Services extends CoreServices = CoreServices,
68
67
  Session extends CoreUserSession = CoreUserSession,
69
68
  > = (
70
- services: MakeRequired<Services, 'eventHub'>,
69
+ services: Services,
71
70
  channel: PikkuChannel<Session, ChannelData, Out>
72
71
  ) => Promise<void>
73
72
 
@@ -76,7 +75,7 @@ export type CoreChannelDisconnection<
76
75
  Services extends CoreServices = CoreServices,
77
76
  Session extends CoreUserSession = CoreUserSession,
78
77
  > = (
79
- services: MakeRequired<Services, 'eventHub'>,
78
+ services: Services,
80
79
  channel: PikkuChannel<Session, ChannelData, never>
81
80
  ) => Promise<void>
82
81
 
@@ -94,7 +93,7 @@ export type CoreChannelMessage<
94
93
  Services extends CoreServices = CoreServices,
95
94
  Session extends CoreUserSession = CoreUserSession,
96
95
  > = (
97
- services: MakeRequired<Services, 'eventHub'>,
96
+ services: Services,
98
97
  channel: PikkuChannel<Session, ChannelData, Out>,
99
98
  data: In
100
99
  ) => Promise<void | Out>
@@ -110,7 +109,7 @@ export type CoreAPIChannel<
110
109
  ChannelData,
111
110
  Channel extends string,
112
111
  ChannelFunctionConnection = CoreChannelConnection<ChannelData>,
113
- ChannelFunctionDisconnection = CoreChannelConnection<ChannelData>,
112
+ ChannelFunctionDisconnection = CoreChannelDisconnection<ChannelData>,
114
113
  ChannelFunctionDefaultMessage = CoreChannelMessage<unknown, unknown, unknown>,
115
114
  ChannelFunctionMessageRoute = CoreChannelMessage<unknown, unknown, unknown>,
116
115
  APIPermission = CoreAPIPermission<ChannelData>,
@@ -143,7 +142,7 @@ export type CoreAPIChannel<
143
142
  docs?: Partial<{
144
143
  description: string
145
144
  response: string
146
- errors: Array<typeof EError>
145
+ errors: Array<typeof PikkuError>
147
146
  tags: string[]
148
147
  }>
149
148
  }
@@ -2,9 +2,9 @@
2
2
  * Base class for custom errors.
3
3
  * @extends {Error}
4
4
  */
5
- export class EError extends Error {
5
+ export class PikkuError extends Error {
6
6
  /**
7
- * Creates an instance of EError.
7
+ * Creates an instance of PikkuError.
8
8
  * @param message - The error message.
9
9
  */
10
10
  constructor(message: string = 'An error occurred') {
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * The server cannot or will not process the request due to client error (e.g., malformed request syntax).
3
3
  */
4
- import { addError, EError } from './error-handler.js'
4
+ import { addError, PikkuError } from './error-handler.js'
5
5
 
6
6
  /**
7
7
  * The server cannot or will not process the request due to client error (e.g., malformed request syntax).
8
8
  * @group Error
9
9
  */
10
- export class BadRequestError extends EError {}
10
+ export class BadRequestError extends PikkuError {}
11
11
  addError(BadRequestError, {
12
12
  status: 400,
13
13
  message:
@@ -18,17 +18,17 @@ addError(BadRequestError, {
18
18
  * Authentication is required and has failed or has not yet been provided.
19
19
  * @group Error
20
20
  */
21
- export class UnauthorizedError extends EError {}
21
+ export class UnauthorizedError extends PikkuError {}
22
22
  /**
23
23
  * More specific error to why it's unauthorized.
24
24
  * @group Error
25
25
  */
26
- export class MissingSessionError extends EError {}
26
+ export class MissingSessionError extends PikkuError {}
27
27
  /**
28
28
  * More specific error to why it's unauthorized.
29
29
  * @group Error
30
30
  */
31
- export class InvalidSessionError extends EError {}
31
+ export class InvalidSessionError extends PikkuError {}
32
32
 
33
33
  addError(UnauthorizedError, {
34
34
  status: 401,
@@ -45,7 +45,7 @@ addError(InvalidSessionError, {
45
45
  * Reserved for future use, often related to digital payment or subscription services.
46
46
  * @group Error
47
47
  */
48
- export class PaymentRequiredError extends EError {}
48
+ export class PaymentRequiredError extends PikkuError {}
49
49
  addError(PaymentRequiredError, {
50
50
  status: 402,
51
51
  message:
@@ -56,7 +56,7 @@ addError(PaymentRequiredError, {
56
56
  * The client does not have permission to access the requested resource.
57
57
  * @group Error
58
58
  */
59
- export class ForbiddenError extends EError {}
59
+ export class ForbiddenError extends PikkuError {}
60
60
  addError(ForbiddenError, {
61
61
  status: 403,
62
62
  message:
@@ -67,7 +67,7 @@ addError(ForbiddenError, {
67
67
  * The request was made from an origin that is not permitted to access this resource.
68
68
  * @group Error
69
69
  */
70
- export class InvalidOriginError extends EError {}
70
+ export class InvalidOriginError extends PikkuError {}
71
71
  addError(InvalidOriginError, {
72
72
  status: 403,
73
73
  message:
@@ -78,7 +78,7 @@ addError(InvalidOriginError, {
78
78
  * The server cannot find the requested resource.
79
79
  * @group Error
80
80
  */
81
- export class NotFoundError extends EError {}
81
+ export class NotFoundError extends PikkuError {}
82
82
  /**
83
83
  * The server cannot find the requested route.
84
84
  * @group Error
@@ -92,7 +92,7 @@ addError(NotFoundError, {
92
92
  * The request method is known by the server but is not supported by the resource.
93
93
  * @group Error
94
94
  */
95
- export class MethodNotAllowedError extends EError {}
95
+ export class MethodNotAllowedError extends PikkuError {}
96
96
  addError(MethodNotAllowedError, {
97
97
  status: 405,
98
98
  message:
@@ -103,7 +103,7 @@ addError(MethodNotAllowedError, {
103
103
  * The requested resource cannot produce a response matching the list of acceptable values in the request's headers.
104
104
  * @group Error
105
105
  */
106
- export class NotAcceptableError extends EError {}
106
+ export class NotAcceptableError extends PikkuError {}
107
107
  addError(NotAcceptableError, {
108
108
  status: 406,
109
109
  message:
@@ -114,7 +114,7 @@ addError(NotAcceptableError, {
114
114
  * The client must authenticate itself to get the requested response.
115
115
  * @group Error
116
116
  */
117
- export class ProxyAuthenticationRequiredError extends EError {}
117
+ export class ProxyAuthenticationRequiredError extends PikkuError {}
118
118
  addError(ProxyAuthenticationRequiredError, {
119
119
  status: 407,
120
120
  message: 'The client must authenticate itself to get the requested response.',
@@ -124,7 +124,7 @@ addError(ProxyAuthenticationRequiredError, {
124
124
  * The server did not receive a timely response from an upstream server.
125
125
  * @group Error
126
126
  */
127
- export class RequestTimeoutError extends EError {}
127
+ export class RequestTimeoutError extends PikkuError {}
128
128
  addError(RequestTimeoutError, {
129
129
  status: 408,
130
130
  message:
@@ -135,7 +135,7 @@ addError(RequestTimeoutError, {
135
135
  * The request could not be completed due to a conflict with the current state of the target resource.
136
136
  * @group Error
137
137
  */
138
- export class ConflictError extends EError {}
138
+ export class ConflictError extends PikkuError {}
139
139
  addError(ConflictError, {
140
140
  status: 409,
141
141
  message:
@@ -146,7 +146,7 @@ addError(ConflictError, {
146
146
  * The resource that is being accessed is no longer available and will not be available again.
147
147
  * @group Error
148
148
  */
149
- export class GoneError extends EError {}
149
+ export class GoneError extends PikkuError {}
150
150
  addError(GoneError, {
151
151
  status: 410,
152
152
  message:
@@ -157,7 +157,7 @@ addError(GoneError, {
157
157
  * The request did not specify the length of its content, which is required by the requested resource.
158
158
  * @group Error
159
159
  */
160
- export class LengthRequiredError extends EError {}
160
+ export class LengthRequiredError extends PikkuError {}
161
161
  addError(LengthRequiredError, {
162
162
  status: 411,
163
163
  message:
@@ -168,7 +168,7 @@ addError(LengthRequiredError, {
168
168
  * The server does not meet one of the preconditions that the requester put on the request.
169
169
  * @group Error
170
170
  */
171
- export class PreconditionFailedError extends EError {}
171
+ export class PreconditionFailedError extends PikkuError {}
172
172
  addError(PreconditionFailedError, {
173
173
  status: 412,
174
174
  message:
@@ -179,7 +179,7 @@ addError(PreconditionFailedError, {
179
179
  * The request is larger than the server is willing or able to process.
180
180
  * @group Error
181
181
  */
182
- export class PayloadTooLargeError extends EError {}
182
+ export class PayloadTooLargeError extends PikkuError {}
183
183
  addError(PayloadTooLargeError, {
184
184
  status: 413,
185
185
  message:
@@ -190,7 +190,7 @@ addError(PayloadTooLargeError, {
190
190
  * The URI requested by the client is longer than the server is willing to interpret.
191
191
  * @group Error
192
192
  */
193
- export class URITooLongError extends EError {}
193
+ export class URITooLongError extends PikkuError {}
194
194
  addError(URITooLongError, {
195
195
  status: 414,
196
196
  message:
@@ -201,7 +201,7 @@ addError(URITooLongError, {
201
201
  * The server does not support the media format of the requested data.
202
202
  * @group Error
203
203
  */
204
- export class UnsupportedMediaTypeError extends EError {}
204
+ export class UnsupportedMediaTypeError extends PikkuError {}
205
205
  addError(UnsupportedMediaTypeError, {
206
206
  status: 415,
207
207
  message:
@@ -212,7 +212,7 @@ addError(UnsupportedMediaTypeError, {
212
212
  * The client has asked for a portion of the file, but the server cannot supply that portion.
213
213
  * @group Error
214
214
  */
215
- export class RangeNotSatisfiableError extends EError {}
215
+ export class RangeNotSatisfiableError extends PikkuError {}
216
216
  addError(RangeNotSatisfiableError, {
217
217
  status: 416,
218
218
  message:
@@ -223,7 +223,7 @@ addError(RangeNotSatisfiableError, {
223
223
  * The server cannot meet the requirements of the Expect request-header field.
224
224
  * @group Error
225
225
  */
226
- export class ExpectationFailedError extends EError {}
226
+ export class ExpectationFailedError extends PikkuError {}
227
227
  addError(ExpectationFailedError, {
228
228
  status: 417,
229
229
  message:
@@ -234,7 +234,7 @@ addError(ExpectationFailedError, {
234
234
  * Indicates that the server understood the content type of the request content, and the syntax of the request content was correct, but it was unable to process the contained instructions.
235
235
  * @group Error
236
236
  */
237
- export class UnprocessableContentError extends EError {}
237
+ export class UnprocessableContentError extends PikkuError {}
238
238
  addError(UnprocessableContentError, {
239
239
  status: 422,
240
240
  message:
@@ -245,7 +245,7 @@ addError(UnprocessableContentError, {
245
245
  * Indicates that the server understood the content type of the request content, and the syntax of the request content was correct, but it was unable to process the contained instructions.
246
246
  * @group Error
247
247
  */
248
- export class LockedError extends EError {}
248
+ export class LockedError extends PikkuError {}
249
249
  addError(LockedError, {
250
250
  status: 423,
251
251
  message:
@@ -256,7 +256,7 @@ addError(LockedError, {
256
256
  * The user has sent too many requests in a given amount of time ("rate limiting").
257
257
  * @group Error
258
258
  */
259
- export class TooManyRequestsError extends EError {}
259
+ export class TooManyRequestsError extends PikkuError {}
260
260
  addError(TooManyRequestsError, {
261
261
  status: 429,
262
262
  message:
@@ -267,7 +267,7 @@ addError(TooManyRequestsError, {
267
267
  * A generic error message, given when no more specific message is suitable.
268
268
  * @group Error
269
269
  */
270
- export class InternalServerError extends EError {}
270
+ export class InternalServerError extends PikkuError {}
271
271
  addError(InternalServerError, {
272
272
  status: 500,
273
273
  message:
@@ -278,7 +278,7 @@ addError(InternalServerError, {
278
278
  * The server does not recognize the request method and cannot support it.
279
279
  * @group Error
280
280
  */
281
- export class NotImplementedError extends EError {}
281
+ export class NotImplementedError extends PikkuError {}
282
282
  addError(NotImplementedError, {
283
283
  status: 501,
284
284
  message:
@@ -289,7 +289,7 @@ addError(NotImplementedError, {
289
289
  * The server was acting as a gateway or proxy and received an invalid response from the upstream server.
290
290
  * @group Error
291
291
  */
292
- export class BadGatewayError extends EError {}
292
+ export class BadGatewayError extends PikkuError {}
293
293
  addError(BadGatewayError, {
294
294
  status: 502,
295
295
  message:
@@ -300,7 +300,7 @@ addError(BadGatewayError, {
300
300
  * The server is currently unavailable (overloaded or down).
301
301
  * @group Error
302
302
  */
303
- export class ServiceUnavailableError extends EError {}
303
+ export class ServiceUnavailableError extends PikkuError {}
304
304
  addError(ServiceUnavailableError, {
305
305
  status: 503,
306
306
  message: 'The server is currently unavailable (overloaded or down).',
@@ -310,7 +310,7 @@ addError(ServiceUnavailableError, {
310
310
  * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
311
311
  * @group Error
312
312
  */
313
- export class GatewayTimeoutError extends EError {}
313
+ export class GatewayTimeoutError extends PikkuError {}
314
314
  addError(GatewayTimeoutError, {
315
315
  status: 504,
316
316
  message:
@@ -321,7 +321,7 @@ addError(GatewayTimeoutError, {
321
321
  * The server does not support the HTTP protocol version used in the request.
322
322
  * @group Error
323
323
  */
324
- export class HTTPVersionNotSupportedError extends EError {}
324
+ export class HTTPVersionNotSupportedError extends PikkuError {}
325
325
  addError(HTTPVersionNotSupportedError, {
326
326
  status: 505,
327
327
  message:
@@ -332,7 +332,7 @@ addError(HTTPVersionNotSupportedError, {
332
332
  * The server took too long to complete the request, reaching the maximum compute time allowed.
333
333
  * @group Error
334
334
  */
335
- export class MaxComputeTimeReachedError extends EError {}
335
+ export class MaxComputeTimeReachedError extends PikkuError {}
336
336
  addError(MaxComputeTimeReachedError, {
337
337
  status: 524,
338
338
  message:
@@ -1,4 +1,4 @@
1
- import { EError } from '../errors/error-handler.js'
1
+ import { PikkuError } from '../errors/error-handler.js'
2
2
  import {
3
3
  APIDocs,
4
4
  CoreServices,
@@ -71,7 +71,7 @@ export type CoreHTTPFunction = {
71
71
  docs?: Partial<{
72
72
  description: string
73
73
  response: string
74
- errors: Array<typeof EError>
74
+ errors: Array<typeof PikkuError>
75
75
  tags: string[]
76
76
  }>
77
77
  }
@@ -101,7 +101,7 @@ export async function runScheduledTask<
101
101
  }
102
102
 
103
103
  singletonServices.logger.info(
104
- `Running schedule task: ${name} | schedule: ${task.schedule}}`
104
+ `Running schedule task: ${name} | schedule: ${task.schedule}`
105
105
  )
106
106
 
107
107
  let allServices = singletonServices
@@ -60,16 +60,15 @@ export type CoreConfig<Config extends Record<string, unknown> = {}> = {
60
60
  /**
61
61
  * Represents a core user session, which can be extended for more specific session information.
62
62
  */
63
- export type CoreUserSession<UserSession = unknown> = UserSession
63
+ export interface CoreUserSession {}
64
64
 
65
65
  /**
66
66
  * Interface for core singleton services provided by Pikku.
67
67
  */
68
- export type CoreSingletonServices<
68
+ export interface CoreSingletonServices<
69
69
  Config extends CoreConfig = CoreConfig,
70
70
  UserSession extends CoreUserSession = CoreUserSession,
71
- UserServices extends Record<string, unknown> = {},
72
- > = {
71
+ > {
73
72
  /** The http permission service used for authorization (optional). */
74
73
  enforceHTTPAccess?: enforceHTTPAccess
75
74
  /** The channel permission service used by the application (optional). */
@@ -90,7 +89,7 @@ export type CoreSingletonServices<
90
89
  eventHub?: EventHubService<unknown>
91
90
  /** SecretServce */
92
91
  secretService?: SecretService
93
- } & UserServices
92
+ }
94
93
 
95
94
  /**
96
95
  * Represents different forms of interaction within Pikku and the outside world.