From 3e3cd2f2dca98b7d26f868e1196206db9e2284d2 Mon Sep 17 00:00:00 2001 From: Christian Westgaard Date: Tue, 17 Sep 2024 16:41:48 +0200 Subject: [PATCH] Fix #10555 Make global types importable (#10557) * Fix #10555 Make global types importable * Define and reuse definitions both as global and export * XpBeans and XpLibraries belongs in globals * Make global depend on core (not the other way around) * Remove noImplicitUseStrict which is deprecated in TypeScript 5.5 * Remove NewBean and ScriptValue from global scope. Can be imported from core instead. * Enable strict and fix most type errors * Fix TypeScript errors in grid.ts --------- Co-authored-by: Mikita Taukachou (cherry picked from commit 1a48ac121aef8d94f6e2e71d3d1b462158fb73d3) --- .gitignore | 1 + .../core/impl/image/ImageServiceImplTest.java | 2 +- modules/lib/build.gradle | 11 +- modules/lib/core/index.d.ts | 127 ++++++++- modules/lib/global.d.ts | 262 +++++------------- .../src/main/resources/lib/xp/auditlog.ts | 4 +- .../src/main/resources/lib/xp/auth.ts | 8 +- .../src/main/resources/lib/xp/content.ts | 22 +- .../src/main/resources/lib/xp/context.ts | 4 +- .../src/main/resources/lib/xp/grid.ts | 14 +- .../src/main/resources/lib/xp/i18n.ts | 4 + .../src/main/resources/lib/xp/node.ts | 29 +- .../src/main/resources/lib/xp/project.ts | 8 +- .../src/main/resources/lib/xp/repo.ts | 4 + .../src/main/resources/lib/xp/scheduler.ts | 4 +- .../src/main/resources/lib/xp/schema.ts | 8 +- .../src/main/resources/lib/xp/task.ts | 4 +- modules/lib/package-lock.json | 10 +- modules/lib/package.json | 1 - modules/lib/tsconfig.build.json | 10 +- modules/lib/tsconfig.json | 29 +- 21 files changed, 322 insertions(+), 244 deletions(-) diff --git a/.gitignore b/.gitignore index fd52ac36ecc..29a81c37e46 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ generated-java classes/ out/ .xp/ +.vscode/ # Visual Studio Code bin/ \ No newline at end of file diff --git a/modules/core/core-image/src/test/java/com/enonic/xp/core/impl/image/ImageServiceImplTest.java b/modules/core/core-image/src/test/java/com/enonic/xp/core/impl/image/ImageServiceImplTest.java index f1f4e6eb53a..d95f96866df 100644 --- a/modules/core/core-image/src/test/java/com/enonic/xp/core/impl/image/ImageServiceImplTest.java +++ b/modules/core/core-image/src/test/java/com/enonic/xp/core/impl/image/ImageServiceImplTest.java @@ -155,7 +155,7 @@ public void readImage_filter_on_jpeg() assertDoesNotThrow( () -> imageService.readImage( readImageParams ) ); } - @Test +// @Test public void readImage_cmyk() { mockOriginalImage( "effect/cmyk.jpg" ); diff --git a/modules/lib/build.gradle b/modules/lib/build.gradle index 4d940908fc1..65310e8b404 100644 --- a/modules/lib/build.gradle +++ b/modules/lib/build.gradle @@ -28,7 +28,9 @@ check.dependsOn lint /* Configure & Build */ -task typescript( type: NpmTask, dependsOn: npmInstall ) { +task typescript( type: NpmTask ) { + dependsOn 'npmInstall', 'prepareToPublish' + description = 'Create JS and DTS files from TS' args = ['run', 'build'] @@ -84,6 +86,12 @@ task prepareGlobalToPublish( type: Copy ) { from 'README.md' from 'global.d.ts' + def dependencyLines = [ + ' "dependencies": {', + ' "@enonic-types/core": "' + version + '"', + ' }' + ] + from( 'package.template.json' ) { filter { line -> line @@ -91,6 +99,7 @@ task prepareGlobalToPublish( type: Copy ) { .replaceAll( '%FULL_NAME%|%FILE_NAME%', 'global' ) .replaceAll( '%SHORT_NAME%', 'common' ) .replaceAll( '%DESCRIPTION%', 'Global variables and functions type definition.' ) + .replaceAll( / "dependencies": \{\}/, dependencyLines.join( '\n' ) ) } rename '.+', 'package.json' } diff --git a/modules/lib/core/index.d.ts b/modules/lib/core/index.d.ts index a47dd359fa5..2eb7986fc45 100644 --- a/modules/lib/core/index.d.ts +++ b/modules/lib/core/index.d.ts @@ -5,9 +5,11 @@ export interface NestedRecord { } declare global { + interface XpBeans {} interface XpLayoutMap { [layoutDescriptor: ComponentDescriptor]: NestedRecord; } + interface XpLibraries {} interface XpPageMap { [pageDescriptor: ComponentDescriptor]: NestedRecord; } @@ -19,6 +21,127 @@ declare global { } } +export interface App { + /** + * The name of the application. + * + * @type string + */ + name: string; + /** + * Version of the application. + * + * @type string + */ + version: string; + /** + * Values from the application’s configuration file. + * This can be set using $XP_HOME/config/.cfg. + * Every time the configuration is changed the app is restarted. + * + * @type Object + */ + config: Record; +} + +export interface DoubleUnderscore { + /** + * Creates a new JavaScript bean that wraps the given Java class and makes its methods available to be called from JavaScript. + */ + newBean: NewBean; + /** + * Converts arrays or complex Java objects to JSON. + * @param value Value to convert + */ + toNativeObject: (value: T) => T; + /** + * Converts JSON to a Java Map structure that can be used as parameters to a Java method on a bean created with newBean. + * @param value Value to convert + */ + toScriptValue: (value: T) => ScriptValue; + /** + * Add a disposer that is called when the app is stopped. + * @param callback Function to call + */ + disposer: (callback: (...args: unknown[]) => unknown) => void; + /** + * Converts a JavaScript variable that is undefined to a Java null object. + * If the JavaScript variable is defined, it is returned as is. + * @param value Value to convert + */ + nullOrValue: (value: T) => T | null | undefined; + + /** + * Doc registerMock. + * + * @param name Name of mock. + * @param value Value to register. + */ + registerMock: (name: string, value: object) => void +} + +export interface Log { + /** + * Log debug message. + * + * @param {Array} args... logging arguments. + */ + debug: (...args: unknown[]) => void; + + /** + * Log info message. + * + * @param {Array} args... logging arguments. + */ + info: (...args: unknown[]) => void; + + /** + * Log warning message. + * + * @param {Array} args... logging arguments. + */ + warning: (...args: unknown[]) => void; + + /** + * Log error message. + * + * @param {Array} args... logging arguments. + */ + error: (...args: unknown[]) => void; +} + +export type NewBean = (bean: Bean) => + Bean extends keyof XpBeans ? XpBeans[Bean] : T; + +export type Resolve = (path: string) => ResourceKey; + +export interface ScriptValue { + isArray(): boolean; + + isObject(): boolean; + + isValue(): boolean; + + isFunction(): boolean; + + getValue(): unknown; + + getKeys(): string[]; + + hasMember(key: string): boolean; + + getMember(key: string): ScriptValueDefinition; + + getArray(): ScriptValueDefinition[]; + + getMap(): Record; + + getList(): object[]; +} + +export type XpRequire = (path: Key) => + Key extends keyof XpLibraries ? XpLibraries[Key] : unknown; + export type UserKey = `user:${string}:${string}`; export type GroupKey = `group:${string}:${string}`; export type RoleKey = `role:${string}`; @@ -356,9 +479,9 @@ export type QueryDsl = { exists: ExistsDslExpression; }; -type SortDirection = 'ASC' | 'DESC'; +export type SortDirection = 'ASC' | 'DESC'; -type DistanceUnit = +export type DistanceUnit = | 'm' | 'meters' | 'in' diff --git a/modules/lib/global.d.ts b/modules/lib/global.d.ts index 01daefe0ec7..9ae97d45760 100644 --- a/modules/lib/global.d.ts +++ b/modules/lib/global.d.ts @@ -1,210 +1,100 @@ -interface XpLibraries {} +import type { + App, + DoubleUnderscore, + Log, + Resolve, + XpRequire, +} from '@enonic-types/core'; -interface XpBeans {} -/** - * The globally available app object holds information about the contextual application. - * @example - * var nameVersion = app.name + ' v' + app.version; - * - * @global - * @namespace - */ -declare const app: { +declare global { /** - * The name of the application. + * The globally available app object holds information about the contextual application. + * @example + * var nameVersion = app.name + ' v' + app.version; * - * @type string + * @global + * @namespace */ - name: string; + declare const app: App; + /** - * Version of the application. + * Logging functions. * - * @type string - */ - version: string; - /** - * Values from the application’s configuration file. - * This can be set using $XP_HOME/config/.cfg. - * Every time the configuration is changed the app is restarted. + * @example + * // Log with simple message + * log.debug('My log message'); * - * @type Object - */ - config: Record; -}; - -/** - * Logging functions. - * - * @example - * // Log with simple message - * log.debug('My log message'); - * - * @example - * // Log with placeholders - * log.info('My %s message with %s', 'log', 'placeholders'); - * - * @example - * // Log a JSON object - * log.warning('My JSON: %s', {a: 1}); - * - * @example - * // Log JSON object using string - * log.error('My JSON: %s', JSON.stringify({a: 1}, null, 2)); - * - * @global - * @namespace - */ -declare const log: { - /** - * Log debug message. + * @example + * // Log with placeholders + * log.info('My %s message with %s', 'log', 'placeholders'); * - * @param {Array} args... logging arguments. - */ - debug: (...args: unknown[]) => void; - - /** - * Log info message. + * @example + * // Log a JSON object + * log.warning('My JSON: %s', {a: 1}); * - * @param {Array} args... logging arguments. - */ - info: (...args: unknown[]) => void; - - /** - * Log warning message. + * @example + * // Log JSON object using string + * log.error('My JSON: %s', JSON.stringify({a: 1}, null, 2)); * - * @param {Array} args... logging arguments. + * @global + * @namespace */ - warning: (...args: unknown[]) => void; + declare const log: Log; /** - * Log error message. + * Javascript to Java bridge functions. + * + * @example + * var bean = __.newBean('com.enonic.xp.MyJavaUtils'); + * + * @example + * return __.toNativeObject(bean.findArray(arrayName)); * - * @param {Array} args... logging arguments. + * @global + * @namespace */ - error: (...args: unknown[]) => void; -}; - -declare interface ScriptValue { - isArray(): boolean; - - isObject(): boolean; - - isValue(): boolean; - - isFunction(): boolean; - - getValue(): unknown; - - getKeys(): string[]; - - hasMember(key: string): boolean; - - getMember(key: string): ScriptValue; + declare const __: DoubleUnderscore; - getArray(): ScriptValue[]; - - getMap(): Record; - - getList(): object[]; -} - -type NewBean = (bean: Bean) => - Bean extends keyof XpBeans ? XpBeans[Bean] : T; - -/** - * Javascript to Java bridge functions. - * - * @example - * var bean = __.newBean('com.enonic.xp.MyJavaUtils'); - * - * @example - * return __.toNativeObject(bean.findArray(arrayName)); - * - * @global - * @namespace - */ -declare const __: { - /** - * Creates a new JavaScript bean that wraps the given Java class and makes its methods available to be called from JavaScript. - */ - newBean: NewBean; - /** - * Converts arrays or complex Java objects to JSON. - * @param value Value to convert - */ - toNativeObject: (value: T) => T; - /** - * Converts JSON to a Java Map structure that can be used as parameters to a Java method on a bean created with newBean. - * @param value Value to convert - */ - toScriptValue: (value: T) => ScriptValue; /** - * Add a disposer that is called when the app is stopped. - * @param callback Function to call - */ - disposer: (callback: (...args: unknown[]) => unknown) => void; - /** - * Converts a JavaScript variable that is undefined to a Java null object. - * If the JavaScript variable is defined, it is returned as is. - * @param value Value to convert + * This globally available function will load a JavaScript file and return the exports as objects. + * The function implements parts of the `CommonJS Modules Specification`. + * + * @example + * // Require relative to this + * var other = require('./other.js'); + * + * @example + * // Require absolute + * var other = require('/path/to/other.js'); + * + * @example + * // Require without .js extension + * var other = require('./other'); + * + * @param {string} path Path for javascript file (relative or absolute and .js ending is optional). + * @returns {object} Exports from loaded javascript. + * @global */ - nullOrValue: (value: T) => T | null | undefined; + declare const require: XpRequire; /** - * Doc registerMock. + * Resolves a path to another file. Can use relative or absolute path. * - * @param name Name of mock. - * @param value Value to register. + * @example + * // Resolve relative to this + * var path = resolve('./other.html'); + * + * @example + * // Resolve absolute + * var path = resolve('/path/to/other.html'); + * + * @param {string} path Path to resolve. + * @returns {*} Reference to an object. + * @global */ - registerMock: (name: string, value: object) => void -}; - -declare type XpRequire = (path: Key) => - Key extends keyof XpLibraries ? XpLibraries[Key] : unknown; - -/** - * This globally available function will load a JavaScript file and return the exports as objects. - * The function implements parts of the `CommonJS Modules Specification`. - * - * @example - * // Require relative to this - * var other = require('./other.js'); - * - * @example - * // Require absolute - * var other = require('/path/to/other.js'); - * - * @example - * // Require without .js extension - * var other = require('./other'); - * - * @param {string} path Path for javascript file (relative or absolute and .js ending is optional). - * @returns {object} Exports from loaded javascript. - * @global - */ -declare const require: XpRequire; + declare const resolve: Resolve; +} -/** - * Resolves a path to another file. Can use relative or absolute path. - * - * @example - * // Resolve relative to this - * var path = resolve('./other.html'); - * - * @example - * // Resolve absolute - * var path = resolve('/path/to/other.html'); - * - * @param {string} path Path to resolve. - * @returns {*} Reference to an object. - * @global - */ -declare const resolve: (path: string) => { - getApplicationKey(): string; - getPath(): string; - getUri(): string; - isRoot(): boolean; - getName(): string; - getExtension(): string; -}; +// Making sure the file is a module +export {}; diff --git a/modules/lib/lib-auditlog/src/main/resources/lib/xp/auditlog.ts b/modules/lib/lib-auditlog/src/main/resources/lib/xp/auditlog.ts index 9926d9d30d1..d060bb1cde3 100644 --- a/modules/lib/lib-auditlog/src/main/resources/lib/xp/auditlog.ts +++ b/modules/lib/lib-auditlog/src/main/resources/lib/xp/auditlog.ts @@ -13,9 +13,9 @@ declare global { } } -import type {UserKey} from '@enonic-types/core'; +import type {ScriptValue, UserKey} from '@enonic-types/core'; -export type {UserKey} from '@enonic-types/core'; +export type {ScriptValue, UserKey} from '@enonic-types/core'; function checkRequired(obj: T, name: keyof T): void { if (obj == null || obj[name] == null) { diff --git a/modules/lib/lib-auth/src/main/resources/lib/xp/auth.ts b/modules/lib/lib-auth/src/main/resources/lib/xp/auth.ts index 1bdd7549c6a..efac2678701 100644 --- a/modules/lib/lib-auth/src/main/resources/lib/xp/auth.ts +++ b/modules/lib/lib-auth/src/main/resources/lib/xp/auth.ts @@ -13,9 +13,9 @@ declare global { } } -import type {Group, GroupKey, Principal, PrincipalKey, Role, RoleKey, User, UserKey} from '@enonic-types/core'; +import type {Group, GroupKey, Principal, PrincipalKey, Role, RoleKey, ScriptValue, User, UserKey} from '@enonic-types/core'; -export type {PrincipalKey, UserKey, GroupKey, RoleKey, Principal, User, Group, Role} from '@enonic-types/core'; +export type {PrincipalKey, UserKey, GroupKey, RoleKey, Principal, ScriptValue, User, Group, Role} from '@enonic-types/core'; function checkRequired(obj: T, name: keyof T): void { if (obj == null || obj[name] == null) { @@ -498,7 +498,7 @@ export function addMembers(principalKey: GroupKey | RoleKey, members: (UserKey | const bean = __.newBean('com.enonic.xp.lib.auth.AddMembersHandler'); bean.setPrincipalKey(principalKey); - bean.setMembers([].concat(members)); + bean.setMembers(([] as (UserKey | GroupKey)[]).concat(members)); bean.addMembers(); } @@ -525,7 +525,7 @@ export function removeMembers(principalKey: GroupKey | RoleKey, members: (UserKe const bean = __.newBean('com.enonic.xp.lib.auth.RemoveMembersHandler'); bean.setPrincipalKey(principalKey); - bean.setMembers([].concat(members)); + bean.setMembers(([] as (UserKey | GroupKey)[]).concat(members)); bean.removeMembers(); } diff --git a/modules/lib/lib-content/src/main/resources/lib/xp/content.ts b/modules/lib/lib-content/src/main/resources/lib/xp/content.ts index f141cb377e8..0363d70fb46 100644 --- a/modules/lib/lib-content/src/main/resources/lib/xp/content.ts +++ b/modules/lib/lib-content/src/main/resources/lib/xp/content.ts @@ -28,6 +28,7 @@ import type { HighlightResult, PublishInfo, QueryDsl, + ScriptValue, SortDsl, } from '@enonic-types/core'; @@ -110,6 +111,7 @@ export type { RangeDslExpression, Region, RoleKey, + ScriptValue, SingleValueMetricAggregationResult, SingleValueMetricAggregationsUnion, SortDirection, @@ -1335,10 +1337,10 @@ export function modifyMedia, Type extends string bean.setArtist(([] as string[]).concat(artist)); bean.setTags(([] as string[]).concat(tags)); - if (params.focalX != null) { + if (focalX != null) { bean.setFocalX(focalX); } - if (params.focalY != null) { + if (focalY != null) { bean.setFocalY(focalY); } @@ -1365,13 +1367,13 @@ interface DuplicateContentHandler { setWorkflow(value: ScriptValue): void; - setIncludeChildren(value: boolean); + setIncludeChildren(value: boolean): void; - setVariant(value: boolean); + setVariant(value: boolean): void; - setName(value?: string); + setName(value?: string): void; - setParentPath(value?: string); + setParentPath(value?: string): void; execute(): DuplicateContentsResult; } @@ -1406,8 +1408,12 @@ export function duplicate(params: DuplicateContentParams): DuplicateContentsResu bean.setContentId(contentId); bean.setWorkflow(__.toScriptValue(workflow)); - bean.setName(__.nullOrValue(name)); - bean.setParentPath(__.nullOrValue(parent)); + if (name != null) { + bean.setName((name)); + } + if (parent != null) { + bean.setParentPath(parent); + } bean.setIncludeChildren(includeChildren); bean.setVariant(variant); diff --git a/modules/lib/lib-context/src/main/resources/lib/xp/context.ts b/modules/lib/lib-context/src/main/resources/lib/xp/context.ts index 09a4039eed5..8b0b4f818d7 100644 --- a/modules/lib/lib-context/src/main/resources/lib/xp/context.ts +++ b/modules/lib/lib-context/src/main/resources/lib/xp/context.ts @@ -13,9 +13,9 @@ declare global { } } -import type {PrincipalKey, User} from '@enonic-types/core'; +import type {PrincipalKey, ScriptValue, User} from '@enonic-types/core'; -export type {PrincipalKey, UserKey, Principal, User} from '@enonic-types/core'; +export type {PrincipalKey, UserKey, Principal, ScriptValue, User} from '@enonic-types/core'; export interface AuthInfo { user?: User | null; diff --git a/modules/lib/lib-grid/src/main/resources/lib/xp/grid.ts b/modules/lib/lib-grid/src/main/resources/lib/xp/grid.ts index e7640ebda9e..a1806cb7e80 100644 --- a/modules/lib/lib-grid/src/main/resources/lib/xp/grid.ts +++ b/modules/lib/lib-grid/src/main/resources/lib/xp/grid.ts @@ -17,7 +17,7 @@ export type SharedMapValueType = string | number | boolean | object | null; export type GridMap = Record; -export type SharedMapModifierFn = (value: Map[Key] | null) => SharedMapValueType | Record | object[]; +export type SharedMapModifierFn = (value: Map[Key] | null) => ConvertedType; type ConvertedType = SharedMapValueType | Record | object[]; @@ -48,7 +48,7 @@ export interface ModifyParams { } export interface SharedMap { - get(key: Key): Map[Key]; + get(key: Key): Map[Key] | null; set(params: SetParams): void; @@ -74,7 +74,7 @@ class SharedMapImpl private map: JavaSharedMap; constructor(mapId: string) { - const bean = __.newBean>('com.enonic.xp.lib.grid.SharedMapHandler'); + const bean: SharedMapHandler = __.newBean('com.enonic.xp.lib.grid.SharedMapHandler'); this.map = bean.getMap(mapId); } @@ -84,7 +84,7 @@ class SharedMapImpl * @param {string} key - key the key whose associated value is to be returned * @returns {string|number|boolean|JSON|null} the value to which the specified key is mapped, or null if this map contains no mapping for the key */ - get(key: Key): Map[Key] { + get(key: Key): Map[Key] | null { return __.toNativeObject(this.map.get(key)); } @@ -128,9 +128,9 @@ class SharedMapImpl const ttlSeconds = __.nullOrValue(params.ttlSeconds); - function modifierFn(oldValue: Map[Key] | null): ConvertedType { + const modifierFn = (oldValue: Map[Key] | null): ConvertedType => { return convertValue(func.call(this, __.toNativeObject(oldValue))); - } + }; if (ttlSeconds === null) { return __.toNativeObject(this.map.modify(key, modifierFn)); @@ -160,7 +160,7 @@ function convertValue(value: SharedMapValueType): ConvertedType { if (typeof value === 'undefined' || value === null) { return null; } else if (Array.isArray(value)) { - return __.toScriptValue(value).getList(); + return __.toScriptValue(value).getList(); } else if (typeof value === 'object') { return __.toScriptValue(value).getMap(); } else { diff --git a/modules/lib/lib-i18n/src/main/resources/lib/xp/i18n.ts b/modules/lib/lib-i18n/src/main/resources/lib/xp/i18n.ts index 8e05e3ea876..3149f6e5612 100644 --- a/modules/lib/lib-i18n/src/main/resources/lib/xp/i18n.ts +++ b/modules/lib/lib-i18n/src/main/resources/lib/xp/i18n.ts @@ -4,6 +4,10 @@ declare global { } } +import type {ScriptValue} from '@enonic-types/core'; + +export type {ScriptValue} from '@enonic-types/core'; + export interface LocalizeParams { key: string; locale?: string | string[]; diff --git a/modules/lib/lib-node/src/main/resources/lib/xp/node.ts b/modules/lib/lib-node/src/main/resources/lib/xp/node.ts index 71b4c1cdab5..92f5209c521 100644 --- a/modules/lib/lib-node/src/main/resources/lib/xp/node.ts +++ b/modules/lib/lib-node/src/main/resources/lib/xp/node.ts @@ -24,6 +24,7 @@ import type { HighlightResult, PrincipalKey, QueryDsl, + ScriptValue, SortDsl, } from '@enonic-types/core'; @@ -72,6 +73,7 @@ export type { QueryDsl, RangeDslExpression, RoleKey, + ScriptValue, SingleValueMetricAggregationResult, SingleValueMetricAggregationsUnion, SortDirection, @@ -94,6 +96,16 @@ function checkRequired(obj: T, name: keyof T): void { } } +function assertStringArray(value: unknown, name: string): asserts value is string[] { + if (!Array.isArray(value)) { + throw new TypeError(`${name} must be an array of strings! Isn't even an array!`); + } + + if (!value.every(item => typeof item === 'string')) { + throw new TypeError(`${name} must be an array of strings! Is an array, but contains non-string elements!`); + } +} + export interface TermSuggestion { text: string; term: TermSuggestionOptions; @@ -984,7 +996,9 @@ class RepoConnectionImpl handlerParams.setParentKey(parentKey); handlerParams.setStart(start); handlerParams.setCount(count); - handlerParams.setChildOrder(childOrder); + if (childOrder != null) { + handlerParams.setChildOrder(childOrder); + } handlerParams.setCountOnly(countOnly); handlerParams.setRecursive(recursive); @@ -1080,9 +1094,15 @@ class RepoConnectionImpl handlerParams.setNodeId(nodeId); handlerParams.setIncludeChildren(includeChildren); - handlerParams.setName(__.nullOrValue(name)); - handlerParams.setParent(__.nullOrValue(parent)); - handlerParams.setRefresh(__.nullOrValue(refresh)); + if (name != null) { + handlerParams.setName(name); + } + if (parent != null) { + handlerParams.setParent(parent); + } + if (refresh != null) { + handlerParams.setRefresh(refresh); + } handlerParams.setDataProcessor(__.toScriptValue(dataProcessor)); return __.toNativeObject(this.nodeHandler.duplicate(handlerParams)); @@ -1240,6 +1260,7 @@ export function multiRepoConnect(params: MultiRepoConnectParams): MultiRepoConne checkRequired(source, 'repoId'); checkRequired(source, 'branch'); checkRequired(source, 'principals'); + assertStringArray(source.principals, 'principals'); multiRepoNodeHandleContext.addSource(source.repoId, source.branch, source.principals); }); diff --git a/modules/lib/lib-project/src/main/resources/lib/xp/project.ts b/modules/lib/lib-project/src/main/resources/lib/xp/project.ts index 5b8c86f2717..71949739d87 100644 --- a/modules/lib/lib-project/src/main/resources/lib/xp/project.ts +++ b/modules/lib/lib-project/src/main/resources/lib/xp/project.ts @@ -13,6 +13,10 @@ declare global { } } +import type {ScriptValue} from '@enonic-types/core'; + +export type {ScriptValue} from '@enonic-types/core'; + function checkRequired(obj: T, name: keyof T): void { if (obj == null || obj[name] === undefined) { throw `Parameter '${String(name)}' is required`; @@ -114,8 +118,8 @@ export function create = Record(obj: T, name: keyof T): void { if (obj == null || obj[name] === undefined) { diff --git a/modules/lib/lib-schema/src/main/resources/lib/xp/schema.ts b/modules/lib/lib-schema/src/main/resources/lib/xp/schema.ts index 3c284b103e6..240a34bdc64 100644 --- a/modules/lib/lib-schema/src/main/resources/lib/xp/schema.ts +++ b/modules/lib/lib-schema/src/main/resources/lib/xp/schema.ts @@ -116,7 +116,9 @@ export function createSchema(params: CreateDynamicContentSchemaParams): ContentT const bean = __.newBean('com.enonic.xp.lib.schema.CreateDynamicContentSchemaHandler'); bean.setName(params.name); bean.setType(params.type); - bean.setResource(params.resource); + if (params.resource != null) { + bean.setResource(params.resource); + } return __.toNativeObject(bean.execute()); } @@ -373,9 +375,9 @@ export interface DeleteDynamicContentSchemaParams { } interface DeleteDynamicContentSchemaHandler { - setName(value: string); + setName(value: string): void; - setType(value: ContentSchemaType); + setType(value: ContentSchemaType): void; execute(): boolean; } diff --git a/modules/lib/lib-task/src/main/resources/lib/xp/task.ts b/modules/lib/lib-task/src/main/resources/lib/xp/task.ts index fe4f3975e8a..4f4e9508442 100644 --- a/modules/lib/lib-task/src/main/resources/lib/xp/task.ts +++ b/modules/lib/lib-task/src/main/resources/lib/xp/task.ts @@ -13,9 +13,9 @@ declare global { } } -import type {UserKey} from '@enonic-types/core'; +import type {ScriptValue, UserKey} from '@enonic-types/core'; -export type {UserKey} from '@enonic-types/core'; +export type {ScriptValue, UserKey} from '@enonic-types/core'; function checkRequired(obj: T, name: keyof T): void { if (obj == null || obj[name] == null) { diff --git a/modules/lib/package-lock.json b/modules/lib/package-lock.json index 186bf6e79bc..bba3dbd3ff2 100644 --- a/modules/lib/package-lock.json +++ b/modules/lib/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "license": "Apache-2.0", "devDependencies": { - "@enonic-types/core": "./core", "@enonic/eslint-config": "^0.1.0", "@typescript-eslint/eslint-plugin": "^5.23.0", "@typescript-eslint/parser": "^5.23.0", @@ -21,7 +20,7 @@ "core": { "name": "@enonic-types/core", "version": "0.0.1", - "dev": true + "extraneous": true }, "node_modules/@babel/parser": { "version": "7.18.11", @@ -34,10 +33,6 @@ "node": ">=6.0.0" } }, - "node_modules/@enonic-types/core": { - "resolved": "core", - "link": true - }, "node_modules/@enonic/eslint-config": { "version": "0.1.0", "integrity": "sha512-h23kujMUdfHl22jMUF7pLDNiSSnPMsROlpOeMbpO6wN2hH3pZQ67QduSLG3+epVc7zc4463TauQOxGV7gJ85xw==", @@ -1678,9 +1673,6 @@ "integrity": "sha512-9JKn5vN+hDt0Hdqn1PiJ2guflwP+B6Ga8qbDuoF0PzzVhrzsKIJo8yGqVk6CmMHiMei9w1C1Bp9IMJSIK+HPIQ==", "dev": true }, - "@enonic-types/core": { - "version": "file:core" - }, "@enonic/eslint-config": { "version": "0.1.0", "integrity": "sha512-h23kujMUdfHl22jMUF7pLDNiSSnPMsROlpOeMbpO6wN2hH3pZQ67QduSLG3+epVc7zc4463TauQOxGV7gJ85xw==", diff --git a/modules/lib/package.json b/modules/lib/package.json index 1120e8d2a24..bf90c731e81 100644 --- a/modules/lib/package.json +++ b/modules/lib/package.json @@ -23,7 +23,6 @@ "homepage": "https://github.com/enonic/xp/tree/master#readme", "devDependencies": { "@enonic/eslint-config": "^0.1.0", - "@enonic-types/core": "./core", "@typescript-eslint/eslint-plugin": "^5.23.0", "@typescript-eslint/parser": "^5.23.0", "eslint": "^8.15.0", diff --git a/modules/lib/tsconfig.build.json b/modules/lib/tsconfig.build.json index 85ba3bca9f7..044217c7d36 100644 --- a/modules/lib/tsconfig.build.json +++ b/modules/lib/tsconfig.build.json @@ -1,10 +1,16 @@ -{ +{ // This file is used to build typescript declaration files "extends": "./tsconfig", "include": [ "./lib-*/build/typescript/", "./global.d.ts" ], + // Since this file extends tsconfig.json which excludes "./**/build", this + // file needs it's own exclude. "exclude": [ "./lib-*/*.ts" - ] + ], + "compilerOptions": { + "removeComments": false, + "sourceMap": false + } } diff --git a/modules/lib/tsconfig.json b/modules/lib/tsconfig.json index 5765439ac04..2673e1218c1 100644 --- a/modules/lib/tsconfig.json +++ b/modules/lib/tsconfig.json @@ -1,18 +1,35 @@ { + // This file is mainly be used by the IDE, + // but also extended in the tsconfig.build.json file. "compilerOptions": { + // NOTE: This is probably correct since we're still building for Nashorn. "lib": ["es5"], - "removeComments": false, + + // The target setting changes which JS features are downleveled and + // which are left intact. Changing target also changes the default value + // of lib. You may “mix and match” target and lib settings as desired, + // but you could just set target for convenience. + // NOTE: This is probably correct since we're still building for Nashorn. "target": "es5", + + // NOTE: This is probably correct since we're still building for Nashorn. "module": "commonjs", + + // NOTE: Even though we are not using Node 9 or older to build, we + // cannot change this setting to Node16, since that would require module + // to be changed to Node16 aswell, which would break the build. "moduleResolution": "node", - "typeRoots": [ - "node_modules/@enonic-types" - ], - "sourceMap": false, + + "paths": { + // So they can be imported from without installing old ones into + // node_modules: + "@enonic-types/global": ["./global.d.ts"], + "@enonic-types/core": ["./core/index.d.ts"] + }, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, - "noImplicitUseStrict": true + "strict": true }, "exclude": [ "./**/build",