@jahia/javascript-modules-library 0.3.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +11 -10
  2. package/bin/jahia-deploy.mjs +27 -0
  3. package/dist/core/server/components/AbsoluteArea.d.ts +39 -0
  4. package/dist/core/server/components/AddContentButtons.d.ts +47 -0
  5. package/dist/core/server/components/AddResources.d.ts +63 -0
  6. package/dist/core/server/components/Area.d.ts +37 -0
  7. package/dist/core/server/components/render/HydrateInBrowser.d.ts +22 -0
  8. package/dist/core/server/components/render/Render.d.ts +31 -0
  9. package/dist/core/server/components/render/RenderInBrowser.d.ts +21 -0
  10. package/dist/core/server/components/render/internal/InBrowser.d.ts +6 -0
  11. package/dist/core/server/framework/defineJahiaComponent.d.ts +9 -0
  12. package/dist/core/server/framework/jahiaComponent.d.ts +28 -0
  13. package/dist/core/server/framework/register.d.ts +11 -0
  14. package/dist/core/server/hooks/useGQLQuery.d.ts +17 -0
  15. package/dist/core/server/hooks/useJCRQuery.d.ts +10 -0
  16. package/dist/core/server/hooks/useServerContext.d.ts +34 -0
  17. package/dist/core/server/hooks/useUrlBuilder.d.ts +52 -0
  18. package/dist/core/server/utils/jcr/getChildNodes.d.ts +14 -0
  19. package/dist/core/server/utils/jcr/getNodeFromPathOrId.d.ts +14 -0
  20. package/dist/core/server/utils/jcr/getNodeProps.d.ts +9 -0
  21. package/dist/core/server/utils/jcr/getNodesByJCRQuery.d.ts +14 -0
  22. package/dist/core/server/utils/urlBuilder/urlBuilder.d.ts +25 -0
  23. package/dist/globals.d.ts +47 -0
  24. package/dist/index.d.ts +38 -0
  25. package/dist/index.js +5 -0
  26. package/dist/nav/server/navBuilder/navBuilder.d.ts +29 -0
  27. package/{types → dist}/org.jahia.modules.javascript.modules.engine.js.server.d.ts +1 -2
  28. package/dist/package.tgz +0 -0
  29. package/package.json +36 -57
  30. package/core/index.js +0 -1
  31. package/core/server/components/AbsoluteArea.js +0 -1
  32. package/core/server/components/AddContentButtons.js +0 -1
  33. package/core/server/components/AddResources.js +0 -1
  34. package/core/server/components/Area.js +0 -1
  35. package/core/server/components/index.js +0 -1
  36. package/core/server/components/render/HydrateInBrowser.js +0 -1
  37. package/core/server/components/render/Render.js +0 -1
  38. package/core/server/components/render/RenderInBrowser.js +0 -1
  39. package/core/server/components/render/index.js +0 -1
  40. package/core/server/components/render/internal/InBrowser.js +0 -1
  41. package/core/server/framework/defineJahiaComponent.js +0 -1
  42. package/core/server/framework/index.js +0 -1
  43. package/core/server/framework/register.js +0 -1
  44. package/core/server/hooks/index.js +0 -1
  45. package/core/server/hooks/useGQLQuery.js +0 -1
  46. package/core/server/hooks/useJCRQuery.js +0 -1
  47. package/core/server/hooks/useServerContext.js +0 -1
  48. package/core/server/hooks/useUrlBuilder.js +0 -1
  49. package/core/server/index.js +0 -1
  50. package/core/server/utils/index.js +0 -1
  51. package/core/server/utils/jcr/getChildNodes.js +0 -1
  52. package/core/server/utils/jcr/getNodeFromPathOrId.js +0 -1
  53. package/core/server/utils/jcr/getNodeProps.js +0 -1
  54. package/core/server/utils/jcr/getNodesByJCRQuery.js +0 -1
  55. package/core/server/utils/jcr/index.js +0 -1
  56. package/core/server/utils/urlBuilder/index.js +0 -1
  57. package/core/server/utils/urlBuilder/urlBuilder.js +0 -1
  58. package/index.js +0 -1
  59. package/nav/index.js +0 -1
  60. package/nav/server/index.js +0 -1
  61. package/nav/server/navBuilder/index.js +0 -1
  62. package/nav/server/navBuilder/navBuilder.js +0 -24
  63. package/types/@jahia/javascript-modules-library-private.d.ts +0 -60
  64. package/types/core/index.d.ts +0 -1
  65. package/types/core/server/components/AbsoluteArea.d.ts +0 -29
  66. package/types/core/server/components/AddContentButtons.d.ts +0 -13
  67. package/types/core/server/components/AddResources.d.ts +0 -31
  68. package/types/core/server/components/Area.d.ts +0 -27
  69. package/types/core/server/components/index.d.ts +0 -5
  70. package/types/core/server/components/render/HydrateInBrowser.d.ts +0 -13
  71. package/types/core/server/components/render/Render.d.ts +0 -23
  72. package/types/core/server/components/render/RenderInBrowser.d.ts +0 -13
  73. package/types/core/server/components/render/index.d.ts +0 -3
  74. package/types/core/server/components/render/internal/InBrowser.d.ts +0 -8
  75. package/types/core/server/framework/defineJahiaComponent.d.ts +0 -41
  76. package/types/core/server/framework/index.d.ts +0 -2
  77. package/types/core/server/framework/register.d.ts +0 -7
  78. package/types/core/server/hooks/index.d.ts +0 -4
  79. package/types/core/server/hooks/useGQLQuery.d.ts +0 -5
  80. package/types/core/server/hooks/useJCRQuery.d.ts +0 -3
  81. package/types/core/server/hooks/useServerContext.d.ts +0 -14
  82. package/types/core/server/hooks/useUrlBuilder.d.ts +0 -31
  83. package/types/core/server/index.d.ts +0 -4
  84. package/types/core/server/utils/index.d.ts +0 -2
  85. package/types/core/server/utils/jcr/getChildNodes.d.ts +0 -9
  86. package/types/core/server/utils/jcr/getNodeFromPathOrId.d.ts +0 -12
  87. package/types/core/server/utils/jcr/getNodeProps.d.ts +0 -7
  88. package/types/core/server/utils/jcr/getNodesByJCRQuery.d.ts +0 -9
  89. package/types/core/server/utils/jcr/index.d.ts +0 -4
  90. package/types/core/server/utils/urlBuilder/index.d.ts +0 -1
  91. package/types/core/server/utils/urlBuilder/urlBuilder.d.ts +0 -27
  92. package/types/globals.d.ts +0 -11
  93. package/types/index.d.ts +0 -19
  94. package/types/nav/index.d.ts +0 -1
  95. package/types/nav/server/index.d.ts +0 -1
  96. package/types/nav/server/navBuilder/index.d.ts +0 -1
  97. package/types/nav/server/navBuilder/navBuilder.d.ts +0 -78
  98. package/types/server.d.ts +0 -27
  99. package/types/servercontext.d.ts +0 -29
  100. /package/{types → dist}/java.io.d.ts +0 -0
  101. /package/{types → dist}/java.net.d.ts +0 -0
  102. /package/{types → dist}/java.security.d.ts +0 -0
  103. /package/{types → dist}/java.util.d.ts +0 -0
  104. /package/{types → dist}/javax.jcr.d.ts +0 -0
  105. /package/{types → dist}/javax.servlet.d.ts +0 -0
  106. /package/{types → dist}/javax.servlet.http.d.ts +0 -0
  107. /package/{types → dist}/org.jahia.services.content.d.ts +0 -0
  108. /package/{types → dist}/org.jahia.services.content.decorator.d.ts +0 -0
  109. /package/{types → dist}/org.jahia.services.query.d.ts +0 -0
  110. /package/{types → dist}/org.jahia.services.render.d.ts +0 -0
  111. /package/{types → dist}/org.jahia.services.usermanager.d.ts +0 -0
  112. /package/{types → dist}/org.osgi.framework.d.ts +0 -0
package/README.md CHANGED
@@ -1,35 +1,36 @@
1
1
  # javascript-modules-library
2
- Javascript Library for NPM Javascript Module Engine
2
+
3
+ Javascript Library for Javascript Module Engine
3
4
 
4
5
  ## Generated types
5
6
 
6
7
  This library contains types generated from Java source code. The types are generated using a tool called java-ts-bind
7
- that was forked here : https://github.com/Jahia/java-ts-bind/tree/finer-excludes . You don't need to checkout this
8
+ that was forked here : https://github.com/Jahia/java-ts-bind/tree/finer-excludes . You don't need to checkout this
8
9
  repository as the scripts will automatically do that for you but we mention it in case you need to make modifications
9
10
  to it.
10
11
 
11
12
  By default, the generated types are committed in this project, but if you need to rebuild/update them, you can do so by
12
13
  using the following steps:
13
14
 
14
- 1. Change to the project directory :
15
+ 1. Change to the project directory :
15
16
 
16
17
  `cd types/generated`
17
18
 
18
- 2. Launch the script that will clone the java-ts-bind repository and build it from source code (it has never been released) :
19
+ 2. Launch the script that will clone the java-ts-bind repository and build it from source code (it has never been released) :
19
20
 
20
21
  `./build.sh`
21
22
 
22
- 3. Update the classes and methods declared in [types/generated/package.json](types/generated/package.json) in case you added/removed classes or methods.
23
+ 3. Update the classes and methods declared in [types/generated/package.json](types/generated/package.json) in case you added/removed classes or methods.
23
24
 
24
- 4. Launch the script that will download all the required source code and JARs for the type generation and that will
25
- also compile the source to generated the required symbols JARs. Then it will generate the types, and finally apply
26
- some post-processing to the generated types to make usable :
25
+ 4. Launch the script that will download all the required source code and JARs for the type generation and that will
26
+ also compile the source to generated the required symbols JARs. Then it will generate the types, and finally apply
27
+ some post-processing to the generated types to make usable :
27
28
 
28
- `./generate.sh`
29
+ `./generate.sh`
29
30
 
30
31
  Note that the generation will take some time on the initial build as it needs to download all the required source code
31
32
  and JARs, and build the projects from the source code.
32
33
 
33
- Once completed, the generated types will be in the following directory :
34
+ Once completed, the generated types will be in the following directory :
34
35
 
35
36
  types/generated/build/types
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ import dotenv from "dotenv";
3
+ import { execSync } from "node:child_process";
4
+ import path from "node:path";
5
+
6
+ dotenv.config();
7
+
8
+ const deployMethod = process.env.JAHIA_DEPLOY_METHOD;
9
+
10
+ const packageFilePath = path.resolve("dist/package.tgz");
11
+
12
+ if (deployMethod === "curl") {
13
+ console.log("Deploying URL curl to Jahia bundles REST API...");
14
+ console.log(
15
+ execSync(
16
+ `curl -s --user ${process.env.JAHIA_USER} --form bundle=@${packageFilePath} --form start=true ${process.env.JAHIA_HOST}/modules/api/bundles`,
17
+ { encoding: "utf8" },
18
+ ),
19
+ );
20
+ } else {
21
+ console.log("Deploying using Docker copy...");
22
+ console.log(
23
+ execSync(`docker cp ${packageFilePath} ${process.env.JAHIA_DOCKER_NAME}:/var/jahia/modules`, {
24
+ encoding: "utf8",
25
+ }),
26
+ );
27
+ }
@@ -0,0 +1,39 @@
1
+ import type React from "react";
2
+ /**
3
+ * Generates an absolute area in which editors may insert content objects.
4
+ *
5
+ * @returns The AbsoluteArea component
6
+ */
7
+ export declare function AbsoluteArea({ name, areaView, allowedTypes, numberOfItems, subNodesView, path, editable, level, areaType, limitedAbsoluteAreaEdit, parameters, }: Readonly<{
8
+ /** The name of the area. */
9
+ name?: string;
10
+ /** The view to use for the area. */
11
+ areaView?: string;
12
+ /** The allowed types for the area. */
13
+ allowedTypes?: string[];
14
+ /** The number of items to display in the area. */
15
+ numberOfItems?: number;
16
+ /** The view to use for the subnodes. */
17
+ subNodesView?: string;
18
+ /** Relative (to the current node) or absolute path to the node to include. */
19
+ path?: string;
20
+ /**
21
+ * Enables or disables edition of this content in edit mode. Mainly used for absolute or
22
+ * references.
23
+ *
24
+ * @default true
25
+ */
26
+ editable?: boolean;
27
+ /** Ancestor level for absolute area - 0 is Home page, 1 first sub-pages, ... */
28
+ level?: number;
29
+ /**
30
+ * Content type to be used to create the area
31
+ *
32
+ * @default jnt:contentList
33
+ */
34
+ areaType?: string;
35
+ /** Is the absolute area editable everywhere or only on the page containing its node. */
36
+ limitedAbsoluteAreaEdit?: boolean;
37
+ /** The parameters to pass to the absolute area */
38
+ parameters?: Record<string, unknown>;
39
+ }>): React.JSX.Element;
@@ -0,0 +1,47 @@
1
+ import type { JSX } from "react";
2
+ /**
3
+ * Generates add content buttons for a content object
4
+ *
5
+ * @returns The add content buttons.
6
+ */
7
+ export declare function AddContentButtons(props: Readonly<{
8
+ /** The node types to add. */
9
+ nodeTypes?: string[];
10
+ /**
11
+ * The child name.
12
+ *
13
+ * @default *
14
+ */
15
+ childName?: string;
16
+ /**
17
+ * If true, the edit check will be performed.
18
+ *
19
+ * @default false
20
+ */
21
+ editCheck?: boolean;
22
+ }>): JSX.Element;
23
+ /**
24
+ * Change nodeTypes="type1 type2 type3" to nodeTypes={["type1", "type2", "type3"]}
25
+ *
26
+ * @deprecated
27
+ */
28
+ export declare function AddContentButtons(props: Readonly<{
29
+ /**
30
+ * Change nodeTypes="type1 type2 type3" to nodeTypes={["type1", "type2", "type3"]}
31
+ *
32
+ * @deprecated
33
+ */
34
+ nodeTypes?: string;
35
+ /**
36
+ * The child name.
37
+ *
38
+ * @default *
39
+ */
40
+ childName?: string;
41
+ /**
42
+ * If true, the edit check will be performed.
43
+ *
44
+ * @default false
45
+ */
46
+ editCheck?: boolean;
47
+ }>): JSX.Element;
@@ -0,0 +1,63 @@
1
+ import type { JSX } from "react";
2
+ /**
3
+ * Adds a resources to the head tag of the HTML page.
4
+ *
5
+ * @returns A React element that renders a script or link tag.
6
+ */
7
+ export declare function AddResources(props: Readonly<{
8
+ /**
9
+ * If true, the resource will be inserted into the document. Typically used for on-demand
10
+ * loading of resources.
11
+ */
12
+ insert?: boolean;
13
+ /**
14
+ * If true, the resource will be loaded asynchronously. For scripts, this means the script will
15
+ * be executed as soon as it's available, without blocking the rest of the page.
16
+ */
17
+ async?: boolean;
18
+ /**
19
+ * If true, the resource will be deferred, i.e., loaded after the document has been parsed. For
20
+ * scripts, this means the script will not be executed until after the page has loaded.
21
+ */
22
+ defer?: boolean;
23
+ /**
24
+ * The type of the resource. This could be 'javascript' for .js files, 'css' for .css files,
25
+ * etc.
26
+ */
27
+ type?: "javascript" | "css";
28
+ /** The path to the resource file, relative to the module. */
29
+ resources?: string;
30
+ /** Inline HTML that markup will be considered as resource. */
31
+ inlineResource?: string;
32
+ /**
33
+ * The title of the resource. This is typically not used for scripts or stylesheets, but may be
34
+ * used for other types of resources.
35
+ */
36
+ title?: string;
37
+ /**
38
+ * A unique key for the resource. This could be used to prevent duplicate resources from being
39
+ * added to the document.
40
+ */
41
+ key?: string;
42
+ /**
43
+ * The HTML tag where the resource should be added. This could be 'head' for resources that
44
+ * should be added to the <head> tag, 'body' for resources that should be added to the <body>
45
+ * tag, etc.
46
+ */
47
+ targetTag?: "head" | "body";
48
+ /**
49
+ * The relationship of the resource to the document. This is typically 'stylesheet' for CSS
50
+ * files.
51
+ */
52
+ rel?: string;
53
+ /**
54
+ * The media for which the resource is intended. This is typically used for CSS files, with
55
+ * values like 'screen', 'print', etc.
56
+ */
57
+ media?: string;
58
+ /**
59
+ * A condition that must be met for the resource to be loaded. This could be used for
60
+ * conditional comments in IE, for example.
61
+ */
62
+ condition?: string;
63
+ }>): JSX.Element;
@@ -0,0 +1,37 @@
1
+ import type { JSX } from "react";
2
+ /**
3
+ * Generates an area in which editors may insert content objects.
4
+ *
5
+ * @returns The Area component
6
+ */
7
+ export declare function Area({ name, areaView, allowedTypes, numberOfItems, subNodesView, path, editable, areaAsSubNode, areaType, parameters, }: Readonly<{
8
+ /** The name of the area. */
9
+ name?: string;
10
+ /** The view to use for the area. */
11
+ areaView?: string;
12
+ /** The allowed types for the area. */
13
+ allowedTypes?: string[];
14
+ /** The number of items to display in the area. */
15
+ numberOfItems?: number;
16
+ /** The view to use for the subnodes. */
17
+ subNodesView?: string;
18
+ /** Relative (to the current node) or absolute path to the node to include. */
19
+ path?: string;
20
+ /**
21
+ * Enables or disables edition of this content in edit mode. Mainly used for absolute or
22
+ * references.
23
+ *
24
+ * @default true
25
+ */
26
+ editable?: boolean;
27
+ /** Allow area to be stored as a subnode */
28
+ areaAsSubNode?: boolean;
29
+ /**
30
+ * Content type to be used to create the area
31
+ *
32
+ * @default jnt:contentList
33
+ */
34
+ areaType?: string;
35
+ /** The parameters to pass to the area */
36
+ parameters?: Record<string, unknown>;
37
+ }>): JSX.Element;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Will render the given React component server side and hydrate it in the browser to make it
3
+ * dynamic. Be careful, the component will not have access to the
4
+ * '@jahia/javascript-modules-library' library from the browser.
5
+ *
6
+ * @returns The component to be hydrated in the browser
7
+ */
8
+ export declare function HydrateInBrowser<T>(props: Readonly<{
9
+ /** The React component. */
10
+ child: React.ComponentType<T>;
11
+ /**
12
+ * The React component props, these props will be serialized/deserialized to be usable server
13
+ * and client side. The serialization is done using
14
+ * [devalue](https://www.npmjs.com/package/devalue) allowing most standard JS types, including
15
+ * `Set` and `Map`.
16
+ */
17
+ props: T & React.JSX.IntrinsicAttributes;
18
+ }>): React.JSX.Element;
19
+ export declare function HydrateInBrowser(props: Readonly<{
20
+ /** The React component. */
21
+ child: React.ComponentType;
22
+ }>): React.JSX.Element;
@@ -0,0 +1,31 @@
1
+ import type { JCRNodeWrapper } from "org.jahia.services.content";
2
+ /**
3
+ * Render a content node
4
+ *
5
+ * @returns The rendered output of the view for the specified content
6
+ */
7
+ export declare function Render({ content, node, path, editable, advanceRenderingConfig, templateType, view, parameters, }: Readonly<{
8
+ /** The content node to render */
9
+ content?: unknown;
10
+ /** The node to render */
11
+ node?: JCRNodeWrapper;
12
+ /** The path to render */
13
+ path?: string;
14
+ /**
15
+ * If the content should be editable
16
+ *
17
+ * @default true
18
+ */
19
+ editable?: boolean;
20
+ /**
21
+ * Specifies if we should render a node or simply include a view. Acceptable values are : none,
22
+ * INCLUDE or OPTION
23
+ */
24
+ advanceRenderingConfig?: "INCLUDE" | "OPTION";
25
+ /** The template type to use (html, json, ...) */
26
+ templateType?: string;
27
+ /** The name of the view variant to use */
28
+ view?: string;
29
+ /** The parameters to pass to the view */
30
+ parameters?: unknown;
31
+ }>): React.JSX.Element;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Will render the given React component in the browser. Be careful, the component will not have
3
+ * access to the '@jahia/javascript-modules-library' library from the browser.
4
+ *
5
+ * @returns The component to be rendered in the browser
6
+ */
7
+ export declare function RenderInBrowser<T>(props: Readonly<{
8
+ /** The React component */
9
+ child: React.ComponentType<T>;
10
+ /**
11
+ * The React component props, these props will be serialized/deserialized to be usable server
12
+ * and client side. The serialization is done using
13
+ * [devalue](https://www.npmjs.com/package/devalue) allowing most standard JS types, including
14
+ * `Set` and `Map`.
15
+ */
16
+ props: T & React.JSX.IntrinsicAttributes;
17
+ }>): React.JSX.Element;
18
+ export declare function RenderInBrowser(props: Readonly<{
19
+ /** The React component */
20
+ child: React.ComponentType;
21
+ }>): React.JSX.Element;
@@ -0,0 +1,6 @@
1
+ declare function InBrowser<T>({ child: Child, props, ssr, }: Readonly<{
2
+ child: React.ComponentType<T>;
3
+ props: T & React.JSX.IntrinsicAttributes;
4
+ ssr?: boolean;
5
+ }>): React.JSX.Element;
6
+ export default InBrowser;
@@ -0,0 +1,9 @@
1
+ import { JahiaComponent } from "./jahiaComponent";
2
+ /**
3
+ * Using this function provides autocomplete on the jahiaComponent properties.
4
+ *
5
+ * @deprecated Use `jahiaComponent()` instead to define and register a component.
6
+ * @param jahiaComponent - An object containing the Jahia component to define.
7
+ * @returns The jahiaComponent object.
8
+ */
9
+ export declare function defineJahiaComponent(jahiaComponent: JahiaComponent): JahiaComponent;
@@ -0,0 +1,28 @@
1
+ import type { JSX } from "react";
2
+ import { type ServerContext } from "../hooks/useServerContext.js";
3
+ export interface JahiaComponent {
4
+ /** The ID of the component (autogenerated but can be overridden) */
5
+ id?: string;
6
+ /**
7
+ * The name of the component.
8
+ *
9
+ * @default "default"
10
+ */
11
+ name?: string;
12
+ /** The display name of the component (in jahia's UI), optional. */
13
+ displayName?: string;
14
+ /** The type of the component. */
15
+ componentType: "template" | "view";
16
+ /** The content node type the component applies to. */
17
+ nodeType: string;
18
+ /** Properties to add on the component, optional. */
19
+ properties?: Record<string, string>;
20
+ }
21
+ /**
22
+ * Defines and registers a Jahia component into the global registry as a view.
23
+ *
24
+ * @param id The ID of the component (autogenerated but can be overridden)
25
+ * @param definitions The definitions of the component
26
+ * @param Component The component to register
27
+ */
28
+ export declare const jahiaComponent: <T extends (props: never, context: ServerContext) => JSX.Element>({ id, ...definitions }: JahiaComponent, Component: T) => T;
@@ -0,0 +1,11 @@
1
+ import type { JahiaComponent } from "./jahiaComponent";
2
+ /**
3
+ * Registers Jahia components into the global registry as views
4
+ *
5
+ * @deprecated Use `jahiaComponent()` instead to define and register a component.
6
+ * @param jahiaComponents An object containing the jahia components to register
7
+ */
8
+ export declare function registerJahiaComponents(jahiaComponents: Record<string | number | symbol, {
9
+ (): React.JSX.Element;
10
+ jahiaComponent: JahiaComponent;
11
+ }>): void;
@@ -0,0 +1,17 @@
1
+ import type { GraphQLFormattedError } from "graphql";
2
+ /**
3
+ * Execute a GraphQL query synchronously
4
+ *
5
+ * @returns The result of the query
6
+ */
7
+ export declare const useGQLQuery: ({ query, variables, operationName, }: {
8
+ /** The GraphQL query to execute */
9
+ query: string;
10
+ /** The variables to use for the query */
11
+ variables?: Record<string, unknown>;
12
+ /** The operation name to use for the query */
13
+ operationName?: string;
14
+ }) => {
15
+ data: any;
16
+ errors?: GraphQLFormattedError[];
17
+ };
@@ -0,0 +1,10 @@
1
+ import type { Node } from "javax.jcr";
2
+ /**
3
+ * Execute a JCR query
4
+ *
5
+ * @returns The result of the query
6
+ */
7
+ export declare const useJCRQuery: ({ query, }: {
8
+ /** The JCR query to execute. */
9
+ query: string;
10
+ }) => Node[];
@@ -0,0 +1,34 @@
1
+ import { type ReactNode } from "react";
2
+ import type { RenderContext, Resource } from "org.jahia.services.render";
3
+ import type { JCRNodeWrapper } from "org.jahia.services.content";
4
+ /**
5
+ * A context object that gives access to the underlying Jahia Java objects that are part of the
6
+ * current rendering context
7
+ */
8
+ export interface ServerContext {
9
+ /**
10
+ * Jahia's rendering context, it provides access to all kinds of context information, such as the
11
+ * current request, response, user, mode, mainResource and more
12
+ */
13
+ renderContext: RenderContext;
14
+ /**
15
+ * The current resource being rendered, which is a combination of the current node and its
16
+ * template/view information
17
+ */
18
+ currentResource: Resource;
19
+ /** The current JCR node being rendered */
20
+ currentNode: JCRNodeWrapper;
21
+ /** The main JCR node being rendered, which is the root node of the current page */
22
+ mainNode: JCRNodeWrapper;
23
+ /** The OSGi bundle key of the current module being rendered */
24
+ bundleKey: string;
25
+ }
26
+ /**
27
+ * Returns the current server context
28
+ *
29
+ * @returns The server context
30
+ */
31
+ export declare function useServerContext(): ServerContext;
32
+ export declare function ServerContextProvider({ renderContext, currentResource, currentNode, mainNode, bundleKey, children, }: ServerContext & {
33
+ readonly children: ReactNode;
34
+ }): React.JSX.Element;
@@ -0,0 +1,52 @@
1
+ interface UrlBuilderType {
2
+ /**
3
+ * Builds a static URL for an asset.
4
+ *
5
+ * @returns The built URL.
6
+ */
7
+ buildStaticUrl(props: {
8
+ /** The path of the asset */
9
+ assetPath: string;
10
+ /**
11
+ * The name of the module used as prefix for the URL. If not provided, the current module is
12
+ * used.
13
+ */
14
+ moduleName?: string;
15
+ /** The parameters to append to the URL */
16
+ parameters?: Record<string, string>;
17
+ }): string;
18
+ /**
19
+ * Builds a URL for a JCR node.
20
+ *
21
+ * @returns {string} The built URL.
22
+ */
23
+ buildNodeUrl(props: {
24
+ /** The path of JCR node */
25
+ nodePath: string;
26
+ /** The extension to use to build the URL */
27
+ extension?: string;
28
+ /** The language to use to build the URL */
29
+ language?: string;
30
+ /** The mode to use to build the URL ('edit', 'preview', 'live') */
31
+ mode?: "edit" | "preview" | "live";
32
+ /** The parameters to append to the URL */
33
+ parameters?: Record<string, string>;
34
+ }): string;
35
+ /**
36
+ * Builds an HTML fragment URL for a JCR node.
37
+ *
38
+ * @returns {string} The built URL.
39
+ */
40
+ buildHtmlFragmentUrl(props: {
41
+ /** The path of JCR node */
42
+ nodePath: string;
43
+ /** The language to use to build the URL */
44
+ language?: string;
45
+ /** The mode to use to build the URL ('edit', 'preview', 'live') */
46
+ mode?: "edit" | "preview" | "live";
47
+ /** The parameters to append to the URL */
48
+ parameters?: Record<string, string>;
49
+ }): string;
50
+ }
51
+ export declare function useUrlBuilder(): UrlBuilderType;
52
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { Node } from "javax.jcr";
2
+ import type { JCRNodeWrapper } from "org.jahia.services.content";
3
+ /**
4
+ * Returns an array of child nodes of a given node.
5
+ *
6
+ * @param node The node to get the child nodes from.
7
+ * @param limit The maximum number of nodes to return (-1 to return all nodes, but be careful with
8
+ * this as it can be very slow and memory consuming, it's better to use a reasonable limit and use
9
+ * pagination if needed)
10
+ * @param offset The offset to start from
11
+ * @param filter A function to filter the nodes to be returned.
12
+ * @returns An array of child nodes.
13
+ */
14
+ export declare function getChildNodes(node: JCRNodeWrapper, limit: number, offset?: number, filter?: ((node: Node) => boolean) | undefined): Node[];
@@ -0,0 +1,14 @@
1
+ import type { JCRNodeWrapper, JCRSessionWrapper } from "org.jahia.services.content";
2
+ /**
3
+ * Returns a node from a path or identifier
4
+ *
5
+ * @param session - The JCR session.
6
+ * @returns The node.
7
+ */
8
+ export declare function getNodeFromPathOrId(props: {
9
+ /** The node identifier */
10
+ identifier: string;
11
+ } | {
12
+ /** The node path */
13
+ path: string;
14
+ }, session: JCRSessionWrapper): JCRNodeWrapper | null;
@@ -0,0 +1,9 @@
1
+ import type { JCRNodeWrapper } from "org.jahia.services.content";
2
+ /**
3
+ * Extracts the properties from a node
4
+ *
5
+ * @param node The node on which to extract the properties
6
+ * @param props The name of the properties to extract
7
+ * @returns An object containing the property values
8
+ */
9
+ export declare function getNodeProps(node: JCRNodeWrapper, props: string[]): Record<string, any>;
@@ -0,0 +1,14 @@
1
+ import type { Node } from "javax.jcr";
2
+ import type { JCRSessionWrapper } from "org.jahia.services.content";
3
+ /**
4
+ * Execute a JCR SQL2 query and return the result as an array of nodes
5
+ *
6
+ * @param session The JCR session to use
7
+ * @param query The JCR SQL2 query to execute
8
+ * @param limit The maximum number of nodes to return (-1 to return all nodes, but be careful with
9
+ * this as it can be very slow and memory consuming, it's better to use a reasonable limit and use
10
+ * pagination if needed)
11
+ * @param offset The offset to start from
12
+ * @returns An array containing the nodes returned by the query
13
+ */
14
+ export declare function getNodesByJCRQuery(session: JCRSessionWrapper, query: string, limit: number, offset?: number): Node[];
@@ -0,0 +1,25 @@
1
+ import type { RenderContext, Resource } from "org.jahia.services.render";
2
+ /** Initialize the registry with default url builders */
3
+ export declare function initUrlBuilder(): void;
4
+ /**
5
+ * Provide URL generation for contents/files If parameters are not valid, or if a node couldn't be
6
+ * found, it will log an warning and return '#'
7
+ *
8
+ * @param renderContext The current renderContext
9
+ * @param currentResource The current resource
10
+ * @returns The final URL
11
+ */
12
+ export declare function buildUrl(props: {
13
+ /** The path of the resource to build the URL for */
14
+ value?: string;
15
+ /** The path of the resource to build the URL for */
16
+ path?: string;
17
+ /** The parameters to append to the URL */
18
+ parameters?: Record<string, string>;
19
+ /** The mode to use to build the URL */
20
+ mode?: string;
21
+ /** The language to use to build the URL */
22
+ language?: string;
23
+ /** The extension to use to build the URL */
24
+ extension?: string;
25
+ }, renderContext: RenderContext, currentResource: Resource): string;
@@ -0,0 +1,47 @@
1
+ /** The global declarations, where top-level objects are exposed to server-side scripts */
2
+ declare global {
3
+ import type { Bundle } from "org.osgi.framework";
4
+
5
+ /**
6
+ * Exposed only during the server-side initial script registration process, not available during
7
+ * rendering
8
+ */
9
+ export const bundle: Bundle;
10
+ }
11
+
12
+ /**
13
+ * This module is used for internal compilation of the project. It should not be used directly in
14
+ * your code.
15
+ */
16
+ declare module "virtual:jahia-server" {
17
+ import type {
18
+ ConfigHelper,
19
+ GQLHelper,
20
+ OSGiHelper,
21
+ RegistryHelper,
22
+ RenderHelper,
23
+ } from "org.jahia.modules.javascript.modules.engine.js.server";
24
+ /**
25
+ * A set of helpers that provide common functionality provided by Jahia for Javascript server-side
26
+ * rendering
27
+ */
28
+ const server: {
29
+ /** This helper provides access to OSGi configuration */
30
+ config: ConfigHelper;
31
+ /** This helper provides access Jahia's GraphQL API, to execute queries and mutations */
32
+ gql: GQLHelper;
33
+ /** This helper provides access to OSGi bundle for resource loading and service access */
34
+ osgi: OSGiHelper;
35
+ /**
36
+ * This helper provides access to Jahia's registry API, to register new UI objects or retrieving
37
+ * existing ones
38
+ */
39
+ registry: RegistryHelper;
40
+ /**
41
+ * This helper provides rendering functions such as registering page resources, adding cache
42
+ * dependencies or rendering components
43
+ */
44
+ render: RenderHelper;
45
+ };
46
+ export default server;
47
+ }