@poppinss/utils 6.9.4 → 7.0.0-next.1
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/README.md +205 -829
- package/build/chunk-SKNTF5Q5.js +14 -0
- package/build/chunk-XFX47BKO.js +23 -0
- package/build/{chunk-XHQBV7AF.js → chunk-YFSCSJNE.js} +3 -9
- package/build/index.d.ts +4 -24
- package/build/index.js +57 -243
- package/build/{src → modules}/assert.js +1 -3
- package/build/{src → modules}/base64.d.ts +2 -2
- package/build/modules/base64.js +43 -0
- package/build/modules/exception.d.ts +1 -0
- package/build/modules/exception.js +12 -0
- package/build/{src → modules/fs}/fs_import_all.d.ts +6 -1
- package/build/{src → modules/fs}/fs_read_all.d.ts +6 -1
- package/build/modules/fs/main.d.ts +2 -0
- package/build/modules/fs/main.js +82 -0
- package/build/modules/json/main.d.ts +2 -0
- package/build/modules/json/main.js +8 -0
- package/build/{src → modules}/json/safe_parse.d.ts +1 -1
- package/build/{src → modules}/json/safe_stringify.d.ts +1 -1
- package/build/{src → modules}/string/main.js +1 -3
- package/build/modules/string/string_builder.d.ts +2 -0
- package/build/modules/string/string_builder.js +6 -0
- package/build/modules/types.d.ts +1 -0
- package/build/modules/types.js +2 -0
- package/build/src/compose.d.ts +12 -10
- package/build/src/define_static_property.d.ts +2 -4
- package/package.json +26 -27
- package/build/chunk-2KG3PWR4.js +0 -17
- package/build/chunk-4V5ON6P7.js +0 -7
- package/build/chunk-EJKUJ44Y.js +0 -12
- package/build/chunk-H54AK3PI.js +0 -7
- package/build/src/exception.d.ts +0 -1
- package/build/src/exception.js +0 -9
- package/build/src/exceptions/main.d.ts +0 -1
- package/build/src/exceptions/main.js +0 -9
- package/build/src/json/main.d.ts +0 -7
- package/build/src/json/main.js +0 -7
- package/build/src/object_builder.d.ts +0 -1
- package/build/src/slash.d.ts +0 -24
- package/build/src/slash.js +0 -7
- package/build/src/string/string_builder.d.ts +0 -3
- package/build/src/string/string_builder.js +0 -9
- package/build/src/types.d.ts +0 -35
- package/build/src/types.js +0 -0
- /package/build/{src → modules}/assert.d.ts +0 -0
- /package/build/{src → modules}/string/main.d.ts +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/natural_sort.ts
|
|
2
|
+
function naturalSort(current, next) {
|
|
3
|
+
return current.localeCompare(next, void 0, { numeric: true, sensitivity: "base" });
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/is_script_file.ts
|
|
7
|
+
import { extname } from "path";
|
|
8
|
+
var JS_MODULES = [".js", ".json", ".cjs", ".mjs"];
|
|
9
|
+
function isScriptFile(filePath) {
|
|
10
|
+
const ext = extname(filePath);
|
|
11
|
+
if (JS_MODULES.includes(ext)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (ext === ".ts" && !filePath.endsWith(".d.ts")) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
naturalSort,
|
|
22
|
+
isScriptFile
|
|
23
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// modules/json/safe_parse.ts
|
|
2
2
|
import { parse } from "secure-json-parse";
|
|
3
3
|
function safeParse(jsonString, reviver) {
|
|
4
4
|
return parse(jsonString, reviver, {
|
|
@@ -7,7 +7,7 @@ function safeParse(jsonString, reviver) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
//
|
|
10
|
+
// modules/json/safe_stringify.ts
|
|
11
11
|
import { configure } from "safe-stable-stringify";
|
|
12
12
|
var stringify = configure({
|
|
13
13
|
bigint: false,
|
|
@@ -27,13 +27,7 @@ function safeStringify(value, replacer, space) {
|
|
|
27
27
|
return stringify(value, jsonStringifyReplacer(replacer), space);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
var json = {
|
|
30
|
+
export {
|
|
32
31
|
safeParse,
|
|
33
32
|
safeStringify
|
|
34
33
|
};
|
|
35
|
-
var main_default = json;
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
main_default
|
|
39
|
-
};
|
package/build/index.d.ts
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
export { Secret } from './src/secret.js';
|
|
2
|
-
export { base64 } from './src/base64.js';
|
|
3
2
|
export { compose } from './src/compose.js';
|
|
4
|
-
export { importDefault } from './src/import_default.js';
|
|
5
|
-
export { defineStaticProperty } from './src/define_static_property.js';
|
|
6
|
-
export { Exception, createError } from './src/exception.js';
|
|
7
3
|
export { flatten } from './src/flatten.js';
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
4
|
+
export { safeEqual } from './src/safe_equal.js';
|
|
5
|
+
export { naturalSort } from './src/natural_sort.js';
|
|
10
6
|
export { isScriptFile } from './src/is_script_file.js';
|
|
7
|
+
export { importDefault } from './src/import_default.js';
|
|
11
8
|
export { MessageBuilder } from './src/message_builder.js';
|
|
12
|
-
export {
|
|
13
|
-
export { ObjectBuilder } from './src/object_builder.js';
|
|
14
|
-
export { safeEqual } from './src/safe_equal.js';
|
|
15
|
-
export { slash } from './src/slash.js';
|
|
16
|
-
export { RuntimeException, InvalidArgumentsException } from './src/exceptions/main.js';
|
|
17
|
-
/**
|
|
18
|
-
* Get dirname for a given file path URL
|
|
19
|
-
*/
|
|
20
|
-
export declare function getDirname(url: string | URL): string;
|
|
21
|
-
/**
|
|
22
|
-
* Get filename for a given file path URL
|
|
23
|
-
*/
|
|
24
|
-
export declare function getFilename(url: string | URL): string;
|
|
25
|
-
/**
|
|
26
|
-
* Join paths to a URL instance or a URL string. The return
|
|
27
|
-
* value will be a file path without the `file:///` protocol.
|
|
28
|
-
*/
|
|
29
|
-
export declare function joinToURL(url: string | URL, ...str: string[]): string;
|
|
9
|
+
export { defineStaticProperty } from './src/define_static_property.js';
|
package/build/index.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Exception,
|
|
3
|
-
createError
|
|
4
|
-
} from "./chunk-H54AK3PI.js";
|
|
5
|
-
import {
|
|
6
|
-
slash
|
|
7
|
-
} from "./chunk-EJKUJ44Y.js";
|
|
8
|
-
import {
|
|
9
|
-
InvalidArgumentsException,
|
|
10
2
|
RuntimeException
|
|
11
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SKNTF5Q5.js";
|
|
12
4
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
isScriptFile,
|
|
6
|
+
naturalSort
|
|
7
|
+
} from "./chunk-XFX47BKO.js";
|
|
15
8
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// index.ts
|
|
20
|
-
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
21
|
-
import { join as pathJoin, dirname as pathDirname } from "path";
|
|
9
|
+
safeParse,
|
|
10
|
+
safeStringify
|
|
11
|
+
} from "./chunk-YFSCSJNE.js";
|
|
22
12
|
|
|
23
13
|
// src/secret.ts
|
|
24
14
|
var REDACTED = "[redacted]";
|
|
@@ -60,51 +50,35 @@ var Secret = class _Secret {
|
|
|
60
50
|
}
|
|
61
51
|
};
|
|
62
52
|
|
|
63
|
-
// src/base64.ts
|
|
64
|
-
var Base64 = class {
|
|
65
|
-
encode(data, encoding) {
|
|
66
|
-
if (typeof data === "string") {
|
|
67
|
-
return Buffer.from(data, encoding).toString("base64");
|
|
68
|
-
}
|
|
69
|
-
if (Buffer.isBuffer(data)) {
|
|
70
|
-
return data.toString("base64");
|
|
71
|
-
}
|
|
72
|
-
return Buffer.from(data).toString("base64");
|
|
73
|
-
}
|
|
74
|
-
decode(encoded, encoding = "utf-8", strict = false) {
|
|
75
|
-
if (Buffer.isBuffer(encoded)) {
|
|
76
|
-
return encoded.toString(encoding);
|
|
77
|
-
}
|
|
78
|
-
const decoded = Buffer.from(encoded, "base64").toString(encoding);
|
|
79
|
-
const isInvalid = this.encode(decoded, encoding) !== encoded;
|
|
80
|
-
if (strict && isInvalid) {
|
|
81
|
-
throw new Error("Cannot decode malformed value");
|
|
82
|
-
}
|
|
83
|
-
return isInvalid ? null : decoded;
|
|
84
|
-
}
|
|
85
|
-
urlEncode(data, encoding) {
|
|
86
|
-
const encoded = typeof data === "string" ? this.encode(data, encoding) : this.encode(data);
|
|
87
|
-
return encoded.replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
|
|
88
|
-
}
|
|
89
|
-
urlDecode(encoded, encoding = "utf-8", strict = false) {
|
|
90
|
-
if (Buffer.isBuffer(encoded)) {
|
|
91
|
-
return encoded.toString(encoding);
|
|
92
|
-
}
|
|
93
|
-
const decoded = Buffer.from(encoded, "base64").toString(encoding);
|
|
94
|
-
const isInvalid = this.urlEncode(decoded, encoding) !== encoded;
|
|
95
|
-
if (strict && isInvalid) {
|
|
96
|
-
throw new Error("Cannot urlDecode malformed value");
|
|
97
|
-
}
|
|
98
|
-
return isInvalid ? null : decoded;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var base64 = new Base64();
|
|
102
|
-
|
|
103
53
|
// src/compose.ts
|
|
104
54
|
function compose(superclass, ...mixins) {
|
|
105
55
|
return mixins.reduce((c, mixin) => mixin(c), superclass);
|
|
106
56
|
}
|
|
107
57
|
|
|
58
|
+
// src/flatten.ts
|
|
59
|
+
import { flattie } from "flattie";
|
|
60
|
+
function flatten(input, glue, keepNullish) {
|
|
61
|
+
return flattie(input, glue, keepNullish);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/safe_equal.ts
|
|
65
|
+
import { Buffer } from "buffer";
|
|
66
|
+
import { timingSafeEqual } from "crypto";
|
|
67
|
+
function safeEqual(trustedValue, userInput) {
|
|
68
|
+
if (typeof trustedValue === "string" && typeof userInput === "string") {
|
|
69
|
+
const trustedLength = Buffer.byteLength(trustedValue);
|
|
70
|
+
const trustedValueBuffer = Buffer.alloc(trustedLength, 0, "utf-8");
|
|
71
|
+
trustedValueBuffer.write(trustedValue);
|
|
72
|
+
const userValueBuffer = Buffer.alloc(trustedLength, 0, "utf-8");
|
|
73
|
+
userValueBuffer.write(userInput);
|
|
74
|
+
return timingSafeEqual(trustedValueBuffer, userValueBuffer) && trustedLength === Buffer.byteLength(userInput);
|
|
75
|
+
}
|
|
76
|
+
return timingSafeEqual(
|
|
77
|
+
Buffer.from(trustedValue),
|
|
78
|
+
Buffer.from(userInput)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
108
82
|
// src/import_default.ts
|
|
109
83
|
async function importDefault(importFn, filePath) {
|
|
110
84
|
const moduleExports = await importFn();
|
|
@@ -119,145 +93,6 @@ async function importDefault(importFn, filePath) {
|
|
|
119
93
|
return moduleExports.default;
|
|
120
94
|
}
|
|
121
95
|
|
|
122
|
-
// src/define_static_property.ts
|
|
123
|
-
import lodash from "@poppinss/utils/lodash";
|
|
124
|
-
function defineStaticProperty(self, propertyName, {
|
|
125
|
-
initialValue,
|
|
126
|
-
strategy
|
|
127
|
-
}) {
|
|
128
|
-
if (!self.hasOwnProperty(propertyName)) {
|
|
129
|
-
const value = self[propertyName];
|
|
130
|
-
if (strategy === "define" || value === void 0) {
|
|
131
|
-
Object.defineProperty(self, propertyName, {
|
|
132
|
-
value: initialValue,
|
|
133
|
-
configurable: true,
|
|
134
|
-
enumerable: true,
|
|
135
|
-
writable: true
|
|
136
|
-
});
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
Object.defineProperty(self, propertyName, {
|
|
140
|
-
value: typeof strategy === "function" ? strategy(value) : lodash.cloneDeep(value),
|
|
141
|
-
configurable: true,
|
|
142
|
-
enumerable: true,
|
|
143
|
-
writable: true
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/flatten.ts
|
|
149
|
-
import { flattie } from "flattie";
|
|
150
|
-
function flatten(input, glue, keepNullish) {
|
|
151
|
-
return flattie(input, glue, keepNullish);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// src/fs_import_all.ts
|
|
155
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
156
|
-
import lodash2 from "@poppinss/utils/lodash";
|
|
157
|
-
import { extname as extname2, relative, sep } from "path";
|
|
158
|
-
|
|
159
|
-
// src/fs_read_all.ts
|
|
160
|
-
import { join } from "path";
|
|
161
|
-
import { readdir, stat } from "fs/promises";
|
|
162
|
-
import { fileURLToPath, pathToFileURL } from "url";
|
|
163
|
-
|
|
164
|
-
// src/natural_sort.ts
|
|
165
|
-
function naturalSort(current, next) {
|
|
166
|
-
return current.localeCompare(next, void 0, { numeric: true, sensitivity: "base" });
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// src/fs_read_all.ts
|
|
170
|
-
function filterDotFiles(fileName) {
|
|
171
|
-
return fileName[0] !== ".";
|
|
172
|
-
}
|
|
173
|
-
async function readFiles(root, files, options, relativePath) {
|
|
174
|
-
const location = join(root, relativePath);
|
|
175
|
-
const stats = await stat(location);
|
|
176
|
-
if (stats.isDirectory()) {
|
|
177
|
-
let locationFiles = await readdir(location);
|
|
178
|
-
await Promise.all(
|
|
179
|
-
locationFiles.filter(filterDotFiles).map((file) => {
|
|
180
|
-
return readFiles(root, files, options, join(relativePath, file));
|
|
181
|
-
})
|
|
182
|
-
);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const pathType = options.pathType || "relative";
|
|
186
|
-
switch (pathType) {
|
|
187
|
-
case "relative":
|
|
188
|
-
files.push(relativePath);
|
|
189
|
-
break;
|
|
190
|
-
case "absolute":
|
|
191
|
-
files.push(location);
|
|
192
|
-
break;
|
|
193
|
-
case "unixRelative":
|
|
194
|
-
files.push(slash(relativePath));
|
|
195
|
-
break;
|
|
196
|
-
case "unixAbsolute":
|
|
197
|
-
files.push(slash(location));
|
|
198
|
-
break;
|
|
199
|
-
case "url":
|
|
200
|
-
files.push(pathToFileURL(location).href);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
async function fsReadAll(location, options) {
|
|
204
|
-
const normalizedLocation = typeof location === "string" ? location : fileURLToPath(location);
|
|
205
|
-
const normalizedOptions = Object.assign({ absolute: false, sort: naturalSort }, options);
|
|
206
|
-
const files = [];
|
|
207
|
-
try {
|
|
208
|
-
await stat(normalizedLocation);
|
|
209
|
-
} catch (error) {
|
|
210
|
-
if (normalizedOptions.ignoreMissingRoot) {
|
|
211
|
-
return [];
|
|
212
|
-
}
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
215
|
-
await readFiles(normalizedLocation, files, normalizedOptions, "");
|
|
216
|
-
if (normalizedOptions.filter) {
|
|
217
|
-
return files.filter(normalizedOptions.filter).sort(normalizedOptions.sort);
|
|
218
|
-
}
|
|
219
|
-
return files.sort(normalizedOptions.sort);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// src/is_script_file.ts
|
|
223
|
-
import { extname } from "path";
|
|
224
|
-
var JS_MODULES = [".js", ".json", ".cjs", ".mjs"];
|
|
225
|
-
function isScriptFile(filePath) {
|
|
226
|
-
const ext = extname(filePath);
|
|
227
|
-
if (JS_MODULES.includes(ext)) {
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
if (ext === ".ts" && !filePath.endsWith(".d.ts")) {
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// src/fs_import_all.ts
|
|
237
|
-
async function importFile(basePath, fileURL, values, options) {
|
|
238
|
-
const filePath = fileURLToPath2(fileURL);
|
|
239
|
-
const fileExtension = extname2(filePath);
|
|
240
|
-
const collectionKey = relative(basePath, filePath).replace(new RegExp(`${fileExtension}$`), "").split(sep);
|
|
241
|
-
const exportedValue = fileExtension === ".json" ? await import(fileURL, { with: { type: "json" } }) : await import(fileURL);
|
|
242
|
-
lodash2.set(
|
|
243
|
-
values,
|
|
244
|
-
options.transformKeys ? options.transformKeys(collectionKey) : collectionKey,
|
|
245
|
-
exportedValue.default ? exportedValue.default : { ...exportedValue }
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
async function fsImportAll(location, options) {
|
|
249
|
-
options = options || {};
|
|
250
|
-
const collection = {};
|
|
251
|
-
const normalizedLocation = typeof location === "string" ? location : fileURLToPath2(location);
|
|
252
|
-
const files = await fsReadAll(normalizedLocation, {
|
|
253
|
-
filter: isScriptFile,
|
|
254
|
-
...options,
|
|
255
|
-
pathType: "url"
|
|
256
|
-
});
|
|
257
|
-
await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options)));
|
|
258
|
-
return collection;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
96
|
// src/message_builder.ts
|
|
262
97
|
import string from "@poppinss/string";
|
|
263
98
|
var MessageBuilder = class {
|
|
@@ -283,13 +118,13 @@ var MessageBuilder = class {
|
|
|
283
118
|
*/
|
|
284
119
|
build(message, expiresIn, purpose) {
|
|
285
120
|
const expiryDate = this.#getExpiryDate(expiresIn);
|
|
286
|
-
return
|
|
121
|
+
return safeStringify({ message, purpose, expiryDate });
|
|
287
122
|
}
|
|
288
123
|
/**
|
|
289
124
|
* Verifies the message for expiry and purpose.
|
|
290
125
|
*/
|
|
291
126
|
verify(message, purpose) {
|
|
292
|
-
const parsed =
|
|
127
|
+
const parsed = safeParse(message);
|
|
293
128
|
if (typeof parsed !== "object" || !parsed) {
|
|
294
129
|
return null;
|
|
295
130
|
}
|
|
@@ -306,60 +141,39 @@ var MessageBuilder = class {
|
|
|
306
141
|
}
|
|
307
142
|
};
|
|
308
143
|
|
|
309
|
-
// src/
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
144
|
+
// src/define_static_property.ts
|
|
145
|
+
import lodash from "@poppinss/utils/lodash";
|
|
146
|
+
function defineStaticProperty(self, propertyName, {
|
|
147
|
+
initialValue,
|
|
148
|
+
strategy
|
|
149
|
+
}) {
|
|
150
|
+
if (!self.hasOwnProperty(propertyName)) {
|
|
151
|
+
const value = self[propertyName];
|
|
152
|
+
if (strategy === "define" || value === void 0) {
|
|
153
|
+
Object.defineProperty(self, propertyName, {
|
|
154
|
+
value: initialValue,
|
|
155
|
+
configurable: true,
|
|
156
|
+
enumerable: true,
|
|
157
|
+
writable: true
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
Object.defineProperty(self, propertyName, {
|
|
162
|
+
value: typeof strategy === "function" ? strategy(value) : lodash.cloneDeep(value),
|
|
163
|
+
configurable: true,
|
|
164
|
+
enumerable: true,
|
|
165
|
+
writable: true
|
|
166
|
+
});
|
|
325
167
|
}
|
|
326
|
-
return timingSafeEqual(
|
|
327
|
-
Buffer2.from(trustedValue),
|
|
328
|
-
Buffer2.from(userInput)
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// index.ts
|
|
333
|
-
function getDirname(url) {
|
|
334
|
-
return pathDirname(getFilename(url));
|
|
335
|
-
}
|
|
336
|
-
function getFilename(url) {
|
|
337
|
-
return fileURLToPath3(url);
|
|
338
|
-
}
|
|
339
|
-
function joinToURL(url, ...str) {
|
|
340
|
-
return pathJoin(getDirname(url), ...str);
|
|
341
168
|
}
|
|
342
|
-
var export_ObjectBuilder = object_builder_exports.ObjectBuilder;
|
|
343
169
|
export {
|
|
344
|
-
Exception,
|
|
345
|
-
InvalidArgumentsException,
|
|
346
170
|
MessageBuilder,
|
|
347
|
-
export_ObjectBuilder as ObjectBuilder,
|
|
348
|
-
RuntimeException,
|
|
349
171
|
Secret,
|
|
350
|
-
base64,
|
|
351
172
|
compose,
|
|
352
|
-
createError,
|
|
353
173
|
defineStaticProperty,
|
|
354
174
|
flatten,
|
|
355
|
-
fsImportAll,
|
|
356
|
-
fsReadAll,
|
|
357
|
-
getDirname,
|
|
358
|
-
getFilename,
|
|
359
175
|
importDefault,
|
|
360
176
|
isScriptFile,
|
|
361
|
-
joinToURL,
|
|
362
177
|
naturalSort,
|
|
363
|
-
safeEqual
|
|
364
|
-
slash
|
|
178
|
+
safeEqual
|
|
365
179
|
};
|
|
@@ -28,5 +28,5 @@ declare class Base64 {
|
|
|
28
28
|
urlDecode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
|
|
29
29
|
urlDecode(encode: Buffer, encoding?: BufferEncoding): string;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
export
|
|
31
|
+
declare const base64: Base64;
|
|
32
|
+
export default base64;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// modules/base64.ts
|
|
2
|
+
var Base64 = class {
|
|
3
|
+
encode(data, encoding) {
|
|
4
|
+
if (typeof data === "string") {
|
|
5
|
+
return Buffer.from(data, encoding).toString("base64");
|
|
6
|
+
}
|
|
7
|
+
if (Buffer.isBuffer(data)) {
|
|
8
|
+
return data.toString("base64");
|
|
9
|
+
}
|
|
10
|
+
return Buffer.from(data).toString("base64");
|
|
11
|
+
}
|
|
12
|
+
decode(encoded, encoding = "utf-8", strict = false) {
|
|
13
|
+
if (Buffer.isBuffer(encoded)) {
|
|
14
|
+
return encoded.toString(encoding);
|
|
15
|
+
}
|
|
16
|
+
const decoded = Buffer.from(encoded, "base64").toString(encoding);
|
|
17
|
+
const isInvalid = this.encode(decoded, encoding) !== encoded;
|
|
18
|
+
if (strict && isInvalid) {
|
|
19
|
+
throw new Error("Cannot decode malformed value");
|
|
20
|
+
}
|
|
21
|
+
return isInvalid ? null : decoded;
|
|
22
|
+
}
|
|
23
|
+
urlEncode(data, encoding) {
|
|
24
|
+
const encoded = typeof data === "string" ? this.encode(data, encoding) : this.encode(data);
|
|
25
|
+
return encoded.replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
|
|
26
|
+
}
|
|
27
|
+
urlDecode(encoded, encoding = "utf-8", strict = false) {
|
|
28
|
+
if (Buffer.isBuffer(encoded)) {
|
|
29
|
+
return encoded.toString(encoding);
|
|
30
|
+
}
|
|
31
|
+
const decoded = Buffer.from(encoded, "base64").toString(encoding);
|
|
32
|
+
const isInvalid = this.urlEncode(decoded, encoding) !== encoded;
|
|
33
|
+
if (strict && isInvalid) {
|
|
34
|
+
throw new Error("Cannot urlDecode malformed value");
|
|
35
|
+
}
|
|
36
|
+
return isInvalid ? null : decoded;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var base64 = new Base64();
|
|
40
|
+
var base64_default = base64;
|
|
41
|
+
export {
|
|
42
|
+
base64_default as default
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RuntimeException, InvalidArgumentsException, Exception, createError, } from '@poppinss/exception';
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export type ImportAllFilesOptions = {
|
|
2
|
+
ignoreMissingRoot?: boolean;
|
|
3
|
+
filter?: (filePath: string, index: number) => boolean;
|
|
4
|
+
sort?: (current: string, next: string) => number;
|
|
5
|
+
transformKeys?: (keys: string[]) => string[];
|
|
6
|
+
};
|
|
2
7
|
/**
|
|
3
8
|
* Returns an array of file paths from the given location. You can
|
|
4
9
|
* optionally filter and sort files by passing relevant options
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export type ReadAllFilesOptions = {
|
|
2
|
+
ignoreMissingRoot?: boolean;
|
|
3
|
+
filter?: (filePath: string, index: number) => boolean;
|
|
4
|
+
sort?: (current: string, next: string) => number;
|
|
5
|
+
pathType?: 'relative' | 'unixRelative' | 'absolute' | 'unixAbsolute' | 'url';
|
|
6
|
+
};
|
|
2
7
|
/**
|
|
3
8
|
* Returns an array of file paths from the given location. You can
|
|
4
9
|
* optionally filter and sort files by passing relevant options
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isScriptFile,
|
|
3
|
+
naturalSort
|
|
4
|
+
} from "../../chunk-XFX47BKO.js";
|
|
5
|
+
|
|
6
|
+
// modules/fs/fs_read_all.ts
|
|
7
|
+
import string from "@poppinss/string";
|
|
8
|
+
import { join, relative, sep } from "path";
|
|
9
|
+
import { readdir, stat } from "fs/promises";
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
11
|
+
async function fsReadAll(location, options) {
|
|
12
|
+
const normalizedLocation = typeof location === "string" ? location : fileURLToPath(location);
|
|
13
|
+
const normalizedOptions = Object.assign({ absolute: false, sort: naturalSort }, options);
|
|
14
|
+
const pathType = normalizedOptions.pathType || "relative";
|
|
15
|
+
try {
|
|
16
|
+
await stat(normalizedLocation);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (normalizedOptions.ignoreMissingRoot) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
const dirents = await readdir(normalizedLocation, { recursive: true, withFileTypes: true });
|
|
24
|
+
const files = dirents.filter((dirent) => {
|
|
25
|
+
if (!dirent.isFile()) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (dirent.name.startsWith(".") || dirent.parentPath.split(sep).some((segment) => segment.startsWith("."))) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}).map((file) => {
|
|
33
|
+
switch (pathType) {
|
|
34
|
+
case "relative":
|
|
35
|
+
return join(relative(normalizedLocation, file.parentPath), file.name);
|
|
36
|
+
case "absolute":
|
|
37
|
+
return join(file.parentPath, file.name);
|
|
38
|
+
case "unixRelative":
|
|
39
|
+
return string.toUnixSlash(join(relative(normalizedLocation, file.parentPath), file.name));
|
|
40
|
+
case "unixAbsolute":
|
|
41
|
+
return string.toUnixSlash(join(file.parentPath, file.name));
|
|
42
|
+
case "url":
|
|
43
|
+
return pathToFileURL(join(file.parentPath, file.name)).href;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (normalizedOptions.filter) {
|
|
47
|
+
return files.filter(normalizedOptions.filter).sort(normalizedOptions.sort);
|
|
48
|
+
}
|
|
49
|
+
return files.sort(normalizedOptions.sort);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// modules/fs/fs_import_all.ts
|
|
53
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
54
|
+
import lodash from "@poppinss/utils/lodash";
|
|
55
|
+
import { extname, relative as relative2, sep as sep2 } from "path";
|
|
56
|
+
async function importFile(basePath, fileURL, values, options) {
|
|
57
|
+
const filePath = fileURLToPath2(fileURL);
|
|
58
|
+
const fileExtension = extname(filePath);
|
|
59
|
+
const collectionKey = relative2(basePath, filePath).replace(new RegExp(`${fileExtension}$`), "").split(sep2);
|
|
60
|
+
const exportedValue = fileExtension === ".json" ? await import(fileURL, { with: { type: "json" } }) : await import(fileURL);
|
|
61
|
+
lodash.set(
|
|
62
|
+
values,
|
|
63
|
+
options.transformKeys ? options.transformKeys(collectionKey) : collectionKey,
|
|
64
|
+
exportedValue.default ? exportedValue.default : { ...exportedValue }
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
async function fsImportAll(location, options) {
|
|
68
|
+
options = options || {};
|
|
69
|
+
const collection = {};
|
|
70
|
+
const normalizedLocation = typeof location === "string" ? location : fileURLToPath2(location);
|
|
71
|
+
const files = await fsReadAll(normalizedLocation, {
|
|
72
|
+
filter: isScriptFile,
|
|
73
|
+
...options,
|
|
74
|
+
pathType: "url"
|
|
75
|
+
});
|
|
76
|
+
await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options)));
|
|
77
|
+
return collection;
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
fsImportAll,
|
|
81
|
+
fsReadAll
|
|
82
|
+
};
|