links-notation 0.21.3 → 0.23.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/index.d.ts CHANGED
@@ -106,6 +106,12 @@ export class Link {
106
106
  /**
107
107
  * Parser options for configuring the parser behavior
108
108
  */
109
+ /**
110
+ * How deep links may nest when nothing says otherwise (64). The same limit
111
+ * applies in every Links Notation implementation.
112
+ */
113
+ export const DEFAULT_MAX_DEPTH: number;
114
+
109
115
  export interface ParserOptions {
110
116
  /**
111
117
  * Maximum input size in bytes (default: 10MB)
@@ -113,7 +119,9 @@ export interface ParserOptions {
113
119
  maxInputSize?: number;
114
120
 
115
121
  /**
116
- * Maximum nesting depth (default: 1000)
122
+ * How deep links may nest: every parenthesized group and every indentation
123
+ * level is one level. A document nested deeper is refused with a ParseError
124
+ * whose maxDepth is set (default: 64)
117
125
  */
118
126
  maxDepth?: number;
119
127
 
@@ -293,6 +301,12 @@ export class ParseError extends Error {
293
301
  * The position the generated parser reported
294
302
  */
295
303
  location: ParseErrorLocation;
304
+
305
+ /**
306
+ * The deepest nesting allowed, when the document is nested deeper than
307
+ * that; null for any other error
308
+ */
309
+ maxDepth: number | null;
296
310
  }
297
311
 
298
312
  /**
@@ -456,3 +470,94 @@ export function formatLinks(
456
470
  links: Link[],
457
471
  lessParentheses?: boolean | FormatOptions | FormatConfig
458
472
  ): string;
473
+
474
+ /** Binary links notation v1: bigint preserves unsigned 64-bit references. */
475
+ export class External {
476
+ value: bigint;
477
+ constructor(value: bigint | number);
478
+ }
479
+ export class ArityRange {
480
+ min: bigint;
481
+ max: bigint | null;
482
+ constructor(min?: bigint | number, max?: bigint | number | null);
483
+ contains(length: bigint | number): boolean;
484
+ readonly fixed: boolean;
485
+ static parse(text: string): ArityRange;
486
+ }
487
+ export interface BinaryLimits {
488
+ maxLinks: number;
489
+ maxReferences: number;
490
+ maxNodes: number;
491
+ maxStringBytes: number;
492
+ maxDepth: number;
493
+ }
494
+ export class DecodeLimits implements BinaryLimits {
495
+ maxLinks: number;
496
+ maxReferences: number;
497
+ maxNodes: number;
498
+ maxStringBytes: number;
499
+ maxDepth: number;
500
+ constructor(values?: Partial<BinaryLimits>);
501
+ static unlimited(): DecodeLimits;
502
+ }
503
+ export class BinaryLinoOptions {
504
+ externalReferences: boolean;
505
+ arity: ArityRange;
506
+ packedWidths: boolean;
507
+ constructor(
508
+ externalReferences?: boolean,
509
+ arity?: ArityRange,
510
+ packedWidths?: boolean
511
+ );
512
+ static ofPacket(packet: LinksPacket): BinaryLinoOptions;
513
+ }
514
+ export type PacketReference = bigint | number | External;
515
+ export type AddressedLink = [bigint | number, PacketReference[]];
516
+ export class Section {
517
+ gap: bigint;
518
+ arity: ArityRange;
519
+ width: number;
520
+ links: PacketReference[][];
521
+ constructor(
522
+ gap: bigint | number,
523
+ arity: ArityRange,
524
+ width: number,
525
+ links: PacketReference[][]
526
+ );
527
+ }
528
+ export class PacketReader {
529
+ bytes: Uint8Array;
530
+ offset: number;
531
+ constructor(bytes: Uint8Array, offset?: number);
532
+ read(limits?: DecodeLimits): LinksPacket | null;
533
+ }
534
+ export class LinksPacket {
535
+ externalReferences: boolean;
536
+ sections: Section[];
537
+ constructor(externalReferences?: boolean, sections?: Section[]);
538
+ links(): [bigint, (bigint | External)[]][];
539
+ validate(limits?: DecodeLimits): this;
540
+ toBytes(limits?: DecodeLimits): Uint8Array;
541
+ static fromBytes(bytes: Uint8Array, limits?: DecodeLimits): LinksPacket;
542
+ static parseLinks(text: string): [bigint, (bigint | External)[]][];
543
+ static pack(
544
+ externalReferences: boolean,
545
+ links: AddressedLink[],
546
+ packedWidths?: boolean
547
+ ): LinksPacket;
548
+ }
549
+ export class BinaryLinoCodec {
550
+ options: BinaryLinoOptions;
551
+ limits: DecodeLimits;
552
+ constructor(options?: BinaryLinoOptions, limits?: DecodeLimits);
553
+ encodePacket(document: Link[]): LinksPacket;
554
+ encode(document: Link[]): Uint8Array;
555
+ decodePacket(packet: LinksPacket): Link[];
556
+ decode(bytes: Uint8Array): Link[];
557
+ parseDocument(text: string, parser?: Parser): Link[];
558
+ formatDocument(document: Link[]): string;
559
+ encodeText(text: string, parser?: Parser): Uint8Array;
560
+ decodeText(bytes: Uint8Array): string;
561
+ }
562
+ export function formatBinaryDocument(document: Link[]): string;
563
+ export function formatBinaryReference(reference: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "links-notation",
3
- "version": "0.21.3",
3
+ "version": "0.23.0",
4
4
  "description": "Links Notation parser for JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "index.d.ts",
@@ -32,10 +32,10 @@
32
32
  },
33
33
  "homepage": "https://github.com/link-foundation/links-notation#readme",
34
34
  "devDependencies": {
35
- "bun-types": "^1.4.0",
36
- "eslint": "^10.9.1",
35
+ "bun-types": "^1.4.2",
36
+ "eslint": "^10.12.0",
37
37
  "peggy": "^5.1.0",
38
- "prettier": "^3.9.6",
38
+ "prettier": "^3.9.9",
39
39
  "typescript": "^7.0.2"
40
40
  }
41
41
  }