@fgv/ts-utils 1.9.4 → 2.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 (211) hide show
  1. package/CHANGELOG.json +26 -0
  2. package/CHANGELOG.md +14 -0
  3. package/dist/ts-utils.d.ts +3007 -0
  4. package/dist/tsdoc-metadata.json +11 -0
  5. package/lib/index.d.ts +12 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +68 -0
  8. package/lib/index.js.map +1 -0
  9. package/lib/packlets/base/brand.d.ts.map +1 -0
  10. package/lib/packlets/base/brand.js +24 -0
  11. package/lib/packlets/base/brand.js.map +1 -0
  12. package/lib/packlets/base/index.d.ts +7 -0
  13. package/lib/packlets/base/index.d.ts.map +1 -0
  14. package/lib/packlets/base/index.js +58 -0
  15. package/lib/packlets/base/index.js.map +1 -0
  16. package/{logger.d.ts → lib/packlets/base/logger.d.ts} +16 -1
  17. package/lib/packlets/base/logger.d.ts.map +1 -0
  18. package/lib/packlets/base/logger.js +128 -0
  19. package/lib/packlets/base/logger.js.map +1 -0
  20. package/{normalize.d.ts → lib/packlets/base/normalize.d.ts} +6 -0
  21. package/lib/packlets/base/normalize.d.ts.map +1 -0
  22. package/lib/packlets/base/normalize.js +139 -0
  23. package/lib/packlets/base/normalize.js.map +1 -0
  24. package/{result.d.ts → lib/packlets/base/result.d.ts} +16 -15
  25. package/lib/packlets/base/result.d.ts.map +1 -0
  26. package/lib/packlets/base/result.js +571 -0
  27. package/lib/packlets/base/result.js.map +1 -0
  28. package/lib/packlets/base/utils.d.ts.map +1 -0
  29. package/lib/packlets/base/utils.js +200 -0
  30. package/lib/packlets/base/utils.js.map +1 -0
  31. package/{converter.d.ts → lib/packlets/conversion/converter.d.ts} +11 -12
  32. package/lib/packlets/conversion/converter.d.ts.map +1 -0
  33. package/lib/packlets/conversion/converter.js +218 -0
  34. package/lib/packlets/conversion/converter.js.map +1 -0
  35. package/{converters.d.ts → lib/packlets/conversion/converters.d.ts} +52 -216
  36. package/lib/packlets/conversion/converters.d.ts.map +1 -0
  37. package/lib/packlets/conversion/converters.js +739 -0
  38. package/lib/packlets/conversion/converters.js.map +1 -0
  39. package/lib/packlets/conversion/index.d.ts +6 -0
  40. package/lib/packlets/conversion/index.d.ts.map +1 -0
  41. package/lib/packlets/conversion/index.js +56 -0
  42. package/lib/packlets/conversion/index.js.map +1 -0
  43. package/lib/packlets/conversion/objectConverter.d.ts +94 -0
  44. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -0
  45. package/lib/packlets/conversion/objectConverter.js +110 -0
  46. package/lib/packlets/conversion/objectConverter.js.map +1 -0
  47. package/lib/packlets/conversion/stringConverter.d.ts +78 -0
  48. package/lib/packlets/conversion/stringConverter.d.ts.map +1 -0
  49. package/lib/packlets/conversion/stringConverter.js +97 -0
  50. package/lib/packlets/conversion/stringConverter.js.map +1 -0
  51. package/{csvHelpers.d.ts → lib/packlets/csv/csvHelpers.d.ts} +1 -1
  52. package/lib/packlets/csv/csvHelpers.d.ts.map +1 -0
  53. package/lib/packlets/csv/csvHelpers.js +69 -0
  54. package/lib/packlets/csv/csvHelpers.js.map +1 -0
  55. package/lib/packlets/csv/index.d.ts +2 -0
  56. package/lib/packlets/csv/index.d.ts.map +1 -0
  57. package/lib/packlets/csv/index.js +39 -0
  58. package/lib/packlets/csv/index.js.map +1 -0
  59. package/{extendedArray.d.ts → lib/packlets/experimental/extendedArray.d.ts} +7 -7
  60. package/lib/packlets/experimental/extendedArray.d.ts.map +1 -0
  61. package/lib/packlets/experimental/extendedArray.js +106 -0
  62. package/lib/packlets/experimental/extendedArray.js.map +1 -0
  63. package/{formatter.d.ts → lib/packlets/experimental/formatter.d.ts} +6 -6
  64. package/lib/packlets/experimental/formatter.d.ts.map +1 -0
  65. package/lib/packlets/experimental/formatter.js +75 -0
  66. package/lib/packlets/experimental/formatter.js.map +1 -0
  67. package/lib/packlets/experimental/index.d.ts +4 -0
  68. package/lib/packlets/experimental/index.d.ts.map +1 -0
  69. package/lib/packlets/experimental/index.js +41 -0
  70. package/lib/packlets/experimental/index.js.map +1 -0
  71. package/{rangeOf.d.ts → lib/packlets/experimental/rangeOf.d.ts} +21 -24
  72. package/lib/packlets/experimental/rangeOf.d.ts.map +1 -0
  73. package/lib/packlets/experimental/rangeOf.js +185 -0
  74. package/lib/packlets/experimental/rangeOf.js.map +1 -0
  75. package/{hash.d.ts → lib/packlets/hash/hash.d.ts} +1 -1
  76. package/lib/packlets/hash/hash.d.ts.map +1 -0
  77. package/lib/packlets/hash/hash.js +168 -0
  78. package/lib/packlets/hash/hash.js.map +1 -0
  79. package/lib/packlets/hash/index.d.ts +2 -0
  80. package/lib/packlets/hash/index.d.ts.map +1 -0
  81. package/lib/packlets/hash/index.js +39 -0
  82. package/lib/packlets/hash/index.js.map +1 -0
  83. package/lib/packlets/record-jar/index.d.ts +2 -0
  84. package/lib/packlets/record-jar/index.d.ts.map +1 -0
  85. package/lib/packlets/record-jar/index.js +39 -0
  86. package/lib/packlets/record-jar/index.js.map +1 -0
  87. package/{recordJarHelpers.d.ts → lib/packlets/record-jar/recordJarHelpers.d.ts} +1 -1
  88. package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +1 -0
  89. package/lib/packlets/record-jar/recordJarHelpers.js +263 -0
  90. package/lib/packlets/record-jar/recordJarHelpers.js.map +1 -0
  91. package/{validation → lib/packlets/validation}/array.d.ts +2 -2
  92. package/lib/packlets/validation/array.d.ts.map +1 -0
  93. package/lib/packlets/validation/array.js +67 -0
  94. package/lib/packlets/validation/array.js.map +1 -0
  95. package/{validation → lib/packlets/validation}/boolean.d.ts +1 -1
  96. package/lib/packlets/validation/boolean.d.ts.map +1 -0
  97. package/lib/packlets/validation/boolean.js +56 -0
  98. package/lib/packlets/validation/boolean.js.map +1 -0
  99. package/lib/packlets/validation/classes.d.ts.map +1 -0
  100. package/lib/packlets/validation/classes.js +38 -0
  101. package/lib/packlets/validation/classes.js.map +1 -0
  102. package/lib/packlets/validation/common.d.ts.map +1 -0
  103. package/lib/packlets/validation/common.js +24 -0
  104. package/lib/packlets/validation/common.js.map +1 -0
  105. package/{validation → lib/packlets/validation}/field.d.ts +1 -1
  106. package/lib/packlets/validation/field.d.ts.map +1 -0
  107. package/lib/packlets/validation/field.js +71 -0
  108. package/lib/packlets/validation/field.js.map +1 -0
  109. package/{validation → lib/packlets/validation}/genericValidator.d.ts +2 -3
  110. package/lib/packlets/validation/genericValidator.d.ts.map +1 -0
  111. package/lib/packlets/validation/genericValidator.js +137 -0
  112. package/lib/packlets/validation/genericValidator.js.map +1 -0
  113. package/lib/packlets/validation/index.d.ts.map +1 -0
  114. package/{validation → lib/packlets/validation}/index.js +1 -1
  115. package/lib/packlets/validation/index.js.map +1 -0
  116. package/{validation → lib/packlets/validation}/number.d.ts +1 -1
  117. package/lib/packlets/validation/number.d.ts.map +1 -0
  118. package/lib/packlets/validation/number.js +54 -0
  119. package/lib/packlets/validation/number.js.map +1 -0
  120. package/{validation → lib/packlets/validation}/object.d.ts +1 -1
  121. package/lib/packlets/validation/object.d.ts.map +1 -0
  122. package/lib/packlets/validation/object.js +139 -0
  123. package/lib/packlets/validation/object.js.map +1 -0
  124. package/{validation → lib/packlets/validation}/string.d.ts +1 -1
  125. package/lib/packlets/validation/string.d.ts.map +1 -0
  126. package/lib/packlets/validation/string.js +54 -0
  127. package/lib/packlets/validation/string.js.map +1 -0
  128. package/lib/packlets/validation/traits.d.ts.map +1 -0
  129. package/lib/packlets/validation/traits.js +58 -0
  130. package/lib/packlets/validation/traits.js.map +1 -0
  131. package/{validation → lib/packlets/validation}/typeGuard.d.ts +1 -1
  132. package/lib/packlets/validation/typeGuard.d.ts.map +1 -0
  133. package/lib/packlets/validation/typeGuard.js +62 -0
  134. package/lib/packlets/validation/typeGuard.js.map +1 -0
  135. package/{validation → lib/packlets/validation}/validator.d.ts +15 -16
  136. package/lib/packlets/validation/validator.d.ts.map +1 -0
  137. package/lib/packlets/validation/validator.js +24 -0
  138. package/lib/packlets/validation/validator.js.map +1 -0
  139. package/{validation → lib/packlets/validation}/validatorBase.d.ts +1 -1
  140. package/lib/packlets/validation/validatorBase.d.ts.map +1 -0
  141. package/lib/packlets/validation/validatorBase.js +41 -0
  142. package/lib/packlets/validation/validatorBase.js.map +1 -0
  143. package/{validation → lib/packlets/validation}/validators.d.ts +3 -6
  144. package/lib/packlets/validation/validators.d.ts.map +1 -0
  145. package/lib/packlets/validation/validators.js +121 -0
  146. package/lib/packlets/validation/validators.js.map +1 -0
  147. package/package.json +21 -20
  148. package/brand.d.ts.map +0 -1
  149. package/brand.js +0 -24
  150. package/converter.d.ts.map +0 -1
  151. package/converter.js +0 -222
  152. package/converters.d.ts.map +0 -1
  153. package/converters.js +0 -896
  154. package/csvHelpers.d.ts.map +0 -1
  155. package/csvHelpers.js +0 -69
  156. package/extendedArray.d.ts.map +0 -1
  157. package/extendedArray.js +0 -106
  158. package/formatter.d.ts.map +0 -1
  159. package/formatter.js +0 -75
  160. package/hash.d.ts.map +0 -1
  161. package/hash.js +0 -168
  162. package/index.d.ts +0 -15
  163. package/index.d.ts.map +0 -1
  164. package/index.js +0 -70
  165. package/logger.d.ts.map +0 -1
  166. package/logger.js +0 -115
  167. package/normalize.d.ts.map +0 -1
  168. package/normalize.js +0 -139
  169. package/rangeOf.d.ts.map +0 -1
  170. package/rangeOf.js +0 -185
  171. package/recordJarHelpers.d.ts.map +0 -1
  172. package/recordJarHelpers.js +0 -262
  173. package/result.d.ts.map +0 -1
  174. package/result.js +0 -569
  175. package/utils.d.ts.map +0 -1
  176. package/utils.js +0 -200
  177. package/validation/array.d.ts.map +0 -1
  178. package/validation/array.js +0 -67
  179. package/validation/boolean.d.ts.map +0 -1
  180. package/validation/boolean.js +0 -59
  181. package/validation/classes.d.ts.map +0 -1
  182. package/validation/classes.js +0 -38
  183. package/validation/common.d.ts.map +0 -1
  184. package/validation/common.js +0 -24
  185. package/validation/field.d.ts.map +0 -1
  186. package/validation/field.js +0 -72
  187. package/validation/genericValidator.d.ts.map +0 -1
  188. package/validation/genericValidator.js +0 -138
  189. package/validation/index.d.ts.map +0 -1
  190. package/validation/number.d.ts.map +0 -1
  191. package/validation/number.js +0 -57
  192. package/validation/object.d.ts.map +0 -1
  193. package/validation/object.js +0 -143
  194. package/validation/string.d.ts.map +0 -1
  195. package/validation/string.js +0 -57
  196. package/validation/traits.d.ts.map +0 -1
  197. package/validation/traits.js +0 -58
  198. package/validation/typeGuard.d.ts.map +0 -1
  199. package/validation/typeGuard.js +0 -62
  200. package/validation/validator.d.ts.map +0 -1
  201. package/validation/validator.js +0 -24
  202. package/validation/validatorBase.d.ts.map +0 -1
  203. package/validation/validatorBase.js +0 -44
  204. package/validation/validators.d.ts.map +0 -1
  205. package/validation/validators.js +0 -119
  206. /package/{brand.d.ts → lib/packlets/base/brand.d.ts} +0 -0
  207. /package/{utils.d.ts → lib/packlets/base/utils.d.ts} +0 -0
  208. /package/{validation → lib/packlets/validation}/classes.d.ts +0 -0
  209. /package/{validation → lib/packlets/validation}/common.d.ts +0 -0
  210. /package/{validation → lib/packlets/validation}/index.d.ts +0 -0
  211. /package/{validation → lib/packlets/validation}/traits.d.ts +0 -0
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022 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 (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.readRecordJarFileSync = exports.parseRecordJarLines = void 0;
48
+ const fs = __importStar(require("fs"));
49
+ const path = __importStar(require("path"));
50
+ const base_1 = require("../base");
51
+ class RecordParser {
52
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
53
+ constructor(options) {
54
+ this.records = [];
55
+ this._fields = {};
56
+ this._name = undefined;
57
+ this._body = undefined;
58
+ this.options = options !== null && options !== void 0 ? options : {};
59
+ }
60
+ static parse(lines, options) {
61
+ return new RecordParser(options)._parse(lines);
62
+ }
63
+ static _parseRecordBody(body) {
64
+ const isContinuation = body.endsWith('\\');
65
+ if (isContinuation) {
66
+ body = body.slice(0, body.length - 1);
67
+ }
68
+ if (this._hasEscapes(body)) {
69
+ const result = this._replaceEscapes(body);
70
+ if (result.isFailure()) {
71
+ return (0, base_1.fail)(result.message);
72
+ }
73
+ body = result.value;
74
+ }
75
+ return (0, base_1.succeed)({ body, isContinuation });
76
+ }
77
+ static _hasEscapes(from) {
78
+ return from.includes('\\') || from.includes('&');
79
+ }
80
+ static _replaceEscapes(body) {
81
+ const invalid = [];
82
+ const escaped = body.replace(/(\\.)|(&#x[a-fA-F0-9]{2,6};)/g, (match) => {
83
+ switch (match) {
84
+ case '\\\\':
85
+ return '\\';
86
+ case '\\&':
87
+ return '&';
88
+ case '\\r':
89
+ return '\r';
90
+ case '\\n':
91
+ return '\n';
92
+ case '\\t':
93
+ return '\t';
94
+ }
95
+ if (match.startsWith('&')) {
96
+ const hexCode = `0x${match.slice(3, match.length - 1)}`;
97
+ const charCode = Number.parseInt(hexCode, 16);
98
+ return String.fromCharCode(charCode);
99
+ }
100
+ invalid.push(match);
101
+ return '\\';
102
+ });
103
+ if (invalid.length > 0) {
104
+ return (0, base_1.fail)(`unrecognized escape "${invalid.join(', ')}" in record-jar body`);
105
+ }
106
+ return (0, base_1.succeed)(escaped);
107
+ }
108
+ static _applyOptions(record, options) {
109
+ if (options.arrayFields) {
110
+ record = Object.assign({}, record); // don't edit incoming values
111
+ const arrayFields = Array.isArray(options.arrayFields)
112
+ ? options.arrayFields
113
+ : options.arrayFields(record);
114
+ for (const field of arrayFields) {
115
+ if ((0, base_1.isKeyOf)(field, record) && typeof record[field] === 'string') {
116
+ const current = record[field];
117
+ record[field] = [current];
118
+ }
119
+ }
120
+ }
121
+ return record;
122
+ }
123
+ _parse(lines) {
124
+ var _a, _b;
125
+ for (let n = 0; n < lines.length; n++) {
126
+ const line = lines[n];
127
+ if (line.startsWith('%%') && !((_a = this._body) === null || _a === void 0 ? void 0 : _a.isContinuation)) {
128
+ const result = this._writePendingRecord();
129
+ if (result.isFailure()) {
130
+ return (0, base_1.fail)(`${n}: ${result.message}`);
131
+ }
132
+ }
133
+ else if (/^\s*$/.test(line)) {
134
+ // ignore blank lines but cancel continuation
135
+ if (this._body) {
136
+ this._body.isContinuation = false;
137
+ }
138
+ continue;
139
+ }
140
+ else if (((_b = this._body) === null || _b === void 0 ? void 0 : _b.isContinuation) || /^\s+/.test(line)) {
141
+ // explicit continuation on previous line or implicit starts with whitespace
142
+ if (this._body === undefined) {
143
+ return (0, base_1.fail)(`${n}: continuation ("${line}") without prior value.`);
144
+ }
145
+ const result = this._parseContinuation(line);
146
+ if (result.isFailure()) {
147
+ return (0, base_1.fail)(`${n}: ${result.message}`);
148
+ }
149
+ this._body = result.value;
150
+ }
151
+ else {
152
+ const result = this._parseField(line);
153
+ if (result.isFailure()) {
154
+ return (0, base_1.fail)(`${n}: ${result.message}`);
155
+ }
156
+ }
157
+ }
158
+ const result = this._writePendingRecord();
159
+ if (result.isFailure()) {
160
+ return (0, base_1.fail)(`${lines.length}: ${result.message}`);
161
+ }
162
+ return (0, base_1.succeed)(this.records);
163
+ }
164
+ _parseField(line) {
165
+ const separatorIndex = line.indexOf(':');
166
+ if (separatorIndex < 1) {
167
+ return (0, base_1.fail)(`malformed line ("${line}") in record-jar.`);
168
+ }
169
+ const parts = [line.slice(0, separatorIndex), line.slice(separatorIndex + 1)];
170
+ return this._writePendingField().onSuccess(() => {
171
+ this._name = parts[0].trimEnd();
172
+ return RecordParser._parseRecordBody(parts[1].trim()).onSuccess((body) => {
173
+ this._body = body;
174
+ return (0, base_1.succeed)(true);
175
+ });
176
+ });
177
+ }
178
+ _parseContinuation(line) {
179
+ var _a, _b;
180
+ let trimmed = line.trim();
181
+ if (!this._body.isContinuation) {
182
+ // istanbul ignore next
183
+ const fixedSize = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.fixedContinuationSize) !== null && _b !== void 0 ? _b : 0;
184
+ if (fixedSize > 0) {
185
+ if (trimmed.length < line.length - fixedSize) {
186
+ // oops, took too much
187
+ trimmed = line.slice(fixedSize);
188
+ }
189
+ }
190
+ }
191
+ return RecordParser._parseRecordBody(trimmed).onSuccess((newBody) => {
192
+ return (0, base_1.succeed)({
193
+ body: `${this._body.body}${newBody.body}`,
194
+ isContinuation: newBody.isContinuation
195
+ });
196
+ });
197
+ }
198
+ _havePendingRecord() {
199
+ return Object.keys(this._fields).length > 0;
200
+ }
201
+ _writePendingRecord() {
202
+ return this._writePendingField().onSuccess(() => {
203
+ let record = this._havePendingRecord() ? this._fields : undefined;
204
+ if (record !== undefined) {
205
+ record = RecordParser._applyOptions(record, this.options);
206
+ this.records.push(record);
207
+ this._fields = {};
208
+ }
209
+ return (0, base_1.succeed)(undefined);
210
+ });
211
+ }
212
+ _writePendingField() {
213
+ if (this._name !== undefined) {
214
+ if (this._body.body.length < 1) {
215
+ return (0, base_1.fail)('empty body value not allowed');
216
+ }
217
+ if (!(0, base_1.isKeyOf)(this._name, this._fields)) {
218
+ this._fields[this._name] = this._body.body;
219
+ }
220
+ else if (typeof this._fields[this._name] === 'string') {
221
+ const current = this._fields[this._name];
222
+ this._fields[this._name] = [current, this._body.body];
223
+ }
224
+ else {
225
+ const current = this._fields[this._name];
226
+ current.push(this._body.body);
227
+ }
228
+ this._name = undefined;
229
+ this._body = undefined;
230
+ }
231
+ return (0, base_1.succeed)(true);
232
+ }
233
+ }
234
+ /**
235
+ * Reads a record-jar from an array of strings, each of which represents one
236
+ * line in the source file.
237
+ * @param lines - the array of strings to be parsed
238
+ * @param options - Optional parser configuration
239
+ * @returns a corresponding array of `Record<string, string>`
240
+ * @public
241
+ */
242
+ function parseRecordJarLines(lines, options) {
243
+ return RecordParser.parse(lines, options);
244
+ }
245
+ exports.parseRecordJarLines = parseRecordJarLines;
246
+ /**
247
+ * Reads a record-jar file from a supplied path.
248
+ * @param srcPath - Source path from which the file is read.
249
+ * @param options - Optional parser configuration
250
+ * @returns The contents of the file as an array of `Record<string, string>`
251
+ * @see https://datatracker.ietf.org/doc/html/draft-phillips-record-jar-01
252
+ * @public
253
+ */
254
+ function readRecordJarFileSync(srcPath, options) {
255
+ return (0, base_1.captureResult)(() => {
256
+ const fullPath = path.resolve(srcPath);
257
+ return fs.readFileSync(fullPath, 'utf8').toString().split(/\r?\n/);
258
+ }).onSuccess((lines) => {
259
+ return parseRecordJarLines(lines, options);
260
+ });
261
+ }
262
+ exports.readRecordJarFileSync = readRecordJarFileSync;
263
+ //# sourceMappingURL=recordJarHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recordJarHelpers.js","sourceRoot":"","sources":["../../../src/packlets/record-jar/recordJarHelpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAE7B,kCAAwE;AA4BxE,MAAM,YAAY;IAQhB,gEAAgE;IAChE,YAAoB,OAAgC;QARpC,YAAO,GAAgB,EAAE,CAAC;QAGhC,YAAO,GAAc,EAAE,CAAC;QACxB,UAAK,GAAuB,SAAS,CAAC;QACtC,UAAK,GAA4B,SAAS,CAAC;QAInD,IAAI,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,KAAe,EAAE,OAAgC;QACnE,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;IAES,MAAM,CAAC,gBAAgB,CAAC,IAAY;QAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,cAAc,EAAE;YAClB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC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AQ,EAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC;AAVD,sDAUC","sourcesContent":["/*\n * Copyright (c) 2022 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport { Result, captureResult, fail, isKeyOf, succeed } from '../base';\n\ninterface IRecordBody {\n body: string;\n isContinuation: boolean;\n}\n\n/**\n * Represents a single record in a JAR file\n * @public\n */\nexport type JarRecord = Record<string, string | string[]>;\n\n/**\n * @public\n */\nexport type JarFieldPicker<T extends JarRecord = JarRecord> = (record: T) => (keyof T)[];\n\n/**\n * Options for a JAR record parser.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface JarRecordParserOptions {\n readonly arrayFields?: string[] | JarFieldPicker;\n readonly fixedContinuationSize?: number;\n}\n\nclass RecordParser {\n public readonly records: JarRecord[] = [];\n public readonly options: JarRecordParserOptions;\n\n protected _fields: JarRecord = {};\n protected _name: string | undefined = undefined;\n protected _body: IRecordBody | undefined = undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private constructor(options?: JarRecordParserOptions) {\n this.options = options ?? {};\n }\n\n public static parse(lines: string[], options?: JarRecordParserOptions): Result<JarRecord[]> {\n return new RecordParser(options)._parse(lines);\n }\n\n protected static _parseRecordBody(body: string): Result<IRecordBody> {\n const isContinuation = body.endsWith('\\\\');\n if (isContinuation) {\n body = body.slice(0, body.length - 1);\n }\n if (this._hasEscapes(body)) {\n const result = this._replaceEscapes(body);\n if (result.isFailure()) {\n return fail(result.message);\n }\n body = result.value;\n }\n return succeed({ body, isContinuation });\n }\n\n protected static _hasEscapes(from: string): boolean {\n return from.includes('\\\\') || from.includes('&');\n }\n\n protected static _replaceEscapes(body: string): Result<string> {\n const invalid: string[] = [];\n const escaped = body.replace(/(\\\\.)|(&#x[a-fA-F0-9]{2,6};)/g, (match) => {\n switch (match) {\n case '\\\\\\\\':\n return '\\\\';\n case '\\\\&':\n return '&';\n case '\\\\r':\n return '\\r';\n case '\\\\n':\n return '\\n';\n case '\\\\t':\n return '\\t';\n }\n if (match.startsWith('&')) {\n const hexCode = `0x${match.slice(3, match.length - 1)}`;\n const charCode = Number.parseInt(hexCode, 16);\n return String.fromCharCode(charCode);\n }\n invalid.push(match);\n return '\\\\';\n });\n if (invalid.length > 0) {\n return fail(`unrecognized escape \"${invalid.join(', ')}\" in record-jar body`);\n }\n return succeed(escaped);\n }\n\n protected static _applyOptions(record: JarRecord, options: JarRecordParserOptions): JarRecord {\n if (options.arrayFields) {\n record = { ...record }; // don't edit incoming values\n const arrayFields = Array.isArray(options.arrayFields)\n ? options.arrayFields\n : options.arrayFields(record);\n\n for (const field of arrayFields) {\n if (isKeyOf(field, record) && typeof record[field] === 'string') {\n const current = record[field] as string;\n record[field] = [current];\n }\n }\n }\n return record;\n }\n\n protected _parse(lines: string[]): Result<JarRecord[]> {\n for (let n = 0; n < lines.length; n++) {\n const line = lines[n];\n if (line.startsWith('%%') && !this._body?.isContinuation) {\n const result = this._writePendingRecord();\n if (result.isFailure()) {\n return fail(`${n}: ${result.message}`);\n }\n } else if (/^\\s*$/.test(line)) {\n // ignore blank lines but cancel continuation\n if (this._body) {\n this._body.isContinuation = false;\n }\n continue;\n } else if (this._body?.isContinuation || /^\\s+/.test(line)) {\n // explicit continuation on previous line or implicit starts with whitespace\n if (this._body === undefined) {\n return fail(`${n}: continuation (\"${line}\") without prior value.`);\n }\n const result = this._parseContinuation(line);\n if (result.isFailure()) {\n return fail(`${n}: ${result.message}`);\n }\n this._body = result.value;\n } else {\n const result = this._parseField(line);\n if (result.isFailure()) {\n return fail(`${n}: ${result.message}`);\n }\n }\n }\n\n const result = this._writePendingRecord();\n if (result.isFailure()) {\n return fail(`${lines.length}: ${result.message}`);\n }\n return succeed(this.records);\n }\n\n protected _parseField(line: string): Result<boolean> {\n const separatorIndex = line.indexOf(':');\n if (separatorIndex < 1) {\n return fail(`malformed line (\"${line}\") in record-jar.`);\n }\n const parts = [line.slice(0, separatorIndex), line.slice(separatorIndex + 1)];\n\n return this._writePendingField().onSuccess(() => {\n this._name = parts[0].trimEnd();\n return RecordParser._parseRecordBody(parts[1].trim()).onSuccess((body) => {\n this._body = body;\n return succeed(true);\n });\n });\n }\n\n protected _parseContinuation(line: string): Result<IRecordBody> {\n let trimmed = line.trim();\n if (!this._body!.isContinuation) {\n // istanbul ignore next\n const fixedSize = this.options?.fixedContinuationSize ?? 0;\n if (fixedSize > 0) {\n if (trimmed.length < line.length - fixedSize) {\n // oops, took too much\n trimmed = line.slice(fixedSize);\n }\n }\n }\n return RecordParser._parseRecordBody(trimmed).onSuccess((newBody) => {\n return succeed({\n body: `${this._body!.body}${newBody.body}`,\n isContinuation: newBody.isContinuation\n });\n });\n }\n\n protected _havePendingRecord(): boolean {\n return Object.keys(this._fields).length > 0;\n }\n\n protected _writePendingRecord(): Result<JarRecord | undefined> {\n return this._writePendingField().onSuccess(() => {\n let record = this._havePendingRecord() ? this._fields : undefined;\n if (record !== undefined) {\n record = RecordParser._applyOptions(record, this.options);\n this.records.push(record);\n this._fields = {};\n }\n return succeed(undefined);\n });\n }\n\n protected _writePendingField(): Result<boolean> {\n if (this._name !== undefined) {\n if (this._body!.body.length < 1) {\n return fail('empty body value not allowed');\n }\n if (!isKeyOf(this._name, this._fields)) {\n this._fields[this._name] = this._body!.body;\n } else if (typeof this._fields[this._name] === 'string') {\n const current = this._fields[this._name] as string;\n this._fields[this._name] = [current, this._body!.body];\n } else {\n const current = this._fields[this._name] as string[];\n current.push(this._body!.body);\n }\n this._name = undefined;\n this._body = undefined;\n }\n return succeed(true);\n }\n}\n\n/**\n * Reads a record-jar from an array of strings, each of which represents one\n * line in the source file.\n * @param lines - the array of strings to be parsed\n * @param options - Optional parser configuration\n * @returns a corresponding array of `Record<string, string>`\n * @public\n */\nexport function parseRecordJarLines(lines: string[], options?: JarRecordParserOptions): Result<JarRecord[]> {\n return RecordParser.parse(lines, options);\n}\n\n/**\n * Reads a record-jar file from a supplied path.\n * @param srcPath - Source path from which the file is read.\n * @param options - Optional parser configuration\n * @returns The contents of the file as an array of `Record<string, string>`\n * @see https://datatracker.ietf.org/doc/html/draft-phillips-record-jar-01\n * @public\n */\nexport function readRecordJarFileSync(\n srcPath: string,\n options?: JarRecordParserOptions\n): Result<JarRecord[]> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n return fs.readFileSync(fullPath, 'utf8').toString().split(/\\r?\\n/);\n }).onSuccess((lines) => {\n return parseRecordJarLines(lines, options);\n });\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Failure } from '../result';
1
+ import { Failure } from '../base';
2
2
  import { Validator, ValidatorOptions } from './validator';
3
3
  import { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';
4
4
  /**
@@ -9,7 +9,7 @@ export interface ArrayValidatorConstructorParams<T, TC = unknown> extends Valida
9
9
  validateElement: Validator<T, TC>;
10
10
  }
11
11
  /**
12
- * An in-place {@link Validation.Validator | Validator} for arrays of validated
12
+ * An in-place {@link Validator | Validator} for arrays of validated
13
13
  * values or objects.
14
14
  * @public
15
15
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/array.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAEhF;;;GAGG;AAEH,MAAM,WAAW,+BAA+B,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAC9D,SAAQ,8BAA8B,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;IAC/C,eAAe,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;CACnC;AAED;;;;GAIG;AACH,qBAAa,cAAc,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;IACzE;;;OAGG;IACH,SAAgB,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAE9C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEtD;;;;OAIG;gBACgB,MAAM,EAAE,+BAA+B,CAAC,CAAC,EAAE,EAAE,CAAC;IAMjE;;;;;;;;OAQG;IACH,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAY1E"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022 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.ArrayValidator = void 0;
25
+ const base_1 = require("../base");
26
+ const validatorBase_1 = require("./validatorBase");
27
+ /**
28
+ * An in-place {@link Validator | Validator} for arrays of validated
29
+ * values or objects.
30
+ * @public
31
+ */
32
+ class ArrayValidator extends validatorBase_1.ValidatorBase {
33
+ /**
34
+ * Constructs a new {@link Validation.Classes.ArrayValidator | ArrayValidator}.
35
+ * @param params - Optional {@link Validation.Classes.ArrayValidatorConstructorParams | init params} for the
36
+ * new {@link Validation.Classes.ArrayValidator | ArrayValidator}.
37
+ */
38
+ constructor(params) {
39
+ var _a;
40
+ super(params);
41
+ this._validateElement = params.validateElement;
42
+ this.options = (_a = params.options) !== null && _a !== void 0 ? _a : {};
43
+ }
44
+ /**
45
+ * Static method which validates that a supplied `unknown` value is a `array`
46
+ * and that every element of the array can be validated by the supplied array
47
+ * validator.
48
+ * @param from - The `unknown` value to be tested.
49
+ * @param context - Optional validation context will be propagated to element validator.
50
+ * @returns Returns `true` if `from` is an `array` of valid elements, or
51
+ * {@link Failure} with an error message if not.
52
+ */
53
+ _validate(from, context) {
54
+ if (Array.isArray(from)) {
55
+ for (const elem of from) {
56
+ const result = this._validateElement.validate(elem, context);
57
+ if (!result.isSuccess()) {
58
+ return (0, base_1.fail)(result.message);
59
+ }
60
+ }
61
+ return true;
62
+ }
63
+ return (0, base_1.fail)(`"${from}": not an array`);
64
+ }
65
+ }
66
+ exports.ArrayValidator = ArrayValidator;
67
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/packlets/validation/array.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AAExC,mDAAgF;AAYhF;;;;GAIG;AACH,MAAa,cAAgC,SAAQ,6BAAsB;IASzE;;;;OAIG;IACH,YAAmB,MAA8C;;QAC/D,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACO,SAAS,CAAI,IAAa,EAAE,OAAY;QAChD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;gBACvB,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC7D,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE;oBACvB,OAAO,IAAA,WAAI,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;iBAC7B;aACF;YACD,OAAO,IAAI,CAAC;SACb;QACD,OAAO,IAAA,WAAI,EAAI,IAAI,IAAI,iBAAiB,CAAC,CAAC;IAC5C,CAAC;CACF;AAzCD,wCAyCC","sourcesContent":["/*\n * Copyright (c) 2022 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { Validator, ValidatorOptions } from './validator';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.ArrayValidator | ArrayValidator}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ArrayValidatorConstructorParams<T, TC = unknown>\n extends ValidatorBaseConstructorParams<T[], TC> {\n validateElement: Validator<T, TC>;\n}\n\n/**\n * An in-place {@link Validator | Validator} for arrays of validated\n * values or objects.\n * @public\n */\nexport class ArrayValidator<T, TC = unknown> extends ValidatorBase<T[], TC> {\n /**\n * {@link Validation.ValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ValidatorOptions<TC>;\n\n protected readonly _validateElement: Validator<T, TC>;\n\n /**\n * Constructs a new {@link Validation.Classes.ArrayValidator | ArrayValidator}.\n * @param params - Optional {@link Validation.Classes.ArrayValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.ArrayValidator | ArrayValidator}.\n */\n public constructor(params: ArrayValidatorConstructorParams<T, TC>) {\n super(params);\n this._validateElement = params.validateElement;\n this.options = params.options ?? {};\n }\n\n /**\n * Static method which validates that a supplied `unknown` value is a `array`\n * and that every element of the array can be validated by the supplied array\n * validator.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context will be propagated to element validator.\n * @returns Returns `true` if `from` is an `array` of valid elements, or\n * {@link Failure} with an error message if not.\n */\n protected _validate<T>(from: unknown, context?: TC): boolean | Failure<T> {\n if (Array.isArray(from)) {\n for (const elem of from) {\n const result = this._validateElement.validate(elem, context);\n if (!result.isSuccess()) {\n return fail(result.message);\n }\n }\n return true;\n }\n return fail<T>(`\"${from}\": not an array`);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Failure } from '../result';
1
+ import { Failure } from '../base';
2
2
  import { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';
3
3
  /**
4
4
  * Parameters used to construct a {@link Validation.Classes.BooleanValidator | BooleanValidator}.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/boolean.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AAEzF;;;GAGG;AACH,MAAM,MAAM,iCAAiC,CAAC,EAAE,GAAG,OAAO,IAAI,iCAAiC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAE7G;;;GAGG;AACH,qBAAa,gBAAgB,CAAC,EAAE,GAAG,OAAO,CAAE,SAAQ,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC;IAC/E;;;;OAIG;gBACgB,MAAM,CAAC,EAAE,iCAAiC,CAAC,EAAE,CAAC;IASjE;;;;;OAKG;WACW,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAMzE"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021 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.BooleanValidator = void 0;
25
+ const base_1 = require("../base");
26
+ const genericValidator_1 = require("./genericValidator");
27
+ /**
28
+ * An in-place {@link Validation.Validator | Validator} for `boolean` values.
29
+ * @public
30
+ */
31
+ class BooleanValidator extends genericValidator_1.GenericValidator {
32
+ /**
33
+ * Constructs a new {@link Validation.Classes.BooleanValidator | BooleanValidator}.
34
+ * @param params - Optional {@link Validation.Classes.BooleanValidatorConstructorParams | init params} for the
35
+ * new {@link Validation.Classes.BooleanValidator | BooleanValidator}.
36
+ */
37
+ constructor(params) {
38
+ // istanbul ignore next
39
+ params = params !== null && params !== void 0 ? params : {};
40
+ super(Object.assign({ validator: BooleanValidator.validateBoolean }, params));
41
+ }
42
+ /**
43
+ * Static method which validates that a supplied `unknown` value is a `boolean`.
44
+ * @param from - The `unknown` value to be tested.
45
+ * @returns Returns `true` if `from` is a `boolean`, or {@link Failure} with an error
46
+ * message if not.
47
+ */
48
+ static validateBoolean(from) {
49
+ if (typeof from === 'boolean') {
50
+ return true;
51
+ }
52
+ return (0, base_1.fail)(`"${from}": not a boolean`);
53
+ }
54
+ }
55
+ exports.BooleanValidator = BooleanValidator;
56
+ //# sourceMappingURL=boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src/packlets/validation/boolean.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,yDAAyF;AAQzF;;;GAGG;AACH,MAAa,gBAA+B,SAAQ,mCAA6B;IAC/E;;;;OAIG;IACH,YAAmB,MAA8C;QAC/D,uBAAuB;QACvB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QACtB,KAAK,iBACH,SAAS,EAAE,gBAAgB,CAAC,eAAe,IACxC,MAAM,EACT,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,eAAe,CAAC,IAAa;QACzC,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE;YAC7B,OAAO,IAAI,CAAC;SACb;QACD,OAAO,IAAA,WAAI,EAAC,IAAI,IAAI,kBAAkB,CAAC,CAAC;IAC1C,CAAC;CACF;AA3BD,4CA2BC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.BooleanValidator | BooleanValidator}.\n * @public\n */\nexport type BooleanValidatorConstructorParams<TC = unknown> = GenericValidatorConstructorParams<boolean, TC>;\n\n/**\n * An in-place {@link Validation.Validator | Validator} for `boolean` values.\n * @public\n */\nexport class BooleanValidator<TC = unknown> extends GenericValidator<boolean, TC> {\n /**\n * Constructs a new {@link Validation.Classes.BooleanValidator | BooleanValidator}.\n * @param params - Optional {@link Validation.Classes.BooleanValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.BooleanValidator | BooleanValidator}.\n */\n public constructor(params?: BooleanValidatorConstructorParams<TC>) {\n // istanbul ignore next\n params = params ?? {};\n super({\n validator: BooleanValidator.validateBoolean,\n ...params\n });\n }\n\n /**\n * Static method which validates that a supplied `unknown` value is a `boolean`.\n * @param from - The `unknown` value to be tested.\n * @returns Returns `true` if `from` is a `boolean`, or {@link Failure} with an error\n * message if not.\n */\n public static validateBoolean(from: unknown): boolean | Failure<boolean> {\n if (typeof from === 'boolean') {\n return true;\n }\n return fail(`\"${from}\": not a boolean`);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EACL,eAAe,EACf,eAAe,EACf,gCAAgC,EAChC,sBAAsB,EACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021 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.TypeGuardValidator = exports.ObjectValidator = exports.NumberValidator = exports.BooleanValidator = exports.StringValidator = exports.ArrayValidator = void 0;
25
+ /* istanbul ignore file */
26
+ var array_1 = require("./array");
27
+ Object.defineProperty(exports, "ArrayValidator", { enumerable: true, get: function () { return array_1.ArrayValidator; } });
28
+ var string_1 = require("./string");
29
+ Object.defineProperty(exports, "StringValidator", { enumerable: true, get: function () { return string_1.StringValidator; } });
30
+ var boolean_1 = require("./boolean");
31
+ Object.defineProperty(exports, "BooleanValidator", { enumerable: true, get: function () { return boolean_1.BooleanValidator; } });
32
+ var number_1 = require("./number");
33
+ Object.defineProperty(exports, "NumberValidator", { enumerable: true, get: function () { return number_1.NumberValidator; } });
34
+ var object_1 = require("./object");
35
+ Object.defineProperty(exports, "ObjectValidator", { enumerable: true, get: function () { return object_1.ObjectValidator; } });
36
+ var typeGuard_1 = require("./typeGuard");
37
+ Object.defineProperty(exports, "TypeGuardValidator", { enumerable: true, get: function () { return typeGuard_1.TypeGuardValidator; } });
38
+ //# sourceMappingURL=classes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classes.js","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,0BAA0B;AAE1B,iCAA0E;AAAjE,uGAAA,cAAc,OAAA;AACvB,mCAA6E;AAApE,yGAAA,eAAe,OAAA;AACxB,qCAAgF;AAAvE,2GAAA,gBAAgB,OAAA;AACzB,mCAA6E;AAApE,yGAAA,eAAe,OAAA;AACxB,mCAKkB;AAHhB,yGAAA,eAAe,OAAA;AAIjB,yCAAsF;AAA7E,+GAAA,kBAAkB,OAAA","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/* istanbul ignore file */\n\nexport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nexport { StringValidator, StringValidatorConstructorParams } from './string';\nexport { BooleanValidator, BooleanValidatorConstructorParams } from './boolean';\nexport { NumberValidator, NumberValidatorConstructorParams } from './number';\nexport {\n FieldValidators,\n ObjectValidator,\n ObjectValidatorConstructorParams,\n ObjectValidatorOptions\n} from './object';\nexport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/common.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022 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
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/validation/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2022 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * A type guard function which validates a specific type, with an optional context\n * that can be used to shape the validation.\n * @public\n */\nexport type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;\n"]}
@@ -1,4 +1,4 @@
1
- import { Failure } from '../result';
1
+ import { Failure } from '../base';
2
2
  import { Validator, ValidatorOptions } from './validator';
3
3
  import { ValidatorBase } from './validatorBase';
4
4
  /**
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/field.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAiB,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AAEH,MAAM,WAAW,qBAAqB,CAAC,EAAE,CAAE,SAAQ,gBAAgB,CAAC,EAAE,CAAC;IACrE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,cAAc,CAAC,CAAC,EAAE,EAAE,GAAG,SAAS,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC;IACzE;;OAEG;IACH,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC;;OAEG;IACH,SAAgB,cAAc,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAE5D;;;;;;;OAOG;gBAED,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAChC,OAAO,CAAC,EAAE,qBAAqB,CAAC,EAAE,CAAC;IASrC;;OAEG;IACH,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAqBvE"}