details: https://hg.nginx.org/njs/rev/5f18ec3b9e53 branches: changeset: 2091:5f18ec3b9e53 user: Dmitry Volyntsev <xei...@nginx.com> date: Wed Apr 26 19:38:21 2023 -0700 description: Types: added forgotten ts types for XML modification API.
diffstat: test/ts/test.ts | 17 ++++++- ts/njs_modules/xml.d.ts | 118 +++++++++++++++++++++-------------------------- 2 files changed, 69 insertions(+), 66 deletions(-) diffs (181 lines): diff -r 2efa017faaed -r 5f18ec3b9e53 test/ts/test.ts --- a/test/ts/test.ts Wed Apr 26 19:38:13 2023 -0700 +++ b/test/ts/test.ts Wed Apr 26 19:38:21 2023 -0700 @@ -174,11 +174,24 @@ function xml_module(str: NjsByteString) children = node.$tags; selectedChildren = node.$tags$xxx; - node?.xxx?.yyy?.$attr$zzz; + node?.$tag$xxx?.$tag$yyy?.$attr$zzz; let buf:Buffer = xml.exclusiveC14n(node); - buf = xml.exclusiveC14n(doc, node.xxx, false); + buf = xml.exclusiveC14n(doc, node.$tag$xxx, false); buf = xml.exclusiveC14n(node, null, true, "aa bb"); + + node.setText("xxx"); + node.removeText(); + node.setText(null); + + node.addChild(node); + node.removeChildren('xx'); + + node.removeAttribute('xx'); + node.removeAllAttributes(); + node.setAttribute('xx', 'yy'); + node.setAttribute('xx', null); + node.$tags = [node, node]; } function crypto_module(str: NjsByteString) { diff -r 2efa017faaed -r 5f18ec3b9e53 ts/njs_modules/xml.d.ts --- a/ts/njs_modules/xml.d.ts Wed Apr 26 19:38:13 2023 -0700 +++ b/ts/njs_modules/xml.d.ts Wed Apr 26 19:38:21 2023 -0700 @@ -2,61 +2,6 @@ declare module "xml" { - type XMLTagName = - | `_${string}` - | `a${string}` - | `b${string}` - | `c${string}` - | `d${string}` - | `e${string}` - | `f${string}` - | `g${string}` - | `h${string}` - | `i${string}` - | `j${string}` - | `k${string}` - | `l${string}` - | `m${string}` - | `n${string}` - | `o${string}` - | `p${string}` - | `q${string}` - | `r${string}` - | `s${string}` - | `t${string}` - | `u${string}` - | `v${string}` - | `w${string}` - | `x${string}` - | `y${string}` - | `z${string}` - | `A${string}` - | `B${string}` - | `C${string}` - | `D${string}` - | `E${string}` - | `F${string}` - | `G${string}` - | `H${string}` - | `I${string}` - | `J${string}` - | `K${string}` - | `L${string}` - | `M${string}` - | `N${string}` - | `O${string}` - | `P${string}` - | `Q${string}` - | `R${string}` - | `S${string}` - | `T${string}` - | `U${string}` - | `V${string}` - | `W${string}` - | `X${string}` - | `Y${string}` - | `Z${string}`; - export interface XMLDoc { /** * The doc's root node. @@ -66,17 +11,68 @@ declare module "xml" { /** * The doc's root by its name or undefined. */ - readonly [rootTagName: XMLTagName]: XMLNode | undefined; + readonly [rootTagName: string]: XMLNode | undefined; } export interface XMLNode { /** - * node.$attr$xxx - the node's attribute value of "xxx". + * Adds a child node. Node is recursively copied before adding. + * @param node - XMLNode to be added. + * @since 0.7.11. + */ + addChild(node: XMLNode): void; + + /** + * node.$attr$xxx - value of the node's attribute "xxx". * @since 0.7.11 the property is writable. */ [key: `$attr$${string}`]: string | undefined; /** + * Removes attribute by name. + * @param name - name of the attribute to remove. + * @since 0.7.11. + */ + removeAttribute(name: string): void; + + /** + * Removes all the attribute of the node. + * @since 0.7.11. + */ + removeAllAttributes(): void; + + /** + * Removes all the children tags named tag_name. + * @param tag_name - name of the children's tags to remove. + * If tag_name is absent all children tags are removed. + * @since 0.7.11. + */ + removeChildren(tag_name?:string): void; + + /** + * Removes the text value of the node. + * @since 0.7.11. + */ + removeText(): void; + + /** + * Sets a value for the attribute. + * @param attr_name - name of the attribute to set. + * @param value - value of the attribute to set. When value is null + * the attribute is removed. + * @since 0.7.11. + */ + setAttribute(attr_name: string, value: string | null): void; + + /** + * Sets a text value for the node. + * @param text - a value to set as a text. If value is null the + * node's text is deleted. + * @since 0.7.11. + */ + setText(text:string | null): void; + + /** * node.$attrs - an XMLAttr wrapper object for all the attributes * of the node. */ @@ -118,13 +114,7 @@ declare module "xml" { /** * node.$tags - all the node's children tags. */ - readonly $tags: XMLNode[] | undefined; - - /** - * node.xxx is the same as node.$tag$xxx. - * @since 0.7.11 the property is writable. - */ - [key: XMLTagName]: XMLNode | undefined; + $tags: XMLNode[] | undefined; } export interface XMLAttr { _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel