@jahia/javascript-modules-library 0.0.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 (87) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +35 -0
  3. package/core/index.js +1 -0
  4. package/core/server/components/AbsoluteArea.js +1 -0
  5. package/core/server/components/AddContentButtons.js +1 -0
  6. package/core/server/components/AddResources.js +1 -0
  7. package/core/server/components/Area.js +1 -0
  8. package/core/server/components/index.js +1 -0
  9. package/core/server/components/render/HydrateInBrowser.js +1 -0
  10. package/core/server/components/render/Render.js +1 -0
  11. package/core/server/components/render/RenderInBrowser.js +1 -0
  12. package/core/server/components/render/index.js +1 -0
  13. package/core/server/components/render/internal/InBrowser.js +1 -0
  14. package/core/server/framework/defineJahiaComponent.js +1 -0
  15. package/core/server/framework/index.js +1 -0
  16. package/core/server/framework/register.js +1 -0
  17. package/core/server/hooks/index.js +1 -0
  18. package/core/server/hooks/useGQLQuery.js +1 -0
  19. package/core/server/hooks/useJCRQuery.js +1 -0
  20. package/core/server/hooks/useServerContext.js +1 -0
  21. package/core/server/hooks/useUrlBuilder.js +1 -0
  22. package/core/server/index.js +1 -0
  23. package/core/server/utils/index.js +1 -0
  24. package/core/server/utils/jcr/getChildNodes.js +1 -0
  25. package/core/server/utils/jcr/getNodeFromPathOrId.js +1 -0
  26. package/core/server/utils/jcr/getNodeProps.js +1 -0
  27. package/core/server/utils/jcr/getNodesByJCRQuery.js +1 -0
  28. package/core/server/utils/jcr/index.js +1 -0
  29. package/core/server/utils/urlBuilder/index.js +1 -0
  30. package/core/server/utils/urlBuilder/urlBuilder.js +1 -0
  31. package/index.js +1 -0
  32. package/nav/index.js +1 -0
  33. package/nav/server/index.js +1 -0
  34. package/nav/server/navBuilder/index.js +1 -0
  35. package/nav/server/navBuilder/navBuilder.js +24 -0
  36. package/package.json +60 -0
  37. package/types/@jahia/javascript-modules-library-private.d.ts +60 -0
  38. package/types/core/index.d.ts +1 -0
  39. package/types/core/server/components/AbsoluteArea.d.ts +29 -0
  40. package/types/core/server/components/AddContentButtons.d.ts +13 -0
  41. package/types/core/server/components/AddResources.d.ts +31 -0
  42. package/types/core/server/components/Area.d.ts +27 -0
  43. package/types/core/server/components/index.d.ts +5 -0
  44. package/types/core/server/components/render/HydrateInBrowser.d.ts +13 -0
  45. package/types/core/server/components/render/Render.d.ts +23 -0
  46. package/types/core/server/components/render/RenderInBrowser.d.ts +13 -0
  47. package/types/core/server/components/render/index.d.ts +3 -0
  48. package/types/core/server/components/render/internal/InBrowser.d.ts +8 -0
  49. package/types/core/server/framework/defineJahiaComponent.d.ts +41 -0
  50. package/types/core/server/framework/index.d.ts +2 -0
  51. package/types/core/server/framework/register.d.ts +7 -0
  52. package/types/core/server/hooks/index.d.ts +4 -0
  53. package/types/core/server/hooks/useGQLQuery.d.ts +5 -0
  54. package/types/core/server/hooks/useJCRQuery.d.ts +3 -0
  55. package/types/core/server/hooks/useServerContext.d.ts +14 -0
  56. package/types/core/server/hooks/useUrlBuilder.d.ts +31 -0
  57. package/types/core/server/index.d.ts +4 -0
  58. package/types/core/server/utils/index.d.ts +2 -0
  59. package/types/core/server/utils/jcr/getChildNodes.d.ts +9 -0
  60. package/types/core/server/utils/jcr/getNodeFromPathOrId.d.ts +12 -0
  61. package/types/core/server/utils/jcr/getNodeProps.d.ts +7 -0
  62. package/types/core/server/utils/jcr/getNodesByJCRQuery.d.ts +9 -0
  63. package/types/core/server/utils/jcr/index.d.ts +4 -0
  64. package/types/core/server/utils/urlBuilder/index.d.ts +1 -0
  65. package/types/core/server/utils/urlBuilder/urlBuilder.d.ts +27 -0
  66. package/types/globals.d.ts +11 -0
  67. package/types/index.d.ts +19 -0
  68. package/types/java.io.d.ts +694 -0
  69. package/types/java.net.d.ts +190 -0
  70. package/types/java.security.d.ts +27 -0
  71. package/types/java.util.d.ts +1536 -0
  72. package/types/javax.jcr.d.ts +1250 -0
  73. package/types/javax.servlet.d.ts +426 -0
  74. package/types/javax.servlet.http.d.ts +1431 -0
  75. package/types/nav/index.d.ts +1 -0
  76. package/types/nav/server/index.d.ts +1 -0
  77. package/types/nav/server/navBuilder/index.d.ts +1 -0
  78. package/types/nav/server/navBuilder/navBuilder.d.ts +78 -0
  79. package/types/org.jahia.modules.npm.modules.engine.js.server.d.ts +292 -0
  80. package/types/org.jahia.services.content.d.ts +1463 -0
  81. package/types/org.jahia.services.content.decorator.d.ts +92 -0
  82. package/types/org.jahia.services.query.d.ts +35 -0
  83. package/types/org.jahia.services.render.d.ts +168 -0
  84. package/types/org.jahia.services.usermanager.d.ts +85 -0
  85. package/types/org.osgi.framework.d.ts +1004 -0
  86. package/types/server.d.ts +27 -0
  87. package/types/servercontext.d.ts +29 -0
@@ -0,0 +1 @@
1
+ export * from "./server";
@@ -0,0 +1 @@
1
+ export * from "./navBuilder";
@@ -0,0 +1 @@
1
+ export * from "./navBuilder";
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Build a navigation menu
3
+ * @param {number} maxDepth the maximum depth of the menu
4
+ * @param {string} base the base path of the menu
5
+ * @param {string} menuEntryView the view to use for each menu entry
6
+ * @param {number} startLevelValue the level at which to start the menu
7
+ * @param {import('org.jahia.services.render').RenderContext} renderContext the current render context
8
+ * @param {import('org.jahia.services.render').Resource} currentResource the current resource
9
+ * @returns {MenuEntry[]} an array of menu entries objects
10
+ */
11
+ export function buildNavMenu(maxDepth: number, base: string, menuEntryView: string, startLevelValue: number, renderContext: import('org.jahia.services.render').RenderContext, currentResource: import('org.jahia.services.render').Resource): MenuEntry[];
12
+ export type MenuItemChild = {
13
+ /**
14
+ * - The page of a menu item child node
15
+ */
16
+ path: string;
17
+ };
18
+ export type MenuEntry = {
19
+ /**
20
+ * - The HTML rendered HTML menu entry
21
+ */
22
+ render: string;
23
+ /**
24
+ * - The node object for the menu entry
25
+ */
26
+ node: import('org.jahia.services.content').JCRNodeWrapper;
27
+ /**
28
+ * - Whether the node is in the path.
29
+ */
30
+ inPath: boolean;
31
+ /**
32
+ * - Whether the node is selected.
33
+ */
34
+ selected: boolean;
35
+ /**
36
+ * - The level of the node.
37
+ */
38
+ level: number;
39
+ /**
40
+ * - The children of the node
41
+ */
42
+ children?: MenuEntry[];
43
+ };
44
+ export type MenuConfig = {
45
+ /**
46
+ * - The current render context
47
+ */
48
+ renderContext: import('org.jahia.services.render').RenderContext;
49
+ /**
50
+ * - The current resource
51
+ */
52
+ currentResource: import('org.jahia.services.render').Resource;
53
+ /**
54
+ * - The workspace to use: 'default' for the edit workspace, 'live' for the live workspace
55
+ */
56
+ workspace: string;
57
+ /**
58
+ * - The name of the menu, used to match with the displayInMenuName property to see if this
59
+ * entry should be displayed in this specified menu
60
+ */
61
+ menuName: string;
62
+ /**
63
+ * - The level at which to start the menu
64
+ */
65
+ startLevelValue: number;
66
+ /**
67
+ * - The maximum depth of the menu
68
+ */
69
+ maxDepth: number;
70
+ /**
71
+ * - The view to use for each menu entry
72
+ */
73
+ menuEntryView?: string;
74
+ /**
75
+ * - The main resource node
76
+ */
77
+ mainResourceNode: import('org.jahia.services.content').JCRNodeWrapper;
78
+ };
@@ -0,0 +1,292 @@
1
+ declare module 'org.jahia.modules.npm.modules.engine.js.server' {
2
+ import { Bundle } from 'org.osgi.framework';
3
+ import { Collection, List, Map } from 'java.util';
4
+
5
+ import { JCRNodeWrapper, JCRCallback } from 'org.jahia.services.content';
6
+ import { Promise } from 'org.jahia.modules.npm.modules.engine.jsengine';
7
+
8
+ import { JCRSiteNode } from 'org.jahia.services.content.decorator';
9
+ import { RenderContext, Resource } from 'org.jahia.services.render';
10
+ /**
11
+ * Java helper to expose OSGi configuration values to Javascript code
12
+ */
13
+ export class ConfigHelper {
14
+ /**
15
+ * Get the list of OSGi configuration PIDs
16
+ * @return an array of String containing the OSGi configuration PIDs
17
+ */
18
+ getConfigPids(): string[];
19
+ /**
20
+ * Get the list of OSGi configuration factory PIDs for a given factory ID
21
+ * @return an array of String containing the OSGi configuration factory PIDs
22
+ */
23
+ getConfigFactoryIdentifiers(factoryPid: string): string[];
24
+ /**
25
+ * Get the configuration values for a given OSGi configuration PID
26
+ * @param configPid the unique identifier of the OSGi configuration
27
+ * @return a Map<String, Object> containing the configuration values
28
+ */
29
+ getConfigValues(configPid: string): any;
30
+ /**
31
+ * Get the configuration values for a given OSGi configuration factory PID and factory identifier
32
+ * @param factoryPid the factory PID
33
+ * @param factoryIdentifier the factory identifier within the given factory PID
34
+ * @return a Map<String, Object> containing the configuration values
35
+ */
36
+ getConfigFactoryValues(factoryPid: string, factoryIdentifier: string): any;
37
+ /**
38
+ * Get a single configuration value for a given OSGi configuration PID and a property key
39
+ * @param configPid the unique identifier of the OSGi configuration
40
+ * @param key the property key
41
+ * @return a String containing the configuration value
42
+ */
43
+ getConfigValue(configPid: string, key: string): string;
44
+ /**
45
+ * Get a single configuration value for a given OSGi configuration factory PID, factory identifier and a
46
+ * property key
47
+ * @param factoryPid the factory PID
48
+ * @param factoryIdentifier the factory identifier within the given factory PID
49
+ * @param key the property key
50
+ * @return a String containing the configuration value
51
+ */
52
+ getConfigFactoryValue(factoryPid: string, factoryIdentifier: string, key: string): string;
53
+ }
54
+ /**
55
+ * Helper class to execute GraphQL queries. It provides both synchronous and asynchronous methods to execute queries.
56
+ */
57
+ export class GQLHelper {
58
+ /**
59
+ * Execute an asynchronous GraphQL query using the specified parameters and return a Promise that will be resolved with the result
60
+ * @param parameters the parameters can contain the following keys:
61
+ *
62
+ * query (string) : the GraphQL query to be executed
63
+ * operationName (string) : the GraphQL operation name
64
+ * variables: the variables as a JSON string or a Map<String, Object>
65
+ * renderContext (RenderContext) : the render context
66
+ * if the renderContext is null, a request will be created with the parameters that were passed,
67
+ * otherwise the request from the renderContext will be used.
68
+ *
69
+ * @return a Promise that will be resolved with the result of the query as a JSON structure or with an error message
70
+ * if there was an error executing the query
71
+ */
72
+ executeQuery(parameters: any): Promise<any>;
73
+ /**
74
+ * Execute a synchronous GraphQL query using the specified parameters and return the result
75
+ * @param parameters the parameters can contain the following keys:
76
+ *
77
+ * query (string) : the GraphQL query to be executed
78
+ * operationName (string) : the GraphQL operation name
79
+ * variables: the variables as a JSON string or a Map<String, Object>
80
+ * renderContext (RenderContext) : the render context
81
+ * if the renderContext is null, a request will be created with the parameters that were passed,
82
+ * otherwise the request from the renderContext will be used.
83
+ *
84
+ * @return the result of the query as a JSON structure
85
+ * @throws ServletException
86
+ * @throws IOException
87
+ */
88
+ executeQuerySync(parameters: any): any;
89
+ }
90
+ /**
91
+ * Helper class to perform JCR operations.
92
+ */
93
+ export class JcrHelper {
94
+ /**
95
+ * Execute JCR operations on a JCR session authenticated using the guest user and the "live" workspace.
96
+ * This is intended for server-side use. Example:
97
+ * * import {server, useServerContext} from '@jahia/javascript-modules-library';
98
+ * ...
99
+ * const {renderContext, currentResource} = useServerContext();
100
+ * server.jcr.doExecuteAsGuest(session => performJcrOperations(session, renderContext, currentResource));
101
+ *
102
+ *
103
+ * @param callback the callback to execute using the JCR session
104
+ * @return the result of the callback
105
+ */
106
+ doExecuteAsGuest(callback: JCRCallback<any>): any;
107
+ }
108
+ /**
109
+ * Helper class to make it possible to access OSGi bundle resources from the JavaScript engine
110
+ */
111
+ export class OSGiHelper {
112
+ /**
113
+ * Get the Osgi Bundle by symbolic name
114
+ * @param symbolicName the symbolic name for the bundle
115
+ * @return if successful, the Bundle, otherwise null
116
+ */
117
+ getBundle(symbolicName: string): Bundle;
118
+ /**
119
+ * Load a resource from an OSGi bundle
120
+ * @param bundle the bundle to load the resource from
121
+ * @param path the path to the resource in the bundle
122
+ * @param optional if false an error message will be logged if the resource is not found, otherwise null will be returned
123
+ * @return a String containing the content of the resource if it was found, null otherwise
124
+ * @throws RenderException
125
+ */
126
+ loadResource(bundle: Bundle, path: string, optional: boolean): string;
127
+ /**
128
+ * Load a properties resource from an OSGi bundle
129
+ * @param bundle the bundle to load the resource from
130
+ * @param path the path to the resource in the bundle
131
+ * @return A Map<String,String> containing the properties
132
+ * @throws RenderException
133
+ */
134
+ loadPropertiesResource(bundle: Bundle, path: string): any;
135
+ lookupComponentPaths(bundle: Bundle, extension: string): Collection<string>;
136
+ }
137
+ /**
138
+ * Helper class to make it possible to access the registry from the JavaScript engine
139
+ */
140
+ export class RegistryHelper {
141
+ /**
142
+ * Get an object from the registry by type and key
143
+ * @param type the type of the object to retrieve
144
+ * @param key the key in the type of the object to retrieve
145
+ * @return the object if found as a Map<String,Object>, otherwise null
146
+ */
147
+ get(type: string, key: string): any;
148
+ /**
149
+ * Search objects from the registry by using a map filter. The filter is a map of key-value pairs that will be used
150
+ * to match objects that have the same values for the keys specified in the filter.
151
+ * @param filter a map of key-value pairs to filter the objects to retrieve
152
+ * @return a List of matching objects
153
+ */
154
+ find(filter: any): any[];
155
+ /**
156
+ * Search objects from the registry by using a map filter and an order by clause. The filter is a map of key-value
157
+ * pairs that will be used to match objects that have the same values for the keys specified in the filter.
158
+ * @param filter a map of key-value pairs to filter the objects to retrieve
159
+ * @param orderBy a string representing the key to use to order the resulting objects. Not that this only works if
160
+ * the key refers to an integer value
161
+ * @return a sorted List of matching objects
162
+ */
163
+ find(filter: any, orderBy: string): any[];
164
+ /**
165
+ * Add a new object in the registry. The object is a map of key-value pairs that will be stored using the specified
166
+ * type and key. Note that if the object already exists, an exception will be thrown. If you want to force the
167
+ * object to be store you should instead use the addOrReplace method.
168
+ * @param type the type of the object to store
169
+ * @param key the key of the object to store within the type
170
+ * @param arguments a Map of key-value pairs representing the object to store
171
+ */
172
+ add(type: string, key: string, ...arguments: any[]): void;
173
+ /**
174
+ * Add a new object in the registry or replace an existing one. The object is a map of key-value pairs that will be
175
+ * stored using the specified type and key. If the object already exists, it will be replaced by the new one.
176
+ * @param type the type of the object to store
177
+ * @param key the key of the object to store within the type
178
+ * @param arguments a Map of key-value pairs representing the object to store
179
+ */
180
+ addOrReplace(type: string, key: string, ...arguments: any[]): void;
181
+ /**
182
+ * Remove an object from the registry by type and key
183
+ * @param type the type of the object to remove
184
+ * @param key the key of the object to remove within the type
185
+ */
186
+ remove(type: string, key: string): void;
187
+ }
188
+ /**
189
+ * Helper class to provide rendering functions to the Javascript engine
190
+ */
191
+ export class RenderHelper {
192
+ transformToJsNode(node: JCRNodeWrapper, includeChildren: boolean, includeDescendants: boolean, includeAllTranslations: boolean): any;
193
+ /**
194
+ * Get the render parameters for the given resource
195
+ * @param resource the resource for which to retrieve the render parameters
196
+ * @return a Map<String,Object> containing the render parameters
197
+ */
198
+ getRenderParameters(resource: Resource): any;
199
+ /**
200
+ * Does a URL encoding of the path. The characters that
201
+ * don't need encoding are those defined 'unreserved' in section 2.3 of
202
+ * the 'URI generic syntax' RFC 2396. Not the entire path string is escaped,
203
+ * but every individual part (i.e. the slashes are not escaped).
204
+ * @param path the path to encode
205
+ * @return a String containing the escaped path
206
+ * @throws NullPointerException if path is null.
207
+ */
208
+ escapePath(path: string): string;
209
+ /**
210
+ * Find the first displayable node in the given node's hierarchy. A displayable node is a node that has a content
211
+ * or page template associated with it.
212
+ * @param node the node at which to start the resolution
213
+ * @param renderContext the current render context
214
+ * @param contextSite the site in which to resolve the template
215
+ * @return the first displayable {@link JCRNodeWrapper} found in the hierarchy
216
+ */
217
+ findDisplayableNode(node: JCRNodeWrapper, renderContext: RenderContext, contextSite: JCRSiteNode): JCRNodeWrapper;
218
+ /**
219
+ * Returns the node which corresponds to the bound component of the j:bindedComponent property in the specified node.
220
+ * @param node the node to get the bound component for
221
+ * @param context current render context
222
+ * @return the bound {@link JCRNodeWrapper}
223
+ */
224
+ getBoundNode(node: JCRNodeWrapper, context: RenderContext): JCRNodeWrapper;
225
+ renderComponent(attr: any, renderContext: RenderContext): string;
226
+ createContentButtons(childName: string, nodeTypes: string, editCheck: boolean, renderContext: RenderContext, currentResource: Resource): string;
227
+ render(attr: any, renderContext: RenderContext, currentResource: Resource): string;
228
+ /**
229
+ * Render a tag that adds resources to the page. Resources might for example be CSS files, Javascript files or inline
230
+ * @param attr may contain the following:
231
+ *
232
+ * insert (boolean) : If true, the resource will be inserted into the document. Typically used
233
+ * for on-demand loading of resources.
234
+ * async (boolean) : If true, the resource will be loaded asynchronously. For scripts, this means
235
+ * the script
236
+ * will be executed as soon as it's available, without blocking the rest of the page.
237
+ * defer (boolean) : If true, the resource will be deferred, i.e., loaded after the document
238
+ * has been parsed.
239
+ * For scripts, this means the script will not be executed until after the page has loaded.
240
+ * type (string) : The type of the resource. This could be 'javascript' for .js files, 'css' for
241
+ * .css files, etc.
242
+ * The type will be used to resolve the directory in the module where the resources are located. For example
243
+ * for the 'css' type it will look for the resources in the css directory of the module.
244
+ * resources (string) : The path to the resource file, relative to the module. It is also allowed to
245
+ * specify multiple resources by separating them with commas. It is also allowed to use absolute URLs to
246
+ * include remote resources.
247
+ * inlineResource (string) : Inline HTML that markup will be considered as a resource.
248
+ * title (string) : The title of the resource. This is typically not used for scripts or stylesheets,
249
+ * but may be used for other types of resources.
250
+ * key (string) : A unique key for the resource. This could be used to prevent duplicate resources
251
+ * from being added to the document.
252
+ * targetTag (string): The HTML tag where the resource should be added. This could be 'head' for
253
+ * resources that should be added to the <head> tag, 'body' for resources that should be added to
254
+ * the <body> tag, etc.
255
+ * rel (string) : The relationship of the resource to the document. This is typically 'stylesheet'
256
+ * for CSS files.
257
+ * media (string) : The media for which the resource is intended. This is typically used for CSS
258
+ * files, with values like 'screen', 'print', etc.
259
+ * condition (string) : A condition that must be met for the resource to be loaded. This could be
260
+ * used for conditional comments in IE, for example.
261
+ *
262
+ * @param renderContext the current rendering context
263
+ * @return a String containing the rendered HTML tags for the provided resources.
264
+ * @throws IllegalAccessException if the underlying tag cannot be accessed
265
+ * @throws InvocationTargetException if the underlying tag cannot be invoked
266
+ * @throws JspException if the underlying tag throws a JSP exception
267
+ * @throws IOException if the underlying tag throws an IO exception
268
+ */
269
+ addResources(attr: any, renderContext: RenderContext): string;
270
+ /**
271
+ * Add a cache dependency to the current resource. This will be used to flush the current resource when the
272
+ * dependencies are modified.
273
+ * @param attr may be the following:
274
+ *
275
+ * node (JCRNodeWrapper) : The node to add as a dependency.
276
+ * uuid (String) : The UUID of the node to add as a dependency.
277
+ * path (String) : The path of the node to add as a dependency.
278
+ * flushOnPathMatchingRegexp (String) : A regular expression that will be used to flush the cache
279
+ * when the path of the modified nodes matches the regular expression.
280
+ *
281
+ * @param renderContext the current rendering context
282
+ * @throws IllegalAccessException if the underlying tag cannot be accessed
283
+ * @throws InvocationTargetException if the underlying tag cannot be invoked
284
+ * @throws JspException if the underlying tag throws a JSP exception
285
+ * @throws IOException if the underlying tag throws an IO exception
286
+ */
287
+ addCacheDependency(attr: any, renderContext: RenderContext): void;
288
+ renderAbsoluteArea(attr: any, renderContext: RenderContext): string;
289
+ renderArea(attr: any, renderContext: RenderContext): string;
290
+ }
291
+
292
+ }