@enonic-types/core 7.14.4 → 7.15.0-A1

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 (2) hide show
  1. package/index.d.ts +480 -7
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -5,9 +5,11 @@ export interface NestedRecord {
5
5
  }
6
6
 
7
7
  declare global {
8
+ interface XpBeans {}
8
9
  interface XpLayoutMap {
9
10
  [layoutDescriptor: ComponentDescriptor]: NestedRecord;
10
11
  }
12
+ interface XpLibraries {}
11
13
  interface XpPageMap {
12
14
  [pageDescriptor: ComponentDescriptor]: NestedRecord;
13
15
  }
@@ -19,6 +21,462 @@ declare global {
19
21
  }
20
22
  }
21
23
 
24
+ export interface App {
25
+ /**
26
+ * The name of the application.
27
+ *
28
+ * @type string
29
+ */
30
+ name: string;
31
+ /**
32
+ * Version of the application.
33
+ *
34
+ * @type string
35
+ */
36
+ version: string;
37
+ /**
38
+ * Values from the application’s configuration file.
39
+ * This can be set using $XP_HOME/config/<app.name>.cfg.
40
+ * Every time the configuration is changed the app is restarted.
41
+ *
42
+ * @type Object
43
+ */
44
+ config: Record<string, string | undefined>;
45
+ }
46
+
47
+ export interface DoubleUnderscore {
48
+ /**
49
+ * Creates a new JavaScript bean that wraps the given Java class and makes its methods available to be called from JavaScript.
50
+ */
51
+ newBean: NewBean;
52
+ /**
53
+ * Converts arrays or complex Java objects to JSON.
54
+ * @param value Value to convert
55
+ */
56
+ toNativeObject: <T = unknown>(value: T) => T;
57
+ /**
58
+ * Converts JSON to a Java Map structure that can be used as parameters to a Java method on a bean created with newBean.
59
+ * @param value Value to convert
60
+ */
61
+ toScriptValue: <T = object>(value: T) => ScriptValue;
62
+ /**
63
+ * Add a disposer that is called when the app is stopped.
64
+ * @param callback Function to call
65
+ */
66
+ disposer: (callback: (...args: unknown[]) => unknown) => void;
67
+ /**
68
+ * Converts a JavaScript variable that is undefined to a Java <code>null</code> object.
69
+ * If the JavaScript variable is defined, it is returned as is.
70
+ * @param value Value to convert
71
+ */
72
+ nullOrValue: <T = object>(value: T) => T | null | undefined;
73
+
74
+ /**
75
+ * Doc registerMock.
76
+ *
77
+ * @param name Name of mock.
78
+ * @param value Value to register.
79
+ */
80
+ registerMock: (name: string, value: object) => void
81
+ }
82
+
83
+ export interface Log {
84
+ /**
85
+ * Log debug message.
86
+ *
87
+ * @param {Array} args... logging arguments.
88
+ */
89
+ debug: (...args: unknown[]) => void;
90
+
91
+ /**
92
+ * Log info message.
93
+ *
94
+ * @param {Array} args... logging arguments.
95
+ */
96
+ info: (...args: unknown[]) => void;
97
+
98
+ /**
99
+ * Log warning message.
100
+ *
101
+ * @param {Array} args... logging arguments.
102
+ */
103
+ warning: (...args: unknown[]) => void;
104
+
105
+ /**
106
+ * Log error message.
107
+ *
108
+ * @param {Array} args... logging arguments.
109
+ */
110
+ error: (...args: unknown[]) => void;
111
+ }
112
+
113
+ export type NewBean = <T = unknown, Bean extends keyof XpBeans | string = string>(bean: Bean) =>
114
+ Bean extends keyof XpBeans ? XpBeans[Bean] : T;
115
+
116
+ export type Resolve = (path: string) => ResourceKey;
117
+
118
+ export interface ScriptValue {
119
+ isArray(): boolean;
120
+
121
+ isObject(): boolean;
122
+
123
+ isValue(): boolean;
124
+
125
+ isFunction(): boolean;
126
+
127
+ getValue(): unknown;
128
+
129
+ getKeys(): string[];
130
+
131
+ hasMember(key: string): boolean;
132
+
133
+ getMember(key: string): ScriptValue;
134
+
135
+ getArray(): ScriptValue[];
136
+
137
+ getMap(): Record<string, unknown>;
138
+
139
+ getList(): object[];
140
+ }
141
+
142
+ export type XpRequire = <Key extends keyof XpLibraries | string = string>(path: Key) =>
143
+ Key extends keyof XpLibraries ? XpLibraries[Key] : unknown;
144
+
145
+ export type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
146
+
147
+ export type Merge<
148
+ A,
149
+ B = Record<string, never>
150
+ > = B extends Record<string, never>
151
+ ? A
152
+ : Pick<A, Exclude<keyof A, keyof B>> & B;
153
+
154
+ export interface ComplexCookie {
155
+ /**
156
+ * The value of the cookie (optional).
157
+ *
158
+ * @type string
159
+ */
160
+ value: string;
161
+ /**
162
+ * A comment (rfc2109) to document the cookie (optional).
163
+ *
164
+ * @type string
165
+ */
166
+ comment?: string;
167
+ /**
168
+ * The expiration date and time for the cookie (optional).
169
+ *
170
+ * @type string
171
+ */
172
+ expires?: Date;
173
+ /**
174
+ * The domain name for which the cookie is set.
175
+ *
176
+ * @type string
177
+ */
178
+ domain?: string;
179
+ /**
180
+ * Indicates whether the cookie should not be accessible via JavaScript (optional).
181
+ *
182
+ * @type string
183
+ */
184
+ httpOnly?: boolean;
185
+ /**
186
+ * The maximum age of the cookie in seconds (optional).
187
+ *
188
+ * @type string
189
+ */
190
+ maxAge?: number;
191
+ /**
192
+ * The path on the server where the cookie should be available.
193
+ *
194
+ * @type string
195
+ */
196
+ path?: string;
197
+ /**
198
+ * Specifies the SameSite attribute (draft RFC) for the cookie (optional).
199
+ *
200
+ * @type string
201
+ */
202
+ sameSite?: LiteralUnion<'lax' | 'strict' | 'none'>;
203
+ /**
204
+ * Indicates whether the cookie should only be sent over HTTPS (optional).
205
+ *
206
+ * @type string
207
+ */
208
+ secure?: boolean;
209
+ }
210
+
211
+ export type RequestBranch = 'draft' | 'master';
212
+ export type RequestGetHeaderFunction = (headerName: string) => string | null;
213
+ export type RequestMethod = 'GET' | 'POST' | ' HEAD' | 'OPTIONS' | ' PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'CONNECT';
214
+ export type RequestMode = 'edit' | 'inline' | 'live' | 'preview' | 'admin';
215
+ export type RequestParams = Record<string, string | string[]>;
216
+ export type RequestScheme = 'http' | 'https';
217
+
218
+ export type RequestCookies = Record<string, string | undefined>;
219
+ export type ResponseCookies = Record<string, string | ComplexCookie | undefined>;
220
+
221
+ export type RequestHeaders = Record<string, string | undefined>;
222
+ export type ResponseHeaders = Record<string, string | number | (string | number)[] | undefined>;
223
+
224
+ export interface DefaultRequestCookies extends RequestCookies {
225
+ JSESSIONID?: string;
226
+ }
227
+
228
+ export type SecFetchDest = 'audio' | 'audioworklet' | 'document' | 'embed' | 'empty' | 'fencedframe' | 'font' | 'frame' | 'iframe' | 'image' | 'manifest' | 'object' | 'paintworklet' | 'report' | 'script' | 'serviceworker' | 'sharedworker' | 'style' | 'track' | 'video' | 'webidentity' | 'worker' | 'xslt';
229
+ export type SecFetchMode = 'cors'| 'navigate' | 'no-cors' | 'same-origin' | 'websocket';
230
+ export type SecFetchSite = 'cross-site' | 'same-origin' | 'same-site' | 'none';
231
+
232
+ export interface DefaultRequestHeaders extends RequestHeaders {
233
+ Accept?: string;
234
+ 'Accept-Charset'?: string;
235
+ 'Accept-Encoding'?: string;
236
+ 'Accept-Language'?: string;
237
+ Authorization?: string;
238
+ 'Cache-Control'?: string;
239
+ Connection?: string;
240
+ 'Content-Length'?: string;
241
+ 'Content-Type'?: string;
242
+ Cookie?: string;
243
+ Host?: string;
244
+ 'If-None-Match'?: string;
245
+ Priority?: string;
246
+ Referer?: string;
247
+ 'Sec-Fetch-Dest'?: LiteralUnion<SecFetchDest>;
248
+ 'Sec-Fetch-Mode'?: LiteralUnion<SecFetchMode>;
249
+ 'Sec-Fetch-Site'?: LiteralUnion<SecFetchSite>
250
+ 'Sec-Fetch-User'?: '?1';
251
+ 'Upgrade-Insecure-Requests'?: '1';
252
+ 'User-Agent'?: string;
253
+ 'X-Forwarded-For'?: string;
254
+ 'X-Forwarded-Host'?: string;
255
+ 'X-Forwarded-Proto'?: LiteralUnion<RequestScheme>;
256
+ 'X-Forwarded-Server'?: string;
257
+ }
258
+
259
+ export interface RequestConstructorParams {
260
+ body?: string;
261
+ branch?: LiteralUnion<RequestBranch>;
262
+ contentType?: string;
263
+ contextPath?: string;
264
+ cookies: RequestCookies;
265
+ headers: RequestHeaders;
266
+ host: string;
267
+ method: LiteralUnion<RequestMethod>;
268
+ mode: LiteralUnion<RequestMode>;
269
+ params: RequestParams;
270
+ path: string;
271
+ port: number;
272
+ rawPath: string;
273
+ remoteAddress: string;
274
+ repositoryId?: string;
275
+ scheme: LiteralUnion<RequestScheme>;
276
+ url: string;
277
+ validTicket?: boolean;
278
+ webSocket: boolean;
279
+ }
280
+
281
+ export interface RequestInterface extends RequestConstructorParams {
282
+ getHeader: RequestGetHeaderFunction;
283
+ }
284
+
285
+ export interface DefaultRequest extends RequestInterface {
286
+ cookies: DefaultRequestCookies;
287
+ headers: DefaultRequestHeaders;
288
+ }
289
+
290
+ export type Request<
291
+ T extends Partial<RequestInterface> = Record<string, never>
292
+ > = Merge<DefaultRequest, T>;
293
+
294
+ export type SerializableRequest<T extends RequestInterface = DefaultRequest> = Omit<
295
+ Partial<T>,
296
+ 'body' | 'contextPath' | 'rawPath' | 'repositoryId' | 'webSocket'
297
+ > & {
298
+ body?: unknown[] | Record<string, unknown> | boolean | number | string | null;
299
+ };
300
+
301
+ export interface DefaultResponseHeaders extends ResponseHeaders {
302
+ 'Cache-Control'?: string;
303
+ 'Content-Encoding'?: string;
304
+ 'Content-Type'?: string;
305
+ 'Content-Security-Policy'?: string;
306
+ 'Date'?: string;
307
+ Etag?: string | number;
308
+ Location?: string;
309
+ }
310
+
311
+ // NOTE Even though PortalResponseSerializer allows non-array values,
312
+ // when it comes back from Java the PortalResponseMapper will always return an array.
313
+ // So perhaps it's better to enforce that, so it's consistent both ways.
314
+ // It also causes problems in ResponseProcessors, since they work with both from and to Java.
315
+ export interface PageContributions {
316
+ headBegin?: string[];
317
+ headEnd?: string[];
318
+ bodyBegin?: string[];
319
+ bodyEnd?: string[];
320
+ }
321
+
322
+ export type ResponseBody = unknown[] | Record<string, unknown> | boolean | number | string | null | ByteSource;
323
+
324
+ export interface MappedResponse {
325
+ applyFilters: boolean;
326
+ body?: ResponseBody;
327
+ contentType: string;
328
+ cookies: ResponseCookies;
329
+ headers: ResponseHeaders;
330
+ pageContributions: PageContributions;
331
+ postProcess: boolean;
332
+ status: number;
333
+ }
334
+
335
+ export interface ResponseInterface extends Partial<MappedResponse> {
336
+ redirect?: string;
337
+ }
338
+
339
+ export interface DefaultResponse extends ResponseInterface {
340
+ contentType?: LiteralUnion<'text/html' | 'application/json'>;
341
+ headers?: DefaultResponseHeaders;
342
+ }
343
+
344
+ export type Response<
345
+ T extends Partial<ResponseInterface> = Record<string, never>
346
+ > = Merge<DefaultResponse, T>;
347
+
348
+ export type RequestHandler<
349
+ RequestFromJava extends RequestInterface = DefaultRequest,
350
+ ResponseToJava extends ResponseInterface = DefaultResponse
351
+ > = (request: RequestFromJava) => ResponseToJava;
352
+
353
+ export type HttpFilterNext<
354
+ RequestToJava extends SerializableRequest = SerializableRequest<DefaultRequest>,
355
+ ResponseToJava extends ResponseInterface = DefaultResponse
356
+ > = (request: RequestToJava) => ResponseToJava;
357
+
358
+ export interface WebSocketSession {
359
+ id: string;
360
+ params: Record<string, string | string[]>;
361
+ path: string;
362
+ user: Omit<User,'type'>;
363
+ }
364
+
365
+ export type WebSocketEventType = 'open' | 'message' | 'error' | 'close';
366
+
367
+ export interface WebSocketEvent<T> {
368
+ data: T;
369
+ closeReason?: number;
370
+ error?: string;
371
+ message?: string;
372
+ session: WebSocketSession;
373
+ type: WebSocketEventType;
374
+ }
375
+
376
+ type WebSocketEventHandler<T = Record<string, unknown>> = (event: WebSocketEvent<T>) => void;
377
+
378
+ export interface Controller<
379
+ Request extends RequestInterface = DefaultRequest,
380
+ Response extends ResponseInterface = DefaultResponse,
381
+ > {
382
+ all?: RequestHandler<Request, Response>;
383
+ connect?: RequestHandler<Request, Response>;
384
+ delete?: RequestHandler<Request, Response>;
385
+ get?: RequestHandler<Request, Response>;
386
+ head?: RequestHandler<Request, Response>;
387
+ options?: RequestHandler<Request, Response>;
388
+ patch?: RequestHandler<Request, Response>;
389
+ post?: RequestHandler<Request, Response>;
390
+ put?: RequestHandler<Request, Response>;
391
+ trace?: RequestHandler<Request, Response>;
392
+ webSocketEvent?: WebSocketEventHandler;
393
+ }
394
+
395
+ export interface ErrorRequest<T extends RequestInterface = DefaultRequest> {
396
+ exception?: unknown;
397
+ message: string;
398
+ request: T;
399
+ status: number;
400
+ }
401
+
402
+ export type ErrorRequestHandler<
403
+ Err extends ErrorRequest = ErrorRequest,
404
+ ResponseToJava extends ResponseInterface = DefaultResponse
405
+ > = (err: Err) => ResponseToJava;
406
+
407
+ export interface ErrorController {
408
+ handle400?: ErrorRequestHandler;
409
+ handle401?: ErrorRequestHandler;
410
+ handle402?: ErrorRequestHandler;
411
+ handle403?: ErrorRequestHandler;
412
+ handle404?: ErrorRequestHandler;
413
+ handle405?: ErrorRequestHandler;
414
+ handle406?: ErrorRequestHandler;
415
+ handle407?: ErrorRequestHandler;
416
+ handle408?: ErrorRequestHandler;
417
+ handle409?: ErrorRequestHandler;
418
+ handle410?: ErrorRequestHandler;
419
+ handle411?: ErrorRequestHandler;
420
+ handle412?: ErrorRequestHandler;
421
+ handle413?: ErrorRequestHandler;
422
+ handle414?: ErrorRequestHandler;
423
+ handle415?: ErrorRequestHandler;
424
+ handle416?: ErrorRequestHandler;
425
+ handle417?: ErrorRequestHandler;
426
+ handle418?: ErrorRequestHandler;
427
+ handle421?: ErrorRequestHandler;
428
+ handle422?: ErrorRequestHandler;
429
+ handle423?: ErrorRequestHandler;
430
+ handle424?: ErrorRequestHandler;
431
+ handle425?: ErrorRequestHandler;
432
+ handle426?: ErrorRequestHandler;
433
+ handle428?: ErrorRequestHandler;
434
+ handle429?: ErrorRequestHandler;
435
+ handle431?: ErrorRequestHandler;
436
+ handle451?: ErrorRequestHandler;
437
+ handle500?: ErrorRequestHandler;
438
+ handle501?: ErrorRequestHandler;
439
+ handle502?: ErrorRequestHandler;
440
+ handle503?: ErrorRequestHandler;
441
+ handle504?: ErrorRequestHandler;
442
+ handle505?: ErrorRequestHandler;
443
+ handle506?: ErrorRequestHandler;
444
+ handle507?: ErrorRequestHandler;
445
+ handle508?: ErrorRequestHandler;
446
+ handle510?: ErrorRequestHandler;
447
+ handle511?: ErrorRequestHandler;
448
+ handleError?: ErrorRequestHandler;
449
+ }
450
+
451
+ export interface IdProviderController extends Controller {
452
+ autoLogin?: RequestHandler;
453
+ handle401?: RequestHandler;
454
+ login?: RequestHandler;
455
+ logout?: RequestHandler;
456
+ }
457
+
458
+ export interface HttpFilterController<
459
+ RequestFromJava extends RequestInterface = DefaultRequest,
460
+ ResponseFromNext extends ResponseInterface = Response,
461
+ ResponseToJava extends ResponseInterface = ResponseFromNext
462
+ > {
463
+ filter: (
464
+ request: RequestFromJava,
465
+ next: HttpFilterNext<
466
+ SerializableRequest<RequestFromJava>,
467
+ ResponseFromNext
468
+ >
469
+ ) => ResponseToJava;
470
+ }
471
+
472
+ export interface ResponseProcessorController<
473
+ RequestFromJava extends RequestInterface = DefaultRequest,
474
+ ResponseFromJava extends MappedResponse = MappedResponse,
475
+ ResponseToJava extends ResponseInterface = Partial<ResponseFromJava>
476
+ > {
477
+ responseProcessor: (request: RequestFromJava, response: ResponseFromJava) => ResponseToJava;
478
+ }
479
+
22
480
  export type UserKey = `user:${string}:${string}`;
23
481
  export type GroupKey = `group:${string}:${string}`;
24
482
  export type RoleKey = `role:${string}`;
@@ -110,6 +568,13 @@ type Part = PartDescriptor extends any // this lets us iterate over every member
110
568
  ? PartComponent<PartDescriptor, XpPartMap[PartDescriptor]>
111
569
  : never;
112
570
 
571
+ export type PageComponentWhenAutomaticTemplate = Record<string,never>;
572
+ export interface PageComponentWhenSpecificTemplate {
573
+ path: '/';
574
+ template: string;
575
+ type: 'page';
576
+ }
577
+
113
578
  export interface PageComponent<
114
579
  Descriptor extends ComponentDescriptor = ComponentDescriptor,
115
580
  Config extends NestedRecord =
@@ -120,12 +585,13 @@ export interface PageComponent<
120
585
  Record<string, Region<(FragmentComponent | LayoutComponent | PartComponent | TextComponent)[]>> =
121
586
  Record<string, Region<(FragmentComponent | Layout | Part | TextComponent)[]>>
122
587
  > {
123
- type: 'page'
124
- descriptor: Descriptor
125
588
  config: Config
589
+ descriptor: Descriptor
126
590
  path: '/'
127
591
  regions: Regions;
592
+ type: 'page'
128
593
  }
594
+
129
595
  type PageDescriptor = keyof XpPageMap;
130
596
  type Page = PageDescriptor extends any // this lets us iterate over every member of the union
131
597
  ? PageComponent<PageDescriptor, XpPageMap[PageDescriptor]>
@@ -140,7 +606,13 @@ export interface TextComponent {
140
606
  export type Component<
141
607
  Descriptor extends ComponentDescriptor = LayoutDescriptor | PageDescriptor | PartDescriptor,
142
608
  Config extends NestedRecord = NestedRecord,
143
- Regions extends Record<string, Region> = Record<string, Region>,
609
+ Regions extends (
610
+ Descriptor extends LayoutDescriptor
611
+ ? Record<string, Region<(FragmentComponent | PartComponent | TextComponent)[]>>
612
+ : Record<string, Region>
613
+ ) = Descriptor extends LayoutDescriptor
614
+ ? Record<string, Region<(FragmentComponent | PartComponent | TextComponent)[]>>
615
+ : Record<string, Region>,
144
616
  > =
145
617
  | FragmentComponent
146
618
  | LayoutComponent<Descriptor, Config, Regions>
@@ -170,6 +642,7 @@ export type Region<
170
642
  Components extends
171
643
  (FragmentComponent | LayoutComponent | PartComponent | TextComponent)[] =
172
644
  (FragmentComponent | Layout | Part | TextComponent)[]
645
+ // @ts-expect-error TODO LayoutRegion can't eat LayoutComponent nor Layout!!!
173
646
  > = PageRegion<Components> | LayoutRegion<Components>;
174
647
 
175
648
  export interface Content<
@@ -178,11 +651,11 @@ export interface Content<
178
651
  _Component extends (
179
652
  Type extends 'portal:fragment'
180
653
  ? LayoutComponent | PartComponent
181
- : PageComponent | Record<string,never>
654
+ : PageComponent | PageComponentWhenSpecificTemplate | PageComponentWhenAutomaticTemplate
182
655
  ) = (
183
656
  Type extends 'portal:fragment'
184
657
  ? Layout | Part
185
- : Page
658
+ : Page | PageComponentWhenSpecificTemplate | PageComponentWhenAutomaticTemplate
186
659
  ),
187
660
  > {
188
661
  _id: string;
@@ -356,9 +829,9 @@ export type QueryDsl = {
356
829
  exists: ExistsDslExpression;
357
830
  };
358
831
 
359
- type SortDirection = 'ASC' | 'DESC';
832
+ export type SortDirection = 'ASC' | 'DESC';
360
833
 
361
- type DistanceUnit =
834
+ export type DistanceUnit =
362
835
  | 'm'
363
836
  | 'meters'
364
837
  | 'in'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic-types/core",
3
- "version": "7.14.4",
3
+ "version": "7.15.0-A1",
4
4
  "description": "Shared type definition for core libraries.",
5
5
  "types": "index.d.ts",
6
6
  "files": [