@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.
- package/dist/index.browser.js +6 -2
- package/dist/index.js +5 -1
- package/dist/packlets/ai-assist/apiClient.js +484 -0
- package/dist/packlets/ai-assist/converters.js +121 -0
- package/dist/packlets/ai-assist/index.js +10 -0
- package/dist/packlets/ai-assist/model.js +90 -0
- package/dist/packlets/ai-assist/registry.js +145 -0
- package/dist/packlets/ai-assist/toolFormats.js +160 -0
- package/dist/packlets/crypto-utils/constants.js +48 -0
- package/dist/packlets/crypto-utils/converters.js +155 -0
- package/dist/packlets/crypto-utils/directEncryptionProvider.js +86 -0
- package/dist/packlets/crypto-utils/encryptedFile.js +161 -0
- package/dist/packlets/crypto-utils/index.browser.js +41 -0
- package/dist/packlets/crypto-utils/index.js +41 -0
- package/dist/packlets/crypto-utils/keystore/converters.js +84 -0
- package/dist/packlets/crypto-utils/keystore/index.js +31 -0
- package/dist/packlets/crypto-utils/keystore/keyStore.js +758 -0
- package/dist/packlets/crypto-utils/keystore/model.js +64 -0
- package/dist/packlets/crypto-utils/model.js +39 -0
- package/dist/packlets/crypto-utils/nodeCryptoProvider.js +159 -0
- package/dist/packlets/experimental/formatter.js +1 -1
- package/dist/packlets/mustache/index.js +23 -0
- package/dist/packlets/mustache/interfaces.js +25 -0
- package/dist/packlets/mustache/mustacheTemplate.js +242 -0
- package/dist/packlets/record-jar/recordJarHelpers.js +1 -1
- package/dist/packlets/yaml/converters.js +46 -0
- package/dist/packlets/yaml/index.js +23 -0
- package/dist/packlets/zip-file-tree/index.js +1 -0
- package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +43 -2
- package/dist/packlets/zip-file-tree/zipFileTreeWriter.js +40 -0
- package/dist/ts-extras.d.ts +1990 -112
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +3 -1
- package/lib/index.browser.js +6 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +9 -1
- package/lib/packlets/ai-assist/apiClient.d.ts +60 -0
- package/lib/packlets/ai-assist/apiClient.js +488 -0
- package/lib/packlets/ai-assist/converters.d.ts +55 -0
- package/lib/packlets/ai-assist/converters.js +124 -0
- package/lib/packlets/ai-assist/index.d.ts +10 -0
- package/lib/packlets/ai-assist/index.js +33 -0
- package/lib/packlets/ai-assist/model.d.ts +222 -0
- package/lib/packlets/ai-assist/model.js +95 -0
- package/lib/packlets/ai-assist/registry.d.ts +25 -0
- package/lib/packlets/ai-assist/registry.js +150 -0
- package/lib/packlets/ai-assist/toolFormats.d.ts +44 -0
- package/lib/packlets/ai-assist/toolFormats.js +166 -0
- package/lib/packlets/crypto-utils/constants.d.ts +26 -0
- package/lib/packlets/crypto-utils/constants.js +51 -0
- package/lib/packlets/crypto-utils/converters.d.ts +58 -0
- package/lib/packlets/crypto-utils/converters.js +192 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts +69 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.js +90 -0
- package/lib/packlets/crypto-utils/encryptedFile.d.ts +88 -0
- package/lib/packlets/crypto-utils/encryptedFile.js +201 -0
- package/lib/packlets/crypto-utils/index.browser.d.ts +14 -0
- package/lib/packlets/crypto-utils/index.browser.js +91 -0
- package/lib/packlets/crypto-utils/index.d.ts +15 -0
- package/lib/packlets/crypto-utils/index.js +88 -0
- package/lib/packlets/crypto-utils/keystore/converters.d.ts +29 -0
- package/lib/packlets/crypto-utils/keystore/converters.js +87 -0
- package/lib/packlets/crypto-utils/keystore/index.d.ts +9 -0
- package/lib/packlets/crypto-utils/keystore/index.js +71 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +239 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.js +795 -0
- package/lib/packlets/crypto-utils/keystore/model.d.ts +245 -0
- package/lib/packlets/crypto-utils/keystore/model.js +68 -0
- package/lib/packlets/crypto-utils/model.d.ts +236 -0
- package/lib/packlets/crypto-utils/model.js +76 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +62 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.js +196 -0
- package/lib/packlets/experimental/formatter.d.ts +1 -1
- package/lib/packlets/experimental/formatter.js +1 -1
- package/lib/packlets/mustache/index.d.ts +3 -0
- package/lib/packlets/mustache/index.js +27 -0
- package/lib/packlets/mustache/interfaces.d.ts +97 -0
- package/lib/packlets/mustache/interfaces.js +26 -0
- package/lib/packlets/mustache/mustacheTemplate.d.ts +76 -0
- package/lib/packlets/mustache/mustacheTemplate.js +249 -0
- package/lib/packlets/record-jar/recordJarHelpers.js +1 -1
- package/lib/packlets/yaml/converters.d.ts +9 -0
- package/lib/packlets/yaml/converters.js +82 -0
- package/lib/packlets/yaml/index.d.ts +2 -0
- package/lib/packlets/yaml/index.js +39 -0
- package/lib/packlets/zip-file-tree/index.d.ts +1 -0
- package/lib/packlets/zip-file-tree/index.js +15 -0
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +31 -2
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +42 -1
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts +27 -0
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.js +43 -0
- package/package.json +37 -18
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.MustacheTemplate = void 0;
|
|
28
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
29
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
30
|
+
/**
|
|
31
|
+
* Default options for MustacheTemplate
|
|
32
|
+
*/
|
|
33
|
+
const DEFAULT_OPTIONS = {
|
|
34
|
+
tags: ['{{', '}}'],
|
|
35
|
+
includeComments: false,
|
|
36
|
+
includePartials: false
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* A helper class for working with Mustache templates that provides
|
|
40
|
+
* validation, variable extraction, and context validation utilities.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
class MustacheTemplate {
|
|
44
|
+
constructor(template, tokens, options) {
|
|
45
|
+
this.template = template;
|
|
46
|
+
this._tokens = tokens;
|
|
47
|
+
this.options = options;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new MustacheTemplate instance.
|
|
51
|
+
* @param template - The Mustache template string to parse
|
|
52
|
+
* @param options - Optional parsing options
|
|
53
|
+
* @returns Success with the template instance, or Failure if parsing fails
|
|
54
|
+
*/
|
|
55
|
+
static create(template, options) {
|
|
56
|
+
const resolvedOptions = MustacheTemplate._resolveOptions(options);
|
|
57
|
+
return MustacheTemplate._parseTokens(template, resolvedOptions).onSuccess((tokens) => {
|
|
58
|
+
return (0, ts_utils_1.succeed)(new MustacheTemplate(template, tokens, resolvedOptions));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Validates that a template string has valid Mustache syntax.
|
|
63
|
+
* @param template - The template string to validate
|
|
64
|
+
* @param options - Optional parsing options
|
|
65
|
+
* @returns Success with true if valid, or Failure with a descriptive error message
|
|
66
|
+
*/
|
|
67
|
+
static validate(template, options) {
|
|
68
|
+
const resolvedOptions = MustacheTemplate._resolveOptions(options);
|
|
69
|
+
return MustacheTemplate._parseTokens(template, resolvedOptions).onSuccess(() => (0, ts_utils_1.succeed)(true));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Checks if this template instance has valid syntax.
|
|
73
|
+
* Always returns Success(true) since parsing succeeded in create().
|
|
74
|
+
* @returns Success with true
|
|
75
|
+
*/
|
|
76
|
+
validate() {
|
|
77
|
+
return (0, ts_utils_1.succeed)(true);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Extracts all variable references from the template.
|
|
81
|
+
* @returns An array of variable references found in the template
|
|
82
|
+
*/
|
|
83
|
+
extractVariables() {
|
|
84
|
+
if (this._variables === undefined) {
|
|
85
|
+
this._variables = this._extractVariablesFromTokens(this._tokens);
|
|
86
|
+
}
|
|
87
|
+
return this._variables;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extracts unique variable names from the template.
|
|
91
|
+
* @returns An array of unique variable name strings (e.g., ['user.name', 'items'])
|
|
92
|
+
*/
|
|
93
|
+
extractVariableNames() {
|
|
94
|
+
const variables = this.extractVariables();
|
|
95
|
+
const seen = new Set();
|
|
96
|
+
const names = [];
|
|
97
|
+
for (const variable of variables) {
|
|
98
|
+
if (!seen.has(variable.name)) {
|
|
99
|
+
seen.add(variable.name);
|
|
100
|
+
names.push(variable.name);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return names;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Validates that a context object has all required variables.
|
|
107
|
+
* @param context - The context object to validate
|
|
108
|
+
* @returns Success with validation result containing details about present/missing variables
|
|
109
|
+
*/
|
|
110
|
+
validateContext(context) {
|
|
111
|
+
const variables = this.extractVariables();
|
|
112
|
+
const presentVariables = [];
|
|
113
|
+
const missingVariables = [];
|
|
114
|
+
const missingDetails = [];
|
|
115
|
+
const checked = new Set();
|
|
116
|
+
for (const variable of variables) {
|
|
117
|
+
if (checked.has(variable.name)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
checked.add(variable.name);
|
|
121
|
+
const lookup = this._lookupPath(context, variable.path);
|
|
122
|
+
if (lookup.found) {
|
|
123
|
+
presentVariables.push(variable.name);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
missingVariables.push(variable.name);
|
|
127
|
+
missingDetails.push({
|
|
128
|
+
variable,
|
|
129
|
+
failedAtSegment: lookup.failedAt,
|
|
130
|
+
existingPath: lookup.existingPath
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return (0, ts_utils_1.succeed)({
|
|
135
|
+
isValid: missingVariables.length === 0,
|
|
136
|
+
presentVariables,
|
|
137
|
+
missingVariables,
|
|
138
|
+
missingDetails
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Renders the template with the given context.
|
|
143
|
+
* Use this for pre-validated contexts where you've already checked
|
|
144
|
+
* that all required variables are present.
|
|
145
|
+
* @param context - The context object for template rendering
|
|
146
|
+
* @returns Success with the rendered string, or Failure if rendering fails
|
|
147
|
+
*/
|
|
148
|
+
render(context) {
|
|
149
|
+
return (0, ts_utils_1.captureResult)(() => mustache_1.default.render(this.template, context));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Validates the context and renders the template if validation passes.
|
|
153
|
+
* @param context - The context object to validate and render with
|
|
154
|
+
* @returns Success with the rendered string, or Failure with validation or render errors
|
|
155
|
+
*/
|
|
156
|
+
validateAndRender(context) {
|
|
157
|
+
return this.validateContext(context).onSuccess((validation) => {
|
|
158
|
+
if (!validation.isValid) {
|
|
159
|
+
const missing = validation.missingVariables.join(', ');
|
|
160
|
+
return (0, ts_utils_1.fail)(`Missing required variables: ${missing}`);
|
|
161
|
+
}
|
|
162
|
+
return this.render(context);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
static _resolveOptions(options) {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
if (options === undefined) {
|
|
168
|
+
return DEFAULT_OPTIONS;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
tags: options.tags ? [options.tags[0], options.tags[1]] : DEFAULT_OPTIONS.tags,
|
|
172
|
+
includeComments: (_a = options.includeComments) !== null && _a !== void 0 ? _a : DEFAULT_OPTIONS.includeComments,
|
|
173
|
+
includePartials: (_b = options.includePartials) !== null && _b !== void 0 ? _b : DEFAULT_OPTIONS.includePartials
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
static _parseTokens(template, options) {
|
|
177
|
+
return (0, ts_utils_1.captureResult)(() => mustache_1.default.parse(template, options.tags));
|
|
178
|
+
}
|
|
179
|
+
_extractVariablesFromTokens(tokens) {
|
|
180
|
+
const variables = [];
|
|
181
|
+
for (const token of tokens) {
|
|
182
|
+
const type = token[0];
|
|
183
|
+
const value = token[1];
|
|
184
|
+
// Skip text tokens
|
|
185
|
+
if (type === 'text') {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
// Handle comments based on options
|
|
189
|
+
if (type === '!' && !this.options.includeComments) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
// Handle partials based on options
|
|
193
|
+
if (type === '>' && !this.options.includePartials) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
// Handle variable tokens: 'name', '&', '#', '^', and optionally '!', '>'
|
|
197
|
+
if (type === 'name' || type === '&' || type === '#' || type === '^' || type === '!' || type === '>') {
|
|
198
|
+
const isSection = type === '#' || type === '^';
|
|
199
|
+
variables.push({
|
|
200
|
+
name: value,
|
|
201
|
+
path: this._parsePath(value),
|
|
202
|
+
tokenType: type,
|
|
203
|
+
isSection
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
// Recursively extract from nested tokens in sections
|
|
207
|
+
if ((type === '#' || type === '^') && token.length > 4) {
|
|
208
|
+
const nestedTokens = token[4];
|
|
209
|
+
if (nestedTokens) {
|
|
210
|
+
variables.push(...this._extractVariablesFromTokens(nestedTokens));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return variables;
|
|
215
|
+
}
|
|
216
|
+
_parsePath(name) {
|
|
217
|
+
// Handle special case of '.' which means current context
|
|
218
|
+
if (name === '.') {
|
|
219
|
+
return ['.'];
|
|
220
|
+
}
|
|
221
|
+
// Split on dots to get path segments
|
|
222
|
+
return name.split('.').filter((segment) => segment.length > 0);
|
|
223
|
+
}
|
|
224
|
+
_lookupPath(context, path) {
|
|
225
|
+
// Handle '.' which always exists if context is not null/undefined
|
|
226
|
+
if (path.length === 1 && path[0] === '.') {
|
|
227
|
+
return { found: context !== undefined && context !== null, existingPath: [] };
|
|
228
|
+
}
|
|
229
|
+
let current = context;
|
|
230
|
+
const existingPath = [];
|
|
231
|
+
for (const segment of path) {
|
|
232
|
+
if (current === undefined || current === null) {
|
|
233
|
+
return { found: false, existingPath, failedAt: segment };
|
|
234
|
+
}
|
|
235
|
+
if (typeof current !== 'object') {
|
|
236
|
+
return { found: false, existingPath, failedAt: segment };
|
|
237
|
+
}
|
|
238
|
+
const obj = current;
|
|
239
|
+
if (!(segment in obj)) {
|
|
240
|
+
return { found: false, existingPath, failedAt: segment };
|
|
241
|
+
}
|
|
242
|
+
current = obj[segment];
|
|
243
|
+
existingPath.push(segment);
|
|
244
|
+
}
|
|
245
|
+
return { found: true, existingPath };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.MustacheTemplate = MustacheTemplate;
|
|
249
|
+
//# sourceMappingURL=mustacheTemplate.js.map
|
|
@@ -153,7 +153,7 @@ class RecordParser {
|
|
|
153
153
|
var _a, _b;
|
|
154
154
|
let trimmed = line.trim();
|
|
155
155
|
if (!this._body.isContinuation) {
|
|
156
|
-
/* c8 ignore next */
|
|
156
|
+
/* c8 ignore next - functional code tested but coverage intermittently missed */
|
|
157
157
|
const fixedSize = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.fixedContinuationSize) !== null && _b !== void 0 ? _b : 0;
|
|
158
158
|
if (fixedSize > 0) {
|
|
159
159
|
if (trimmed.length < line.length - fixedSize) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Converter } from '@fgv/ts-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a converter that parses YAML string content and then applies the supplied converter.
|
|
4
|
+
* @param converter - Converter to apply to the parsed YAML
|
|
5
|
+
* @returns Converter that parses YAML then validates
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare function yamlConverter<T>(converter: Converter<T>): Converter<T>;
|
|
9
|
+
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
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.yamlConverter = yamlConverter;
|
|
58
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
59
|
+
const yaml = __importStar(require("js-yaml"));
|
|
60
|
+
/**
|
|
61
|
+
* Creates a converter that parses YAML string content and then applies the supplied converter.
|
|
62
|
+
* @param converter - Converter to apply to the parsed YAML
|
|
63
|
+
* @returns Converter that parses YAML then validates
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
function yamlConverter(converter) {
|
|
67
|
+
return new ts_utils_1.Conversion.BaseConverter((from) => {
|
|
68
|
+
if (typeof from !== 'string') {
|
|
69
|
+
return (0, ts_utils_1.fail)('Input must be a string');
|
|
70
|
+
}
|
|
71
|
+
const parseResult = (0, ts_utils_1.captureResult)(() => yaml.load(from));
|
|
72
|
+
if (parseResult.isFailure()) {
|
|
73
|
+
return (0, ts_utils_1.fail)(`Failed to parse YAML: ${parseResult.message}`);
|
|
74
|
+
}
|
|
75
|
+
const parsed = parseResult.value;
|
|
76
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
77
|
+
return (0, ts_utils_1.fail)('Failed to parse YAML: YAML content must be an object');
|
|
78
|
+
}
|
|
79
|
+
return converter.convert(parsed);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
__exportStar(require("./converters"), exports);
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -20,6 +20,20 @@
|
|
|
20
20
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
* SOFTWARE.
|
|
22
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
+
};
|
|
23
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
38
|
exports.ZipDirectoryItem = exports.ZipFileItem = exports.ZipFileTreeAccessors = void 0;
|
|
25
39
|
/**
|
|
@@ -35,4 +49,5 @@ var zipFileTreeAccessors_1 = require("./zipFileTreeAccessors");
|
|
|
35
49
|
Object.defineProperty(exports, "ZipFileTreeAccessors", { enumerable: true, get: function () { return zipFileTreeAccessors_1.ZipFileTreeAccessors; } });
|
|
36
50
|
Object.defineProperty(exports, "ZipFileItem", { enumerable: true, get: function () { return zipFileTreeAccessors_1.ZipFileItem; } });
|
|
37
51
|
Object.defineProperty(exports, "ZipDirectoryItem", { enumerable: true, get: function () { return zipFileTreeAccessors_1.ZipDirectoryItem; } });
|
|
52
|
+
__exportStar(require("./zipFileTreeWriter"), exports);
|
|
38
53
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Result, Converter, Validator } from '@fgv/ts-utils';
|
|
1
|
+
import { Result, Converter, Validator, DetailedResult } from '@fgv/ts-utils';
|
|
2
2
|
import { FileTree, JsonValue } from '@fgv/ts-json-base';
|
|
3
3
|
/**
|
|
4
4
|
* Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
|
|
@@ -52,6 +52,22 @@ export declare class ZipFileItem<TCT extends string = string> implements FileTre
|
|
|
52
52
|
* @param accessors - The ZIP file tree accessors.
|
|
53
53
|
*/
|
|
54
54
|
constructor(zipFilePath: string, contents: string, accessors: ZipFileTreeAccessors<TCT>);
|
|
55
|
+
/**
|
|
56
|
+
* Returns a boolean indicating whether this file can be saved.
|
|
57
|
+
*/
|
|
58
|
+
getIsMutable(): DetailedResult<boolean, FileTree.SaveDetail>;
|
|
59
|
+
/**
|
|
60
|
+
* Sets the contents of the file as parsed JSON.
|
|
61
|
+
* @param json - The JSON to set as the contents of the file.
|
|
62
|
+
* @returns A Result indicating success or failure.
|
|
63
|
+
*/
|
|
64
|
+
setContents(json: JsonValue): Result<JsonValue>;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the contents of the file as a string.
|
|
67
|
+
* @param contents - The string to set as the contents of the file.
|
|
68
|
+
* @returns A Result indicating success or failure.
|
|
69
|
+
*/
|
|
70
|
+
setRawContents(contents: string): Result<string>;
|
|
55
71
|
/**
|
|
56
72
|
* Sets the content type of the file.
|
|
57
73
|
* @param contentType - The content type of the file.
|
|
@@ -103,7 +119,7 @@ export declare class ZipDirectoryItem<TCT extends string = string> implements Fi
|
|
|
103
119
|
* File tree accessors for ZIP archives.
|
|
104
120
|
* @public
|
|
105
121
|
*/
|
|
106
|
-
export declare class ZipFileTreeAccessors<TCT extends string = string> implements FileTree.
|
|
122
|
+
export declare class ZipFileTreeAccessors<TCT extends string = string> implements FileTree.IMutableFileTreeAccessors<TCT> {
|
|
107
123
|
/**
|
|
108
124
|
* The unzipped file data.
|
|
109
125
|
*/
|
|
@@ -175,6 +191,19 @@ export declare class ZipFileTreeAccessors<TCT extends string = string> implement
|
|
|
175
191
|
* Builds the cache of all items in the ZIP archive.
|
|
176
192
|
*/
|
|
177
193
|
private _buildItemCache;
|
|
194
|
+
/**
|
|
195
|
+
* Returns a boolean indicating whether this file can be saved.
|
|
196
|
+
* @param path - The path of the file.
|
|
197
|
+
* @returns A `DetailedResult` indicating success or failure.
|
|
198
|
+
*/
|
|
199
|
+
fileIsMutable(__path: string): DetailedResult<boolean, FileTree.SaveDetail>;
|
|
200
|
+
/**
|
|
201
|
+
* Saves the contents of a file.
|
|
202
|
+
* @param path - The path of the file.
|
|
203
|
+
* @param contents - The contents of the file.
|
|
204
|
+
* @returns A `Result` indicating success or failure.
|
|
205
|
+
*/
|
|
206
|
+
saveFileContents(__path: string, __contents: string): Result<string>;
|
|
178
207
|
/**
|
|
179
208
|
* Resolves paths to an absolute path.
|
|
180
209
|
*/
|
|
@@ -61,6 +61,30 @@ class ZipFileItem {
|
|
|
61
61
|
this.extension = accessors.getExtension(zipFilePath);
|
|
62
62
|
this.baseName = accessors.getBaseName(zipFilePath, this.extension);
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns a boolean indicating whether this file can be saved.
|
|
66
|
+
*/
|
|
67
|
+
getIsMutable() {
|
|
68
|
+
return this._accessors.fileIsMutable(this.absolutePath);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Sets the contents of the file as parsed JSON.
|
|
72
|
+
* @param json - The JSON to set as the contents of the file.
|
|
73
|
+
* @returns A Result indicating success or failure.
|
|
74
|
+
*/
|
|
75
|
+
setContents(json) {
|
|
76
|
+
return (0, ts_utils_1.captureResult)(() => JSON.stringify(json, null, 2)).onSuccess((contents) => this.setRawContents(contents).onSuccess(() => ts_utils_1.Success.with(json)));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Sets the contents of the file as a string.
|
|
80
|
+
* @param contents - The string to set as the contents of the file.
|
|
81
|
+
* @returns A Result indicating success or failure.
|
|
82
|
+
*/
|
|
83
|
+
setRawContents(contents) {
|
|
84
|
+
return this.getIsMutable().asResult.onSuccess(() =>
|
|
85
|
+
/* c8 ignore next - unreachable: ZIP files are always read-only */
|
|
86
|
+
this._accessors.saveFileContents(this.absolutePath, contents));
|
|
87
|
+
}
|
|
64
88
|
/**
|
|
65
89
|
* Sets the content type of the file.
|
|
66
90
|
* @param contentType - The content type of the file.
|
|
@@ -182,7 +206,7 @@ class ZipFileTreeAccessors {
|
|
|
182
206
|
resolve((0, ts_utils_1.succeed)(new ZipFileTreeAccessors(files, normalizedParams)));
|
|
183
207
|
}
|
|
184
208
|
});
|
|
185
|
-
/* c8 ignore next
|
|
209
|
+
/* c8 ignore next 5 - defensive coding: fflate reports errors via callback, not exceptions */
|
|
186
210
|
}
|
|
187
211
|
catch (error) {
|
|
188
212
|
resolve((0, ts_utils_1.fail)(`Failed to load ZIP archive: ${error instanceof Error ? error.message : String(error)}`));
|
|
@@ -243,6 +267,23 @@ class ZipFileTreeAccessors {
|
|
|
243
267
|
this._itemCache.set(absolutePath, item);
|
|
244
268
|
});
|
|
245
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Returns a boolean indicating whether this file can be saved.
|
|
272
|
+
* @param path - The path of the file.
|
|
273
|
+
* @returns A `DetailedResult` indicating success or failure.
|
|
274
|
+
*/
|
|
275
|
+
fileIsMutable(__path) {
|
|
276
|
+
return (0, ts_utils_1.failWithDetail)('ZIP files are read-only', 'not-supported');
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Saves the contents of a file.
|
|
280
|
+
* @param path - The path of the file.
|
|
281
|
+
* @param contents - The contents of the file.
|
|
282
|
+
* @returns A `Result` indicating success or failure.
|
|
283
|
+
*/
|
|
284
|
+
saveFileContents(__path, __contents) {
|
|
285
|
+
return (0, ts_utils_1.failWithDetail)('ZIP files are read-only', 'not-supported');
|
|
286
|
+
}
|
|
246
287
|
/**
|
|
247
288
|
* Resolves paths to an absolute path.
|
|
248
289
|
*/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Simple interface for a file to be added to a zip file.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface IZipTextFile {
|
|
7
|
+
readonly path: string;
|
|
8
|
+
readonly contents: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Supported compression levels for zip files.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export type ZipCompressionLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
15
|
+
/**
|
|
16
|
+
* Options for creating a zip file from text files.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export interface ICreateZipOptions {
|
|
20
|
+
readonly level?: ZipCompressionLevel;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a zip file from an array of text files.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function createZipFromTextFiles(files: ReadonlyArray<IZipTextFile>, options?: ICreateZipOptions): Result<Uint8Array>;
|
|
27
|
+
//# sourceMappingURL=zipFileTreeWriter.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2026 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.createZipFromTextFiles = createZipFromTextFiles;
|
|
25
|
+
const fflate_1 = require("fflate");
|
|
26
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
27
|
+
/**
|
|
28
|
+
* Creates a zip file from an array of text files.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
function createZipFromTextFiles(files, options) {
|
|
32
|
+
return (0, ts_utils_1.captureResult)(() => {
|
|
33
|
+
var _a;
|
|
34
|
+
const out = {};
|
|
35
|
+
for (const f of files) {
|
|
36
|
+
const normalizedPath = f.path.replace(/^\/+/, '');
|
|
37
|
+
out[normalizedPath] = (0, fflate_1.strToU8)(f.contents);
|
|
38
|
+
}
|
|
39
|
+
return (0, fflate_1.zipSync)(out, { level: (_a = options === null || options === void 0 ? void 0 : options.level) !== null && _a !== void 0 ? _a : 6 });
|
|
40
|
+
/* c8 ignore next - defensive: zipSync only throws on internal library errors */
|
|
41
|
+
}).withErrorFormat((e) => `Failed to create zip: ${e}`);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=zipFileTreeWriter.js.map
|