Skip to content

Commit

Permalink
More type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ComLock committed Dec 13, 2024
1 parent 2eaa359 commit 3f8ad58
Show file tree
Hide file tree
Showing 23 changed files with 36 additions and 106 deletions.
6 changes: 1 addition & 5 deletions src/main/resources/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
export {
Cache,
Component,
ComponentType,
EntryName,
OneOrMore,
PageContributions,
React4xp,
Request,
Response,
Stats,
} from './types/index.d';

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lib/enonic/react4xp/React4xp.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type {
Component,
PageContributions,
Request,
Response,
} from '@enonic-types/core';
import type {
Entry,
Id,
Instance,
PageContributions,
// React4xp as React4xpNamespace,
UrlType
} from '@enonic-types/lib-react4xp';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Request } from '../../../../..';
import type { Request } from '@enonic-types/core';
import type { React4xp } from '../../React4xp';
import isEditMode from '/lib/enonic/react4xp/React4xp/utils/isEditMode';
import getSsrConfig from '/lib/enonic/react4xp/React4xp/utils/getSsrConfig';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {
PageContributions,
Request,
} from '@enonic-types/core';
import type {
AppConfig,
UrlType
} from '@enonic-types/lib-react4xp';
import type {
PageContributions,
Request
} from '../../../../..';
import type { React4xp } from '../../React4xp';
import { isSet } from '@enonic/js-utils/value/isSet';
//import {toStr} from '@enonic/js-utils/value/toStr';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Request} from '../../../../..';
import type {Request} from '@enonic-types/core';
import type {React4xp} from '../../React4xp';


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { React4xp } from '@enonic-types/lib-react4xp';
import type { React4xp } from '..';


export function renderWarningPlaceholder(this: React4xp) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lib/enonic/react4xp/asset/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
Request,
Response
} from '../../../..';
} from '@enonic-types/core';


import {includes} from '@enonic/js-utils/array/includes';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
Request,
Response
} from '../../../..';
} from '@enonic-types/core';
import {startsWith} from '@enonic/js-utils/string/startsWith';
// import {toStr} from '@enonic/js-utils/value/toStr';
import {eTagGetter} from '/lib/enonic/react4xp/asset/eTagGetter';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type {
Response,
} from '../../..';
import type { Response } from '@enonic-types/core';


import {forceArray} from '@enonic/js-utils/array/forceArray';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type {
EntryName,
OneOrMore,
React4xp as React4xpNamespace
} from '../../../../index.d';


import {isString} from '@enonic/js-utils/value/isString';


export function forceTrimmedArray(entryNames :OneOrMore<React4xpNamespace.EntryName> = []) :Array<React4xpNamespace.EntryName> {
export function forceTrimmedArray(entryNames: OneOrMore<EntryName> = []): EntryName[] {
if (isString(entryNames)) {
const trimmed = entryNames.trim();
return (trimmed === "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
EntryName,
OneOrMore,
React4xp as React4xpNamespace
} from '../../../../index.d';


Expand All @@ -11,7 +11,7 @@ import {readComponentChunkNamesCached} from '/lib/enonic/react4xp/dependencies/r
import {IS_PROD_MODE} from '/lib/enonic/react4xp/xp/appHelper';


export function getComponentChunkNames(entryNames :OneOrMore<React4xpNamespace.EntryName>) {
export function getComponentChunkNames(entryNames: OneOrMore<EntryName>) {
const componentChunkNames = IS_PROD_MODE
? readComponentChunkNamesCached(entryNames)
: readComponentChunkNames(forceTrimmedArray(entryNames));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { UrlType } from '@enonic-types/lib-react4xp';
import type {
EntryName,
OneOrMore,
React4xp as React4xpNamespace
} from '../../../../index.d';


Expand All @@ -11,7 +11,7 @@ import { getComponentChunkNames } from '/lib/enonic/react4xp/dependencies/getCom

// NOTE: This function is exported in ..React4xp.ts, so a major release is needed to change it's signature.
// TODO: Change to single param with two properties.
export function getComponentChunkUrls(entries: OneOrMore<React4xpNamespace.EntryName>, {
export function getComponentChunkUrls(entries: OneOrMore<EntryName>, {
urlType // default is app.config['react4xp.urlType'] || 'server'
}: {
urlType?: UrlType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type {
EntryName,
OneOrMore,
React4xp as React4xpNamespace
} from '../../../../index.d';


import {forceTrimmedArray} from '/lib/enonic/react4xp/dependencies/forceTrimmedArray';


export function normalizeEntryNames(entryNames :OneOrMore<React4xpNamespace.EntryName> = []) :Array<React4xpNamespace.EntryName> {
export function normalizeEntryNames(entryNames: OneOrMore<EntryName> = []): EntryName[] {
const arr = forceTrimmedArray(entryNames);
arr.sort()
return arr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
EntryName,
OneOrMore,
React4xp as React4xpNamespace
} from '../../../../index.d';


Expand All @@ -24,7 +24,7 @@ let buildStatsEntrypoints :Object|undefined;
* ASSUMES that stats.json.entrypoints is an object where the keys are entry names without file extensions, mapping to values that are objects,
* which in turn have an "assets" key, under which are the full file names of the entry's dependencies.
* If the input array is empty or null, returns ALL dependency chunk names. */
export function readComponentChunkNames(entryNames :OneOrMore<React4xpNamespace.EntryName>) {
export function readComponentChunkNames(entryNames: OneOrMore<EntryName>) {
//log.debug('readComponentChunkNames(%s)', toStr(entryNames));

// Just verify that it exists and has a content:
Expand All @@ -39,7 +39,7 @@ export function readComponentChunkNames(entryNames :OneOrMore<React4xpNamespace.
const output = [];
const missing = [];

(entryNames as Array<React4xpNamespace.EntryName>).forEach(entry => {
(entryNames as Array<EntryName>).forEach(entry => {
try {
let data = buildStatsEntrypoints[entry];
if (!data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
EntryName,
OneOrMore,
React4xp as React4xpNamespace
} from '../../../../index.d';


Expand All @@ -14,7 +14,7 @@ import {readComponentChunkNames} from '/lib/enonic/react4xp/dependencies/readCom
// WARNING: Do not cache anything that contains assetRoot, it changes per context!
// But since this doesn't contain assetRoot, it's ok to cache :)
// Cached version of readComponentChunkNames - used in prod mode
export function readComponentChunkNamesCached(entryNames :OneOrMore<React4xpNamespace.EntryName>) :Array<string> {
export function readComponentChunkNamesCached(entryNames: OneOrMore<EntryName>): string[] {
entryNames = normalizeEntryNames(entryNames);

const cacheKey = getSiteLocalCacheKey(entryNames.join("*"));
Expand Down
5 changes: 2 additions & 3 deletions src/main/resources/lib/enonic/react4xp/htmlHandling.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { Request } from '@enonic-types/core';
import type {
Id,
React4xp,
Instance,
} from '@enonic-types/lib-react4xp';
//import type {React4xp} from './React4xp';


export function buildErrorContainer(
heading: string,
message: string,
request: Request,
react4xpObj: React4xp.Instance | {
react4xpObj: Instance | {
jsxPath: string|object
react4xpId: Id
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PageContributions } from '@enonic-types/core';
import type { UrlType } from '@enonic-types/lib-react4xp';
import type {
EntryName,
OneOrMore,
PageContributions,
React4xp as React4xpNamespace
} from '../../../../index.d';


Expand All @@ -24,7 +24,7 @@ export function buildPageContributions({
suppressJS,
urlType // default is app.config['react4xp.urlType'] || 'server'
}: {
entries: OneOrMore<React4xpNamespace.EntryName>
entries: OneOrMore<EntryName>
suppressJS: boolean
urlType?: UrlType
}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PageContributions } from '@enonic-types/core';
import type { UrlType } from '@enonic-types/lib-react4xp';
import type {
OneOrMore,
PageContributions,
React4xp as React4xpNamespace
EntryName,
OneOrMore
} from '../../../../index.d';


Expand Down Expand Up @@ -30,7 +30,7 @@ export function getAndMerge({
suppressJS,
urlType // default is app.config['react4xp.urlType'] || 'server'
}: {
entryNames: OneOrMore<React4xpNamespace.EntryName>
entryNames: OneOrMore<EntryName>
incomingPgContrib: PageContributions
newPgContrib: PageContributions
suppressJS: boolean
Expand Down
36 changes: 0 additions & 36 deletions src/main/resources/types/Component.d.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1 @@
// import type { Region } from "@enonic-types/lib-portal";
export type { Component, PageComponent, PartComponent, TextComponent } from "@enonic-types/lib-portal";

export type ComponentType = 'fragment'|'layout'|'page'|'part'|'text'; // image? region?


// export interface PageComponent<PageConfig extends object = object> {
// config: PageConfig
// descriptor: string
// path: string
// regions: Record<string,Region>
// template: string // TODO: Missing from lib-portal
// type: 'page'
// }


// export interface PartComponent<PartConfig extends object = object> {
// config: PartConfig
// descriptor: string
// path: string
// type: ComponentType
// }


// export interface TextComponent {
// path: string
// text: string
// type: 'text'
// }

// export type Component = PageComponent | PartComponent// | TextComponent;

// This is stricter than lib-portal
// interface Region<Name extends string = ''> {
// components: Array<PartComponent | TextComponent>
// name: Name
// }
8 changes: 0 additions & 8 deletions src/main/resources/types/DoubleUnderscore.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/resources/types/Log.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/resources/types/PageContributions.d.ts

This file was deleted.

11 changes: 2 additions & 9 deletions src/main/resources/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
export {AppConfig} from './Application.d';
export {Cache} from './Cache.d';
export {
Component,
ComponentType
} from './Component.d';
export {ComponentType} from './Component.d';
export type { PageTemplateContent } from './ContentTypes';
export {DoubleUnderscore} from './DoubleUnderscore.d';
export {Log} from './Log.d';
export {PageContributions} from './PageContributions.d';
export {
Entry,
EntryName,
Id,
Instance,
Props,
React4xp,
UrlType
} from './React4xp.d';
export {Stats} from './Stats.d';
Expand Down

0 comments on commit 3f8ad58

Please sign in to comment.