From 3399838f710f60a92d5f7de1151bbc8255dcc9db Mon Sep 17 00:00:00 2001 From: Jean Machuca Date: Sun, 20 Oct 2024 21:41:56 -0300 Subject: [PATCH] types generation commands --- package.json | 7 +- src/index.d.ts | 19 +- tsconfig.d.json | 4 +- tsconfig.json | 6 +- types/index.d.ts | 472 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 490 insertions(+), 18 deletions(-) create mode 100644 types/index.d.ts diff --git a/package.json b/package.json index a6e3ee7e..b76867ea 100644 --- a/package.json +++ b/package.json @@ -6,19 +6,20 @@ "module": "build/index.mjs", "browser": "browser/index.js", "type": "commonjs", - "types": "src/**/*.d.ts", + "types": "build/index.d.ts", "exports": { ".": { "require": "./build/index.cjs", "import": "./build/index.mjs", - "types": "./src/types.d.ts" + "types": "./build/index.d.ts" }, "./package.json": "./package.json" }, "license": "LGPL-3.0", "scripts": { - "build": "npm run build:ts && npm run build:browser", + "build": "npm run build:ts-types && npm run build:ts && npm run build:browser", "build:ts": "npm test && npx tsc", + "build:ts-types": "npx tsc --project tsconfig.d.json", "build:browser": "npx -y esbuild@0.17.19 build/*.js --bundle --outdir=browser --keep-names --minify --global-name=global --sourcemap --splitting --chunk-names=chunks/[name]-[hash] --format=esm --target=es2021", "start": "qcobjects-shell", "test": "(npm run lint && (npx jasmine))", diff --git a/src/index.d.ts b/src/index.d.ts index 6b021dc9..6d9a11d8 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,11 +1,8 @@ -// Type definitions for QCObjects 2.4 -// Project: https://qcobjects.dev -// Definitions by: Jean Machuca -// Definitions: https://qcobjects.dev - -/** - */ - -import QCObjects from "qcobjects"; - -export = QCObjects; +declare module "QCObjects" { + const _exports: {}; + export = _exports; +} +declare module "index" { + import QCObjects from "QCObjects"; + export default QCObjects; +} diff --git a/tsconfig.d.json b/tsconfig.d.json index fdf55d0f..a76ff10a 100644 --- a/tsconfig.d.json +++ b/tsconfig.d.json @@ -8,11 +8,11 @@ "strictPropertyInitialization": true, "noImplicitThis": true, "alwaysStrict": true, - "outFile": "src/types.d.ts", + "outFile": "src/index.d.ts", "typeRoots": ["types", "node_modules/@types", "@typescript-eslint"], "allowSyntheticDefaultImports":true, "esModuleInterop": true }, - "include": ["src/**/*.ts", "src/static/js/packages/components/*.d.ts"], + "include": ["src/**/*.ts", "src/static/js/packages/components/*.d.ts", "types/*.d.ts"], "exclude": ["src/**/*.spec.js", "src/*.js", "src/*.d.ts", "src/**/*.d.ts"] } diff --git a/tsconfig.json b/tsconfig.json index 32f1424f..de332dba 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,8 +8,10 @@ "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ "outDir": "build", /* Specify an output folder for all emitted files. */ "allowSyntheticDefaultImports":true, - "esModuleInterop": true + "esModuleInterop": true, + "baseUrl": ".", + "typeRoots": ["types", "node_modules/@types", "@typescript-eslint"] }, "include": ["src/**/*.ts", "src/**/*.mts", "src/**/*.cts"], - "exclude": ["src/**/*.spec.js", "src/*.js"] + "exclude": ["src/**/*.spec.js", "src/*.js","src/*.d.ts", "src/**/*.d.ts"] } diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 00000000..eff2a2de --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,472 @@ +// Type definitions for QCObjects 2.4 +// Project: https://qcobjects.dev +// Definitions by: Jean Machuca +// Definitions: https://qcobjects.dev + +import { ClientRequest } from "http"; +import { Http2SecureServer, Http2Server, Http2ServerRequest, Http2Stream } from "http2"; +import { Stream } from "stream"; + +declare namespace QCObjects { + type Microservice = { + domain: string; + basePath: string; + body: any; + stream?: Http2Stream | Stream; + request?: Http2ServerRequest | ClientRequest; + } + + class Route { + name: string; + description?: string; + path: string; + microservice: string; + redirect_to?: string; + headers?: any; + responseHeaders?: any; + cors?: any; + } + + class BackendMicroservice extends InheritClass { + domain: string; + body: QCObjectsElement | QCObjectsShadowedElement | HTMLElement | string | undefined; + basePath: string; + route: Route; + projectPath?: string; + stream?: Http2Stream | Stream; + request?: Http2ServerRequest | ClientRequest; + routeParams?: any; + server: Http2SecureServer | Http2Server; + + constructor(microservice: Microservice); + + cors(): void; + head(formData?: object | string): void; + get(formData?: object | string): void; + post(formData?: object | string): void; + put(formData?: object | string): void; + delete(formData?: object | string): void; + connect(formData?: object | string): void; + options(formData?: object | string): void; + trace(formData?: object | string): void; + patch(formData?: object | string): void; + finishWithBody(stream?: Http2Stream | Stream): void; + done(): void; + + } + + + class QCObjectsElement extends HTMLElement { + subelements(query: string): Array; + } + class QCObjectsShadowedElement extends ShadowRoot { + style: any; + subelements(query: string): Array; + } + + class Logger { + debugEnabled: boolean; + infoEnabled: boolean; + warnEnabled: boolean; + debug(message: any): string; + warn(message: any): string; + info(message: any): string; + + } + function Class(className: string, extendsFrom: any, definition: any): any; + class _Crypt { + last_string: string; + last_key: string; + construct: boolean; + _new_(o: any): void; + _encrypt(): string; + _decrypt(): string; + static encrypt(_string_: string, key: string): string; + static decrypt(_string_: string, key: string): string; + + } + class TagElements extends Array { + show(): void; + hide(): void; + effect(): void; + findElements(elementName: string): TagElements; + } + class DefaultTemplateHandler { + template: string; + __definition: any; + constructor({ component, template }); + assign(data: any): any; + } + class SourceJS { + domain: string; + basePath: string; + body: QCObjectsElement | HTMLElement; + type: string; + containerTag: string; + url: string; + data: any; + async: boolean; + external: boolean; + set(name: string, value: any): void; + get(name: string): any; + status: boolean; + done(): void; + fail(): void; + rebuild(): void; + Cast(o: any): any; + _new_(properties: any): void; + + } + class SourceCSS { + domain: string; + basePath: string; + body: QCObjectsElement | HTMLElement; + url: string; + data: any; + async: boolean; + external: boolean; + set(name: string, value: any): void; + get(name: string): any; + done(): void; + fail(): void; + rebuild(): void; + Cast(o: any): any; + _new_(properties: any): void; + + } + class ArrayList extends Array { } + class ArrayCollection { + source: ArrayList; + changed(prop: string, value: any): any; + push(value: any): void; + pop(value: any): void; + _new_(source: ArrayList): void; + } + class GlobalSettings { + _GLOBAL: any; + set(name: string, value: any): void; + get(name: string, _default: any): any; + static __start__(): Promise; + } + class GLOBAL extends GlobalSettings { } + class DDO { + constructor({ + instance, + name: string, + fget, + fset, + value: any + }); + } + type CacheController = { + cache:ComplexStorageCache; + cachedObjectID:string; + cachedResponse?:any; + } + type ComplexCacheParams = { + index:string; + load (cacheController?:CacheController):any; + alternate(cacheController?:CacheController):any; + } + class ComplexStorageCache { + object: any; + index: string; + load(cacheController: ComplexStorageCache): void; + alternate(cacheController: ComplexStorageCache): void; + clear(): void; + getCached(object: any): any; + getID(object: any): any; + getItem(cachedObjectID: string): JSON | null; + setItem(cachedObjectID: string, value: any): void; + isEmpty(object: any): boolean; + save(object: any, cachedNewResponse: string): void; + + constructor(cache:ComplexCacheParams); + + } + class _ComponentWidget_ extends HTMLElement { } + + function asyncLoad(callback: Function, args: Array): any; + function RegisterClass(_class_: any, namespace: string): void; + function ComponentURI({ COMPONENTS_BASE_PATH, COMPONENT_NAME, TPLEXTENSION, TPL_SOURCE }): string; + function waitUntil(func: Function, exp: Function): void; + function _super_(className: string, classMethodName: string, params?: Array): any; + function _DOMCreateElement(elementName: string): QCObjectsElement | HTMLElement; + function shortCode(): string; + function __getType__(_class_: any): string; + function is_a(obj: any, typeName: string): boolean; + function _DataStringify(data: any): string; + function serviceLoader(service: Service, _async: boolean): Promise; + function componentLoader(component: Component, _async: boolean): Promise; + function ObjectName(o: any): string; + function isQCObjects_Class(_: any): boolean; + function isQCObjects_Object(_: any): boolean; + function NamespaceRef(namespace: string): any; + function RegisterWidget(widgetName: string): void; + function RegisterWidgets(...widgetList: Array): void; + function range(start: number, stop: number, step: number): Array; + function getDocumentLayout(): string; + function Export(fn: Function): Function; + function New(__class__: any, args: any): any; + function Tag(tagName: string, innerHTML?: string): TagElements; + function Ready(e: Function): void; + function _methods_(_: any): Array; + function set(_: any, _value_: any): any; + function get(_: any, _defaultValue_: any): any; + function __start__(): void; + + + + class InheritClass { + __instanceID: number; + __classType?: string; + __definition?: any; + __new__?(): void; + __namespace?: string; + body?: QCObjectsElement | QCObjectsShadowedElement | HTMLElement | string | null | undefined; + constructor(o?:any); + } + + class Processor extends InheritClass { + component: Component; + processors: Array; + process(template: string, component: Component): any; + processObject(obj: any, component: Component): any; + setProcessor(proc: Function): any; + constructor(...args: Array); + + } + + type ComponentParams = { + name: string; + template?: string; + templateURI?: string; + tplsource?: string; + tplextension?: string; + url?: string; + method?: string; + data?: any; + reload?: boolean; + shadowed?: boolean; + cached?: boolean; + _body?: QCObjectsElement; + __promise__?: Promise; + __shadowRoot?: QCObjectsShadowedElement; + body?: QCObjectsElement; + shadowRoot?: QCObjectsShadowedElement; + splashScreenComponent?: Component; + controller?: Controller; + view?: View; + }; + + type ComponentDoneResponse = { + request?: XMLHttpRequest; + component?: Component; + }; + + class Component extends InheritClass { + name: string; + _body: QCObjectsElement | HTMLElement; + body: QCObjectsElement | HTMLElement; + templateURI: string; + tplsource: string; + tplextension: string; + template: string; + validRoutingWays: Array; + basePath: string; + domain: string; + templateHandler: string; + processorHandler: Processor; + routingWay: string; + routingNodes: Array; + routings: Array; + routingPath: string; + routingPaths: Array; + _componentHelpers: Array; + subcomponents: Array; + splashScreenComponent?: Component; + controller: Controller | null; + view: View | null; + effect: Effect; + effectClass: string; + method: string; + static cached: boolean; + __promise__?: Promise; + data: any; + shadowed?: boolean; + shadowRoot?: QCObjectsShadowedElement; + cacheIndex: string; + parsedAssignmentText: string; + routingSelected: Array; + routingParams: {}; + subtags: Array; + bodyAttributes: any; + dataAttributes: any; + serviceData?:any; + constructor(component: ComponentParams); + static route(): Promise; + __done__(): Promise; + _bindroute(): void; + __buildSubComponents__(rebuildObjects: boolean): Array; + _generateRoutingPaths(componentBody: QCObjectsElement | HTMLElement): Promise; + _reroute_(): Promise; + createServiceInstance(): Promise; + createControllerInstance(): Promise<{ component: Component, controller: Controller }>; + createEffectInstance(): Promise<{ component: Component, effect: Effect }>; + createViewInstance(): Promise<{ component: Component, view: View }>; + done(standardResponse: ComponentDoneResponse): Promise; + fail({ error: any, component: Component }); + hostElements(tagFilter: string): Array; + set(name: string, value: any): void; + get(name: string): any; + feedComponent(): void; + rebuild(): Promise<{ request: XMLHttpRequest, component: Component }>; + Cast(oClass: any): any; + fullscreen(): void; + closefullscreen(): void; + parseTemplate(template: string): string; + lazyLoadImages(): any | null; + applyTransitionEffect(effectClassName: string): void; + applyObserveTransitionEffect(effectClassName: string): void | null; + scrollIntoHash(): void; + i18n_translate(): void; + addComponentHelper(componentHelper: Function): void; + runComponentHelpers(): void; + + } + + class CONFIG extends InheritClass { + _CONFIG_ENC: string; + _CONFIG: any; + static set(_: any, _value_: any): any; + static get(_: any, _defaultValue_: any): any; + __definition: any; + } + + type ControllerParams = { + component: Component; + dependencies: Array; + }; + + class Controller { + __classType: string; + __definition: any; + __new__(): any; + __namespace: string; + body?: QCObjectsElement | HTMLElement; + component: Component; + dependencies?: Array; + constructor(controller: ControllerParams); + routingSelectedAttr(attrName: string): any; + isTouchable(): boolean; + onpress(subelementSelector: string, handler: EventListener): void; + createRoutingController(): void; + + + done(...args: Array); + fail(...args: Array); + } + + type ViewParams = { + component: Component; + dependencies: Array; + }; + + class View { + __classType: string; + __definition: any; + __new__(): any; + __namespace: string; + body: QCObjectsElement | HTMLElement; + component: Component; + constructor(view: ViewParams); + done(...args: Array); + fail(...args: Array); + } + + class Service extends InheritClass { + kind: string; + domain: string; + basePath: string; + url: string; + method: string; + data: any; + reload: boolean; + cached: boolean; + headers: any; + template: any; + set(name: string, value: any): void; + get(name: string): any; + done({ request: XMLHttpRequest, service: Service }); + fail(...args: Array); + } + class JSONService extends Service { + JSONresponse: JSON; + } + class ConfigService extends JSONService { + configFileName: string; + } + class VO { } + type EffectParams = { + duration:number; + timing(timeFraction:number):number; + draw(progress:number); + }; + + class Effect extends InheritClass { + duration: number; + apply(...args: Array): any; + animate (effect:EffectParams); + } + class TransitionEffect extends Effect { + component: Component; + defaultParams: { + alphaFrom?: number, + alphaTo?: number, + angleFrom?: number, + angleTo?: number, + radiusFrom?: number, + radiusTo?: number, + scaleFrom?: number, + scaleTo?: number + }; + duration: number; + fitToHeight: boolean; + fitToWidth: boolean; + effects: Array; + + } + type TimerParams = { + duration:number; + timing(timeFraction:number):number; + intervalInterceptor(progress:number); + }; + + class Timer extends InheritClass { + duration: number; + alive: boolean; + thread(timer:TimerParams):void; + } + class Toggle { + _toggle: boolean; + _inverse: boolean; + _positive: Function; + _negative: Function; + _dispatched?: boolean; + _args: Array; + + constructor(positive: Function, negative: Function, args: Array); + + } + + let logger: Logger; + let _sdk_: Promise; + let global: GLOBAL; + + function ClassFactory(className: string): any; + function Package(packageName: string, classesList?: Array | undefined): Array | undefined; + function Import(packageName: string, ready?: Function, external?: boolean): any; + +} + +export = QCObjects; \ No newline at end of file