tw5-typed 0.1.12 → 0.2.0

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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "description": "Types for tiddlywiki",
3
3
  "license": "MIT",
4
4
  "name": "tw5-typed",
5
- "version": "0.1.12",
5
+ "version": "0.2.0",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
7
  "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
8
  "bugs": {
@@ -20,28 +20,28 @@
20
20
  "prepublishOnly": "npx tsc --noEmit"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^17.0.22",
24
- "@typescript-eslint/eslint-plugin": "5.16.0",
25
- "@typescript-eslint/parser": "5.16.0",
26
- "eslint": "8.11.0",
23
+ "@types/node": "^17.0.23",
24
+ "@typescript-eslint/eslint-plugin": "5.17.0",
25
+ "@typescript-eslint/parser": "5.17.0",
26
+ "eslint": "8.12.0",
27
27
  "eslint-config-prettier": "8.5.0",
28
28
  "eslint-config-standard": "16.0.3",
29
29
  "eslint-config-standard-with-typescript": "21.0.1",
30
30
  "eslint-import-resolver-alias": "1.1.2",
31
- "eslint-import-resolver-typescript": "2.5.0",
31
+ "eslint-import-resolver-typescript": "2.7.0",
32
32
  "eslint-plugin-html": "6.2.0",
33
33
  "eslint-plugin-import": "2.25.4",
34
- "eslint-plugin-n": "15.0.1",
34
+ "eslint-plugin-n": "15.1.0",
35
35
  "eslint-plugin-node": "11.1.0",
36
36
  "eslint-plugin-prettier": "4.0.0",
37
37
  "eslint-plugin-promise": "6.0.0",
38
38
  "eslint-plugin-react": "7.29.4",
39
- "eslint-plugin-react-hooks": "4.3.0",
39
+ "eslint-plugin-react-hooks": "4.4.0",
40
40
  "eslint-plugin-security": "1.4.0",
41
41
  "eslint-plugin-security-node": "1.1.1",
42
42
  "eslint-plugin-typescript-sort-keys": "2.1.0",
43
- "eslint-plugin-unicorn": "41.0.1",
44
- "prettier": "2.6.0",
45
- "typescript": "4.6.2"
43
+ "eslint-plugin-unicorn": "42.0.0",
44
+ "prettier": "2.6.1",
45
+ "typescript": "4.6.3"
46
46
  }
47
47
  }
package/src/Wiki.d.ts CHANGED
@@ -29,6 +29,10 @@ declare module 'tiddlywiki' {
29
29
  * Update existed tiddler based on the title field.
30
30
  */
31
31
  addTiddler: (tiddler: Tiddler | ITiddlerFields) => void;
32
+ /**
33
+ * Call `addTiddler` for each iton of the list
34
+ */
35
+ addTiddlers: (tiddler: Array<Tiddler | ITiddlerFields>) => void;
32
36
  /**
33
37
  * Get tiddler's text field, with an optional default text.
34
38
  * If have _is_skinny field, will just return null (this is a rare case, so not put in the return type for now).
package/src/ast.d.ts CHANGED
@@ -1,38 +1,37 @@
1
1
  declare module 'tiddlywiki' {
2
2
  export interface IParseTreeAttribute {
3
- start?: number;
3
+ end?: number;
4
4
  name?: string;
5
+ start?: number;
5
6
  type: 'string' | 'number';
6
7
  value: string;
7
- end?: number;
8
8
  }
9
9
 
10
10
  export interface IWikiASTNode {
11
- type: string;
11
+ attributes?: Record<string, IParseTreeAttribute>;
12
12
  children?: IParseTreeNode[];
13
- start?: number;
14
13
  end?: number;
15
14
  isBlock?: boolean;
16
15
  isSelfClosing?: boolean;
17
- attributes?: Record<string, IParseTreeAttribute>;
18
16
  orderedAttributes?: IParseTreeAttribute[];
17
+ start?: number;
18
+ type: string;
19
19
  }
20
20
  export interface ITextParseTreeNode extends IWikiASTNode {
21
- type: 'text';
22
21
  text: string;
22
+ type: 'text';
23
23
  }
24
24
  export interface ILinkParseTreeNode extends IWikiASTNode {
25
- type: 'link';
26
25
  text: string;
26
+ type: 'link';
27
27
  }
28
28
  export type HTMLTags = keyof HTMLElementTagNameMap | 'strike';
29
29
 
30
30
  export interface IDomParseTreeNode extends IWikiASTNode {
31
- type: 'element';
32
31
  tag: HTMLTags;
32
+ type: 'element';
33
33
  }
34
34
  export interface ICodeBlockParseTreeNode extends IWikiASTNode {
35
- type: 'codeblock';
36
35
  attributes: {
37
36
  code?:
38
37
  | {
@@ -47,22 +46,23 @@ declare module 'tiddlywiki' {
47
46
  }
48
47
  | undefined;
49
48
  };
49
+ type: 'codeblock';
50
50
  }
51
- export interface IMacroParamCallParseTreeNode extends IWikiASTNode {
51
+ export interface IMacroParameterCallParseTreeNode extends IWikiASTNode {
52
+ name?: string;
52
53
  type: 'macro-parameter';
53
54
  value: string;
54
- name?: string;
55
55
  }
56
56
  export interface IMacroCallParseTreeNode extends IWikiASTNode {
57
- type: 'macrocall';
58
57
  name: string;
59
- params: IMacroParamCallParseTreeNode[];
58
+ params: IMacroParameterCallParseTreeNode[];
59
+ type: 'macrocall';
60
60
  }
61
61
  export interface ICustomParseTreeNode extends IWikiASTNode {
62
- type: string;
62
+ params: IMacroParameterCallParseTreeNode[];
63
63
  tag?: string;
64
- params: IMacroParamCallParseTreeNode[];
65
64
  text?: string;
65
+ type: string;
66
66
  }
67
- export type IParseTreeNode = IDomParseTreeNode | IMacroParamCallParseTreeNode | IMacroCallParseTreeNode | ITextParseTreeNode | ICustomParseTreeNode;
67
+ export type IParseTreeNode = IDomParseTreeNode | IMacroParameterCallParseTreeNode | IMacroCallParseTreeNode | ITextParseTreeNode | ICustomParseTreeNode;
68
68
  }
@@ -93,7 +93,10 @@ Either way, we could interpret the `!` flag on the filter, if present, to mean t
93
93
  As with [JavaScript Macros](#JavaScript%20Macros), filter operators should not make modifications to tiddlers, but only return a list of tiddlers or a tiddler iterator.
94
94
 
95
95
  */
96
- export type IFilterOperator = (source: (iter: SourceIterator) => void, operator: IFilterOperatorParameterOperator) => string[] | ((iter: SourceIterator) => void);
96
+ export type IFilterOperator = (
97
+ source: (iter: SourceIterator) => void,
98
+ operator: IFilterOperatorParameterOperator,
99
+ ) => string[] | ((iter: SourceIterator) => void);
97
100
 
98
101
  /**
99
102
  * A [tiddler iterator](#Tiddler%20Iterators) representing the results of the previous filter step (or all tiddlers, if this filter appears first in an expression), conventionally named `source`.
package/src/index.d.ts CHANGED
@@ -1,24 +1,19 @@
1
1
  /// <reference path="tw.d.ts" />
2
-
3
- export * from 'tiddlywiki';
2
+ /// <reference path="server.d.ts" />
4
3
 
5
4
  import * as TW from 'tiddlywiki';
6
5
 
7
- import '@types/node';
6
+ export * from 'tiddlywiki';
8
7
  declare global {
9
- const $tw: TW.ITiddlyWiki;
10
- // const Buffer: ?Buffer;
11
- // const clearInterval: typeof global.clearInterval;
12
- // const clearTimeout: typeof global.clearTimeout;
13
- // const console: Console;
14
- // const exports: TW.ITWModuleExports;
15
- // const module: { exports: TW.ITWModuleExports; readonly id: string };
16
- // const process: ?NodeJS.Process;
17
- // const require: ITWRequire;
18
- // const setInterval: typeof global.setInterval;
19
- // const setTimeout: typeof global.setTimeout;
20
- }
21
-
22
- declare module '@types/tiddlywiki' {
23
- export const TiddlyWiki: TW.TW5InitFunction;
8
+ const $tw: TW.ITiddlyWiki;
9
+ // const Buffer: ?Buffer;
10
+ // const clearInterval: typeof global.clearInterval;
11
+ // const clearTimeout: typeof global.clearTimeout;
12
+ // const console: Console;
13
+ // const exports: TW.ITWModuleExports;
14
+ // const module: { exports: TW.ITWModuleExports; readonly id: string };
15
+ // const process: ?NodeJS.Process;
16
+ // const require: ITWRequire;
17
+ // const setInterval: typeof global.setInterval;
18
+ // const setTimeout: typeof global.setTimeout;
24
19
  }
package/src/modules.d.ts CHANGED
@@ -69,7 +69,7 @@ declare module 'tiddlywiki' {
69
69
  * @param {(title, moduleExports) => void} callback function called as callback(title,moduleExports) for each module
70
70
  * @memberof ITWModules
71
71
  */
72
- forEachModuleOfType(moduleType: string, callback: (title, moduleExports) => void): void;
72
+ forEachModuleOfType(moduleType: string, callback: (title: string, moduleExports: unknown) => void): void;
73
73
  /** Get all the modules of a particular type in a hashmap by their `name` field */
74
74
  getModulesByTypeAsHashmap(moduleType: string, nameField: string): Record<string, IModuleInfo>;
75
75
  /** hashmap by module name of moduleInfo */
package/src/parser.d.ts CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  declare module 'tiddlywiki' {
4
4
  export interface IParserOptions {
5
- /**
6
- * While calling `getCacheForTiddler`, use inlineParseTree or blockParseTree
7
- */
8
- parseAsInline?: boolean;
9
5
  /**
10
6
  * Optional source uri, used in parseText
11
7
  */
12
8
  _canonical_uri?: string;
9
+ /**
10
+ * While calling `getCacheForTiddler`, use inlineParseTree or blockParseTree
11
+ */
12
+ parseAsInline?: boolean;
13
13
  }
14
14
 
15
15
  export class WikiParseRule {
@@ -20,18 +20,18 @@ declare module 'tiddlywiki' {
20
20
  nextTag?: null;
21
21
  /** `{type: 'macrocall', start: 261, params: Array(1), name: 'reuse-tiddler', end: 290}` */
22
22
  nextCall?: {
23
- type: string;
24
- start: number;
25
23
  end: number;
26
- /** `{ type: 'macro-parameter'; start: 276; value: '快速创建新笔记按钮'; end: 288 }` */
27
- params: { type: string; start: number; end: number; value: string };
28
24
  name: string;
25
+ /** `{ type: 'macro-parameter'; start: 276; value: '快速创建新笔记按钮'; end: 288 }` */
26
+ params: { end: number; start: number; type: string; value: string };
27
+ start: number;
28
+ type: string;
29
29
  };
30
30
  }
31
31
  export class WikiParser {
32
- blockRules: { rule: WikiParseRule; matchIndex?: number }[];
33
- inlineRules: { rule: WikiParseRule; matchIndex?: number }[];
34
- pragmaRules: { rule: WikiParseRule; matchIndex?: number }[];
32
+ blockRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
33
+ inlineRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
34
+ pragmaRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
35
35
  configTrimWhiteSpace: boolean;
36
36
  pos: number;
37
37
  source: string;
@@ -0,0 +1,28 @@
1
+ /// <reference path="Wiki.d.ts" />
2
+
3
+ import type Http from 'http';
4
+
5
+ declare module 'tiddlywiki' {
6
+ export interface IServerStatus {
7
+ anonymous: boolean;
8
+ read_only: boolean;
9
+ space: {
10
+ recipe: string;
11
+ };
12
+ tiddlywiki_version: string;
13
+ username: string;
14
+ }
15
+
16
+ export interface ServerEndpointContext {
17
+ data: string;
18
+ wiki: Wiki;
19
+ }
20
+ /**
21
+ * @link https://talk.tiddlywiki.org/t/what-is-the-state-in-server-route-handler/2877
22
+ */
23
+ export type ServerEndpointHandler<T = Record<string, any>> = (
24
+ request: Http.ClientRequest,
25
+ response: Http.ServerResponse,
26
+ context: ServerEndpointContext & T,
27
+ ) => void;
28
+ }
package/src/tw.d.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  /// <reference path="parser.d.ts" />
9
9
  /// <reference path="ast.d.ts" />
10
10
 
11
+ import { Server } from 'http';
12
+
11
13
  declare module 'tiddlywiki' {
12
14
  export interface IBootFilesIndexItem {
13
15
  filepath: string;
@@ -24,8 +26,6 @@ declare module 'tiddlywiki' {
24
26
  tiddlers: ITiddlerFields[];
25
27
  }
26
28
 
27
- export class Server {}
28
-
29
29
  export interface IFileExtensionInfo {
30
30
  type: string;
31
31
  }
@@ -43,11 +43,11 @@ declare module 'tiddlywiki' {
43
43
 
44
44
  boot: {
45
45
  argv: string[];
46
+ boot(callback?: () => unknown): void;
46
47
  files: IBootFilesIndex;
47
48
  log(logString: string): void;
48
49
  logMessages: string[];
49
50
  startup(options: { callback?: () => unknown }): void;
50
- boot(callback?: () => unknown): void;
51
51
  /** Default boot tasks */
52
52
  tasks: {
53
53
  readBrowserTiddlers: boolean;
package/src/utils.d.ts CHANGED
@@ -6,15 +6,15 @@ declare module 'tiddlywiki' {
6
6
  export type TWDOMElement = Element;
7
7
  export type TWEachCallback<T> = (element?: unknown, index?: string | number, object?: T) => boolean | undefined;
8
8
  export interface ITWUtils {
9
+ Crypto: typeof Crypto;
10
+ PasswordPrompt: typeof PasswordPrompt;
9
11
  /**
10
12
  * Alternative to `element.classList.add`, add a css class name to an element, see issue for detail.
11
13
  * @link https://github.com/Jermolene/TiddlyWiki5/issues/6475
12
- * @param element
13
- * @param className
14
+ * @param element
15
+ * @param className
14
16
  */
15
17
  addClass(element: Element, className: string): void;
16
- Crypto: typeof Crypto;
17
- PasswordPrompt: typeof PasswordPrompt;
18
18
  /** Returns true if the version string A is greater than the version string B. Returns true if the versions are the same */
19
19
  checkVersions(versionStringA: string, versionStringB: string): boolean;
20
20
  /**
@@ -102,6 +102,7 @@ declare module 'tiddlywiki' {
102
102
  parseDate(value: string | Date): Date;
103
103
  /** Parse a block of name:value fields. The `fields` object is used as the basis for the return value */
104
104
  parseFields(text: string, fields?: object): object;
105
+ parseJSONSafe(input: string): any;
105
106
  /** Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne" */
106
107
  parseStringArray(value: string | string[], allowDuplicate?: boolean): string[];
107
108
  /** Parse a semantic version string into its constituent parts -- see https://semver.org */