Collection.d.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import type { Schema } from '../schema/Schema.js';
  2. import { NODE_TYPE } from './identity.js';
  3. import { NodeBase } from './Node.js';
  4. export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node;
  5. export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) => path is null | undefined;
  6. export declare abstract class Collection extends NodeBase {
  7. schema: Schema | undefined;
  8. [NODE_TYPE]: symbol;
  9. items: unknown[];
  10. /** An optional anchor on this node. Used by alias nodes. */
  11. anchor?: string;
  12. /**
  13. * If true, stringify this and all child nodes using flow rather than
  14. * block styles.
  15. */
  16. flow?: boolean;
  17. constructor(type: symbol, schema?: Schema);
  18. /**
  19. * Create a copy of this collection.
  20. *
  21. * @param schema - If defined, overwrites the original's schema
  22. */
  23. clone(schema?: Schema): Collection;
  24. /** Adds a value to the collection. */
  25. abstract add(value: unknown): void;
  26. /**
  27. * Removes a value from the collection.
  28. * @returns `true` if the item was found and removed.
  29. */
  30. abstract delete(key: unknown): boolean;
  31. /**
  32. * Returns item at `key`, or `undefined` if not found. By default unwraps
  33. * scalar values from their surrounding node; to disable set `keepScalar` to
  34. * `true` (collections are always returned intact).
  35. */
  36. abstract get(key: unknown, keepScalar?: boolean): unknown;
  37. /**
  38. * Checks if the collection includes a value with the key `key`.
  39. */
  40. abstract has(key: unknown): boolean;
  41. /**
  42. * Sets a value in this collection. For `!!set`, `value` needs to be a
  43. * boolean to add/remove the item from the set.
  44. */
  45. abstract set(key: unknown, value: unknown): void;
  46. /**
  47. * Adds a value to the collection. For `!!map` and `!!omap` the value must
  48. * be a Pair instance or a `{ key, value }` object, which may not have a key
  49. * that already exists in the map.
  50. */
  51. addIn(path: Iterable<unknown>, value: unknown): void;
  52. /**
  53. * Removes a value from the collection.
  54. * @returns `true` if the item was found and removed.
  55. */
  56. deleteIn(path: Iterable<unknown>): boolean;
  57. /**
  58. * Returns item at `key`, or `undefined` if not found. By default unwraps
  59. * scalar values from their surrounding node; to disable set `keepScalar` to
  60. * `true` (collections are always returned intact).
  61. */
  62. getIn(path: Iterable<unknown>, keepScalar?: boolean): unknown;
  63. hasAllNullValues(allowScalar?: boolean): boolean;
  64. /**
  65. * Checks if the collection includes a value with the key `key`.
  66. */
  67. hasIn(path: Iterable<unknown>): boolean;
  68. /**
  69. * Sets a value in this collection. For `!!set`, `value` needs to be a
  70. * boolean to add/remove the item from the set.
  71. */
  72. setIn(path: Iterable<unknown>, value: unknown): void;
  73. }