@fgv/ts-extras 5.1.0-11 → 5.1.0-14

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.
@@ -360,14 +360,21 @@ export class KeyStore {
360
360
  return succeed({ entry, replaced });
361
361
  }
362
362
  /**
363
- * Imports an existing secret key.
363
+ * Imports raw 32-byte key material into the vault.
364
+ *
365
+ * Always validates that the key is exactly 32 bytes (AES-256). The optional
366
+ * `type` field is a classification label stored with the entry; it does not
367
+ * change the validation rules. For importing UTF-8 API key strings (variable
368
+ * length), use {@link KeyStore.importApiKey} instead.
369
+ *
364
370
  * @param name - Unique name for the secret
365
- * @param key - The 32-byte AES-256 key
366
- * @param options - Optional description, whether to replace existing
371
+ * @param key - The 32-byte AES-256 key material
372
+ * @param options - Optional type classification, description, whether to replace existing
367
373
  * @returns Success with entry, Failure if locked, key invalid, or exists and !replace
368
374
  * @public
369
375
  */
370
376
  importSecret(name, key, options) {
377
+ var _a;
371
378
  if (!this._secrets) {
372
379
  return fail('Key store is locked');
373
380
  }
@@ -383,7 +390,7 @@ export class KeyStore {
383
390
  }
384
391
  const entry = {
385
392
  name,
386
- type: 'encryption-key',
393
+ type: (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : 'encryption-key',
387
394
  key: new Uint8Array(key), // Copy to prevent external modification
388
395
  description: options === null || options === void 0 ? void 0 : options.description,
389
396
  createdAt: getCurrentTimestamp()
@@ -116,6 +116,18 @@ export class NodeCryptoProvider {
116
116
  });
117
117
  });
118
118
  }
119
+ /**
120
+ * Computes a SHA-256 hash of the given data.
121
+ * @param data - UTF-8 string to hash
122
+ * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
123
+ */
124
+ async sha256(data) {
125
+ return captureResult(() => {
126
+ const hash = crypto.createHash('sha256');
127
+ hash.update(data, 'utf8');
128
+ return hash.digest('hex');
129
+ });
130
+ }
119
131
  // ============================================================================
120
132
  // Platform Utility Methods
121
133
  // ============================================================================
@@ -20,4 +20,5 @@
20
20
  * SOFTWARE.
21
21
  */
22
22
  export * from './converters';
23
+ export * from './serializers';
23
24
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Copyright (c) 2024 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { captureResult, fail } from '@fgv/ts-utils';
23
+ import * as yaml from 'js-yaml';
24
+ /**
25
+ * Serializes a value to a YAML string.
26
+ * @param value - The value to serialize (must be an object or array)
27
+ * @param options - Optional serialization options
28
+ * @returns `Success` with YAML string, or `Failure` with error
29
+ * @public
30
+ */
31
+ export function yamlStringify(value, options) {
32
+ if (value === null || value === undefined) {
33
+ return fail('Cannot serialize null or undefined to YAML');
34
+ }
35
+ if (typeof value !== 'object') {
36
+ return fail('YAML serialization requires an object or array');
37
+ }
38
+ return captureResult(() => yaml.dump(value, {
39
+ indent: options === null || options === void 0 ? void 0 : options.indent,
40
+ flowLevel: options === null || options === void 0 ? void 0 : options.flowLevel,
41
+ sortKeys: options === null || options === void 0 ? void 0 : options.sortKeys,
42
+ lineWidth: options === null || options === void 0 ? void 0 : options.lineWidth,
43
+ noRefs: options === null || options === void 0 ? void 0 : options.noRefs,
44
+ noArrayIndent: options === null || options === void 0 ? void 0 : options.noArrayIndent,
45
+ forceQuotes: options === null || options === void 0 ? void 0 : options.forceQuotes
46
+ }));
47
+ }
48
+ //# sourceMappingURL=serializers.js.map
@@ -939,6 +939,12 @@ declare interface ICryptoProvider {
939
939
  * @returns Success with derived 32-byte key, or Failure with error
940
940
  */
941
941
  deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
942
+ /**
943
+ * Computes a SHA-256 hash of the given data.
944
+ * @param data - UTF-8 string to hash
945
+ * @returns Success with hex-encoded hash string, or Failure with error
946
+ */
947
+ sha256(data: string): Promise<Result<string>>;
942
948
  /**
943
949
  * Generates cryptographically secure random bytes.
944
950
  * @param length - Number of bytes to generate
@@ -1095,6 +1101,19 @@ declare interface IEncryptionResult {
1095
1101
  readonly encryptedData: Uint8Array;
1096
1102
  }
1097
1103
 
1104
+ /**
1105
+ * Options for importing raw key material via {@link KeyStore.importSecret}.
1106
+ * Extends {@link IImportSecretOptions} with a type classification.
1107
+ * @public
1108
+ */
1109
+ declare interface IImportKeyOptions extends IImportSecretOptions {
1110
+ /**
1111
+ * Secret type classification for the imported key material.
1112
+ * @defaultValue 'encryption-key'
1113
+ */
1114
+ readonly type?: KeyStoreSecretType;
1115
+ }
1116
+
1098
1117
  /**
1099
1118
  * Options for importing a secret.
1100
1119
  * @public
@@ -1432,6 +1451,42 @@ declare interface IVariableRef {
1432
1451
  readonly isSection: boolean;
1433
1452
  }
1434
1453
 
1454
+ /**
1455
+ * Options for YAML serialization, mirroring commonly-used `js-yaml` `DumpOptions`.
1456
+ * @public
1457
+ */
1458
+ declare interface IYamlSerializeOptions {
1459
+ /**
1460
+ * Indentation width in spaces (default: 2).
1461
+ */
1462
+ readonly indent?: number;
1463
+ /**
1464
+ * Nesting level at which to switch from block to flow style.
1465
+ * -1 means block style everywhere (default: -1).
1466
+ */
1467
+ readonly flowLevel?: number;
1468
+ /**
1469
+ * If true, sort keys when dumping (default: false).
1470
+ */
1471
+ readonly sortKeys?: boolean;
1472
+ /**
1473
+ * Maximum line width (default: 80).
1474
+ */
1475
+ readonly lineWidth?: number;
1476
+ /**
1477
+ * If true, don't convert duplicate objects into references (default: false).
1478
+ */
1479
+ readonly noRefs?: boolean;
1480
+ /**
1481
+ * If true, don't add an indentation level to array elements (default: false).
1482
+ */
1483
+ readonly noArrayIndent?: boolean;
1484
+ /**
1485
+ * If true, all non-key strings will be quoted (default: false).
1486
+ */
1487
+ readonly forceQuotes?: boolean;
1488
+ }
1489
+
1435
1490
  /**
1436
1491
  * Simple interface for a file to be added to a zip file.
1437
1492
  * @public
@@ -1500,6 +1555,7 @@ declare namespace KeyStore {
1500
1555
  IAddSecretResult,
1501
1556
  IAddSecretOptions,
1502
1557
  IImportSecretOptions,
1558
+ IImportKeyOptions,
1503
1559
  IAddSecretFromPasswordOptions,
1504
1560
  DEFAULT_SECRET_ITERATIONS,
1505
1561
  IAddSecretFromPasswordResult
@@ -1644,14 +1700,20 @@ declare class KeyStore_2 implements IEncryptionProvider {
1644
1700
  */
1645
1701
  addSecret(name: string, options?: IAddSecretOptions): Promise<Result<IAddSecretResult>>;
1646
1702
  /**
1647
- * Imports an existing secret key.
1703
+ * Imports raw 32-byte key material into the vault.
1704
+ *
1705
+ * Always validates that the key is exactly 32 bytes (AES-256). The optional
1706
+ * `type` field is a classification label stored with the entry; it does not
1707
+ * change the validation rules. For importing UTF-8 API key strings (variable
1708
+ * length), use {@link KeyStore.importApiKey} instead.
1709
+ *
1648
1710
  * @param name - Unique name for the secret
1649
- * @param key - The 32-byte AES-256 key
1650
- * @param options - Optional description, whether to replace existing
1711
+ * @param key - The 32-byte AES-256 key material
1712
+ * @param options - Optional type classification, description, whether to replace existing
1651
1713
  * @returns Success with entry, Failure if locked, key invalid, or exists and !replace
1652
1714
  * @public
1653
1715
  */
1654
- importSecret(name: string, key: Uint8Array, options?: IImportSecretOptions): Result<IAddSecretResult>;
1716
+ importSecret(name: string, key: Uint8Array, options?: IImportKeyOptions): Result<IAddSecretResult>;
1655
1717
  /**
1656
1718
  * Adds a secret derived from a password using PBKDF2.
1657
1719
  *
@@ -1980,6 +2042,12 @@ declare class NodeCryptoProvider implements ICryptoProvider {
1980
2042
  * @returns `Success` with derived 32-byte key, or `Failure` with an error.
1981
2043
  */
1982
2044
  deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
2045
+ /**
2046
+ * Computes a SHA-256 hash of the given data.
2047
+ * @param data - UTF-8 string to hash
2048
+ * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
2049
+ */
2050
+ sha256(data: string): Promise<Result<string>>;
1983
2051
  /**
1984
2052
  * Generates cryptographically secure random bytes.
1985
2053
  * @param length - Number of bytes to generate
@@ -2292,7 +2360,9 @@ declare const uint8ArrayFromBase64: Converter<Uint8Array>;
2292
2360
 
2293
2361
  declare namespace Yaml {
2294
2362
  export {
2295
- yamlConverter
2363
+ yamlConverter,
2364
+ yamlStringify,
2365
+ IYamlSerializeOptions
2296
2366
  }
2297
2367
  }
2298
2368
  export { Yaml }
@@ -2305,6 +2375,15 @@ export { Yaml }
2305
2375
  */
2306
2376
  declare function yamlConverter<T>(converter: Converter<T>): Converter<T>;
2307
2377
 
2378
+ /**
2379
+ * Serializes a value to a YAML string.
2380
+ * @param value - The value to serialize (must be an object or array)
2381
+ * @param options - Optional serialization options
2382
+ * @returns `Success` with YAML string, or `Failure` with error
2383
+ * @public
2384
+ */
2385
+ declare function yamlStringify(value: unknown, options?: IYamlSerializeOptions): Result<string>;
2386
+
2308
2387
  /**
2309
2388
  * Supported compression levels for zip files.
2310
2389
  * @public
@@ -1,7 +1,7 @@
1
1
  import { JsonValue } from '@fgv/ts-json-base';
2
2
  import { Result } from '@fgv/ts-utils';
3
3
  import { ICryptoProvider, IEncryptedFile, IEncryptionConfig, IEncryptionProvider, SecretProvider } from '../model';
4
- import { IAddSecretFromPasswordOptions, IAddSecretFromPasswordResult, IAddSecretOptions, IAddSecretResult, IImportSecretOptions, IKeyStoreCreateParams, IKeyStoreFile, IKeyStoreOpenParams, IKeyStoreSecretEntry, KeyStoreLockState, KeyStoreSecretType } from './model';
4
+ import { IAddSecretFromPasswordOptions, IAddSecretFromPasswordResult, IAddSecretOptions, IAddSecretResult, IImportKeyOptions, IImportSecretOptions, IKeyStoreCreateParams, IKeyStoreFile, IKeyStoreOpenParams, IKeyStoreSecretEntry, KeyStoreLockState, KeyStoreSecretType } from './model';
5
5
  /**
6
6
  * Password-protected key store for managing encryption secrets.
7
7
  *
@@ -140,14 +140,20 @@ export declare class KeyStore implements IEncryptionProvider {
140
140
  */
141
141
  addSecret(name: string, options?: IAddSecretOptions): Promise<Result<IAddSecretResult>>;
142
142
  /**
143
- * Imports an existing secret key.
143
+ * Imports raw 32-byte key material into the vault.
144
+ *
145
+ * Always validates that the key is exactly 32 bytes (AES-256). The optional
146
+ * `type` field is a classification label stored with the entry; it does not
147
+ * change the validation rules. For importing UTF-8 API key strings (variable
148
+ * length), use {@link KeyStore.importApiKey} instead.
149
+ *
144
150
  * @param name - Unique name for the secret
145
- * @param key - The 32-byte AES-256 key
146
- * @param options - Optional description, whether to replace existing
151
+ * @param key - The 32-byte AES-256 key material
152
+ * @param options - Optional type classification, description, whether to replace existing
147
153
  * @returns Success with entry, Failure if locked, key invalid, or exists and !replace
148
154
  * @public
149
155
  */
150
- importSecret(name: string, key: Uint8Array, options?: IImportSecretOptions): Result<IAddSecretResult>;
156
+ importSecret(name: string, key: Uint8Array, options?: IImportKeyOptions): Result<IAddSecretResult>;
151
157
  /**
152
158
  * Adds a secret derived from a password using PBKDF2.
153
159
  *
@@ -396,14 +396,21 @@ class KeyStore {
396
396
  return (0, ts_utils_1.succeed)({ entry, replaced });
397
397
  }
398
398
  /**
399
- * Imports an existing secret key.
399
+ * Imports raw 32-byte key material into the vault.
400
+ *
401
+ * Always validates that the key is exactly 32 bytes (AES-256). The optional
402
+ * `type` field is a classification label stored with the entry; it does not
403
+ * change the validation rules. For importing UTF-8 API key strings (variable
404
+ * length), use {@link KeyStore.importApiKey} instead.
405
+ *
400
406
  * @param name - Unique name for the secret
401
- * @param key - The 32-byte AES-256 key
402
- * @param options - Optional description, whether to replace existing
407
+ * @param key - The 32-byte AES-256 key material
408
+ * @param options - Optional type classification, description, whether to replace existing
403
409
  * @returns Success with entry, Failure if locked, key invalid, or exists and !replace
404
410
  * @public
405
411
  */
406
412
  importSecret(name, key, options) {
413
+ var _a;
407
414
  if (!this._secrets) {
408
415
  return (0, ts_utils_1.fail)('Key store is locked');
409
416
  }
@@ -419,7 +426,7 @@ class KeyStore {
419
426
  }
420
427
  const entry = {
421
428
  name,
422
- type: 'encryption-key',
429
+ type: (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : 'encryption-key',
423
430
  key: new Uint8Array(key), // Copy to prevent external modification
424
431
  description: options === null || options === void 0 ? void 0 : options.description,
425
432
  createdAt: getCurrentTimestamp()
@@ -199,6 +199,18 @@ export interface IImportSecretOptions extends IAddSecretOptions {
199
199
  */
200
200
  readonly replace?: boolean;
201
201
  }
202
+ /**
203
+ * Options for importing raw key material via {@link KeyStore.importSecret}.
204
+ * Extends {@link IImportSecretOptions} with a type classification.
205
+ * @public
206
+ */
207
+ export interface IImportKeyOptions extends IImportSecretOptions {
208
+ /**
209
+ * Secret type classification for the imported key material.
210
+ * @defaultValue 'encryption-key'
211
+ */
212
+ readonly type?: KeyStoreSecretType;
213
+ }
202
214
  /**
203
215
  * Options for adding a secret derived from a password.
204
216
  * @public
@@ -145,6 +145,12 @@ export interface ICryptoProvider {
145
145
  * @returns Success with derived 32-byte key, or Failure with error
146
146
  */
147
147
  deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
148
+ /**
149
+ * Computes a SHA-256 hash of the given data.
150
+ * @param data - UTF-8 string to hash
151
+ * @returns Success with hex-encoded hash string, or Failure with error
152
+ */
153
+ sha256(data: string): Promise<Result<string>>;
148
154
  /**
149
155
  * Generates cryptographically secure random bytes.
150
156
  * @param length - Number of bytes to generate
@@ -35,6 +35,12 @@ export declare class NodeCryptoProvider implements ICryptoProvider {
35
35
  * @returns `Success` with derived 32-byte key, or `Failure` with an error.
36
36
  */
37
37
  deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
38
+ /**
39
+ * Computes a SHA-256 hash of the given data.
40
+ * @param data - UTF-8 string to hash
41
+ * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
42
+ */
43
+ sha256(data: string): Promise<Result<string>>;
38
44
  /**
39
45
  * Generates cryptographically secure random bytes.
40
46
  * @param length - Number of bytes to generate
@@ -152,6 +152,18 @@ class NodeCryptoProvider {
152
152
  });
153
153
  });
154
154
  }
155
+ /**
156
+ * Computes a SHA-256 hash of the given data.
157
+ * @param data - UTF-8 string to hash
158
+ * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
159
+ */
160
+ async sha256(data) {
161
+ return (0, ts_utils_1.captureResult)(() => {
162
+ const hash = crypto.createHash('sha256');
163
+ hash.update(data, 'utf8');
164
+ return hash.digest('hex');
165
+ });
166
+ }
155
167
  // ============================================================================
156
168
  // Platform Utility Methods
157
169
  // ============================================================================
@@ -1,2 +1,3 @@
1
1
  export * from './converters';
2
+ export * from './serializers';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -36,4 +36,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  __exportStar(require("./converters"), exports);
39
+ __exportStar(require("./serializers"), exports);
39
40
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,45 @@
1
+ import { Result } from '@fgv/ts-utils';
2
+ /**
3
+ * Options for YAML serialization, mirroring commonly-used `js-yaml` `DumpOptions`.
4
+ * @public
5
+ */
6
+ export interface IYamlSerializeOptions {
7
+ /**
8
+ * Indentation width in spaces (default: 2).
9
+ */
10
+ readonly indent?: number;
11
+ /**
12
+ * Nesting level at which to switch from block to flow style.
13
+ * -1 means block style everywhere (default: -1).
14
+ */
15
+ readonly flowLevel?: number;
16
+ /**
17
+ * If true, sort keys when dumping (default: false).
18
+ */
19
+ readonly sortKeys?: boolean;
20
+ /**
21
+ * Maximum line width (default: 80).
22
+ */
23
+ readonly lineWidth?: number;
24
+ /**
25
+ * If true, don't convert duplicate objects into references (default: false).
26
+ */
27
+ readonly noRefs?: boolean;
28
+ /**
29
+ * If true, don't add an indentation level to array elements (default: false).
30
+ */
31
+ readonly noArrayIndent?: boolean;
32
+ /**
33
+ * If true, all non-key strings will be quoted (default: false).
34
+ */
35
+ readonly forceQuotes?: boolean;
36
+ }
37
+ /**
38
+ * Serializes a value to a YAML string.
39
+ * @param value - The value to serialize (must be an object or array)
40
+ * @param options - Optional serialization options
41
+ * @returns `Success` with YAML string, or `Failure` with error
42
+ * @public
43
+ */
44
+ export declare function yamlStringify(value: unknown, options?: IYamlSerializeOptions): Result<string>;
45
+ //# sourceMappingURL=serializers.d.ts.map
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }) : function(o, v) {
37
+ o["default"] = v;
38
+ });
39
+ var __importStar = (this && this.__importStar) || (function () {
40
+ var ownKeys = function(o) {
41
+ ownKeys = Object.getOwnPropertyNames || function (o) {
42
+ var ar = [];
43
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
44
+ return ar;
45
+ };
46
+ return ownKeys(o);
47
+ };
48
+ return function (mod) {
49
+ if (mod && mod.__esModule) return mod;
50
+ var result = {};
51
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
52
+ __setModuleDefault(result, mod);
53
+ return result;
54
+ };
55
+ })();
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.yamlStringify = yamlStringify;
58
+ const ts_utils_1 = require("@fgv/ts-utils");
59
+ const yaml = __importStar(require("js-yaml"));
60
+ /**
61
+ * Serializes a value to a YAML string.
62
+ * @param value - The value to serialize (must be an object or array)
63
+ * @param options - Optional serialization options
64
+ * @returns `Success` with YAML string, or `Failure` with error
65
+ * @public
66
+ */
67
+ function yamlStringify(value, options) {
68
+ if (value === null || value === undefined) {
69
+ return (0, ts_utils_1.fail)('Cannot serialize null or undefined to YAML');
70
+ }
71
+ if (typeof value !== 'object') {
72
+ return (0, ts_utils_1.fail)('YAML serialization requires an object or array');
73
+ }
74
+ return (0, ts_utils_1.captureResult)(() => yaml.dump(value, {
75
+ indent: options === null || options === void 0 ? void 0 : options.indent,
76
+ flowLevel: options === null || options === void 0 ? void 0 : options.flowLevel,
77
+ sortKeys: options === null || options === void 0 ? void 0 : options.sortKeys,
78
+ lineWidth: options === null || options === void 0 ? void 0 : options.lineWidth,
79
+ noRefs: options === null || options === void 0 ? void 0 : options.noRefs,
80
+ noArrayIndent: options === null || options === void 0 ? void 0 : options.noArrayIndent,
81
+ forceQuotes: options === null || options === void 0 ? void 0 : options.forceQuotes
82
+ }));
83
+ }
84
+ //# sourceMappingURL=serializers.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-extras",
3
- "version": "5.1.0-11",
3
+ "version": "5.1.0-14",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-extras.d.ts",
@@ -86,10 +86,10 @@
86
86
  "@types/js-yaml": "~4.0.9",
87
87
  "typedoc": "~0.28.16",
88
88
  "typedoc-plugin-markdown": "~4.9.0",
89
- "@fgv/heft-dual-rig": "5.1.0-11",
90
- "@fgv/ts-utils-jest": "5.1.0-11",
91
- "@fgv/typedoc-compact-theme": "5.1.0-11",
92
- "@fgv/ts-utils": "5.1.0-11"
89
+ "@fgv/heft-dual-rig": "5.1.0-14",
90
+ "@fgv/typedoc-compact-theme": "5.1.0-14",
91
+ "@fgv/ts-utils-jest": "5.1.0-14",
92
+ "@fgv/ts-utils": "5.1.0-14"
93
93
  },
94
94
  "dependencies": {
95
95
  "luxon": "^3.7.2",
@@ -97,10 +97,10 @@
97
97
  "papaparse": "^5.4.1",
98
98
  "fflate": "~0.8.2",
99
99
  "js-yaml": "~4.1.1",
100
- "@fgv/ts-json-base": "5.1.0-11"
100
+ "@fgv/ts-json-base": "5.1.0-14"
101
101
  },
102
102
  "peerDependencies": {
103
- "@fgv/ts-utils": "5.1.0-11"
103
+ "@fgv/ts-utils": "5.1.0-14"
104
104
  },
105
105
  "repository": {
106
106
  "type": "git",