@fgv/ts-extras 5.0.2 → 5.1.0-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.
Files changed (92) hide show
  1. package/dist/index.browser.js +6 -2
  2. package/dist/index.js +5 -1
  3. package/dist/packlets/ai-assist/apiClient.js +484 -0
  4. package/dist/packlets/ai-assist/converters.js +121 -0
  5. package/dist/packlets/ai-assist/index.js +10 -0
  6. package/dist/packlets/ai-assist/model.js +90 -0
  7. package/dist/packlets/ai-assist/registry.js +145 -0
  8. package/dist/packlets/ai-assist/toolFormats.js +160 -0
  9. package/dist/packlets/crypto-utils/constants.js +48 -0
  10. package/dist/packlets/crypto-utils/converters.js +155 -0
  11. package/dist/packlets/crypto-utils/directEncryptionProvider.js +86 -0
  12. package/dist/packlets/crypto-utils/encryptedFile.js +161 -0
  13. package/dist/packlets/crypto-utils/index.browser.js +41 -0
  14. package/dist/packlets/crypto-utils/index.js +41 -0
  15. package/dist/packlets/crypto-utils/keystore/converters.js +84 -0
  16. package/dist/packlets/crypto-utils/keystore/index.js +31 -0
  17. package/dist/packlets/crypto-utils/keystore/keyStore.js +758 -0
  18. package/dist/packlets/crypto-utils/keystore/model.js +64 -0
  19. package/dist/packlets/crypto-utils/model.js +39 -0
  20. package/dist/packlets/crypto-utils/nodeCryptoProvider.js +159 -0
  21. package/dist/packlets/experimental/formatter.js +1 -1
  22. package/dist/packlets/mustache/index.js +23 -0
  23. package/dist/packlets/mustache/interfaces.js +25 -0
  24. package/dist/packlets/mustache/mustacheTemplate.js +242 -0
  25. package/dist/packlets/record-jar/recordJarHelpers.js +1 -1
  26. package/dist/packlets/yaml/converters.js +46 -0
  27. package/dist/packlets/yaml/index.js +23 -0
  28. package/dist/packlets/zip-file-tree/index.js +1 -0
  29. package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +43 -2
  30. package/dist/packlets/zip-file-tree/zipFileTreeWriter.js +40 -0
  31. package/dist/ts-extras.d.ts +1990 -112
  32. package/dist/tsdoc-metadata.json +1 -1
  33. package/lib/index.browser.d.ts +3 -1
  34. package/lib/index.browser.js +6 -1
  35. package/lib/index.d.ts +5 -1
  36. package/lib/index.js +9 -1
  37. package/lib/packlets/ai-assist/apiClient.d.ts +60 -0
  38. package/lib/packlets/ai-assist/apiClient.js +488 -0
  39. package/lib/packlets/ai-assist/converters.d.ts +55 -0
  40. package/lib/packlets/ai-assist/converters.js +124 -0
  41. package/lib/packlets/ai-assist/index.d.ts +10 -0
  42. package/lib/packlets/ai-assist/index.js +33 -0
  43. package/lib/packlets/ai-assist/model.d.ts +222 -0
  44. package/lib/packlets/ai-assist/model.js +95 -0
  45. package/lib/packlets/ai-assist/registry.d.ts +25 -0
  46. package/lib/packlets/ai-assist/registry.js +150 -0
  47. package/lib/packlets/ai-assist/toolFormats.d.ts +44 -0
  48. package/lib/packlets/ai-assist/toolFormats.js +166 -0
  49. package/lib/packlets/crypto-utils/constants.d.ts +26 -0
  50. package/lib/packlets/crypto-utils/constants.js +51 -0
  51. package/lib/packlets/crypto-utils/converters.d.ts +58 -0
  52. package/lib/packlets/crypto-utils/converters.js +192 -0
  53. package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts +69 -0
  54. package/lib/packlets/crypto-utils/directEncryptionProvider.js +90 -0
  55. package/lib/packlets/crypto-utils/encryptedFile.d.ts +88 -0
  56. package/lib/packlets/crypto-utils/encryptedFile.js +201 -0
  57. package/lib/packlets/crypto-utils/index.browser.d.ts +14 -0
  58. package/lib/packlets/crypto-utils/index.browser.js +91 -0
  59. package/lib/packlets/crypto-utils/index.d.ts +15 -0
  60. package/lib/packlets/crypto-utils/index.js +88 -0
  61. package/lib/packlets/crypto-utils/keystore/converters.d.ts +29 -0
  62. package/lib/packlets/crypto-utils/keystore/converters.js +87 -0
  63. package/lib/packlets/crypto-utils/keystore/index.d.ts +9 -0
  64. package/lib/packlets/crypto-utils/keystore/index.js +71 -0
  65. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +239 -0
  66. package/lib/packlets/crypto-utils/keystore/keyStore.js +795 -0
  67. package/lib/packlets/crypto-utils/keystore/model.d.ts +245 -0
  68. package/lib/packlets/crypto-utils/keystore/model.js +68 -0
  69. package/lib/packlets/crypto-utils/model.d.ts +236 -0
  70. package/lib/packlets/crypto-utils/model.js +76 -0
  71. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +62 -0
  72. package/lib/packlets/crypto-utils/nodeCryptoProvider.js +196 -0
  73. package/lib/packlets/experimental/formatter.d.ts +1 -1
  74. package/lib/packlets/experimental/formatter.js +1 -1
  75. package/lib/packlets/mustache/index.d.ts +3 -0
  76. package/lib/packlets/mustache/index.js +27 -0
  77. package/lib/packlets/mustache/interfaces.d.ts +97 -0
  78. package/lib/packlets/mustache/interfaces.js +26 -0
  79. package/lib/packlets/mustache/mustacheTemplate.d.ts +76 -0
  80. package/lib/packlets/mustache/mustacheTemplate.js +249 -0
  81. package/lib/packlets/record-jar/recordJarHelpers.js +1 -1
  82. package/lib/packlets/yaml/converters.d.ts +9 -0
  83. package/lib/packlets/yaml/converters.js +82 -0
  84. package/lib/packlets/yaml/index.d.ts +2 -0
  85. package/lib/packlets/yaml/index.js +39 -0
  86. package/lib/packlets/zip-file-tree/index.d.ts +1 -0
  87. package/lib/packlets/zip-file-tree/index.js +15 -0
  88. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +31 -2
  89. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +42 -1
  90. package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts +27 -0
  91. package/lib/packlets/zip-file-tree/zipFileTreeWriter.js +43 -0
  92. package/package.json +37 -18
@@ -0,0 +1,196 @@
1
+ "use strict";
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ var desc = Object.getOwnPropertyDescriptor(m, k);
24
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
25
+ desc = { enumerable: true, get: function() { return m[k]; } };
26
+ }
27
+ Object.defineProperty(o, k2, desc);
28
+ }) : (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ o[k2] = m[k];
31
+ }));
32
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
33
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
34
+ }) : function(o, v) {
35
+ o["default"] = v;
36
+ });
37
+ var __importStar = (this && this.__importStar) || (function () {
38
+ var ownKeys = function(o) {
39
+ ownKeys = Object.getOwnPropertyNames || function (o) {
40
+ var ar = [];
41
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
42
+ return ar;
43
+ };
44
+ return ownKeys(o);
45
+ };
46
+ return function (mod) {
47
+ if (mod && mod.__esModule) return mod;
48
+ var result = {};
49
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
50
+ __setModuleDefault(result, mod);
51
+ return result;
52
+ };
53
+ })();
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.nodeCryptoProvider = exports.NodeCryptoProvider = void 0;
56
+ const crypto = __importStar(require("crypto"));
57
+ const ts_utils_1 = require("@fgv/ts-utils");
58
+ const Constants = __importStar(require("./constants"));
59
+ /**
60
+ * Node.js implementation of {@link CryptoUtils.ICryptoProvider} using the built-in crypto module.
61
+ * Uses AES-256-GCM for authenticated encryption.
62
+ * @public
63
+ */
64
+ class NodeCryptoProvider {
65
+ /**
66
+ * Encrypts plaintext using AES-256-GCM.
67
+ * @param plaintext - UTF-8 string to encrypt
68
+ * @param key - 32-byte encryption key
69
+ * @returns `Success` with encryption result, or `Failure` with an error.
70
+ */
71
+ async encrypt(plaintext, key) {
72
+ return (0, ts_utils_1.captureResult)(() => {
73
+ if (key.length !== Constants.AES_256_KEY_SIZE) {
74
+ throw new Error(`Key must be ${Constants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
75
+ }
76
+ // Generate random IV
77
+ const iv = crypto.randomBytes(Constants.GCM_IV_SIZE);
78
+ // Create cipher
79
+ const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
80
+ // Encrypt
81
+ const encrypted = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
82
+ // Get auth tag
83
+ const authTag = cipher.getAuthTag();
84
+ return {
85
+ iv: new Uint8Array(iv),
86
+ authTag: new Uint8Array(authTag),
87
+ encryptedData: new Uint8Array(encrypted)
88
+ };
89
+ });
90
+ }
91
+ /**
92
+ * Decrypts ciphertext using AES-256-GCM.
93
+ * @param encryptedData - Encrypted bytes
94
+ * @param key - 32-byte decryption key
95
+ * @param iv - Initialization vector (12 bytes)
96
+ * @param authTag - GCM authentication tag (16 bytes)
97
+ * @returns `Success` with decrypted UTF-8 string, or `Failure` with an error.
98
+ */
99
+ async decrypt(encryptedData, key, iv, authTag) {
100
+ if (key.length !== Constants.AES_256_KEY_SIZE) {
101
+ return (0, ts_utils_1.fail)(`Key must be ${Constants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
102
+ }
103
+ if (iv.length !== Constants.GCM_IV_SIZE) {
104
+ return (0, ts_utils_1.fail)(`IV must be ${Constants.GCM_IV_SIZE} bytes, got ${iv.length}`);
105
+ }
106
+ if (authTag.length !== Constants.GCM_AUTH_TAG_SIZE) {
107
+ return (0, ts_utils_1.fail)(`Auth tag must be ${Constants.GCM_AUTH_TAG_SIZE} bytes, got ${authTag.length}`);
108
+ }
109
+ return (0, ts_utils_1.captureResult)(() => {
110
+ // Create decipher
111
+ const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(key), Buffer.from(iv));
112
+ // Set auth tag
113
+ decipher.setAuthTag(Buffer.from(authTag));
114
+ // Decrypt
115
+ const decrypted = Buffer.concat([decipher.update(Buffer.from(encryptedData)), decipher.final()]);
116
+ return decrypted.toString('utf8');
117
+ }).withErrorFormat((e) => `Decryption failed: ${e}`);
118
+ }
119
+ /**
120
+ * Generates a random 32-byte key suitable for AES-256.
121
+ * @returns `Success` with generated key, or `Failure` with an error.
122
+ */
123
+ async generateKey() {
124
+ return (0, ts_utils_1.captureResult)(() => {
125
+ const key = crypto.randomBytes(Constants.AES_256_KEY_SIZE);
126
+ return new Uint8Array(key);
127
+ });
128
+ }
129
+ /**
130
+ * Derives a key from a password using PBKDF2.
131
+ * @param password - Password string
132
+ * @param salt - Salt bytes (should be at least 16 bytes)
133
+ * @param iterations - Number of iterations (recommend 100000+)
134
+ * @returns `Success` with derived 32-byte key, or `Failure` with an error.
135
+ */
136
+ async deriveKey(password, salt, iterations) {
137
+ if (iterations < 1) {
138
+ return (0, ts_utils_1.fail)('Iterations must be at least 1');
139
+ }
140
+ if (salt.length < 8) {
141
+ return (0, ts_utils_1.fail)('Salt should be at least 8 bytes');
142
+ }
143
+ return new Promise((resolve) => {
144
+ crypto.pbkdf2(password, Buffer.from(salt), iterations, Constants.AES_256_KEY_SIZE, 'sha256', (err, derivedKey) => {
145
+ /* c8 ignore next 3 - PBKDF2 internal errors are hard to trigger with valid parameters */
146
+ if (err) {
147
+ resolve((0, ts_utils_1.fail)(`Key derivation failed: ${err.message}`));
148
+ }
149
+ else {
150
+ resolve((0, ts_utils_1.succeed)(new Uint8Array(derivedKey)));
151
+ }
152
+ });
153
+ });
154
+ }
155
+ // ============================================================================
156
+ // Platform Utility Methods
157
+ // ============================================================================
158
+ /**
159
+ * Generates cryptographically secure random bytes.
160
+ * @param length - Number of bytes to generate
161
+ * @returns Success with random bytes, or Failure with error
162
+ */
163
+ generateRandomBytes(length) {
164
+ if (length < 1) {
165
+ return ts_utils_1.Failure.with('Length must be at least 1');
166
+ }
167
+ return (0, ts_utils_1.captureResult)(() => new Uint8Array(crypto.randomBytes(length)));
168
+ }
169
+ /**
170
+ * Encodes binary data to base64 string.
171
+ * @param data - Binary data to encode
172
+ * @returns Base64-encoded string
173
+ */
174
+ toBase64(data) {
175
+ return Buffer.from(data).toString('base64');
176
+ }
177
+ /**
178
+ * Decodes base64 string to binary data.
179
+ * @param base64 - Base64-encoded string
180
+ * @returns Success with decoded bytes, or Failure if invalid base64
181
+ */
182
+ fromBase64(base64) {
183
+ // Check for obviously invalid characters
184
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(base64)) {
185
+ return ts_utils_1.Failure.with('Invalid base64 string');
186
+ }
187
+ return ts_utils_1.Success.with(new Uint8Array(Buffer.from(base64, 'base64')));
188
+ }
189
+ }
190
+ exports.NodeCryptoProvider = NodeCryptoProvider;
191
+ /**
192
+ * Singleton instance of {@link CryptoUtils.NodeCryptoProvider}.
193
+ * @public
194
+ */
195
+ exports.nodeCryptoProvider = new NodeCryptoProvider();
196
+ //# sourceMappingURL=nodeCryptoProvider.js.map
@@ -31,7 +31,7 @@ export declare class FormattableBase {
31
31
  */
32
32
  protected static _tryAddDetail(details: string[], label: string, value: string | undefined): void;
33
33
  /**
34
- * {@inheritdoc Experimental.Formattable.format}
34
+ * {@inheritDoc Experimental.Formattable.format}
35
35
  */
36
36
  format(template: string): Result<string>;
37
37
  }
@@ -48,7 +48,7 @@ class FormattableBase {
48
48
  }
49
49
  }
50
50
  /**
51
- * {@inheritdoc Experimental.Formattable.format}
51
+ * {@inheritDoc Experimental.Formattable.format}
52
52
  */
53
53
  format(template) {
54
54
  return (0, ts_utils_1.captureResult)(() => mustache_1.default.render(template, this));
@@ -0,0 +1,3 @@
1
+ export { IContextValidationResult, IMissingVariableDetail, IMustacheTemplateOptions, IVariableRef, MustacheTokenType } from './interfaces';
2
+ export { MustacheTemplate } from './mustacheTemplate';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020 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
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.MustacheTemplate = void 0;
25
+ var mustacheTemplate_1 = require("./mustacheTemplate");
26
+ Object.defineProperty(exports, "MustacheTemplate", { enumerable: true, get: function () { return mustacheTemplate_1.MustacheTemplate; } });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Type of a Mustache token as returned by Mustache.parse()
3
+ * @public
4
+ */
5
+ export type MustacheTokenType = 'text' | 'name' | '&' | '#' | '^' | '!' | '>' | '=';
6
+ /**
7
+ * Represents a variable reference extracted from a Mustache template.
8
+ * @public
9
+ */
10
+ export interface IVariableRef {
11
+ /**
12
+ * The raw variable name as it appears in the template (e.g., 'user.name')
13
+ */
14
+ readonly name: string;
15
+ /**
16
+ * The path segments parsed from the variable name (e.g., ['user', 'name'])
17
+ */
18
+ readonly path: readonly string[];
19
+ /**
20
+ * The type of token this variable was extracted from
21
+ */
22
+ readonly tokenType: MustacheTokenType;
23
+ /**
24
+ * Whether this variable is used in a section context (# or ^)
25
+ * Section variables may reference arrays/objects for iteration
26
+ */
27
+ readonly isSection: boolean;
28
+ }
29
+ /**
30
+ * Details about a missing variable in context validation.
31
+ * @public
32
+ */
33
+ export interface IMissingVariableDetail {
34
+ /**
35
+ * The variable reference that is missing
36
+ */
37
+ readonly variable: IVariableRef;
38
+ /**
39
+ * The path segment where the lookup failed
40
+ * (e.g., for 'user.profile.name' if 'profile' is missing, this would be 'profile')
41
+ */
42
+ readonly failedAtSegment?: string;
43
+ /**
44
+ * The parent path that exists (e.g., ['user'] if 'user' exists but 'user.profile' does not)
45
+ */
46
+ readonly existingPath: readonly string[];
47
+ }
48
+ /**
49
+ * Result of context validation, containing details about missing variables.
50
+ * @public
51
+ */
52
+ export interface IContextValidationResult {
53
+ /**
54
+ * Whether the context is valid (has all required variables)
55
+ */
56
+ readonly isValid: boolean;
57
+ /**
58
+ * Variables that are present in the context
59
+ */
60
+ readonly presentVariables: readonly string[];
61
+ /**
62
+ * Variables that are missing from the context
63
+ */
64
+ readonly missingVariables: readonly string[];
65
+ /**
66
+ * Detailed information about each missing variable
67
+ */
68
+ readonly missingDetails: readonly IMissingVariableDetail[];
69
+ }
70
+ /**
71
+ * Options for template parsing and validation.
72
+ * @public
73
+ */
74
+ export interface IMustacheTemplateOptions {
75
+ /**
76
+ * Custom opening and closing tags (default: `['{{', '}}']`)
77
+ */
78
+ readonly tags?: readonly [string, string];
79
+ /**
80
+ * Whether to include comment tokens in variable extraction (default: false)
81
+ */
82
+ readonly includeComments?: boolean;
83
+ /**
84
+ * Whether to include partial references in variable extraction (default: false)
85
+ */
86
+ readonly includePartials?: boolean;
87
+ }
88
+ /**
89
+ * Required version of options with all fields populated.
90
+ * @internal
91
+ */
92
+ export interface IRequiredMustacheTemplateOptions {
93
+ readonly tags: [string, string];
94
+ readonly includeComments: boolean;
95
+ readonly includePartials: boolean;
96
+ }
97
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /* c8 ignore start - Type definitions only, no runtime code */
3
+ /*
4
+ * Copyright (c) 2020 Erik Fortune
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ /* c8 ignore stop */
26
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1,76 @@
1
+ import { Result } from '@fgv/ts-utils';
2
+ import { IContextValidationResult, IMustacheTemplateOptions, IRequiredMustacheTemplateOptions, IVariableRef } from './interfaces';
3
+ /**
4
+ * A helper class for working with Mustache templates that provides
5
+ * validation, variable extraction, and context validation utilities.
6
+ * @public
7
+ */
8
+ export declare class MustacheTemplate {
9
+ /**
10
+ * The original template string
11
+ */
12
+ readonly template: string;
13
+ /**
14
+ * The options used for parsing this template
15
+ */
16
+ readonly options: Readonly<IRequiredMustacheTemplateOptions>;
17
+ private readonly _tokens;
18
+ private _variables?;
19
+ private constructor();
20
+ /**
21
+ * Creates a new MustacheTemplate instance.
22
+ * @param template - The Mustache template string to parse
23
+ * @param options - Optional parsing options
24
+ * @returns Success with the template instance, or Failure if parsing fails
25
+ */
26
+ static create(template: string, options?: IMustacheTemplateOptions): Result<MustacheTemplate>;
27
+ /**
28
+ * Validates that a template string has valid Mustache syntax.
29
+ * @param template - The template string to validate
30
+ * @param options - Optional parsing options
31
+ * @returns Success with true if valid, or Failure with a descriptive error message
32
+ */
33
+ static validate(template: string, options?: IMustacheTemplateOptions): Result<true>;
34
+ /**
35
+ * Checks if this template instance has valid syntax.
36
+ * Always returns Success(true) since parsing succeeded in create().
37
+ * @returns Success with true
38
+ */
39
+ validate(): Result<true>;
40
+ /**
41
+ * Extracts all variable references from the template.
42
+ * @returns An array of variable references found in the template
43
+ */
44
+ extractVariables(): readonly IVariableRef[];
45
+ /**
46
+ * Extracts unique variable names from the template.
47
+ * @returns An array of unique variable name strings (e.g., ['user.name', 'items'])
48
+ */
49
+ extractVariableNames(): readonly string[];
50
+ /**
51
+ * Validates that a context object has all required variables.
52
+ * @param context - The context object to validate
53
+ * @returns Success with validation result containing details about present/missing variables
54
+ */
55
+ validateContext(context: unknown): Result<IContextValidationResult>;
56
+ /**
57
+ * Renders the template with the given context.
58
+ * Use this for pre-validated contexts where you've already checked
59
+ * that all required variables are present.
60
+ * @param context - The context object for template rendering
61
+ * @returns Success with the rendered string, or Failure if rendering fails
62
+ */
63
+ render(context: unknown): Result<string>;
64
+ /**
65
+ * Validates the context and renders the template if validation passes.
66
+ * @param context - The context object to validate and render with
67
+ * @returns Success with the rendered string, or Failure with validation or render errors
68
+ */
69
+ validateAndRender(context: unknown): Result<string>;
70
+ private static _resolveOptions;
71
+ private static _parseTokens;
72
+ private _extractVariablesFromTokens;
73
+ private _parsePath;
74
+ private _lookupPath;
75
+ }
76
+ //# sourceMappingURL=mustacheTemplate.d.ts.map