@enonic-types/lib-content 0.1.0 → 7.11.0-B1

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.
@@ -1,886 +1,908 @@
1
- /**
2
- * Functions and constants to find and manipulate content.
3
- *
4
- * @example
5
- * var contentLib = require('/lib/xp/content');
6
- *
7
- * @module content
8
- */
9
- declare global {
10
- interface XpLibraries {
11
- '/lib/xp/content': typeof import('./content');
12
- }
13
- }
14
- declare type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
15
- export declare const ARCHIVE_ROOT_PATH: string;
16
- export declare const CONTENT_ROOT_PATH: string;
17
- /**
18
- * @typedef ContentType
19
- * @type Object
20
- * @property {string} name Name of the content type.
21
- * @property {string} displayName Display name of the content type.
22
- * @property {string} description Description of the content type.
23
- * @property {string} superType Name of the super type, or null if it has no super type.
24
- * @property {boolean} abstract Whether or not content of this type may be instantiated.
25
- * @property {boolean} final Whether or not it may be used as super type of other content types.
26
- * @property {boolean} allowChildContent Whether or not allow creating child items on content of this type.
27
- * @property {string} displayNameExpression ES6 string template for generating the content name based on values in the content form.
28
- * @property {object} [icon] Icon of the content type.
29
- * @property {object} [icon.data] Stream with the binary data for the icon.
30
- * @property {string} [icon.mimeType] Mime type of the icon image.
31
- * @property {string} [icon.modifiedTime] Modified time of the icon. May be used for caching.
32
- * @property {object[]} form Form schema represented as an array of form items: Input, ItemSet, Layout, OptionSet.
33
- */
34
- export interface GetContentParams {
35
- key: string;
36
- versionId?: string | null;
37
- }
38
- export interface Attachment {
39
- name: string;
40
- label?: string;
41
- size: number;
42
- mimeType: string;
43
- }
44
- export interface Attachments {
45
- [key: string]: Attachment;
46
- }
47
- export interface PublishInfo {
48
- from?: string;
49
- to?: string;
50
- first?: string;
51
- }
52
- export declare type XDataEntry = Record<string, Record<string, unknown>>;
53
- export declare type XData = Record<string, XDataEntry>;
54
- export declare type WorkflowState = 'IN_PROGRESS' | 'PENDING_APPROVAL' | 'REJECTED' | 'READY';
55
- export declare type WorkflowCheckState = 'PENDING' | 'REJECTED' | 'APPROVED';
56
- export interface Workflow {
57
- state: WorkflowState;
58
- checks?: Record<string, WorkflowCheckState>;
59
- }
60
- export declare type ContentInheritType = 'CONTENT' | 'PARENT' | 'NAME' | 'SORT';
61
- export interface Bucket {
62
- [subAggregationName: string]: BucketsAggregation | StatsAggregation | SingleValueMetricAggregation | string | number | undefined;
63
- key: string;
64
- docCount: number;
65
- }
66
- export interface NumericBucket extends Bucket {
67
- from?: number;
68
- to?: number;
69
- }
70
- export interface DateBucket extends Bucket {
71
- from?: string;
72
- to?: string;
73
- }
74
- export interface BucketsAggregation {
75
- buckets: (DateBucket | NumericBucket)[];
76
- }
77
- export interface StatsAggregation {
78
- count: number;
79
- min: number;
80
- max: number;
81
- avg: number;
82
- sum: number;
83
- }
84
- export interface SingleValueMetricAggregation {
85
- value: number;
86
- }
87
- export declare type AggregationsResult = BucketsAggregation | StatsAggregation | SingleValueMetricAggregation;
88
- export declare type Aggregation = TermsAggregation | HistogramAggregation | DateHistogramAggregation | NumericRangeAggregation | DateRangeAggregation | StatsAggregation | GeoDistanceAggregation | MinAggregation | MaxAggregation | ValueCountAggregation;
89
- export interface TermsAggregation {
90
- terms: {
91
- field: string;
92
- order?: string;
93
- size?: number;
94
- minDocCount?: number;
95
- };
96
- aggregations?: {
97
- [subAggregations: string]: Aggregation;
98
- };
99
- }
100
- export interface HistogramAggregation {
101
- histogram: {
102
- field: string;
103
- order?: string;
104
- interval?: number;
105
- extendedBoundMin?: number;
106
- extendedBoundMax?: number;
107
- minDocCount?: number;
108
- };
109
- aggregations?: {
110
- [subAggregations: string]: Aggregation;
111
- };
112
- }
113
- export interface DateHistogramAggregation {
114
- dateHistogram: {
115
- field: string;
116
- interval?: string;
117
- minDocCount?: number;
118
- format: string;
119
- };
120
- aggregations?: {
121
- [subAggregations: string]: Aggregation;
122
- };
123
- }
124
- export interface NumericRange {
125
- from?: number;
126
- to?: number;
127
- key?: string;
128
- }
129
- export interface NumericRangeAggregation {
130
- range: {
131
- field: string;
132
- ranges?: NumericRange[];
133
- };
134
- aggregations?: {
135
- [subAggregations: string]: Aggregation;
136
- };
137
- }
138
- export interface NumericRangeAggregation {
139
- range: {
140
- field: string;
141
- ranges?: NumericRange[];
142
- };
143
- aggregations?: {
144
- [subAggregations: string]: Aggregation;
145
- };
146
- }
147
- export interface DateRange {
148
- from?: string;
149
- to?: string;
150
- key?: string;
151
- }
152
- export interface DateRangeAggregation {
153
- dateRange: {
154
- field: string;
155
- format: string;
156
- ranges: DateRange[];
157
- };
158
- aggregations?: {
159
- [subAggregations: string]: Aggregation;
160
- };
161
- }
162
- export interface StatsAggregation {
163
- stats: {
164
- field: string;
165
- };
166
- }
167
- export interface GeoDistanceAggregation {
168
- geoDistance: {
169
- field: string;
170
- unit: string;
171
- origin?: {
172
- lat: string;
173
- lon: string;
174
- };
175
- ranges?: NumericRange[];
176
- };
177
- }
178
- export interface MinAggregation {
179
- min: {
180
- field: string;
181
- };
182
- }
183
- export interface MaxAggregation {
184
- max: {
185
- field: string;
186
- };
187
- }
188
- export interface ValueCountAggregation {
189
- count: {
190
- field: string;
191
- };
192
- }
193
- export interface Highlight {
194
- encoder?: 'default' | 'html';
195
- tagsSchema?: 'styled';
196
- fragmenter?: 'simple' | 'span';
197
- fragmentSize?: number;
198
- noMatchSize?: number;
199
- numberOfFragments?: number;
200
- order?: 'score' | 'none';
201
- preTag?: string;
202
- postTag?: string;
203
- requireFieldMatch?: boolean;
204
- properties?: Record<string, Highlight>;
205
- }
206
- export interface HighlightResult {
207
- [highlightedFieldName: string]: string[];
208
- }
209
- export interface ExistsFilter {
210
- exists: {
211
- field: string;
212
- };
213
- }
214
- export interface NotExistsFilter {
215
- notExists: {
216
- field: string;
217
- };
218
- }
219
- export interface HasValueFilter {
220
- hasValue: {
221
- field: string;
222
- values: unknown[];
223
- };
224
- }
225
- export interface IdsFilter {
226
- ids: {
227
- values: string[];
228
- };
229
- }
230
- export interface BooleanFilter {
231
- boolean: {
232
- must?: Filter[];
233
- mustNot?: Filter[];
234
- should?: Filter[];
235
- };
236
- }
237
- export declare type Filter = ExistsFilter | NotExistsFilter | HasValueFilter | IdsFilter | BooleanFilter;
238
- export declare type FormItemType = 'Input' | 'ItemSet' | 'Layout' | 'OptionSet';
239
- export declare type InputType = 'Time' | 'DateTime' | 'CheckBox' | 'ComboBox' | 'Long' | 'Double' | 'RadioButton' | 'TextArea' | 'ContentTypeFilter' | 'GeoPoint' | 'TextLine' | 'Tag' | 'CustomSelector' | 'AttachmentUploader' | 'ContentSelector' | 'MediaSelector' | 'ImageSelector' | 'Date' | 'MediaUploader' | 'SiteConfigurator' | 'HtmlArea';
240
- export interface FormItemSet {
241
- formItemType: string | FormItemType;
242
- name: string;
243
- label: string;
244
- customText: string;
245
- helpText: string;
246
- maximize: boolean;
247
- inputType: InputType;
248
- occurrences: {
249
- maximum: number;
250
- minimum: number;
251
- };
252
- items: FormItem[];
253
- }
254
- export interface FormItemLayout {
255
- formItemType: string | FormItemType;
256
- name: string;
257
- label: string;
258
- items: unknown;
259
- }
260
- export declare type ValueType = 'BinaryReference' | 'Boolean' | 'DateTime' | 'Double' | 'GeoPoint' | 'Link' | 'LocalDateTime' | 'LocalDate' | 'LocalTime' | 'Long' | 'PropertySet' | 'Reference' | 'String' | 'Xml';
261
- export interface FormItemInput {
262
- formItemType: string | FormItemType;
263
- name: string;
264
- label: string;
265
- customText: string;
266
- helpText: string;
267
- validationRegexp: string;
268
- maximize: boolean;
269
- inputType: InputType;
270
- occurrences: {
271
- maximum: number;
272
- minimum: number;
273
- };
274
- default: {
275
- value: string;
276
- type: ValueType;
277
- };
278
- config: {
279
- [configName: string]: {
280
- [attributeKey: string]: string;
281
- value: string;
282
- }[];
283
- };
284
- }
285
- export interface FormItemOptionSet {
286
- formItemType: string | FormItemType;
287
- name: string;
288
- label: string;
289
- expanded: boolean;
290
- helpText: string;
291
- occurrences: {
292
- maximum: number;
293
- minimum: number;
294
- };
295
- selection: {
296
- maximum: number;
297
- minimum: number;
298
- };
299
- options: {
300
- name: string;
301
- label: string;
302
- helpText: string;
303
- default: boolean;
304
- items: FormItem[];
305
- }[];
306
- }
307
- export declare type FormItem = FormItemSet | FormItemLayout | FormItemOptionSet | FormItemInput;
308
- export declare type DslQueryType = LiteralUnion<'dateTime' | 'time'> | number | boolean;
309
- export declare type DslOperator = 'OR' | 'AND';
310
- export interface TermDslExpression {
311
- field: string;
312
- value: unknown;
313
- type?: DslQueryType;
314
- boost?: number;
315
- }
316
- export interface InDslExpression {
317
- field: string;
318
- values: unknown[];
319
- type?: DslQueryType;
320
- boost?: number;
321
- }
322
- export interface LikeDslExpression {
323
- field: string;
324
- value: string;
325
- type?: DslQueryType;
326
- boost?: number;
327
- }
328
- export interface RangeDslExpression {
329
- field: string;
330
- type?: DslQueryType;
331
- lt?: unknown;
332
- lte?: unknown;
333
- gt?: unknown;
334
- gte?: unknown;
335
- boost?: number;
336
- }
337
- export interface PathMatchDslExpression {
338
- field: string;
339
- path: string;
340
- minimumMatch?: number;
341
- boost?: number;
342
- }
343
- export interface MatchAllDslExpression {
344
- boost?: number;
345
- }
346
- export interface FulltextDslExpression {
347
- fields: string[];
348
- query: string;
349
- operator?: DslOperator;
350
- }
351
- export interface NgramDslExpression {
352
- fields: string[];
353
- query: string;
354
- operator?: DslOperator;
355
- }
356
- export interface StemmedDslExpression {
357
- fields: string[];
358
- query: string;
359
- language: string;
360
- }
361
- export interface BooleanDslExpression {
362
- should?: DslExpression | DslExpression[];
363
- must?: DslExpression | DslExpression[];
364
- mustNot?: DslExpression | DslExpression[];
365
- filter?: DslExpression | DslExpression[];
366
- }
367
- export declare type DslExpression = TermDslExpression | InDslExpression | LikeDslExpression | RangeDslExpression | PathMatchDslExpression | MatchAllDslExpression | FulltextDslExpression | NgramDslExpression | BooleanDslExpression | StemmedDslExpression;
368
- export interface QueryDsl {
369
- boolean?: BooleanDslExpression;
370
- ngram?: NgramDslExpression;
371
- fulltext?: FulltextDslExpression;
372
- matchAll?: MatchAllDslExpression;
373
- pathMatch?: PathMatchDslExpression;
374
- range?: RangeDslExpression;
375
- like?: LikeDslExpression;
376
- in?: InDslExpression;
377
- term?: TermDslExpression;
378
- }
379
- export interface Content {
380
- _id: string;
381
- _name: string;
382
- _path: string;
383
- _score: number;
384
- creator: string;
385
- modifier: string;
386
- createdTime: string;
387
- modifiedTime: string;
388
- owner: string;
389
- type: string;
390
- displayName: string;
391
- hasChildren: boolean;
392
- language: string;
393
- valid: boolean;
394
- originProject: string;
395
- childOrder?: string;
396
- _sort?: object[];
397
- data: Record<string, unknown>;
398
- x: XData;
399
- attachments: Attachments;
400
- publish?: PublishInfo;
401
- workflow?: Workflow;
402
- inherit?: ContentInheritType[];
403
- }
404
- /**
405
- * This function fetches a content.
406
- *
407
- * @example-ref examples/content/get.js
408
- *
409
- * @param {object} params JSON with the parameters.
410
- * @param {string} params.key Path or id to the content.
411
- * @param {string} [params.versionId] Version Id of the content.
412
- *
413
- * @returns {object} The content (as JSON) fetched from the repository.
414
- */
415
- export declare function get(params: GetContentParams): Content | null;
416
- /**
417
- * This function returns a content attachments.
418
- *
419
- * @example-ref examples/content/getAttachments.js
420
- *e
421
- * @param {string} key Path or id to the content.
422
- *
423
- * @returns {object} An object with all the attachments that belong to the content, where the key is the attachment name. Or null if the content cannot be found.
424
- */
425
- export declare function getAttachments(key: string): Attachments | null;
426
- export interface GetAttachmentStreamParams {
427
- key: string;
428
- name: string;
429
- }
430
- /**
431
- * This function returns a data-stream for the specified content attachment.
432
- *
433
- * @example-ref examples/content/getAttachmentStream.js
434
- *
435
- * @param {object} params JSON with the parameters.
436
- * @param {string} params.key Path or id to the content.
437
- * @param {string} params.name Attachment name.
438
- *
439
- * @returns {*} Stream of the attachment data.
440
- */
441
- export declare function getAttachmentStream(params: GetAttachmentStreamParams): object | null;
442
- export interface AddAttachmentParam {
443
- key: string;
444
- name: string;
445
- mimeType: string;
446
- data: object;
447
- label?: string;
448
- }
449
- /**
450
- * Adds an attachment to an existing content.
451
- *
452
- * @example-ref examples/content/addAttachment.js
453
- *
454
- * @param {object} params JSON with the parameters.
455
- * @param {string} params.key Path or id to the content.
456
- * @param {string} params.name Attachment name.
457
- * @param {string} params.mimeType Attachment content type.
458
- * @param {string} [params.label] Attachment label.
459
- * @param {object} params.data Stream with the binary data for the attachment.
460
- */
461
- export declare function addAttachment(params: AddAttachmentParam): void;
462
- export interface RemoveAttachmentParams {
463
- key: string;
464
- name: string | string[];
465
- }
466
- /**
467
- * Removes an attachment from an existing content.
468
- *
469
- * @example-ref examples/content/removeAttachment.js
470
- *
471
- * @param {object} params JSON with the parameters.
472
- * @param {string} params.key Path or id to the content.
473
- * @param {string|string[]} params.name Attachment name, or array of names.
474
- */
475
- export declare function removeAttachment(params: RemoveAttachmentParams): void;
476
- export interface Site extends Content {
477
- description: string;
478
- }
479
- export interface GetSiteParams {
480
- key?: string | null;
481
- }
482
- /**
483
- * This function returns the parent site of a content.
484
- *
485
- * @example-ref examples/content/getSite.js
486
- *
487
- * @param {object} params JSON with the parameters.
488
- * @param {string} params.key Path or id to the content.
489
- *
490
- * @returns {object} The current site as JSON.
491
- */
492
- export declare function getSite(params: GetSiteParams): Site;
493
- export interface GetSiteConfigParams {
494
- key: string;
495
- applicationKey: string;
496
- }
497
- export declare type SiteConfig = Record<string, unknown>;
498
- /**
499
- * This function returns the site configuration for this app in the parent site of a content.
500
- *
501
- * @example-ref examples/content/getSiteConfig.js
502
- *
503
- * @param {object} params JSON with the parameters.
504
- * @param {string} params.key Path or id to the content.
505
- * @param {string} params.applicationKey Application key.
506
- *
507
- * @returns {object} The site configuration for current application as JSON.
508
- */
509
- export declare function getSiteConfig(params: GetSiteConfigParams): SiteConfig;
510
- export interface DeleteContentParams {
511
- key: string;
512
- }
513
- /**
514
- * This function deletes a content.
515
- *
516
- * @example-ref examples/content/delete.js
517
- *
518
- * @param {object} params JSON with the parameters.
519
- * @param {string} params.key Path or id to the content.
520
- *
521
- * @returns {boolean} True if deleted, false otherwise.
522
- */
523
- declare function _delete(params: DeleteContentParams): boolean;
524
- export { _delete as delete, };
525
- export interface ContentsResult {
526
- total: number;
527
- count: number;
528
- hits: Content[];
529
- aggregations?: Record<string, AggregationsResult>;
530
- highlight?: Record<string, HighlightResult>;
531
- }
532
- export interface GetChildContentParams {
533
- key: string;
534
- start?: number;
535
- count?: number;
536
- sort?: string;
537
- }
538
- /**
539
- * This function fetches children of a content.
540
- *
541
- * @example-ref examples/content/getChildren.js
542
- *
543
- * @param {object} params JSON with the parameters.
544
- * @param {string} params.key Path or id to the parent content.
545
- * @param {number} [params.start=0] Start index (used for paging).
546
- * @param {number} [params.count=10] Number of contents to fetch.
547
- * @param {string} [params.sort] Sorting expression.
548
- *
549
- * @returns {Object} Result (of content) fetched from the repository.
550
- */
551
- export declare function getChildren(params: GetChildContentParams): ContentsResult;
552
- export declare type IdGeneratorSupplier = (value: string) => string;
553
- export interface CreateContentParams {
554
- name?: string;
555
- parentPath: string;
556
- displayName?: string;
557
- requireValid?: boolean;
558
- refresh?: boolean;
559
- contentType: string;
560
- language?: string;
561
- childOrder?: string;
562
- data?: object;
563
- x?: object;
564
- idGenerator: IdGeneratorSupplier;
565
- workflow?: object;
566
- }
567
- /**
568
- * This function creates a content.
569
- *
570
- * The parameter `name` is optional, but if it is not set then `displayName` must be specified. When name is not set, the
571
- * system will auto-generate a `name` based on the `displayName`, by lower-casing and replacing certain characters. If there
572
- * is already a content with the auto-generated name, a suffix will be added to the `name` in order to make it unique.
573
- *
574
- * To create a content where the name is not important and there could be multiple instances under the same parent content,
575
- * skip the `name` parameter and specify a `displayName`.
576
- *
577
- * @example-ref examples/content/create.js
578
- *
579
- * @param {object} params JSON with the parameters.
580
- * @param {string} [params.name] Name of content.
581
- * @param {string} params.parentPath Path to place content under.
582
- * @param {string} [params.displayName] Display name. Default is same as `name`.
583
- * @param {boolean} [params.requireValid=true] The content has to be valid, according to the content type, to be created. If requireValid=true and the content is not strictly valid, an error will be thrown.
584
- * @param {boolean} [params.refresh=true] If refresh is true, the created content will to be searchable through queries immediately, else within 1 second. Since there is a performance penalty doing this refresh, refresh should be set to false for bulk operations.
585
- * @param {string} params.contentType Content type to use.
586
- * @param {string} [params.language] The language tag representing the content’s locale.
587
- * @param {string} [params.childOrder] Default ordering of children when doing getChildren if no order is given in query
588
- * @param {object} params.data Actual content data.
589
- * @param {object} [params.x] eXtra data to use.
590
- * @param {object} [params.workflow] Workflow information to use. Default has state READY and empty check list.
591
- *
592
- * @returns {object} Content created as JSON.
593
- */
594
- export declare function create(params: CreateContentParams): Content;
595
- export interface QueryContentParams {
596
- start?: number;
597
- count?: number;
598
- query?: QueryDsl | string;
599
- filters?: Filter | Filter[];
600
- aggregations?: Record<string, Aggregation>;
601
- sort?: string | object | object[];
602
- contentTypes?: string[];
603
- highlight?: Highlight;
604
- }
605
- /**
606
- * This command queries content.
607
- *
608
- * @example-ref examples/content/query.js
609
- *
610
- * @param {object} params JSON with the parameters.
611
- * @param {number} [params.start=0] Start index (used for paging).
612
- * @param {number} [params.count=10] Number of contents to fetch.
613
- * @param {string|object} params.query Query expression.
614
- * @param {object} [params.filters] Filters to apply to query result
615
- * @param {string|object|object[]} [params.sort] Sorting expression.
616
- * @param {string} [params.aggregations] Aggregations expression.
617
- * @param {string[]} [params.contentTypes] Content types to filter on.
618
- *
619
- * @returns {Object} Result of query.
620
- */
621
- export declare function query(params: QueryContentParams): ContentsResult;
622
- export interface ModifyContentParams {
623
- key: string;
624
- editor: (v: Content) => Content;
625
- requireValid?: boolean;
626
- }
627
- /**
628
- * This function modifies a content.
629
- *
630
- * @example-ref examples/content/modify.js
631
- *
632
- * @param {object} params JSON with the parameters.
633
- * @param {string} params.key Path or id to the content.
634
- * @param {function} params.editor Editor callback function.
635
- * @param {boolean} [params.requireValid=true] The content has to be valid, according to the content type, to be updated. If requireValid=true and the content is not strictly valid, an error will be thrown.
636
- *
637
- * @returns {object} Modified content as JSON.
638
- */
639
- export declare function modify(params: ModifyContentParams): Content;
640
- export interface Schedule {
641
- from?: string;
642
- to?: string;
643
- }
644
- export interface PublishContentParams {
645
- keys: string[];
646
- sourceBranch: string;
647
- targetBranch: string;
648
- schedule: Schedule;
649
- includeChildren?: boolean;
650
- excludeChildrenIds?: string[];
651
- includeDependencies?: boolean;
652
- message: string;
653
- }
654
- export interface PublishContentResult {
655
- pushedContents: string[];
656
- deletedContents: string[];
657
- failedContents: string[];
658
- }
659
- /**
660
- * This function publishes content to a branch.
661
- *
662
- * @example-ref examples/content/publish.js
663
- *
664
- * @param {object} params JSON with the parameters.
665
- * @param {string[]} params.keys List of all content keys(path or id) that should be published.
666
- * @param {string} params.sourceBranch The branch where the content to be published is stored.
667
- * @param {string} params.targetBranch The branch to which the content should be published. Technically, publishing is just a move from one branch
668
- * to another, and publishing user content from master to draft is therefore also valid usage of this function, which may be practical if user input to a web-page is stored on master.
669
- * @param {object} [params.schedule] Schedule the publish.
670
- * @param {string} [params.schedule.from] Time from which the content is considered published. Defaults to the time of the publish
671
- * @param {string} [params.schedule.to] Time until which the content is considered published.
672
- * @param {string[]} [params.excludeChildrenIds] List of all content keys which children should be excluded from publishing content.
673
- * @param {boolean} [params.includeDependencies=true] Whether all related content should be included when publishing content.
674
- * @param {string} params.message Publish message.
675
- *
676
- * @returns {object} Status of the publish operation in JSON.
677
- */
678
- export declare function publish(params: PublishContentParams): PublishContentResult;
679
- export interface UnpublishContentParams {
680
- keys: string[];
681
- }
682
- /**
683
- * This function unpublishes content that had been published to the master branch.
684
- *
685
- * @example-ref examples/content/unpublish.js
686
- *
687
- * @param {object} params JSON with the parameters.
688
- * @param {string[]} params.keys List of all content keys(path or id) that should be unpublished.
689
- *
690
- * @returns {string[]} List with ids of the content that were unpublished.
691
- */
692
- export declare function unpublish(params: UnpublishContentParams): string[];
693
- export interface ContentExistsParams {
694
- key: string;
695
- }
696
- /**
697
- * Check if content exists.
698
- *
699
- * @example-ref examples/content/exists.js
700
- *
701
- * @param {string} params.key content id.
702
- *
703
- * @returns {boolean} True if exist, false otherwise.
704
- */
705
- export declare function exists(params: ContentExistsParams): boolean;
706
- export interface CreateMediaParams {
707
- name: string;
708
- parentPath: string;
709
- mimeType: string;
710
- focalX: string;
711
- focalY: string;
712
- data: string;
713
- idGenerator: (v: string) => string;
714
- }
715
- /**
716
- * Creates a media content.
717
- *
718
- * @example-ref examples/content/createMedia.js
719
- *
720
- * @param {object} params JSON with the parameters.
721
- * @param {string} params.name Name of content.
722
- * @param {string} [params.parentPath=/] Path to place content under.
723
- * @param {string} [params.mimeType] Mime-type of the data.
724
- * @param {number} [params.focalX] Focal point for X axis (if it's an image).
725
- * @param {number} [params.focalY] Focal point for Y axis (if it's an image).
726
- * @param params.data Data (as stream) to use.
727
- *
728
- * @returns {object} Returns the created media content.
729
- */
730
- export declare function createMedia(params: CreateMediaParams): Content;
731
- export interface MoveContentParams {
732
- source: string;
733
- target: string;
734
- }
735
- /**
736
- * Rename a content or move it to a new path.
737
- *
738
- * @example-ref examples/content/move.js
739
- *
740
- * @param {object} params JSON with the parameters.
741
- * @param {string} params.source Path or id of the content to be moved or renamed.
742
- * @param {string} params.target New path or name for the content. If the target ends in slash '/', it specifies the parent path where to be moved. Otherwise it means the new desired path or name for the content.
743
- *
744
- * @returns {object} The content that was moved or renamed.
745
- */
746
- export declare function move(params: MoveContentParams): Content;
747
- export interface ArchiveContentParams {
748
- content: string;
749
- }
750
- /**
751
- * Archive a content.
752
- *
753
- * @example-ref examples/content/archive.js
754
- *
755
- * @param {object} params JSON with the parameters.
756
- * @param {string} params.content Path or id of the content to be archived.
757
- *
758
- * @returns {string[]} List with ids of the contents that were archived.
759
- */
760
- export declare function archive(params: ArchiveContentParams): string[];
761
- export interface RestoreContentParams {
762
- content: string;
763
- path: string;
764
- }
765
- /**
766
- * Restore a content from the archive.
767
- *
768
- * @example-ref examples/content/restore.js
769
- *
770
- * @param {object} params JSON with the parameters.
771
- * @param {string} params.content Path or id of the content to be restored.
772
- * @param {string} params.path Path of parent for restored content.
773
- *
774
- * @returns {string[]} List with ids of the contents that were restored.
775
- */
776
- export declare function restore(params: RestoreContentParams): string[];
777
- export declare type Permission = 'READ' | 'CREATE' | 'MODIFY' | 'DELETE' | 'PUBLISH' | 'READ_PERMISSIONS' | 'WRITE_PERMISSIONS';
778
- export interface AccessControlEntry {
779
- principal: string;
780
- allow?: Permission[];
781
- deny?: Permission[];
782
- }
783
- export interface SetPermissionsParams {
784
- key: string;
785
- inheritPermissions: boolean;
786
- overwriteChildPermissions: boolean;
787
- permissions: AccessControlEntry[];
788
- }
789
- export interface Permissions {
790
- inheritsPermissions: boolean;
791
- permissions?: Permission[];
792
- }
793
- /**
794
- * Sets permissions on a content.
795
- *
796
- * @example-ref examples/content/setPermissions.js
797
- *
798
- * @param {object} params JSON parameters.
799
- * @param {string} params.key Path or id of the content.
800
- * @param {boolean} [params.inheritPermissions] Set to true if the content must inherit permissions. Default to false.
801
- * @param {boolean} [params.overwriteChildPermissions] Set to true to overwrite child permissions. Default to false.
802
- * @param {array} [params.permissions] Array of permissions.
803
- * @param {string} params.permissions.principal Principal key.
804
- * @param {array} params.permissions.allow Allowed permissions.
805
- * @param {array} params.permissions.deny Denied permissions.
806
- * @returns {boolean} True if successful, false otherwise.
807
- */
808
- export declare function setPermissions(params: SetPermissionsParams): boolean;
809
- export interface GetPermissionsParams {
810
- key: string;
811
- }
812
- /**
813
- * Gets permissions on a content.
814
- *
815
- * @example-ref examples/content/getPermissions.js
816
- *
817
- * @param {object} params JSON parameters.
818
- * @param {string} params.key Path or id of the content.
819
- * @returns {object} Content permissions.
820
- */
821
- export declare function getPermissions(params: GetPermissionsParams): Permissions | null;
822
- export interface Icon {
823
- data: object;
824
- mimeType: string;
825
- modifiedTime: string;
826
- }
827
- export interface ContentType {
828
- name: string;
829
- displayName: string;
830
- description: string;
831
- superType: string;
832
- abstract: boolean;
833
- final: boolean;
834
- allowChildContent: boolean;
835
- displayNameExpression: string;
836
- modifiedTime: string;
837
- icon?: Icon;
838
- form: FormItem[];
839
- }
840
- /**
841
- * Returns the properties and icon of the specified content type.
842
- *
843
- * @example-ref examples/content/getType.js
844
- *
845
- * @param name Name of the content type, as 'app:name' (e.g. 'com.enonic.myapp:article').
846
- * @returns {ContentType} The content type object if found, or null otherwise. See ContentType type definition below.
847
- */
848
- export declare function getType(name: string): ContentType;
849
- /**
850
- * Returns the list of all the content types currently registered in the system.
851
- *
852
- * @example-ref examples/content/getTypes.js
853
- *
854
- * @returns {ContentType[]} Array with all the content types found. See ContentType type definition below.
855
- */
856
- export declare function getTypes(): ContentType[];
857
- export interface GetOutboundDependenciesParams {
858
- key: string;
859
- }
860
- /**
861
- * Returns outbound dependencies on a content.
862
- *
863
- * @param {object} params JSON parameters.
864
- * @param {string} params.key Path or id of the content.
865
- * @returns {object} Content Ids.
866
- */
867
- export declare function getOutboundDependencies(params: GetOutboundDependenciesParams): string[];
868
- export interface ResetInheritanceParams {
869
- key: string;
870
- projectName: string;
871
- inherit: ContentInheritType[];
872
- }
873
- export interface ResetInheritanceHandler {
874
- setKey(value: string): void;
875
- setProjectName(value: string): void;
876
- setInherit(value: ContentInheritType[]): void;
877
- execute(): void;
878
- }
879
- /** Resets dropped inherit flags back.
880
- *
881
- * @param {object} params JSON parameters.
882
- * @param {string} params.key Path or id of the content.
883
- * @param {string} params.projectName name of project with content.
884
- * @param {string[]} params.inherit flags to be reset.
885
- */
886
- export declare function resetInheritance(params: ResetInheritanceParams): void;
1
+ /**
2
+ * Functions and constants to find and manipulate content.
3
+ *
4
+ * @example
5
+ * var contentLib = require('/lib/xp/content');
6
+ *
7
+ * @module content
8
+ */
9
+ declare global {
10
+ interface XpLibraries {
11
+ '/lib/xp/content': typeof import('./content');
12
+ }
13
+ }
14
+ declare type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
15
+ export declare const ARCHIVE_ROOT_PATH: string;
16
+ export declare const CONTENT_ROOT_PATH: string;
17
+ export interface GetContentParams {
18
+ key: string;
19
+ versionId?: string | null;
20
+ }
21
+ export interface Attachment {
22
+ name: string;
23
+ label?: string;
24
+ size: number;
25
+ mimeType: string;
26
+ }
27
+ export interface Attachments {
28
+ [key: string]: Attachment;
29
+ }
30
+ export interface PublishInfo {
31
+ from?: string;
32
+ to?: string;
33
+ first?: string;
34
+ }
35
+ export declare type XDataEntry = Record<string, Record<string, unknown>>;
36
+ export declare type XData = Record<string, XDataEntry>;
37
+ export declare type WorkflowState = 'IN_PROGRESS' | 'PENDING_APPROVAL' | 'REJECTED' | 'READY';
38
+ export declare type WorkflowCheckState = 'PENDING' | 'REJECTED' | 'APPROVED';
39
+ export interface Workflow {
40
+ state: WorkflowState;
41
+ checks?: Record<string, WorkflowCheckState>;
42
+ }
43
+ export declare type ContentInheritType = 'CONTENT' | 'PARENT' | 'NAME' | 'SORT';
44
+ export interface Bucket {
45
+ [subAggregationName: string]: BucketsAggregation | StatsAggregation | SingleValueMetricAggregation | string | number | undefined;
46
+ key: string;
47
+ docCount: number;
48
+ }
49
+ export interface NumericBucket extends Bucket {
50
+ from?: number;
51
+ to?: number;
52
+ }
53
+ export interface DateBucket extends Bucket {
54
+ from?: string;
55
+ to?: string;
56
+ }
57
+ export interface BucketsAggregation {
58
+ buckets: (DateBucket | NumericBucket)[];
59
+ }
60
+ export interface StatsAggregation {
61
+ count: number;
62
+ min: number;
63
+ max: number;
64
+ avg: number;
65
+ sum: number;
66
+ }
67
+ export interface SingleValueMetricAggregation {
68
+ value: number;
69
+ }
70
+ export declare type AggregationsResult = BucketsAggregation | StatsAggregation | SingleValueMetricAggregation;
71
+ export declare type Aggregation = TermsAggregation | HistogramAggregation | DateHistogramAggregation | NumericRangeAggregation | DateRangeAggregation | StatsAggregation | GeoDistanceAggregation | MinAggregation | MaxAggregation | ValueCountAggregation;
72
+ export interface TermsAggregation {
73
+ terms: {
74
+ field: string;
75
+ order?: string;
76
+ size?: number;
77
+ minDocCount?: number;
78
+ };
79
+ aggregations?: {
80
+ [subAggregations: string]: Aggregation;
81
+ };
82
+ }
83
+ export interface HistogramAggregation {
84
+ histogram: {
85
+ field: string;
86
+ order?: string;
87
+ interval?: number;
88
+ extendedBoundMin?: number;
89
+ extendedBoundMax?: number;
90
+ minDocCount?: number;
91
+ };
92
+ aggregations?: {
93
+ [subAggregations: string]: Aggregation;
94
+ };
95
+ }
96
+ export interface DateHistogramAggregation {
97
+ dateHistogram: {
98
+ field: string;
99
+ interval?: string;
100
+ minDocCount?: number;
101
+ format: string;
102
+ };
103
+ aggregations?: {
104
+ [subAggregations: string]: Aggregation;
105
+ };
106
+ }
107
+ export interface NumericRange {
108
+ from?: number;
109
+ to?: number;
110
+ key?: string;
111
+ }
112
+ export interface NumericRangeAggregation {
113
+ range: {
114
+ field: string;
115
+ ranges?: NumericRange[];
116
+ };
117
+ aggregations?: {
118
+ [subAggregations: string]: Aggregation;
119
+ };
120
+ }
121
+ export interface NumericRangeAggregation {
122
+ range: {
123
+ field: string;
124
+ ranges?: NumericRange[];
125
+ };
126
+ aggregations?: {
127
+ [subAggregations: string]: Aggregation;
128
+ };
129
+ }
130
+ export interface DateRange {
131
+ from?: string;
132
+ to?: string;
133
+ key?: string;
134
+ }
135
+ export interface DateRangeAggregation {
136
+ dateRange: {
137
+ field: string;
138
+ format: string;
139
+ ranges: DateRange[];
140
+ };
141
+ aggregations?: {
142
+ [subAggregations: string]: Aggregation;
143
+ };
144
+ }
145
+ export interface StatsAggregation {
146
+ stats: {
147
+ field: string;
148
+ };
149
+ }
150
+ export interface GeoDistanceAggregation {
151
+ geoDistance: {
152
+ field: string;
153
+ unit: string;
154
+ origin?: {
155
+ lat: string;
156
+ lon: string;
157
+ };
158
+ ranges?: NumericRange[];
159
+ };
160
+ }
161
+ export interface MinAggregation {
162
+ min: {
163
+ field: string;
164
+ };
165
+ }
166
+ export interface MaxAggregation {
167
+ max: {
168
+ field: string;
169
+ };
170
+ }
171
+ export interface ValueCountAggregation {
172
+ count: {
173
+ field: string;
174
+ };
175
+ }
176
+ export interface Highlight {
177
+ encoder?: 'default' | 'html';
178
+ tagsSchema?: 'styled';
179
+ fragmenter?: 'simple' | 'span';
180
+ fragmentSize?: number;
181
+ noMatchSize?: number;
182
+ numberOfFragments?: number;
183
+ order?: 'score' | 'none';
184
+ preTag?: string;
185
+ postTag?: string;
186
+ requireFieldMatch?: boolean;
187
+ properties?: Record<string, Highlight>;
188
+ }
189
+ export interface HighlightResult {
190
+ [highlightedFieldName: string]: string[];
191
+ }
192
+ export interface ExistsFilter {
193
+ exists: {
194
+ field: string;
195
+ };
196
+ }
197
+ export interface NotExistsFilter {
198
+ notExists: {
199
+ field: string;
200
+ };
201
+ }
202
+ export interface HasValueFilter {
203
+ hasValue: {
204
+ field: string;
205
+ values: unknown[];
206
+ };
207
+ }
208
+ export interface IdsFilter {
209
+ ids: {
210
+ values: string[];
211
+ };
212
+ }
213
+ export interface BooleanFilter {
214
+ boolean: {
215
+ must?: Filter[];
216
+ mustNot?: Filter[];
217
+ should?: Filter[];
218
+ };
219
+ }
220
+ export declare type Filter = ExistsFilter | NotExistsFilter | HasValueFilter | IdsFilter | BooleanFilter;
221
+ export declare type FormItemType = 'Input' | 'ItemSet' | 'Layout' | 'OptionSet';
222
+ export declare type InputType = 'Time' | 'DateTime' | 'CheckBox' | 'ComboBox' | 'Long' | 'Double' | 'RadioButton' | 'TextArea' | 'ContentTypeFilter' | 'GeoPoint' | 'TextLine' | 'Tag' | 'CustomSelector' | 'AttachmentUploader' | 'ContentSelector' | 'MediaSelector' | 'ImageSelector' | 'Date' | 'MediaUploader' | 'SiteConfigurator' | 'HtmlArea';
223
+ export interface FormItemSet {
224
+ formItemType: string | FormItemType;
225
+ name: string;
226
+ label: string;
227
+ customText: string;
228
+ helpText: string;
229
+ maximize: boolean;
230
+ inputType: InputType;
231
+ occurrences: {
232
+ maximum: number;
233
+ minimum: number;
234
+ };
235
+ items: FormItem[];
236
+ }
237
+ export interface FormItemLayout {
238
+ formItemType: string | FormItemType;
239
+ name: string;
240
+ label: string;
241
+ items: FormItem[];
242
+ }
243
+ export declare type ValueType = 'BinaryReference' | 'Boolean' | 'DateTime' | 'Double' | 'GeoPoint' | 'Link' | 'LocalDateTime' | 'LocalDate' | 'LocalTime' | 'Long' | 'PropertySet' | 'Reference' | 'String' | 'Xml';
244
+ export interface FormItemInput {
245
+ formItemType: string | FormItemType;
246
+ name: string;
247
+ label: string;
248
+ customText: string;
249
+ helpText: string;
250
+ validationRegexp: string;
251
+ maximize: boolean;
252
+ inputType: InputType;
253
+ occurrences: {
254
+ maximum: number;
255
+ minimum: number;
256
+ };
257
+ default: {
258
+ value: string;
259
+ type: ValueType;
260
+ };
261
+ config: {
262
+ [configName: string]: {
263
+ [attributeKey: string]: string;
264
+ value: string;
265
+ }[];
266
+ };
267
+ }
268
+ export interface FormItemOptionSet {
269
+ formItemType: string | FormItemType;
270
+ name: string;
271
+ label: string;
272
+ expanded: boolean;
273
+ helpText: string;
274
+ occurrences: {
275
+ maximum: number;
276
+ minimum: number;
277
+ };
278
+ selection: {
279
+ maximum: number;
280
+ minimum: number;
281
+ };
282
+ options: {
283
+ name: string;
284
+ label: string;
285
+ helpText: string;
286
+ default: boolean;
287
+ items: FormItem[];
288
+ }[];
289
+ }
290
+ export declare type FormItem = FormItemSet | FormItemLayout | FormItemOptionSet | FormItemInput;
291
+ export declare type DslQueryType = LiteralUnion<'dateTime' | 'time'> | number | boolean;
292
+ export declare type DslOperator = 'OR' | 'AND';
293
+ export interface TermDslExpression {
294
+ field: string;
295
+ value: unknown;
296
+ type?: DslQueryType;
297
+ boost?: number;
298
+ }
299
+ export interface InDslExpression {
300
+ field: string;
301
+ values: unknown[];
302
+ type?: DslQueryType;
303
+ boost?: number;
304
+ }
305
+ export interface LikeDslExpression {
306
+ field: string;
307
+ value: string;
308
+ type?: DslQueryType;
309
+ boost?: number;
310
+ }
311
+ export interface RangeDslExpression {
312
+ field: string;
313
+ type?: DslQueryType;
314
+ lt?: unknown;
315
+ lte?: unknown;
316
+ gt?: unknown;
317
+ gte?: unknown;
318
+ boost?: number;
319
+ }
320
+ export interface PathMatchDslExpression {
321
+ field: string;
322
+ path: string;
323
+ minimumMatch?: number;
324
+ boost?: number;
325
+ }
326
+ export interface MatchAllDslExpression {
327
+ boost?: number;
328
+ }
329
+ export interface FulltextDslExpression {
330
+ fields: string[];
331
+ query: string;
332
+ operator?: DslOperator;
333
+ }
334
+ export interface NgramDslExpression {
335
+ fields: string[];
336
+ query: string;
337
+ operator?: DslOperator;
338
+ }
339
+ export interface StemmedDslExpression {
340
+ fields: string[];
341
+ query: string;
342
+ language: string;
343
+ }
344
+ export interface BooleanDslExpression {
345
+ should?: DslExpression | DslExpression[];
346
+ must?: DslExpression | DslExpression[];
347
+ mustNot?: DslExpression | DslExpression[];
348
+ filter?: DslExpression | DslExpression[];
349
+ }
350
+ export declare type DslExpression = TermDslExpression | InDslExpression | LikeDslExpression | RangeDslExpression | PathMatchDslExpression | MatchAllDslExpression | FulltextDslExpression | NgramDslExpression | BooleanDslExpression | StemmedDslExpression;
351
+ export declare type QueryDsl = {
352
+ boolean: BooleanDslExpression;
353
+ } | {
354
+ ngram: NgramDslExpression;
355
+ } | {
356
+ fulltext: FulltextDslExpression;
357
+ } | {
358
+ matchAll: MatchAllDslExpression;
359
+ } | {
360
+ pathMatch: PathMatchDslExpression;
361
+ } | {
362
+ range: RangeDslExpression;
363
+ } | {
364
+ like: LikeDslExpression;
365
+ } | {
366
+ in: InDslExpression;
367
+ } | {
368
+ term: TermDslExpression;
369
+ };
370
+ export declare type SortDirection = 'ASC' | 'DESC';
371
+ export declare type DistanceUnit = 'm' | 'meters' | 'in' | 'inch' | 'yd' | 'yards' | 'ft' | 'feet' | 'km' | 'kilometers' | 'NM' | 'nmi' | 'nauticalmiles' | 'mm' | 'millimeters' | 'cm' | 'centimeters' | 'mi' | 'miles';
372
+ export interface FieldSortDsl {
373
+ field: string;
374
+ direction?: SortDirection;
375
+ }
376
+ export interface GeoDistanceSortDsl extends FieldSortDsl {
377
+ unit?: DistanceUnit;
378
+ location?: {
379
+ lat: number;
380
+ lon: number;
381
+ };
382
+ }
383
+ export declare type SortDsl = FieldSortDsl | GeoDistanceSortDsl;
384
+ export interface Content {
385
+ _id: string;
386
+ _name: string;
387
+ _path: string;
388
+ _score: number;
389
+ creator: string;
390
+ modifier: string;
391
+ createdTime: string;
392
+ modifiedTime: string;
393
+ owner: string;
394
+ type: string;
395
+ displayName: string;
396
+ hasChildren: boolean;
397
+ language: string;
398
+ valid: boolean;
399
+ originProject: string;
400
+ childOrder?: string;
401
+ _sort?: object[];
402
+ data: Record<string, unknown>;
403
+ x: XData;
404
+ attachments: Attachments;
405
+ publish?: PublishInfo;
406
+ workflow?: Workflow;
407
+ inherit?: ContentInheritType[];
408
+ }
409
+ /**
410
+ * This function fetches a content.
411
+ *
412
+ * @example-ref examples/content/get.js
413
+ *
414
+ * @param {object} params JSON with the parameters.
415
+ * @param {string} params.key Path or id to the content.
416
+ * @param {string} [params.versionId] Version Id of the content.
417
+ *
418
+ * @returns {object} The content (as JSON) fetched from the repository.
419
+ */
420
+ export declare function get(params: GetContentParams): Content | null;
421
+ /**
422
+ * This function returns a content attachments.
423
+ *
424
+ * @example-ref examples/content/getAttachments.js
425
+ *
426
+ * @param {string} key Path or id to the content.
427
+ *
428
+ * @returns {object} An object with all the attachments that belong to the content, where the key is the attachment name. Or null if the content cannot be found.
429
+ */
430
+ export declare function getAttachments(key: string): Attachments | null;
431
+ export interface GetAttachmentStreamParams {
432
+ key: string;
433
+ name: string;
434
+ }
435
+ /**
436
+ * This function returns a data-stream for the specified content attachment.
437
+ *
438
+ * @example-ref examples/content/getAttachmentStream.js
439
+ *
440
+ * @param {object} params JSON with the parameters.
441
+ * @param {string} params.key Path or id to the content.
442
+ * @param {string} params.name Attachment name.
443
+ *
444
+ * @returns {*} Stream of the attachment data.
445
+ */
446
+ export declare function getAttachmentStream(params: GetAttachmentStreamParams): object | null;
447
+ export interface AddAttachmentParam {
448
+ key: string;
449
+ name: string;
450
+ mimeType: string;
451
+ data: object;
452
+ label?: string;
453
+ }
454
+ /**
455
+ * Adds an attachment to an existing content.
456
+ *
457
+ * @example-ref examples/content/addAttachment.js
458
+ *
459
+ * @param {object} params JSON with the parameters.
460
+ * @param {string} params.key Path or id to the content.
461
+ * @param {string} params.name Attachment name.
462
+ * @param {string} params.mimeType Attachment content type.
463
+ * @param {string} [params.label] Attachment label.
464
+ * @param {object} params.data Stream with the binary data for the attachment.
465
+ */
466
+ export declare function addAttachment(params: AddAttachmentParam): void;
467
+ export interface RemoveAttachmentParams {
468
+ key: string;
469
+ name: string | string[];
470
+ }
471
+ /**
472
+ * Removes an attachment from an existing content.
473
+ *
474
+ * @example-ref examples/content/removeAttachment.js
475
+ *
476
+ * @param {object} params JSON with the parameters.
477
+ * @param {string} params.key Path or id to the content.
478
+ * @param {string|string[]} params.name Attachment name, or array of names.
479
+ */
480
+ export declare function removeAttachment(params: RemoveAttachmentParams): void;
481
+ export interface Site extends Content {
482
+ description: string;
483
+ }
484
+ export interface GetSiteParams {
485
+ key?: string | null;
486
+ }
487
+ /**
488
+ * This function returns the parent site of a content.
489
+ *
490
+ * @example-ref examples/content/getSite.js
491
+ *
492
+ * @param {object} params JSON with the parameters.
493
+ * @param {string} params.key Path or id to the content.
494
+ *
495
+ * @returns {object} The current site as JSON.
496
+ */
497
+ export declare function getSite(params: GetSiteParams): Site | null;
498
+ export interface GetSiteConfigParams {
499
+ key: string;
500
+ applicationKey: string;
501
+ }
502
+ export declare type SiteConfig = Record<string, unknown>;
503
+ /**
504
+ * This function returns the site configuration for this app in the parent site of a content.
505
+ *
506
+ * @example-ref examples/content/getSiteConfig.js
507
+ *
508
+ * @param {object} params JSON with the parameters.
509
+ * @param {string} params.key Path or id to the content.
510
+ * @param {string} params.applicationKey Application key.
511
+ *
512
+ * @returns {object} The site configuration for current application as JSON.
513
+ */
514
+ export declare function getSiteConfig(params: GetSiteConfigParams): SiteConfig | null;
515
+ export interface DeleteContentParams {
516
+ key: string;
517
+ }
518
+ /**
519
+ * This function deletes a content.
520
+ *
521
+ * @example-ref examples/content/delete.js
522
+ *
523
+ * @param {object} params JSON with the parameters.
524
+ * @param {string} params.key Path or id to the content.
525
+ *
526
+ * @returns {boolean} True if deleted, false otherwise.
527
+ */
528
+ declare function _delete(params: DeleteContentParams): boolean;
529
+ export { _delete as delete, };
530
+ export interface ContentsResult {
531
+ total: number;
532
+ count: number;
533
+ hits: Content[];
534
+ aggregations?: Record<string, AggregationsResult>;
535
+ highlight?: Record<string, HighlightResult>;
536
+ }
537
+ export interface GetChildContentParams {
538
+ key: string;
539
+ start?: number;
540
+ count?: number;
541
+ sort?: string;
542
+ }
543
+ /**
544
+ * This function fetches children of a content.
545
+ *
546
+ * @example-ref examples/content/getChildren.js
547
+ *
548
+ * @param {object} params JSON with the parameters.
549
+ * @param {string} params.key Path or id to the parent content.
550
+ * @param {number} [params.start=0] Start index (used for paging).
551
+ * @param {number} [params.count=10] Number of contents to fetch.
552
+ * @param {string} [params.sort] Sorting expression.
553
+ *
554
+ * @returns {Object} Result (of content) fetched from the repository.
555
+ */
556
+ export declare function getChildren(params: GetChildContentParams): ContentsResult;
557
+ export declare type IdGeneratorSupplier = (value: string) => string;
558
+ export interface CreateContentParams {
559
+ name?: string;
560
+ parentPath: string;
561
+ displayName?: string;
562
+ requireValid?: boolean;
563
+ refresh?: boolean;
564
+ contentType: string;
565
+ language?: string;
566
+ childOrder?: string;
567
+ data?: object;
568
+ x?: object;
569
+ idGenerator: IdGeneratorSupplier;
570
+ workflow?: object;
571
+ }
572
+ /**
573
+ * This function creates a content.
574
+ *
575
+ * The parameter `name` is optional, but if it is not set then `displayName` must be specified. When name is not set, the
576
+ * system will auto-generate a `name` based on the `displayName`, by lower-casing and replacing certain characters. If there
577
+ * is already a content with the auto-generated name, a suffix will be added to the `name` in order to make it unique.
578
+ *
579
+ * To create a content where the name is not important and there could be multiple instances under the same parent content,
580
+ * skip the `name` parameter and specify a `displayName`.
581
+ *
582
+ * @example-ref examples/content/create.js
583
+ *
584
+ * @param {object} params JSON with the parameters.
585
+ * @param {string} [params.name] Name of content.
586
+ * @param {string} params.parentPath Path to place content under.
587
+ * @param {string} [params.displayName] Display name. Default is same as `name`.
588
+ * @param {boolean} [params.requireValid=true] The content has to be valid, according to the content type, to be created. If requireValid=true and the content is not strictly valid, an error will be thrown.
589
+ * @param {boolean} [params.refresh=true] If refresh is true, the created content will to be searchable through queries immediately, else within 1 second. Since there is a performance penalty doing this refresh, refresh should be set to false for bulk operations.
590
+ * @param {string} params.contentType Content type to use.
591
+ * @param {string} [params.language] The language tag representing the content’s locale.
592
+ * @param {string} [params.childOrder] Default ordering of children when doing getChildren if no order is given in query
593
+ * @param {object} params.data Actual content data.
594
+ * @param {object} [params.x] eXtra data to use.
595
+ * @param {object} [params.workflow] Workflow information to use. Default has state READY and empty check list.
596
+ *
597
+ * @returns {object} Content created as JSON.
598
+ */
599
+ export declare function create(params: CreateContentParams): Content;
600
+ export interface QueryContentParams {
601
+ start?: number;
602
+ count?: number;
603
+ query?: QueryDsl | string;
604
+ sort?: string | SortDsl | SortDsl[];
605
+ filters?: Filter | Filter[];
606
+ aggregations?: Record<string, Aggregation>;
607
+ contentTypes?: string[];
608
+ highlight?: Highlight;
609
+ }
610
+ /**
611
+ * This command queries content.
612
+ *
613
+ * @example-ref examples/content/query.js
614
+ *
615
+ * @param {object} params JSON with the parameters.
616
+ * @param {number} [params.start=0] Start index (used for paging).
617
+ * @param {number} [params.count=10] Number of contents to fetch.
618
+ * @param {string|object} params.query Query expression.
619
+ * @param {object|object[]} [params.filters] Filters to apply to query result
620
+ * @param {string|object|object[]} [params.sort] Sorting expression.
621
+ * @param {object} [params.aggregations] Aggregations expression.
622
+ * @param {string[]} [params.contentTypes] Content types to filter on.
623
+ *
624
+ * @returns {object} Result of query.
625
+ */
626
+ export declare function query(params: QueryContentParams): ContentsResult;
627
+ export interface ModifyContentParams {
628
+ key: string;
629
+ editor: (v: Content) => Content;
630
+ requireValid?: boolean;
631
+ }
632
+ /**
633
+ * This function modifies a content.
634
+ *
635
+ * @example-ref examples/content/modify.js
636
+ *
637
+ * @param {object} params JSON with the parameters.
638
+ * @param {string} params.key Path or id to the content.
639
+ * @param {function} params.editor Editor callback function.
640
+ * @param {boolean} [params.requireValid=true] The content has to be valid, according to the content type, to be updated. If requireValid=true and the content is not strictly valid, an error will be thrown.
641
+ *
642
+ * @returns {object} Modified content as JSON.
643
+ */
644
+ export declare function modify(params: ModifyContentParams): Content | null;
645
+ export interface Schedule {
646
+ from?: string;
647
+ to?: string;
648
+ }
649
+ export interface PublishContentParams {
650
+ keys: string[];
651
+ sourceBranch: string;
652
+ targetBranch: string;
653
+ schedule: Schedule;
654
+ includeChildren?: boolean;
655
+ excludeChildrenIds?: string[];
656
+ includeDependencies?: boolean;
657
+ message: string;
658
+ }
659
+ export interface PublishContentResult {
660
+ pushedContents: string[];
661
+ deletedContents: string[];
662
+ failedContents: string[];
663
+ }
664
+ /**
665
+ * This function publishes content to a branch.
666
+ *
667
+ * @example-ref examples/content/publish.js
668
+ *
669
+ * @param {object} params JSON with the parameters.
670
+ * @param {string[]} params.keys List of all content keys(path or id) that should be published.
671
+ * @param {string} params.sourceBranch The branch where the content to be published is stored.
672
+ * @param {string} params.targetBranch The branch to which the content should be published. Technically, publishing is just a move from one branch
673
+ * to another, and publishing user content from master to draft is therefore also valid usage of this function, which may be practical if user input to a web-page is stored on master.
674
+ * @param {object} [params.schedule] Schedule the publish.
675
+ * @param {string} [params.schedule.from] Time from which the content is considered published. Defaults to the time of the publish
676
+ * @param {string} [params.schedule.to] Time until which the content is considered published.
677
+ * @param {string[]} [params.excludeChildrenIds] List of all content keys which children should be excluded from publishing content.
678
+ * @param {boolean} [params.includeDependencies=true] Whether all related content should be included when publishing content.
679
+ * @param {string} params.message Publish message.
680
+ *
681
+ * @returns {object} Status of the publish operation in JSON.
682
+ */
683
+ export declare function publish(params: PublishContentParams): PublishContentResult;
684
+ export interface UnpublishContentParams {
685
+ keys: string[];
686
+ }
687
+ /**
688
+ * This function unpublishes content that had been published to the master branch.
689
+ *
690
+ * @example-ref examples/content/unpublish.js
691
+ *
692
+ * @param {object} params JSON with the parameters.
693
+ * @param {string[]} params.keys List of all content keys(path or id) that should be unpublished.
694
+ *
695
+ * @returns {string[]} List with ids of the content that were unpublished.
696
+ */
697
+ export declare function unpublish(params: UnpublishContentParams): string[];
698
+ export interface ContentExistsParams {
699
+ key: string;
700
+ }
701
+ /**
702
+ * Check if content exists.
703
+ *
704
+ * @example-ref examples/content/exists.js
705
+ *
706
+ * @param {string} params.key content id.
707
+ *
708
+ * @returns {boolean} True if exist, false otherwise.
709
+ */
710
+ export declare function exists(params: ContentExistsParams): boolean;
711
+ export interface CreateMediaParams {
712
+ name: string;
713
+ parentPath: string;
714
+ mimeType: string;
715
+ focalX: string;
716
+ focalY: string;
717
+ data: string;
718
+ idGenerator: (v: string) => string;
719
+ }
720
+ /**
721
+ * Creates a media content.
722
+ *
723
+ * @example-ref examples/content/createMedia.js
724
+ *
725
+ * @param {object} params JSON with the parameters.
726
+ * @param {string} params.name Name of content.
727
+ * @param {string} [params.parentPath=/] Path to place content under.
728
+ * @param {string} [params.mimeType] Mime-type of the data.
729
+ * @param {number} [params.focalX] Focal point for X axis (if it's an image).
730
+ * @param {number} [params.focalY] Focal point for Y axis (if it's an image).
731
+ * @param params.data Data (as stream) to use.
732
+ *
733
+ * @returns {object} Returns the created media content.
734
+ */
735
+ export declare function createMedia(params: CreateMediaParams): Content;
736
+ export interface MoveContentParams {
737
+ source: string;
738
+ target: string;
739
+ }
740
+ /**
741
+ * Rename a content or move it to a new path.
742
+ *
743
+ * @example-ref examples/content/move.js
744
+ *
745
+ * @param {object} params JSON with the parameters.
746
+ * @param {string} params.source Path or id of the content to be moved or renamed.
747
+ * @param {string} params.target New path or name for the content. If the target ends in slash '/', it specifies the parent path where to be moved. Otherwise it means the new desired path or name for the content.
748
+ *
749
+ * @returns {object} The content that was moved or renamed.
750
+ */
751
+ export declare function move(params: MoveContentParams): Content;
752
+ export interface ArchiveContentParams {
753
+ content: string;
754
+ }
755
+ /**
756
+ * Archive a content.
757
+ *
758
+ * @example-ref examples/content/archive.js
759
+ *
760
+ * @param {object} params JSON with the parameters.
761
+ * @param {string} params.content Path or id of the content to be archived.
762
+ *
763
+ * @returns {string[]} List with ids of the contents that were archived.
764
+ */
765
+ export declare function archive(params: ArchiveContentParams): string[];
766
+ export interface RestoreContentParams {
767
+ content: string;
768
+ path: string;
769
+ }
770
+ /**
771
+ * Restore a content from the archive.
772
+ *
773
+ * @example-ref examples/content/restore.js
774
+ *
775
+ * @param {object} params JSON with the parameters.
776
+ * @param {string} params.content Path or id of the content to be restored.
777
+ * @param {string} params.path Path of parent for restored content.
778
+ *
779
+ * @returns {string[]} List with ids of the contents that were restored.
780
+ */
781
+ export declare function restore(params: RestoreContentParams): string[];
782
+ export declare type Permission = 'READ' | 'CREATE' | 'MODIFY' | 'DELETE' | 'PUBLISH' | 'READ_PERMISSIONS' | 'WRITE_PERMISSIONS';
783
+ export interface AccessControlEntry {
784
+ principal: string;
785
+ allow?: Permission[];
786
+ deny?: Permission[];
787
+ }
788
+ export interface SetPermissionsParams {
789
+ key: string;
790
+ inheritPermissions: boolean;
791
+ overwriteChildPermissions: boolean;
792
+ permissions: AccessControlEntry[];
793
+ }
794
+ export interface Permissions {
795
+ inheritsPermissions: boolean;
796
+ permissions?: Permission[];
797
+ }
798
+ /**
799
+ * Sets permissions on a content.
800
+ *
801
+ * @example-ref examples/content/setPermissions.js
802
+ *
803
+ * @param {object} params JSON parameters.
804
+ * @param {string} params.key Path or id of the content.
805
+ * @param {boolean} [params.inheritPermissions] Set to true if the content must inherit permissions. Default to false.
806
+ * @param {boolean} [params.overwriteChildPermissions] Set to true to overwrite child permissions. Default to false.
807
+ * @param {array} [params.permissions] Array of permissions.
808
+ * @param {string} params.permissions.principal Principal key.
809
+ * @param {array} params.permissions.allow Allowed permissions.
810
+ * @param {array} params.permissions.deny Denied permissions.
811
+ * @returns {boolean} True if successful, false otherwise.
812
+ */
813
+ export declare function setPermissions(params: SetPermissionsParams): boolean;
814
+ export interface GetPermissionsParams {
815
+ key: string;
816
+ }
817
+ /**
818
+ * Gets permissions on a content.
819
+ *
820
+ * @example-ref examples/content/getPermissions.js
821
+ *
822
+ * @param {object} params JSON parameters.
823
+ * @param {string} params.key Path or id of the content.
824
+ * @returns {object} Content permissions.
825
+ */
826
+ export declare function getPermissions(params: GetPermissionsParams): Permissions | null;
827
+ export interface Icon {
828
+ data: object;
829
+ mimeType: string;
830
+ modifiedTime: string;
831
+ }
832
+ /**
833
+ * @typedef ContentType
834
+ * @type Object
835
+ * @property {string} name Name of the content type.
836
+ * @property {string} displayName Display name of the content type.
837
+ * @property {string} description Description of the content type.
838
+ * @property {string} superType Name of the super type, or null if it has no super type.
839
+ * @property {boolean} abstract Whether or not content of this type may be instantiated.
840
+ * @property {boolean} final Whether or not it may be used as super type of other content types.
841
+ * @property {boolean} allowChildContent Whether or not allow creating child items on content of this type.
842
+ * @property {string} displayNameExpression ES6 string template for generating the content name based on values in the content form.
843
+ * @property {object} [icon] Icon of the content type.
844
+ * @property {object} [icon.data] Stream with the binary data for the icon.
845
+ * @property {string} [icon.mimeType] Mime type of the icon image.
846
+ * @property {string} [icon.modifiedTime] Modified time of the icon. May be used for caching.
847
+ * @property {object[]} form Form schema represented as an array of form items: Input, ItemSet, Layout, OptionSet.
848
+ */
849
+ export interface ContentType {
850
+ name: string;
851
+ displayName: string;
852
+ description: string;
853
+ superType: string;
854
+ abstract: boolean;
855
+ final: boolean;
856
+ allowChildContent: boolean;
857
+ displayNameExpression: string;
858
+ modifiedTime: string;
859
+ icon?: Icon;
860
+ form: FormItem[];
861
+ }
862
+ /**
863
+ * Returns the properties and icon of the specified content type.
864
+ *
865
+ * @example-ref examples/content/getType.js
866
+ *
867
+ * @param name Name of the content type, as 'app:name' (e.g. 'com.enonic.myapp:article').
868
+ * @returns {ContentType} The content type object if found, or null otherwise. See ContentType type definition below.
869
+ */
870
+ export declare function getType(name: string): ContentType | null;
871
+ /**
872
+ * Returns the list of all the content types currently registered in the system.
873
+ *
874
+ * @example-ref examples/content/getTypes.js
875
+ *
876
+ * @returns {ContentType[]} Array with all the content types found. See ContentType type definition below.
877
+ */
878
+ export declare function getTypes(): ContentType[];
879
+ export interface GetOutboundDependenciesParams {
880
+ key: string;
881
+ }
882
+ /**
883
+ * Returns outbound dependencies on a content.
884
+ *
885
+ * @param {object} params JSON parameters.
886
+ * @param {string} params.key Path or id of the content.
887
+ * @returns {object} Content Ids.
888
+ */
889
+ export declare function getOutboundDependencies(params: GetOutboundDependenciesParams): string[];
890
+ export interface ResetInheritanceParams {
891
+ key: string;
892
+ projectName: string;
893
+ inherit: ContentInheritType[];
894
+ }
895
+ export interface ResetInheritanceHandler {
896
+ setKey(value: string): void;
897
+ setProjectName(value: string): void;
898
+ setInherit(value: ContentInheritType[]): void;
899
+ execute(): void;
900
+ }
901
+ /** Resets dropped inherit flags back.
902
+ *
903
+ * @param {object} params JSON parameters.
904
+ * @param {string} params.key Path or id of the content.
905
+ * @param {string} params.projectName name of project with content.
906
+ * @param {string[]} params.inherit flags to be reset.
907
+ */
908
+ export declare function resetInheritance(params: ResetInheritanceParams): void;