From 5bc33ae979955dfd082f8c21f0bb84b49bacb290 Mon Sep 17 00:00:00 2001 From: Aaron Holderman Date: Wed, 26 Sep 2018 11:27:41 -0600 Subject: [PATCH] fix tests --- types/apostrophe/apostrophe-tests.ts | 14 + types/apostrophe/index.d.ts | 513 ++++++++++++++------------- types/apostrophe/tsconfig.json | 1 + types/apostrophe/tslint.json | 7 +- 4 files changed, 292 insertions(+), 243 deletions(-) diff --git a/types/apostrophe/apostrophe-tests.ts b/types/apostrophe/apostrophe-tests.ts index e69de29bb2..f86500702b 100644 --- a/types/apostrophe/apostrophe-tests.ts +++ b/types/apostrophe/apostrophe-tests.ts @@ -0,0 +1,14 @@ +import { AposModuleOptions } from "apostrophe"; + +const testModuleOptions: AposModuleOptions = { + extend: "apostrophe-widgets", + label: "Test Widget", + addFields: [ + { + name: "title", + label: "Test Title", + type: "string", + required: true + } + ] +}; diff --git a/types/apostrophe/index.d.ts b/types/apostrophe/index.d.ts index 890edeae67..efc8f3fda4 100644 --- a/types/apostrophe/index.d.ts +++ b/types/apostrophe/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/apostrophecms/apostrophe#readme // Definitions by: My Self // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 export = apostrophe; export as namespace apos; @@ -9,264 +10,292 @@ export as namespace apos; declare function apostrophe(options: any, ...args: any[]): any; declare namespace apostrophe { - const moogBundle: { - directory: string; - modules: string[]; - }; + const moogBundle: { + directory: string; + modules: string[]; + }; - const prototype: {}; + const prototype: {}; - const ui: { - globalBusy: (state: any) => any; - link: ( - sel: string, - verb: string, - object: object, - callback?: Function - ) => any; - }; + const ui: { + globalBusy: (state: any) => any; + link: ( + sel: string, + verb: string, + object: object, + callback?: () => any + ) => any; + }; - const pages: { - page: { _id: string; type: string; _url?: string }; - }; + const pages: { + page: { _id: string; type: string; _url?: string }; + }; - const adminBar: { - link: (name: string, callback: () => any) => void; - }; + const adminBar: { + link: (name: string, callback: () => any) => void; + }; - const change: (arg: object | string) => any; + function change(arg: object | string): any; - const create: (type: string, options: any, callback?: Function) => any; + function create(type: string, options: any, callback?: () => any): any; - const contextPiece: { - _id: string; - title: string; - slug: string; - type: string; - }; + const contextPiece: { + _id: string; + title: string; + slug: string; + type: string; + }; - const define: ( - type: string | string[], - definition: any, - extending?: any - ) => any; + function define( + type: string | string[], + definition: any, + extending?: any + ): any; - const docs: { - getManager: (type: string) => void; - setManager: (type: string, manager: any) => void; - lock: (id: string, callback?: Function) => void; - lockAndWatch: (id: string, callback?: Function) => void; - unlock: (_id: string, sync: any, callback?: Function) => any; - }; + const docs: { + getManager: (type: string) => void; + setManager: (type: string, manager: any) => void; + lock: (id: string, callback?: () => any) => void; + lockAndWatch: (id: string, callback?: () => any) => void; + unlock: (_id: string, sync: any, callback?: () => any) => any; + }; - const emit: (name: string, arg?: any) => any; + function emit(name: string, arg?: any): any; - const modules: object; + const modules: object; - const modalSupport: { - stack: any[]; - initialized: boolean; - depth: number; - all: any[]; - getTopModalOrBody: () => string; - getLatestModal: () => null | string; - closeTopModal: () => void; - cancelTopModal: () => void; - }; + const modalSupport: { + stack: any[]; + initialized: boolean; + depth: number; + all: any[]; + getTopModalOrBody: () => string; + getLatestModal: () => null | string; + closeTopModal: () => void; + cancelTopModal: () => void; + }; - const notify: (message: string | object, options: AposObject) => any; + function notify(message: string | object, options: AposObject): any; - const off: (eventName: string, fn?: Function) => any; + function off(eventName: string, fn?: () => any): any; - const on: (eventName: string, fn?: Function) => any; + function on(eventName: string, fn?: () => any): any; - const schemas: { - convert: ( - $el: HTMLElement, - schema: Schema, - data: any, - options: any, - callback?: Function - ) => any; - newInstance: (schema: Schema) => any; - populate: ( - data: any, - name: string, - $field: any, - callback?: () => void, - $el?: HTMLElement, - field?: any - ) => any; - returnToError: ( - $el: HTMLElement, - schema: Schema, - errorPath: any, - error: any, - callback: Function - ) => void; - }; + const schemas: { + convert: ( + $el: HTMLElement, + schema: Schema, + data: any, + options: any, + callback?: () => any + ) => any; + newInstance: (schema: Schema) => any; + populate: ( + data: any, + name: string, + $field: any, + callback?: () => void, + $el?: HTMLElement, + field?: any + ) => any; + returnToError: ( + $el: HTMLElement, + schema: Schema, + errorPath: any, + error: any, + callback: () => any + ) => void; + }; - const utils: { - capitalizeFirst: (s: string) => string; - camelName: (s: string) => string; - error: (msg: string) => void; - generateId: () => string; - }; + const utils: { + capitalizeFirst: (s: string) => string; + camelName: (s: string) => string; + error: (msg: string) => void; + generateId: () => string; + }; - const versions: { - edit: (id: string, afterRevert?: () => void) => any; - }; + const versions: { + edit: (id: string, afterRevert?: () => void) => any; + }; + + interface AposObject { + [key: string]: any; + } + + interface Field { + name: string; + type: string; + label: string; + required?: boolean; + options?: AposObject; + } + + type Fields = Field[]; + + interface AposType { + name: string; + converters: { + string( + req: any, + data: any, + name: string, + object: AposObject, + field: any, + callback: () => any + ): void; + form( + req: any, + data: any, + name: string, + object: AposObject, + field: any, + callback: () => any + ): void; + }; + empty?(field: any, value: any): void; + bless?(req: any, field: any): void; + index(value: any, field: any, texts: any): void; + } + + interface Schema { + createRoutes(): any[]; + pushAssets(): void; + pushCreateSingleton(): void; + compose(options: AposObject): void; + refine(schema: Schema, options: AposObject): void; + toGroups(fields: Fields): void; + subset(schema: Schema, fields: Fields): Schema; + newInstance(schema: Schema): any; + subsetInstance(schema: Schema, instance: AposObject): any; + empty(schema: Schema, object: AposObject): void; + indexFields(schema: Schema, object: AposObject, texts: any): void; + convert( + req: any, + schema: Schema, + to: any, + object: AposObject, + output: any, + callback: () => any + ): void; + isVisible(schema: Schema, object: AposObject, name: string): void; + export( + req: any, + schema: Schema, + to: any, + object: AposObject, + output: any, + callback: () => any + ): void; + joinDriver( + req: any, + method: any, + reverse: any, + items: any, + idField: any, + relationshipsField: any, + objectField: any, + options: any, + callback: () => any + ): void; + join( + req: any, + schema: Schema, + objectOrArray: any, + withJoins: any, + callback: () => any + ): void; + addFieldType(type: AposType): void; + getFieldType(typeName: string): void; + addFilters(schema: Schema, options: any, cursor: any): void; + joinFilterChoices(field: any, cursor: any, valueField: any): void; + addJoinSlugFilter(field: any, cursor: any, suffix: any): void; + pageServe(req: any): void; + sortedDistinct(property: any, cursor: any, callback: () => any): void; + cursorFilterInterested(cursor: any, name: string): void; + afterInit(): void; + validate(schema: Schema, options: any): void; + } + + interface AposModule { + emit(name: string): void; + on(name: string, methodName: any, fn: () => any): void; + } + + type AposCoreModules = + | "apostrophe-admin-bar" + | "apostrophe-any-page-manager" + | "apostrophe-areas" + | "apostrophe-assets" + | "apostrophe-attachments" + | "apostrophe-browser-utils" + | "apostrophe-caches" + | "apostrophe-custom-pages" + | "apostrophe-db" + | "apostrophe-doc-type-manager" + | "apostrophe-docs" + | "apostrophe-email" + | "apostrophe-express" + | "apostrophe-files" + | "apostrophe-files-widgets" + | "apostrophe-global" + | "apostrophe-groups" + | "apostrophe-html-widgets" + | "apostrophe-i18n" + | "apostrophe-images" + | "apostrophe-images-widgets" + | "apostrophe-jobs" + | "apostrophe-launder" + | "apostrophe-locks" + | "apostrophe-login" + | "apostrophe-migrations" + | "apostrophe-modal" + | "apostrophe-module" + | "apostrophe-notifications" + | "apostrophe-oembed" + | "apostrophe-pager" + | "apostrophe-pages" + | "apostrophe-permissions" + | "apostrophe-pieces" + | "apostrophe-pieces-pages" + | "apostrophe-pieces-widgets" + | "apostrophe-polymorphic-manager" + | "apostrophe-push" + | "apostrophe-rich-text-widgets" + | "apostrophe-schemas" + | "apostrophe-search" + | "apostrophe-service-bridge" + | "apostrophe-soft-redirects" + | "apostrophe-tags" + | "apostrophe-tasks" + | "apostrophe-templates" + | "apostrophe-ui" + | "apostrophe-urls" + | "apostrophe-users" + | "apostrophe-utils" + | "apostrophe-versions" + | "apostrophe-video-fields" + | "apostrophe-video-widgets" + | "apostrophe-widgets"; + + interface AposModuleOptions { + extend: AposCoreModules; + name?: string; + label: string; + pluralLabel?: string; + playerData?: false | string[]; + scene?: "user"; + addFields?: Field[]; + removeFields?: Field[]; + arrangeFields?: { + name: string; + label: string; + fields: string[]; + }[]; + defer?: boolean; + filters?: { + projection?: { + [key: string]: number; + }; + }; + } } - -type AposObject = { - [key: string]: any; -}; - -type Fields = { - [key: string]: any; -}[]; - -type AposType = { - name: string; - converters: { - string( - req: any, - data: any, - name: string, - object: AposObject, - field: any, - callback: Function - ): void; - form( - req: any, - data: any, - name: string, - object: AposObject, - field: any, - callback: Function - ): void; - }; - empty?(field: any, value: any): void; - bless?(req: any, field: any): void; - index(value: any, field: any, texts: any): void; -}; - -type Schema = { - createRoutes(): any[]; - pushAssets(): void; - pushCreateSingleton(): void; - compose(options: AposObject): void; - refine(schema: Schema, options: AposObject): void; - toGroups(fields: Fields): void; - subset(schema: Schema, fields: Fields): Schema; - newInstance(schema: Schema): any; - subsetInstance(schema: Schema, instance: AposObject): any; - empty(schema: Schema, object: AposObject): void; - indexFields(schema: Schema, object: AposObject, texts: any): void; - convert( - req: any, - schema: Schema, - to: any, - object: AposObject, - output: any, - callback: Function - ): void; - isVisible(schema: Schema, object: AposObject, name: string): void; - export( - req: any, - schema: Schema, - to: any, - object: AposObject, - output: any, - callback: Function - ): void; - joinDriver( - req: any, - method: any, - reverse: any, - items: any, - idField: any, - relationshipsField: any, - objectField: any, - options: any, - callback: Function - ): void; - join( - req: any, - schema: Schema, - objectOrArray: any, - withJoins: any, - callback: Function - ): void; - addFieldType(type: AposType): void; - getFieldType(typeName: string): void; - addFilters(schema: Schema, options: any, cursor: any): void; - joinFilterChoices(field: any, cursor: any, valueField: any): void; - addJoinSlugFilter(field: any, cursor: any, suffix: any): void; - pageServe(req: any): void; - sortedDistinct(property: any, cursor: any, callback: Function): void; - cursorFilterInterested(cursor: any, name: string): void; - afterInit(): void; - validate(schema: Schema, options: any): void; -}; - -type AposModule = { - emit(name: string): void; - on(name: string, methodName: any, fn: Function): void; -}; - -type AposCoreModules = - | "apostrophe-admin-bar" - | "apostrophe-any-page-manager" - | "apostrophe-areas" - | "apostrophe-assets" - | "apostrophe-attachments" - | "apostrophe-browser-utils" - | "apostrophe-caches" - | "apostrophe-custom-pages" - | "apostrophe-db" - | "apostrophe-doc-type-manager" - | "apostrophe-docs" - | "apostrophe-email" - | "apostrophe-express" - | "apostrophe-files" - | "apostrophe-files-widgets" - | "apostrophe-global" - | "apostrophe-groups" - | "apostrophe-html-widgets" - | "apostrophe-i18n" - | "apostrophe-images" - | "apostrophe-images-widgets" - | "apostrophe-jobs" - | "apostrophe-launder" - | "apostrophe-locks" - | "apostrophe-login" - | "apostrophe-migrations" - | "apostrophe-modal" - | "apostrophe-module" - | "apostrophe-notifications" - | "apostrophe-oembed" - | "apostrophe-pager" - | "apostrophe-pages" - | "apostrophe-permissions" - | "apostrophe-pieces" - | "apostrophe-pieces-pages" - | "apostrophe-pieces-widgets" - | "apostrophe-polymorphic-manager" - | "apostrophe-push" - | "apostrophe-rich-text-widgets" - | "apostrophe-schemas" - | "apostrophe-search" - | "apostrophe-service-bridge" - | "apostrophe-soft-redirects" - | "apostrophe-tags" - | "apostrophe-tasks" - | "apostrophe-templates" - | "apostrophe-ui" - | "apostrophe-urls" - | "apostrophe-users" - | "apostrophe-utils" - | "apostrophe-versions" - | "apostrophe-video-fields" - | "apostrophe-video-widgets" - | "apostrophe-widgets"; diff --git a/types/apostrophe/tsconfig.json b/types/apostrophe/tsconfig.json index 24c5d48f85..6df1f1b3b8 100644 --- a/types/apostrophe/tsconfig.json +++ b/types/apostrophe/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/apostrophe/tslint.json b/types/apostrophe/tslint.json index 3db14f85ea..30332ffc41 100644 --- a/types/apostrophe/tslint.json +++ b/types/apostrophe/tslint.json @@ -1 +1,6 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dt.json", + "rules": { + "array-type": [true, "array"] + } +}