update
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.once = once;
|
||||
var _async = require("./async.js");
|
||||
function once(fn) {
|
||||
let result;
|
||||
let resultP;
|
||||
let promiseReferenced = false;
|
||||
return function* () {
|
||||
if (!result) {
|
||||
if (resultP) {
|
||||
promiseReferenced = true;
|
||||
return yield* (0, _async.waitFor)(resultP);
|
||||
}
|
||||
if (!(yield* (0, _async.isAsync)())) {
|
||||
try {
|
||||
result = {
|
||||
ok: true,
|
||||
value: yield* fn()
|
||||
};
|
||||
} catch (error) {
|
||||
result = {
|
||||
ok: false,
|
||||
value: error
|
||||
};
|
||||
}
|
||||
} else {
|
||||
let resolve, reject;
|
||||
resultP = new Promise((res, rej) => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
try {
|
||||
result = {
|
||||
ok: true,
|
||||
value: yield* fn()
|
||||
};
|
||||
resultP = null;
|
||||
if (promiseReferenced) resolve(result.value);
|
||||
} catch (error) {
|
||||
result = {
|
||||
ok: false,
|
||||
value: error
|
||||
};
|
||||
resultP = null;
|
||||
if (promiseReferenced) reject(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.ok) return result.value;else throw result.value;
|
||||
};
|
||||
}
|
||||
0 && 0;
|
||||
|
||||
//# sourceMappingURL=functional.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 C L M G N O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I"},C:{"1":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC qC rC","2":"nC LC"},D:{"1":"0 1 2 3 4 5 6 7 8 9 E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","2":"J PB K D"},E:{"1":"J PB K D E F A B C L M G tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"sC SC"},F:{"1":"0 1 2 3 4 5 6 7 8 B C G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 6C 7C FC kC 8C GC","2":"F 4C 5C"},G:{"1":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"2":"WD"},I:{"1":"LC J I ZD aD lC bD cD","16":"XD YD"},J:{"1":"D A"},K:{"1":"B C H FC kC GC","16":"A"},L:{"1":"I"},M:{"1":"EC"},N:{"2":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:6,C:"Wav audio format",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"47":0.00126,"49":0.00126,"52":0.00126,"56":0.00126,"72":0.00505,"77":0.00126,"84":0.00505,"88":0.00126,"100":0.00126,"106":0.05684,"113":0.00126,"114":0.00505,"115":0.11493,"127":0.00379,"128":0.01263,"131":0.00505,"132":0.00253,"133":0.00253,"134":0.00758,"135":0.27786,"136":0.53046,"137":0.02273,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 48 50 51 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 73 74 75 76 78 79 80 81 82 83 85 86 87 89 90 91 92 93 94 95 96 97 98 99 101 102 103 104 105 107 108 109 110 111 112 116 117 118 119 120 121 122 123 124 125 126 129 130 138 139 140 3.5 3.6"},D:{"5":0.00126,"40":0.00126,"42":0.00126,"57":0.00126,"60":0.00126,"63":0.01895,"64":0.00505,"66":0.00126,"67":0.00126,"68":0.00884,"70":0.00126,"74":0.00126,"79":0.05557,"81":0.00126,"85":0.00126,"87":0.00126,"94":0.00253,"95":0.00126,"98":0.00126,"102":0.00126,"103":0.05178,"104":0.00505,"109":0.08841,"111":0.0101,"114":0.00379,"116":0.00253,"118":0.00126,"119":0.00758,"120":0.00126,"121":0.00379,"122":0.01516,"123":0.00126,"124":0.0101,"125":0.00126,"126":0.00884,"127":0.00379,"128":0.00884,"129":0.00758,"130":0.02021,"131":0.03789,"132":0.03915,"133":1.04955,"134":1.22511,_:"4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 41 43 44 45 46 47 48 49 50 51 52 53 54 55 56 58 59 61 62 65 69 71 72 73 75 76 77 78 80 83 84 86 88 89 90 91 92 93 96 97 99 100 101 105 106 107 108 110 112 113 115 117 135 136 137 138"},F:{"79":0.00126,"82":0.64034,"87":0.00505,"95":0.00253,"98":0.00126,"109":0.00758,"115":0.00253,"116":0.01137,"117":0.69465,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 80 81 83 84 85 86 88 89 90 91 92 93 94 96 97 99 100 101 102 103 104 105 106 107 108 110 111 112 113 114 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"12":0.00505,"13":0.00126,"14":0.00379,"16":0.00379,"17":0.00379,"18":0.02273,"84":0.00253,"88":0.00126,"90":0.00126,"92":0.03284,"100":0.00505,"109":0.00126,"112":0.00126,"113":0.00884,"114":0.00126,"119":0.00126,"121":0.00126,"122":0.00253,"124":0.00379,"125":0.00379,"126":0.00505,"127":0.02905,"129":0.00253,"130":0.00253,"131":0.01768,"132":0.05431,"133":0.29049,"134":0.40921,_:"15 79 80 81 83 85 86 87 89 91 93 94 95 96 97 98 99 101 102 103 104 105 106 107 108 110 111 115 116 117 118 120 123 128"},E:{_:"0 4 5 6 7 8 9 10 11 12 13 14 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 15.2-15.3 15.4 15.5 16.0 16.1 16.3 16.4 16.5 17.0 17.2 17.3 17.4 17.5 18.4","15.6":0.0101,"16.2":0.00126,"16.6":0.00253,"17.1":0.00126,"17.6":0.00505,"18.0":0.00126,"18.1":0.00126,"18.2":0.02779,"18.3":0.01768},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.0015,"5.0-5.1":0,"6.0-6.1":0.00449,"7.0-7.1":0.003,"8.1-8.4":0,"9.0-9.2":0.00225,"9.3":0.01048,"10.0-10.2":0.00075,"10.3":0.01722,"11.0-11.2":0.07937,"11.3-11.4":0.00524,"12.0-12.1":0.003,"12.2-12.5":0.07413,"13.0-13.1":0.0015,"13.2":0.00225,"13.3":0.003,"13.4-13.7":0.01048,"14.0-14.4":0.02621,"14.5-14.8":0.03145,"15.0-15.1":0.01722,"15.2-15.3":0.01722,"15.4":0.02097,"15.5":0.02396,"15.6-15.8":0.29501,"16.0":0.04193,"16.1":0.08611,"16.2":0.04493,"16.3":0.07787,"16.4":0.01722,"16.5":0.0322,"16.6-16.7":0.34967,"17.0":0.02097,"17.1":0.03744,"17.2":0.02845,"17.3":0.03968,"17.4":0.07937,"17.5":0.17671,"17.6-17.7":0.5129,"18.0":0.14376,"18.1":0.47022,"18.2":0.2104,"18.3":4.39747,"18.4":0.06514},P:{"21":0.0403,"22":0.02015,"23":0.01007,"24":0.02015,"25":0.02015,"26":0.14104,"27":0.3929,_:"4 20 8.2 9.2 10.1 12.0 13.0 14.0 15.0 17.0","5.0-5.4":0.17126,"6.2-6.4":0.01007,"7.2-7.4":0.07052,"11.1-11.2":0.02015,"16.0":0.01007,"18.0":0.01007,"19.0":0.05037},I:{"0":0.01744,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00001,"4.4":0,"4.4.3-4.4.4":0.00002},K:{"0":1.83941,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{"2.5":0.01747,_:"3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.09611},Q:{"14.9":0.00874},O:{"0":0.52422},H:{"0":0.24},L:{"0":82.08922}};
|
||||
@@ -0,0 +1,699 @@
|
||||
/**
|
||||
* @fileoverview The main file for the humanfs package.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
/* global URL, TextDecoder, TextEncoder */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("@humanfs/types").HfsImpl} HfsImpl */
|
||||
/** @typedef {import("@humanfs/types").HfsDirectoryEntry} HfsDirectoryEntry */
|
||||
/** @typedef {import("@humanfs/types").HfsWalkEntry} HfsWalkEntry */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
/**
|
||||
* Error to represent when a method is missing on an impl.
|
||||
*/
|
||||
export class NoSuchMethodError extends Error {
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {string} methodName The name of the method that was missing.
|
||||
*/
|
||||
constructor(methodName) {
|
||||
super(`Method "${methodName}" does not exist on impl.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to represent when a method is not supported on an impl. This happens
|
||||
* when a method on `Hfs` is called with one name and the corresponding method
|
||||
* on the impl has a different name. (Example: `text()` and `bytes()`.)
|
||||
*/
|
||||
export class MethodNotSupportedError extends Error {
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {string} methodName The name of the method that was missing.
|
||||
*/
|
||||
constructor(methodName) {
|
||||
super(`Method "${methodName}" is not supported on this impl.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to represent when an impl is already set.
|
||||
*/
|
||||
export class ImplAlreadySetError extends Error {
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
constructor() {
|
||||
super(`Implementation already set.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given path is a valid file path.
|
||||
* @param {any} fileOrDirPath The path to check.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} When the path is not a non-empty string.
|
||||
*/
|
||||
function assertValidFileOrDirPath(fileOrDirPath) {
|
||||
if (
|
||||
!fileOrDirPath ||
|
||||
(!(fileOrDirPath instanceof URL) && typeof fileOrDirPath !== "string")
|
||||
) {
|
||||
throw new TypeError("Path must be a non-empty string or URL.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given file contents are valid.
|
||||
* @param {any} contents The contents to check.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} When the contents are not a string or ArrayBuffer.
|
||||
*/
|
||||
function assertValidFileContents(contents) {
|
||||
if (
|
||||
typeof contents !== "string" &&
|
||||
!(contents instanceof ArrayBuffer) &&
|
||||
!ArrayBuffer.isView(contents)
|
||||
) {
|
||||
throw new TypeError(
|
||||
"File contents must be a string, ArrayBuffer, or ArrayBuffer view.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given contents to Uint8Array.
|
||||
* @param {any} contents The data to convert.
|
||||
* @returns {Uint8Array} The converted Uint8Array.
|
||||
* @throws {TypeError} When the contents are not a string or ArrayBuffer.
|
||||
*/
|
||||
function toUint8Array(contents) {
|
||||
if (contents instanceof Uint8Array) {
|
||||
return contents;
|
||||
}
|
||||
|
||||
if (typeof contents === "string") {
|
||||
return encoder.encode(contents);
|
||||
}
|
||||
|
||||
if (contents instanceof ArrayBuffer) {
|
||||
return new Uint8Array(contents);
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(contents)) {
|
||||
const bytes = contents.buffer.slice(
|
||||
contents.byteOffset,
|
||||
contents.byteOffset + contents.byteLength,
|
||||
);
|
||||
return new Uint8Array(bytes);
|
||||
}
|
||||
throw new TypeError(
|
||||
"Invalid contents type. Expected string or ArrayBuffer.",
|
||||
);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A class representing a log entry.
|
||||
*/
|
||||
export class LogEntry {
|
||||
/**
|
||||
* The type of log entry.
|
||||
* @type {string}
|
||||
*/
|
||||
type;
|
||||
|
||||
/**
|
||||
* The data associated with the log entry.
|
||||
* @type {any}
|
||||
*/
|
||||
data;
|
||||
|
||||
/**
|
||||
* The time at which the log entry was created.
|
||||
* @type {number}
|
||||
*/
|
||||
timestamp = Date.now();
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {string} type The type of log entry.
|
||||
* @param {any} [data] The data associated with the log entry.
|
||||
*/
|
||||
constructor(type, data) {
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representing a file system utility library.
|
||||
* @implements {HfsImpl}
|
||||
*/
|
||||
export class Hfs {
|
||||
/**
|
||||
* The base implementation for this instance.
|
||||
* @type {HfsImpl}
|
||||
*/
|
||||
#baseImpl;
|
||||
|
||||
/**
|
||||
* The current implementation for this instance.
|
||||
* @type {HfsImpl}
|
||||
*/
|
||||
#impl;
|
||||
|
||||
/**
|
||||
* A map of log names to their corresponding entries.
|
||||
* @type {Map<string,Array<LogEntry>>}
|
||||
*/
|
||||
#logs = new Map();
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {object} options The options for the instance.
|
||||
* @param {HfsImpl} options.impl The implementation to use.
|
||||
*/
|
||||
constructor({ impl }) {
|
||||
this.#baseImpl = impl;
|
||||
this.#impl = impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an entry onto all currently open logs.
|
||||
* @param {string} methodName The name of the method being called.
|
||||
* @param {...*} args The arguments to the method.
|
||||
* @returns {void}
|
||||
*/
|
||||
#log(methodName, ...args) {
|
||||
for (const logs of this.#logs.values()) {
|
||||
logs.push(new LogEntry("call", { methodName, args }));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new log with the given name.
|
||||
* @param {string} name The name of the log to start;
|
||||
* @returns {void}
|
||||
* @throws {Error} When the log already exists.
|
||||
* @throws {TypeError} When the name is not a non-empty string.
|
||||
*/
|
||||
logStart(name) {
|
||||
if (!name || typeof name !== "string") {
|
||||
throw new TypeError("Log name must be a non-empty string.");
|
||||
}
|
||||
|
||||
if (this.#logs.has(name)) {
|
||||
throw new Error(`Log "${name}" already exists.`);
|
||||
}
|
||||
|
||||
this.#logs.set(name, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends a log with the given name and returns the entries.
|
||||
* @param {string} name The name of the log to end.
|
||||
* @returns {Array<LogEntry>} The entries in the log.
|
||||
* @throws {Error} When the log does not exist.
|
||||
*/
|
||||
logEnd(name) {
|
||||
if (this.#logs.has(name)) {
|
||||
const logs = this.#logs.get(name);
|
||||
this.#logs.delete(name);
|
||||
return logs;
|
||||
}
|
||||
|
||||
throw new Error(`Log "${name}" does not exist.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the current implementation is the base implementation.
|
||||
* @returns {boolean} True if the current implementation is the base implementation.
|
||||
*/
|
||||
isBaseImpl() {
|
||||
return this.#impl === this.#baseImpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the implementation for this instance.
|
||||
* @param {object} impl The implementation to use.
|
||||
* @returns {void}
|
||||
*/
|
||||
setImpl(impl) {
|
||||
this.#log("implSet", impl);
|
||||
|
||||
if (this.#impl !== this.#baseImpl) {
|
||||
throw new ImplAlreadySetError();
|
||||
}
|
||||
|
||||
this.#impl = impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the implementation for this instance back to its original.
|
||||
* @returns {void}
|
||||
*/
|
||||
resetImpl() {
|
||||
this.#log("implReset");
|
||||
this.#impl = this.#baseImpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given method exists on the current implementation.
|
||||
* @param {string} methodName The name of the method to check.
|
||||
* @returns {void}
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
*/
|
||||
#assertImplMethod(methodName) {
|
||||
if (typeof this.#impl[methodName] !== "function") {
|
||||
throw new NoSuchMethodError(methodName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given method exists on the current implementation, and if not,
|
||||
* throws an error with a different method name.
|
||||
* @param {string} methodName The name of the method to check.
|
||||
* @param {string} targetMethodName The name of the method that should be reported
|
||||
* as an error when methodName does not exist.
|
||||
* @returns {void}
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
*/
|
||||
#assertImplMethodAlt(methodName, targetMethodName) {
|
||||
if (typeof this.#impl[methodName] !== "function") {
|
||||
throw new MethodNotSupportedError(targetMethodName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the given method on the current implementation.
|
||||
* @param {string} methodName The name of the method to call.
|
||||
* @param {...any} args The arguments to the method.
|
||||
* @returns {any} The return value from the method.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
*/
|
||||
#callImplMethod(methodName, ...args) {
|
||||
this.#log(methodName, ...args);
|
||||
this.#assertImplMethod(methodName);
|
||||
return this.#impl[methodName](...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the given method on the current implementation and doesn't log the call.
|
||||
* @param {string} methodName The name of the method to call.
|
||||
* @param {...any} args The arguments to the method.
|
||||
* @returns {any} The return value from the method.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
*/
|
||||
#callImplMethodWithoutLog(methodName, ...args) {
|
||||
this.#assertImplMethod(methodName);
|
||||
return this.#impl[methodName](...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the given method on the current implementation but logs a different method name.
|
||||
* @param {string} methodName The name of the method to call.
|
||||
* @param {string} targetMethodName The name of the method to log.
|
||||
* @param {...any} args The arguments to the method.
|
||||
* @returns {any} The return value from the method.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
*/
|
||||
#callImplMethodAlt(methodName, targetMethodName, ...args) {
|
||||
this.#log(targetMethodName, ...args);
|
||||
this.#assertImplMethodAlt(methodName, targetMethodName);
|
||||
return this.#impl[methodName](...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given file and returns the contents as text. Assumes UTF-8 encoding.
|
||||
* @param {string|URL} filePath The file to read.
|
||||
* @returns {Promise<string|undefined>} The contents of the file.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the file path is not a non-empty string.
|
||||
*/
|
||||
async text(filePath) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
|
||||
const result = await this.#callImplMethodAlt("bytes", "text", filePath);
|
||||
return result ? decoder.decode(result) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given file and returns the contents as JSON. Assumes UTF-8 encoding.
|
||||
* @param {string|URL} filePath The file to read.
|
||||
* @returns {Promise<any|undefined>} The contents of the file as JSON.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {SyntaxError} When the file contents are not valid JSON.
|
||||
* @throws {TypeError} When the file path is not a non-empty string.
|
||||
*/
|
||||
async json(filePath) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
|
||||
const result = await this.#callImplMethodAlt("bytes", "json", filePath);
|
||||
return result ? JSON.parse(decoder.decode(result)) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given file and returns the contents as an ArrayBuffer.
|
||||
* @param {string|URL} filePath The file to read.
|
||||
* @returns {Promise<ArrayBuffer|undefined>} The contents of the file as an ArrayBuffer.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the file path is not a non-empty string.
|
||||
* @deprecated Use bytes() instead.
|
||||
*/
|
||||
async arrayBuffer(filePath) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
|
||||
const result = await this.#callImplMethodAlt(
|
||||
"bytes",
|
||||
"arrayBuffer",
|
||||
filePath,
|
||||
);
|
||||
return result?.buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given file and returns the contents as an Uint8Array.
|
||||
* @param {string|URL} filePath The file to read.
|
||||
* @returns {Promise<Uint8Array|undefined>} The contents of the file as an Uint8Array.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the file path is not a non-empty string.
|
||||
*/
|
||||
async bytes(filePath) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
return this.#callImplMethod("bytes", filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the given data to the given file. Creates any necessary directories along the way.
|
||||
* If the data is a string, UTF-8 encoding is used.
|
||||
* @param {string|URL} filePath The file to write.
|
||||
* @param {string|ArrayBuffer|ArrayBufferView} contents The data to write.
|
||||
* @returns {Promise<void>} A promise that resolves when the file is written.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the file path is not a non-empty string.
|
||||
*/
|
||||
async write(filePath, contents) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
assertValidFileContents(contents);
|
||||
this.#log("write", filePath, contents);
|
||||
|
||||
let value = toUint8Array(contents);
|
||||
return this.#callImplMethodWithoutLog("write", filePath, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the given data to the given file. Creates any necessary directories along the way.
|
||||
* If the data is a string, UTF-8 encoding is used.
|
||||
* @param {string|URL} filePath The file to append to.
|
||||
* @param {string|ArrayBuffer|ArrayBufferView} contents The data to append.
|
||||
* @returns {Promise<void>} A promise that resolves when the file is appended to.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the file path is not a non-empty string.
|
||||
* @throws {TypeError} When the file contents are not a string or ArrayBuffer.
|
||||
* @throws {Error} When the file cannot be appended to.
|
||||
*/
|
||||
async append(filePath, contents) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
assertValidFileContents(contents);
|
||||
this.#log("append", filePath, contents);
|
||||
|
||||
let value = toUint8Array(contents);
|
||||
return this.#callImplMethodWithoutLog("append", filePath, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given file exists.
|
||||
* @param {string|URL} filePath The file to check.
|
||||
* @returns {Promise<boolean>} True if the file exists.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the file path is not a non-empty string.
|
||||
*/
|
||||
async isFile(filePath) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
return this.#callImplMethod("isFile", filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given directory exists.
|
||||
* @param {string|URL} dirPath The directory to check.
|
||||
* @returns {Promise<boolean>} True if the directory exists.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the directory path is not a non-empty string.
|
||||
*/
|
||||
async isDirectory(dirPath) {
|
||||
assertValidFileOrDirPath(dirPath);
|
||||
return this.#callImplMethod("isDirectory", dirPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the given directory.
|
||||
* @param {string|URL} dirPath The directory to create.
|
||||
* @returns {Promise<void>} A promise that resolves when the directory is created.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the directory path is not a non-empty string.
|
||||
*/
|
||||
async createDirectory(dirPath) {
|
||||
assertValidFileOrDirPath(dirPath);
|
||||
return this.#callImplMethod("createDirectory", dirPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given file or empty directory.
|
||||
* @param {string|URL} filePath The file to delete.
|
||||
* @returns {Promise<boolean>} A promise that resolves when the file or
|
||||
* directory is deleted, true if the file or directory is deleted, false
|
||||
* if the file or directory does not exist.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the file path is not a non-empty string.
|
||||
*/
|
||||
async delete(filePath) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
return this.#callImplMethod("delete", filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given file or directory recursively.
|
||||
* @param {string|URL} dirPath The directory to delete.
|
||||
* @returns {Promise<boolean>} A promise that resolves when the file or
|
||||
* directory is deleted, true if the file or directory is deleted, false
|
||||
* if the file or directory does not exist.
|
||||
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
||||
* @throws {TypeError} When the directory path is not a non-empty string.
|
||||
*/
|
||||
async deleteAll(dirPath) {
|
||||
assertValidFileOrDirPath(dirPath);
|
||||
return this.#callImplMethod("deleteAll", dirPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of directory entries for the given path.
|
||||
* @param {string|URL} dirPath The path to the directory to read.
|
||||
* @returns {AsyncIterable<HfsDirectoryEntry>} A promise that resolves with the
|
||||
* directory entries.
|
||||
* @throws {TypeError} If the directory path is not a string or URL.
|
||||
* @throws {Error} If the directory cannot be read.
|
||||
*/
|
||||
async *list(dirPath) {
|
||||
assertValidFileOrDirPath(dirPath);
|
||||
yield* await this.#callImplMethod("list", dirPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks a directory using a depth-first traversal and returns the entries
|
||||
* from the traversal.
|
||||
* @param {string|URL} dirPath The path to the directory to walk.
|
||||
* @param {Object} [options] The options for the walk.
|
||||
* @param {(entry:HfsWalkEntry) => Promise<boolean>|boolean} [options.directoryFilter] A filter function to determine
|
||||
* if a directory's entries should be included in the walk.
|
||||
* @param {(entry:HfsWalkEntry) => Promise<boolean>|boolean} [options.entryFilter] A filter function to determine if
|
||||
* an entry should be included in the walk.
|
||||
* @returns {AsyncIterable<HfsWalkEntry>} A promise that resolves with the
|
||||
* directory entries.
|
||||
* @throws {TypeError} If the directory path is not a string or URL.
|
||||
* @throws {Error} If the directory cannot be read.
|
||||
*/
|
||||
async *walk(
|
||||
dirPath,
|
||||
{ directoryFilter = () => true, entryFilter = () => true } = {},
|
||||
) {
|
||||
assertValidFileOrDirPath(dirPath);
|
||||
this.#log("walk", dirPath, { directoryFilter, entryFilter });
|
||||
|
||||
// inner function for recursion without additional logging
|
||||
const walk = async function* (
|
||||
dirPath,
|
||||
{ directoryFilter, entryFilter, parentPath = "", depth = 1 },
|
||||
) {
|
||||
let dirEntries;
|
||||
|
||||
try {
|
||||
dirEntries = await this.#callImplMethodWithoutLog(
|
||||
"list",
|
||||
dirPath,
|
||||
);
|
||||
} catch (error) {
|
||||
// if the directory does not exist then return an empty array
|
||||
if (error.code === "ENOENT") {
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise, rethrow the error
|
||||
throw error;
|
||||
}
|
||||
|
||||
for await (const listEntry of dirEntries) {
|
||||
const walkEntry = {
|
||||
path: listEntry.name,
|
||||
depth,
|
||||
...listEntry,
|
||||
};
|
||||
|
||||
if (parentPath) {
|
||||
walkEntry.path = `${parentPath}/${walkEntry.path}`;
|
||||
}
|
||||
|
||||
// first emit the entry but only if the entry filter returns true
|
||||
let shouldEmitEntry = entryFilter(walkEntry);
|
||||
if (shouldEmitEntry.then) {
|
||||
shouldEmitEntry = await shouldEmitEntry;
|
||||
}
|
||||
|
||||
if (shouldEmitEntry) {
|
||||
yield walkEntry;
|
||||
}
|
||||
|
||||
// if it's a directory then yield the entry and walk the directory
|
||||
if (listEntry.isDirectory) {
|
||||
// if the directory filter returns false, skip the directory
|
||||
let shouldWalkDirectory = directoryFilter(walkEntry);
|
||||
if (shouldWalkDirectory.then) {
|
||||
shouldWalkDirectory = await shouldWalkDirectory;
|
||||
}
|
||||
|
||||
if (!shouldWalkDirectory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// make sure there's a trailing slash on the directory path before appending
|
||||
const directoryPath =
|
||||
dirPath instanceof URL
|
||||
? new URL(
|
||||
listEntry.name,
|
||||
dirPath.href.endsWith("/")
|
||||
? dirPath.href
|
||||
: `${dirPath.href}/`,
|
||||
)
|
||||
: `${dirPath.endsWith("/") ? dirPath : `${dirPath}/`}${listEntry.name}`;
|
||||
|
||||
yield* walk(directoryPath, {
|
||||
directoryFilter,
|
||||
entryFilter,
|
||||
parentPath: walkEntry.path,
|
||||
depth: depth + 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
yield* walk(dirPath, { directoryFilter, entryFilter });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the given file.
|
||||
* @param {string|URL} filePath The path to the file to read.
|
||||
* @returns {Promise<number>} A promise that resolves with the size of the file.
|
||||
* @throws {TypeError} If the file path is not a string or URL.
|
||||
* @throws {Error} If the file cannot be read.
|
||||
*/
|
||||
async size(filePath) {
|
||||
assertValidFileOrDirPath(filePath);
|
||||
return this.#callImplMethod("size", filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last modified timestamp of the given file or directory.
|
||||
* @param {string|URL} fileOrDirPath The path to the file or directory.
|
||||
* @returns {Promise<Date|undefined>} A promise that resolves with the last modified date
|
||||
* or undefined if the file or directory does not exist.
|
||||
* @throws {TypeError} If the path is not a string or URL.
|
||||
*/
|
||||
async lastModified(fileOrDirPath) {
|
||||
assertValidFileOrDirPath(fileOrDirPath);
|
||||
return this.#callImplMethod("lastModified", fileOrDirPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copys a file from one location to another.
|
||||
* @param {string|URL} source The path to the file to copy.
|
||||
* @param {string|URL} destination The path to the new file.
|
||||
* @returns {Promise<void>} A promise that resolves when the file is copied.
|
||||
* @throws {TypeError} If the file path is not a string or URL.
|
||||
* @throws {Error} If the file cannot be copied.
|
||||
*/
|
||||
async copy(source, destination) {
|
||||
assertValidFileOrDirPath(source);
|
||||
assertValidFileOrDirPath(destination);
|
||||
return this.#callImplMethod("copy", source, destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a file or directory from one location to another.
|
||||
* @param {string|URL} source The path to the file or directory to copy.
|
||||
* @param {string|URL} destination The path to copy the file or directory to.
|
||||
* @returns {Promise<void>} A promise that resolves when the file or directory is
|
||||
* copied.
|
||||
* @throws {TypeError} If the directory path is not a string or URL.
|
||||
* @throws {Error} If the directory cannot be copied.
|
||||
*/
|
||||
async copyAll(source, destination) {
|
||||
assertValidFileOrDirPath(source);
|
||||
assertValidFileOrDirPath(destination);
|
||||
return this.#callImplMethod("copyAll", source, destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a file from the source path to the destination path.
|
||||
* @param {string|URL} source The location of the file to move.
|
||||
* @param {string|URL} destination The destination of the file to move.
|
||||
* @returns {Promise<void>} A promise that resolves when the move is complete.
|
||||
* @throws {TypeError} If the file or directory paths are not strings.
|
||||
* @throws {Error} If the file or directory cannot be moved.
|
||||
*/
|
||||
async move(source, destination) {
|
||||
assertValidFileOrDirPath(source);
|
||||
assertValidFileOrDirPath(destination);
|
||||
return this.#callImplMethod("move", source, destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a file or directory from one location to another.
|
||||
* @param {string|URL} source The path to the file or directory to move.
|
||||
* @param {string|URL} destination The path to move the file or directory to.
|
||||
* @returns {Promise<void>} A promise that resolves when the file or directory is
|
||||
* moved.
|
||||
* @throws {TypeError} If the source is not a string or URL.
|
||||
* @throws {TypeError} If the destination is not a string or URL.
|
||||
* @throws {Error} If the file or directory cannot be moved.
|
||||
*/
|
||||
async moveAll(source, destination) {
|
||||
assertValidFileOrDirPath(source);
|
||||
assertValidFileOrDirPath(destination);
|
||||
return this.#callImplMethod("moveAll", source, destination);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"2":"C L M G N O P","132":"0 9 Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I"},C:{"2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC qC rC","322":"0 9 CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC"},D:{"2":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB","66":"0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC","132":"0 9 Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC"},E:{"2":"J PB K D E F A B C sC SC tC uC vC wC TC FC GC","578":"L M G xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C"},F:{"2":"1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB 4C 5C 6C 7C FC kC 8C GC","66":"pB qB rB sB tB uB vB wB xB yB zB 0B","132":"0 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z"},G:{"2":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"2":"WD"},I:{"2":"LC J I XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"2":"A B C FC kC GC","132":"H"},L:{"132":"I"},M:{"322":"EC"},N:{"2":"A B"},O:{"2":"HC"},P:{"2":"J dD eD fD gD hD TC iD","132":"1 2 3 4 5 6 7 8 jD kD lD mD IC JC KC nD"},Q:{"2":"oD"},R:{"2":"pD"},S:{"2":"qD","322":"rD"}},B:4,C:"WebXR Device API",D:true};
|
||||
@@ -0,0 +1,2 @@
|
||||
exports.extract = require('./extract')
|
||||
exports.pack = require('./pack')
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_interopRequireDefault","obj","__esModule","default"],"sources":["../../src/helpers/interopRequireDefault.ts"],"sourcesContent":["/* @minVersion 7.0.0-beta.0 */\n\nexport default function _interopRequireDefault(obj: any) {\n return obj && obj.__esModule ? obj : { default: obj };\n}\n"],"mappings":";;;;;;AAEe,SAASA,sBAAsBA,CAACC,GAAQ,EAAE;EACvD,OAAOA,GAAG,IAAIA,GAAG,CAACC,UAAU,GAAGD,GAAG,GAAG;IAAEE,OAAO,EAAEF;EAAI,CAAC;AACvD","ignoreList":[]}
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Check whether a given character is a regional indicator symbol.
|
||||
* @param {number} code The character code to check.
|
||||
* @returns {boolean} `true` if the character is a regional indicator symbol.
|
||||
*/
|
||||
module.exports = function isRegionalIndicatorSymbol(code) {
|
||||
return code >= 0x1f1e6 && code <= 0x1f1ff;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":[],"sources":["../../../src/config/files/types.ts"],"sourcesContent":["import type { InputOptions } from \"../index.ts\";\n\nexport type ConfigFile = {\n filepath: string;\n dirname: string;\n options: InputOptions & { babel?: unknown };\n};\n\nexport type IgnoreFile = {\n filepath: string;\n dirname: string;\n ignore: Array<RegExp>;\n};\n\nexport type RelativeConfig = {\n // The actual config, either from package.json#babel, .babelrc, or\n // .babelrc.js, if there was one.\n config: ConfigFile | null;\n // The .babelignore, if there was one.\n ignore: IgnoreFile | null;\n};\n\nexport type FilePackageData = {\n // The file in the package.\n filepath: string;\n // Any ancestor directories of the file that are within the package.\n directories: Array<string>;\n // The contents of the package.json. May not be found if the package just\n // terminated at a node_modules folder without finding one.\n pkg: ConfigFile | null;\n // True if a package.json or node_modules folder was found while traversing\n // the directory structure.\n isPackage: boolean;\n};\n"],"mappings":"","ignoreList":[]}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_gensync","data","require","_index","_index2","_rewriteStackTrace","transformRunner","gensync","transform","code","opts","config","loadConfig","run","exports","optsOrCallback","maybeCallback","callback","undefined","beginHiddenCallStack","sync","errback","transformSync","args","transformAsync","async"],"sources":["../src/transform.ts"],"sourcesContent":["import gensync, { type Handler } from \"gensync\";\n\nimport loadConfig from \"./config/index.ts\";\nimport type { InputOptions, ResolvedConfig } from \"./config/index.ts\";\nimport { run } from \"./transformation/index.ts\";\n\nimport type { FileResult, FileResultCallback } from \"./transformation/index.ts\";\nimport { beginHiddenCallStack } from \"./errors/rewrite-stack-trace.ts\";\n\nexport type { FileResult } from \"./transformation/index.ts\";\n\ntype Transform = {\n (code: string, callback: FileResultCallback): void;\n (\n code: string,\n opts: InputOptions | undefined | null,\n callback: FileResultCallback,\n ): void;\n (code: string, opts?: InputOptions | null): FileResult | null;\n};\n\nconst transformRunner = gensync(function* transform(\n code: string,\n opts?: InputOptions,\n): Handler<FileResult | null> {\n const config: ResolvedConfig | null = yield* loadConfig(opts);\n if (config === null) return null;\n\n return yield* run(config, code);\n});\n\nexport const transform: Transform = function transform(\n code,\n optsOrCallback?: InputOptions | null | undefined | FileResultCallback,\n maybeCallback?: FileResultCallback,\n) {\n let opts: InputOptions | undefined | null;\n let callback: FileResultCallback | undefined;\n if (typeof optsOrCallback === \"function\") {\n callback = optsOrCallback;\n opts = undefined;\n } else {\n opts = optsOrCallback;\n callback = maybeCallback;\n }\n\n if (callback === undefined) {\n if (process.env.BABEL_8_BREAKING) {\n throw new Error(\n \"Starting from Babel 8.0.0, the 'transform' function expects a callback. If you need to call it synchronously, please use 'transformSync'.\",\n );\n } else {\n // console.warn(\n // \"Starting from Babel 8.0.0, the 'transform' function will expect a callback. If you need to call it synchronously, please use 'transformSync'.\",\n // );\n return beginHiddenCallStack(transformRunner.sync)(code, opts);\n }\n }\n\n beginHiddenCallStack(transformRunner.errback)(code, opts, callback);\n};\n\nexport function transformSync(\n ...args: Parameters<typeof transformRunner.sync>\n) {\n return beginHiddenCallStack(transformRunner.sync)(...args);\n}\nexport function transformAsync(\n ...args: Parameters<typeof transformRunner.async>\n) {\n return beginHiddenCallStack(transformRunner.async)(...args);\n}\n"],"mappings":";;;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,IAAAE,MAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AAGA,IAAAG,kBAAA,GAAAH,OAAA;AAcA,MAAMI,eAAe,GAAGC,SAAMA,CAAC,CAAC,UAAUC,SAASA,CACjDC,IAAY,EACZC,IAAmB,EACS;EAC5B,MAAMC,MAA6B,GAAG,OAAO,IAAAC,cAAU,EAACF,IAAI,CAAC;EAC7D,IAAIC,MAAM,KAAK,IAAI,EAAE,OAAO,IAAI;EAEhC,OAAO,OAAO,IAAAE,WAAG,EAACF,MAAM,EAAEF,IAAI,CAAC;AACjC,CAAC,CAAC;AAEK,MAAMD,SAAoB,GAAAM,OAAA,CAAAN,SAAA,GAAG,SAASA,SAASA,CACpDC,IAAI,EACJM,cAAqE,EACrEC,aAAkC,EAClC;EACA,IAAIN,IAAqC;EACzC,IAAIO,QAAwC;EAC5C,IAAI,OAAOF,cAAc,KAAK,UAAU,EAAE;IACxCE,QAAQ,GAAGF,cAAc;IACzBL,IAAI,GAAGQ,SAAS;EAClB,CAAC,MAAM;IACLR,IAAI,GAAGK,cAAc;IACrBE,QAAQ,GAAGD,aAAa;EAC1B;EAEA,IAAIC,QAAQ,KAAKC,SAAS,EAAE;IAKnB;MAIL,OAAO,IAAAC,uCAAoB,EAACb,eAAe,CAACc,IAAI,CAAC,CAACX,IAAI,EAAEC,IAAI,CAAC;IAC/D;EACF;EAEA,IAAAS,uCAAoB,EAACb,eAAe,CAACe,OAAO,CAAC,CAACZ,IAAI,EAAEC,IAAI,EAAEO,QAAQ,CAAC;AACrE,CAAC;AAEM,SAASK,aAAaA,CAC3B,GAAGC,IAA6C,EAChD;EACA,OAAO,IAAAJ,uCAAoB,EAACb,eAAe,CAACc,IAAI,CAAC,CAAC,GAAGG,IAAI,CAAC;AAC5D;AACO,SAASC,cAAcA,CAC5B,GAAGD,IAA8C,EACjD;EACA,OAAO,IAAAJ,uCAAoB,EAACb,eAAe,CAACmB,KAAK,CAAC,CAAC,GAAGF,IAAI,CAAC;AAC7D;AAAC","ignoreList":[]}
|
||||
@@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
var traverse = module.exports = function (schema, opts, cb) {
|
||||
// Legacy support for v0.3.1 and earlier.
|
||||
if (typeof opts == 'function') {
|
||||
cb = opts;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
cb = opts.cb || cb;
|
||||
var pre = (typeof cb == 'function') ? cb : cb.pre || function() {};
|
||||
var post = cb.post || function() {};
|
||||
|
||||
_traverse(opts, pre, post, schema, '', schema);
|
||||
};
|
||||
|
||||
|
||||
traverse.keywords = {
|
||||
additionalItems: true,
|
||||
items: true,
|
||||
contains: true,
|
||||
additionalProperties: true,
|
||||
propertyNames: true,
|
||||
not: true
|
||||
};
|
||||
|
||||
traverse.arrayKeywords = {
|
||||
items: true,
|
||||
allOf: true,
|
||||
anyOf: true,
|
||||
oneOf: true
|
||||
};
|
||||
|
||||
traverse.propsKeywords = {
|
||||
definitions: true,
|
||||
properties: true,
|
||||
patternProperties: true,
|
||||
dependencies: true
|
||||
};
|
||||
|
||||
traverse.skipKeywords = {
|
||||
default: true,
|
||||
enum: true,
|
||||
const: true,
|
||||
required: true,
|
||||
maximum: true,
|
||||
minimum: true,
|
||||
exclusiveMaximum: true,
|
||||
exclusiveMinimum: true,
|
||||
multipleOf: true,
|
||||
maxLength: true,
|
||||
minLength: true,
|
||||
pattern: true,
|
||||
format: true,
|
||||
maxItems: true,
|
||||
minItems: true,
|
||||
uniqueItems: true,
|
||||
maxProperties: true,
|
||||
minProperties: true
|
||||
};
|
||||
|
||||
|
||||
function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
|
||||
if (schema && typeof schema == 'object' && !Array.isArray(schema)) {
|
||||
pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
||||
for (var key in schema) {
|
||||
var sch = schema[key];
|
||||
if (Array.isArray(sch)) {
|
||||
if (key in traverse.arrayKeywords) {
|
||||
for (var i=0; i<sch.length; i++)
|
||||
_traverse(opts, pre, post, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i);
|
||||
}
|
||||
} else if (key in traverse.propsKeywords) {
|
||||
if (sch && typeof sch == 'object') {
|
||||
for (var prop in sch)
|
||||
_traverse(opts, pre, post, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
|
||||
}
|
||||
} else if (key in traverse.keywords || (opts.allKeys && !(key in traverse.skipKeywords))) {
|
||||
_traverse(opts, pre, post, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema);
|
||||
}
|
||||
}
|
||||
post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function escapeJsonPtr(str) {
|
||||
return str.replace(/~/g, '~0').replace(/\//g, '~1');
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// forward declarations
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface ReadableStream {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub for https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface AbortSignal {}
|
||||
|
||||
/**
|
||||
* Stub for https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface ReadableStream<R = any> {}
|
||||
|
||||
/**
|
||||
* Stub for https://developer.mozilla.org/en-US/docs/Web/API/Uint8Array
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface Uint8Array {}
|
||||
}
|
||||
|
||||
import { ReactNode } from "react";
|
||||
import { ErrorInfo } from "./client";
|
||||
|
||||
export interface PrerenderOptions {
|
||||
bootstrapScriptContent?: string;
|
||||
bootstrapScripts?: string[];
|
||||
bootstrapModules?: string[];
|
||||
identifierPrefix?: string;
|
||||
namespaceURI?: string;
|
||||
onError?: (error: unknown, errorInfo: ErrorInfo) => string | void;
|
||||
progressiveChunkSize?: number;
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
export interface PrerenderResult {
|
||||
prelude: ReadableStream<Uint8Array>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only available in the environments with [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) (this includes browsers, Deno, and some modern edge runtimes).
|
||||
*
|
||||
* @see [API](https://react.dev/reference/react-dom/static/prerender)
|
||||
*/
|
||||
export function prerender(
|
||||
reactNode: ReactNode,
|
||||
options?: PrerenderOptions,
|
||||
): Promise<PrerenderResult>;
|
||||
|
||||
export interface PrerenderToNodeStreamResult {
|
||||
prelude: NodeJS.ReadableStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only available in the environments with [Node.js Streams](https://nodejs.dev/learn/nodejs-streams).
|
||||
*
|
||||
* @see [API](https://react.dev/reference/react-dom/static/prerenderToNodeStream)
|
||||
*
|
||||
* @param children
|
||||
* @param options
|
||||
*/
|
||||
export function prerenderToNodeStream(
|
||||
reactNode: ReactNode,
|
||||
options?: PrerenderOptions,
|
||||
): Promise<PrerenderToNodeStreamResult>;
|
||||
|
||||
export const version: string;
|
||||
@@ -0,0 +1,610 @@
|
||||
import type { HistoryState, ParsedHistoryState } from '@tanstack/history'
|
||||
import type {
|
||||
AllParams,
|
||||
CatchAllPaths,
|
||||
CurrentPath,
|
||||
FullSearchSchema,
|
||||
FullSearchSchemaInput,
|
||||
ParentPath,
|
||||
RouteByPath,
|
||||
RouteByToPath,
|
||||
RoutePaths,
|
||||
RouteToPath,
|
||||
ToPath,
|
||||
} from './routeInfo'
|
||||
import type {
|
||||
AnyRouter,
|
||||
RegisteredRouter,
|
||||
ViewTransitionOptions,
|
||||
} from './router'
|
||||
import type {
|
||||
ConstrainLiteral,
|
||||
Expand,
|
||||
MakeDifferenceOptional,
|
||||
NoInfer,
|
||||
NonNullableUpdater,
|
||||
PickRequired,
|
||||
Updater,
|
||||
WithoutEmpty,
|
||||
} from './utils'
|
||||
import type { ParsedLocation } from './location'
|
||||
|
||||
export type IsRequiredParams<TParams> =
|
||||
Record<never, never> extends TParams ? never : true
|
||||
|
||||
export type ParsePathParams<T extends string, TAcc = never> = T &
|
||||
`${string}$${string}` extends never
|
||||
? TAcc
|
||||
: T extends `${string}$${infer TPossiblyParam}`
|
||||
? TPossiblyParam extends ''
|
||||
? TAcc
|
||||
: TPossiblyParam & `${string}/${string}` extends never
|
||||
? TPossiblyParam | TAcc
|
||||
: TPossiblyParam extends `${infer TParam}/${infer TRest}`
|
||||
? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc>
|
||||
: never
|
||||
: TAcc
|
||||
|
||||
export type AddTrailingSlash<T> = T extends `${string}/` ? T : `${T & string}/`
|
||||
|
||||
export type RemoveTrailingSlashes<T> = T & `${string}/` extends never
|
||||
? T
|
||||
: T extends `${infer R}/`
|
||||
? R
|
||||
: T
|
||||
|
||||
export type AddLeadingSlash<T> = T & `/${string}` extends never
|
||||
? `/${T & string}`
|
||||
: T
|
||||
|
||||
export type RemoveLeadingSlashes<T> = T & `/${string}` extends never
|
||||
? T
|
||||
: T extends `/${infer R}`
|
||||
? R
|
||||
: T
|
||||
|
||||
type JoinPath<TLeft extends string, TRight extends string> = TRight extends ''
|
||||
? TLeft
|
||||
: TLeft extends ''
|
||||
? TRight
|
||||
: `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`
|
||||
|
||||
type RemoveLastSegment<
|
||||
T extends string,
|
||||
TAcc extends string = '',
|
||||
> = T extends `${infer TSegment}/${infer TRest}`
|
||||
? TRest & `${string}/${string}` extends never
|
||||
? TRest extends ''
|
||||
? TAcc
|
||||
: `${TAcc}${TSegment}`
|
||||
: RemoveLastSegment<TRest, `${TAcc}${TSegment}/`>
|
||||
: TAcc
|
||||
|
||||
export type ResolveCurrentPath<
|
||||
TFrom extends string,
|
||||
TTo extends string,
|
||||
> = TTo extends '.'
|
||||
? TFrom
|
||||
: TTo extends './'
|
||||
? AddTrailingSlash<TFrom>
|
||||
: TTo & `./${string}` extends never
|
||||
? never
|
||||
: TTo extends `./${infer TRest}`
|
||||
? AddLeadingSlash<JoinPath<TFrom, TRest>>
|
||||
: never
|
||||
|
||||
export type ResolveParentPath<
|
||||
TFrom extends string,
|
||||
TTo extends string,
|
||||
> = TTo extends '../' | '..'
|
||||
? TFrom extends '' | '/'
|
||||
? never
|
||||
: AddLeadingSlash<RemoveLastSegment<TFrom>>
|
||||
: TTo & `../${string}` extends never
|
||||
? AddLeadingSlash<JoinPath<TFrom, TTo>>
|
||||
: TFrom extends '' | '/'
|
||||
? never
|
||||
: TTo extends `../${infer ToRest}`
|
||||
? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest>
|
||||
: AddLeadingSlash<JoinPath<TFrom, TTo>>
|
||||
|
||||
export type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom
|
||||
? TTo
|
||||
: string extends TTo
|
||||
? TFrom
|
||||
: undefined extends TTo
|
||||
? TFrom
|
||||
: TTo extends string
|
||||
? TFrom extends string
|
||||
? TTo extends `/${string}`
|
||||
? TTo
|
||||
: TTo extends `..${string}`
|
||||
? ResolveParentPath<TFrom, TTo>
|
||||
: TTo extends `.${string}`
|
||||
? ResolveCurrentPath<TFrom, TTo>
|
||||
: AddLeadingSlash<JoinPath<TFrom, TTo>>
|
||||
: never
|
||||
: never
|
||||
|
||||
export type FindDescendantToPaths<
|
||||
TRouter extends AnyRouter,
|
||||
TPrefix extends string,
|
||||
> = `${TPrefix}/${string}` & RouteToPath<TRouter>
|
||||
|
||||
export type InferDescendantToPaths<
|
||||
TRouter extends AnyRouter,
|
||||
TPrefix extends string,
|
||||
TPaths = FindDescendantToPaths<TRouter, TPrefix>,
|
||||
> = TPaths extends `${TPrefix}/`
|
||||
? never
|
||||
: TPaths extends `${TPrefix}/${infer TRest}`
|
||||
? TRest
|
||||
: never
|
||||
|
||||
export type RelativeToPath<
|
||||
TRouter extends AnyRouter,
|
||||
TTo extends string,
|
||||
TResolvedPath extends string,
|
||||
> =
|
||||
| (TResolvedPath & RouteToPath<TRouter> extends never
|
||||
? never
|
||||
: ToPath<TRouter, TTo>)
|
||||
| `${RemoveTrailingSlashes<TTo>}/${InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TResolvedPath>>}`
|
||||
|
||||
export type RelativeToParentPath<
|
||||
TRouter extends AnyRouter,
|
||||
TFrom extends string,
|
||||
TTo extends string,
|
||||
TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,
|
||||
> =
|
||||
| RelativeToPath<TRouter, TTo, TResolvedPath>
|
||||
| (TTo extends `${string}..` | `${string}../`
|
||||
? TResolvedPath extends '/' | ''
|
||||
? never
|
||||
: FindDescendantToPaths<
|
||||
TRouter,
|
||||
RemoveTrailingSlashes<TResolvedPath>
|
||||
> extends never
|
||||
? never
|
||||
: `${RemoveTrailingSlashes<TTo>}/${ParentPath<TRouter>}`
|
||||
: never)
|
||||
|
||||
export type RelativeToCurrentPath<
|
||||
TRouter extends AnyRouter,
|
||||
TFrom extends string,
|
||||
TTo extends string,
|
||||
TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,
|
||||
> = RelativeToPath<TRouter, TTo, TResolvedPath> | CurrentPath<TRouter>
|
||||
|
||||
export type AbsoluteToPath<TRouter extends AnyRouter, TFrom extends string> =
|
||||
| (string extends TFrom
|
||||
? CurrentPath<TRouter>
|
||||
: TFrom extends `/`
|
||||
? never
|
||||
: CurrentPath<TRouter>)
|
||||
| (string extends TFrom
|
||||
? ParentPath<TRouter>
|
||||
: TFrom extends `/`
|
||||
? never
|
||||
: ParentPath<TRouter>)
|
||||
| RouteToPath<TRouter>
|
||||
| (TFrom extends '/'
|
||||
? never
|
||||
: string extends TFrom
|
||||
? never
|
||||
: InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TFrom>>)
|
||||
|
||||
export type RelativeToPathAutoComplete<
|
||||
TRouter extends AnyRouter,
|
||||
TFrom extends string,
|
||||
TTo extends string,
|
||||
> = string extends TTo
|
||||
? string
|
||||
: string extends TFrom
|
||||
? AbsoluteToPath<TRouter, TFrom>
|
||||
: TTo & `..${string}` extends never
|
||||
? TTo & `.${string}` extends never
|
||||
? AbsoluteToPath<TRouter, TFrom>
|
||||
: RelativeToCurrentPath<TRouter, TFrom, TTo>
|
||||
: RelativeToParentPath<TRouter, TFrom, TTo>
|
||||
|
||||
export type NavigateOptions<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TFrom extends string = string,
|
||||
TTo extends string | undefined = '.',
|
||||
TMaskFrom extends string = TFrom,
|
||||
TMaskTo extends string = '.',
|
||||
> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps
|
||||
|
||||
/**
|
||||
* The NavigateOptions type is used to describe the options that can be used when describing a navigation action in TanStack Router.
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType)
|
||||
*/
|
||||
export interface NavigateOptionProps {
|
||||
/**
|
||||
* If set to `true`, the router will scroll the element with an id matching the hash into view with default `ScrollIntoViewOptions`.
|
||||
* If set to `false`, the router will not scroll the element with an id matching the hash into view.
|
||||
* If set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options.
|
||||
* @default true
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#hashscrollintoview)
|
||||
* @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)
|
||||
*/
|
||||
hashScrollIntoView?: boolean | ScrollIntoViewOptions
|
||||
/**
|
||||
* `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.
|
||||
* @default false
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#replace)
|
||||
*/
|
||||
replace?: boolean
|
||||
/**
|
||||
* Defaults to `true` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.
|
||||
* If `false`, the scroll position will not be reset to 0,0 after the location is committed to history.
|
||||
* @default true
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#resetscroll)
|
||||
*/
|
||||
resetScroll?: boolean
|
||||
/** @deprecated All navigations now use startTransition under the hood */
|
||||
startTransition?: boolean
|
||||
/**
|
||||
* If set to `true`, the router will wrap the resulting navigation in a `document.startViewTransition()` call.
|
||||
* If `ViewTransitionOptions`, route navigations will be called using `document.startViewTransition({update, types})`
|
||||
* where `types` will be the strings array passed with `ViewTransitionOptions["types"]`.
|
||||
* If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.
|
||||
*
|
||||
* If the browser does not support this api, this option will be ignored.
|
||||
* @default false
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition)
|
||||
* @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition)
|
||||
* @see [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types)
|
||||
*/
|
||||
viewTransition?: boolean | ViewTransitionOptions
|
||||
/**
|
||||
* If `true`, navigation will ignore any blockers that might prevent it.
|
||||
* @default false
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#ignoreblocker)
|
||||
*/
|
||||
ignoreBlocker?: boolean
|
||||
/**
|
||||
* If `true`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation.
|
||||
* @default false
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#reloaddocument)
|
||||
*/
|
||||
reloadDocument?: boolean
|
||||
/**
|
||||
* This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target.
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)
|
||||
*/
|
||||
href?: string
|
||||
}
|
||||
|
||||
export type ToOptions<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TFrom extends string = string,
|
||||
TTo extends string | undefined = '.',
|
||||
TMaskFrom extends string = TFrom,
|
||||
TMaskTo extends string = '.',
|
||||
> = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>
|
||||
|
||||
export interface MaskOptions<
|
||||
in out TRouter extends AnyRouter,
|
||||
in out TMaskFrom extends string,
|
||||
in out TMaskTo extends string,
|
||||
> {
|
||||
_fromLocation?: ParsedLocation
|
||||
mask?: ToMaskOptions<TRouter, TMaskFrom, TMaskTo>
|
||||
}
|
||||
|
||||
export type ToMaskOptions<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TMaskFrom extends string = string,
|
||||
TMaskTo extends string = '.',
|
||||
> = ToSubOptions<TRouter, TMaskFrom, TMaskTo> & {
|
||||
unmaskOnReload?: boolean
|
||||
}
|
||||
|
||||
export type ToSubOptions<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TFrom extends string = string,
|
||||
TTo extends string | undefined = '.',
|
||||
> = ToSubOptionsProps<TRouter, TFrom, TTo> &
|
||||
SearchParamOptions<TRouter, TFrom, TTo> &
|
||||
PathParamOptions<TRouter, TFrom, TTo>
|
||||
|
||||
export interface RequiredToOptions<
|
||||
in out TRouter extends AnyRouter,
|
||||
in out TFrom extends string,
|
||||
in out TTo extends string | undefined,
|
||||
> {
|
||||
to: ToPathOption<TRouter, TFrom, TTo> & {}
|
||||
}
|
||||
|
||||
export interface OptionalToOptions<
|
||||
in out TRouter extends AnyRouter,
|
||||
in out TFrom extends string,
|
||||
in out TTo extends string | undefined,
|
||||
> {
|
||||
to?: ToPathOption<TRouter, TFrom, TTo> & {}
|
||||
}
|
||||
|
||||
export type MakeToRequired<
|
||||
TRouter extends AnyRouter,
|
||||
TFrom extends string,
|
||||
TTo extends string | undefined,
|
||||
> = string extends TFrom
|
||||
? string extends TTo
|
||||
? OptionalToOptions<TRouter, TFrom, TTo>
|
||||
: TTo & CatchAllPaths<TRouter> extends never
|
||||
? RequiredToOptions<TRouter, TFrom, TTo>
|
||||
: OptionalToOptions<TRouter, TFrom, TTo>
|
||||
: OptionalToOptions<TRouter, TFrom, TTo>
|
||||
|
||||
export type ToSubOptionsProps<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
||||
TTo extends string | undefined = '.',
|
||||
> = MakeToRequired<TRouter, TFrom, TTo> & {
|
||||
hash?: true | Updater<string>
|
||||
state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>
|
||||
from?: FromPathOption<TRouter, TFrom> & {}
|
||||
}
|
||||
|
||||
export type ParamsReducerFn<
|
||||
in out TRouter extends AnyRouter,
|
||||
in out TParamVariant extends ParamVariant,
|
||||
in out TFrom,
|
||||
in out TTo,
|
||||
> = (
|
||||
current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,
|
||||
) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
|
||||
|
||||
type ParamsReducer<
|
||||
TRouter extends AnyRouter,
|
||||
TParamVariant extends ParamVariant,
|
||||
TFrom,
|
||||
TTo,
|
||||
> =
|
||||
| Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
|
||||
| (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {})
|
||||
|
||||
type ParamVariant = 'PATH' | 'SEARCH'
|
||||
|
||||
export type ResolveRoute<
|
||||
TRouter extends AnyRouter,
|
||||
TFrom,
|
||||
TTo,
|
||||
TPath = ResolveRelativePath<TFrom, TTo>,
|
||||
> = TPath extends string
|
||||
? TFrom extends TPath
|
||||
? RouteByPath<TRouter['routeTree'], TPath>
|
||||
: RouteByToPath<TRouter, TPath>
|
||||
: never
|
||||
|
||||
type ResolveFromParamType<TParamVariant extends ParamVariant> =
|
||||
TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'
|
||||
|
||||
type ResolveFromAllParams<
|
||||
TRouter extends AnyRouter,
|
||||
TParamVariant extends ParamVariant,
|
||||
> = TParamVariant extends 'PATH'
|
||||
? AllParams<TRouter['routeTree']>
|
||||
: FullSearchSchema<TRouter['routeTree']>
|
||||
|
||||
type ResolveFromParams<
|
||||
TRouter extends AnyRouter,
|
||||
TParamVariant extends ParamVariant,
|
||||
TFrom,
|
||||
> = string extends TFrom
|
||||
? ResolveFromAllParams<TRouter, TParamVariant>
|
||||
: RouteByPath<
|
||||
TRouter['routeTree'],
|
||||
TFrom
|
||||
>['types'][ResolveFromParamType<TParamVariant>]
|
||||
|
||||
type ResolveToParamType<TParamVariant extends ParamVariant> =
|
||||
TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput'
|
||||
|
||||
type ResolveAllToParams<
|
||||
TRouter extends AnyRouter,
|
||||
TParamVariant extends ParamVariant,
|
||||
> = TParamVariant extends 'PATH'
|
||||
? AllParams<TRouter['routeTree']>
|
||||
: FullSearchSchemaInput<TRouter['routeTree']>
|
||||
|
||||
export type ResolveToParams<
|
||||
TRouter extends AnyRouter,
|
||||
TParamVariant extends ParamVariant,
|
||||
TFrom,
|
||||
TTo,
|
||||
> =
|
||||
ResolveRelativePath<TFrom, TTo> extends infer TPath
|
||||
? undefined extends TPath
|
||||
? never
|
||||
: string extends TPath
|
||||
? ResolveAllToParams<TRouter, TParamVariant>
|
||||
: TPath extends CatchAllPaths<TRouter>
|
||||
? ResolveAllToParams<TRouter, TParamVariant>
|
||||
: ResolveRoute<
|
||||
TRouter,
|
||||
TFrom,
|
||||
TTo
|
||||
>['types'][ResolveToParamType<TParamVariant>]
|
||||
: never
|
||||
|
||||
type ResolveRelativeToParams<
|
||||
TRouter extends AnyRouter,
|
||||
TParamVariant extends ParamVariant,
|
||||
TFrom,
|
||||
TTo,
|
||||
TToParams = ResolveToParams<TRouter, TParamVariant, TFrom, TTo>,
|
||||
> = TParamVariant extends 'SEARCH'
|
||||
? TToParams
|
||||
: string extends TFrom
|
||||
? TToParams
|
||||
: MakeDifferenceOptional<
|
||||
ResolveFromParams<TRouter, TParamVariant, TFrom>,
|
||||
TToParams
|
||||
>
|
||||
|
||||
export interface MakeOptionalSearchParams<
|
||||
in out TRouter extends AnyRouter,
|
||||
in out TFrom,
|
||||
in out TTo,
|
||||
> {
|
||||
search?: true | (ParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {})
|
||||
}
|
||||
|
||||
export interface MakeOptionalPathParams<
|
||||
in out TRouter extends AnyRouter,
|
||||
in out TFrom,
|
||||
in out TTo,
|
||||
> {
|
||||
params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> & {})
|
||||
}
|
||||
|
||||
type MakeRequiredParamsReducer<
|
||||
TRouter extends AnyRouter,
|
||||
TParamVariant extends ParamVariant,
|
||||
TFrom,
|
||||
TTo,
|
||||
> =
|
||||
| (string extends TFrom
|
||||
? never
|
||||
: ResolveFromParams<TRouter, TParamVariant, TFrom> extends WithoutEmpty<
|
||||
PickRequired<
|
||||
ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>
|
||||
>
|
||||
>
|
||||
? true
|
||||
: never)
|
||||
| (ParamsReducer<TRouter, TParamVariant, TFrom, TTo> & {})
|
||||
|
||||
export interface MakeRequiredPathParams<
|
||||
in out TRouter extends AnyRouter,
|
||||
in out TFrom,
|
||||
in out TTo,
|
||||
> {
|
||||
params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {}
|
||||
}
|
||||
|
||||
export interface MakeRequiredSearchParams<
|
||||
in out TRouter extends AnyRouter,
|
||||
in out TFrom,
|
||||
in out TTo,
|
||||
> {
|
||||
search: MakeRequiredParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {}
|
||||
}
|
||||
|
||||
export type IsRequired<
|
||||
TRouter extends AnyRouter,
|
||||
TParamVariant extends ParamVariant,
|
||||
TFrom,
|
||||
TTo,
|
||||
> =
|
||||
ResolveRelativePath<TFrom, TTo> extends infer TPath
|
||||
? undefined extends TPath
|
||||
? never
|
||||
: TPath extends CatchAllPaths<TRouter>
|
||||
? never
|
||||
: IsRequiredParams<
|
||||
ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>
|
||||
>
|
||||
: never
|
||||
|
||||
export type SearchParamOptions<TRouter extends AnyRouter, TFrom, TTo> =
|
||||
IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never
|
||||
? MakeOptionalSearchParams<TRouter, TFrom, TTo>
|
||||
: MakeRequiredSearchParams<TRouter, TFrom, TTo>
|
||||
|
||||
export type PathParamOptions<TRouter extends AnyRouter, TFrom, TTo> =
|
||||
IsRequired<TRouter, 'PATH', TFrom, TTo> extends never
|
||||
? MakeOptionalPathParams<TRouter, TFrom, TTo>
|
||||
: MakeRequiredPathParams<TRouter, TFrom, TTo>
|
||||
|
||||
export type ToPathOption<
|
||||
TRouter extends AnyRouter = AnyRouter,
|
||||
TFrom extends string = string,
|
||||
TTo extends string | undefined = string,
|
||||
> = ConstrainLiteral<
|
||||
TTo,
|
||||
RelativeToPathAutoComplete<
|
||||
TRouter,
|
||||
NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',
|
||||
NoInfer<TTo> & string
|
||||
>
|
||||
>
|
||||
|
||||
export type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<
|
||||
TFrom,
|
||||
RoutePaths<TRouter['routeTree']>
|
||||
>
|
||||
|
||||
/**
|
||||
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/navigation#active-options)
|
||||
*/
|
||||
export interface ActiveOptions {
|
||||
/**
|
||||
* If true, the link will be active if the current route matches the `to` route path exactly (no children routes)
|
||||
* @default false
|
||||
*/
|
||||
exact?: boolean
|
||||
/**
|
||||
* If true, the link will only be active if the current URL hash matches the `hash` prop
|
||||
* @default false
|
||||
*/
|
||||
includeHash?: boolean
|
||||
/**
|
||||
* If true, the link will only be active if the current URL search params inclusively match the `search` prop
|
||||
* @default true
|
||||
*/
|
||||
includeSearch?: boolean
|
||||
/**
|
||||
* This modifies the `includeSearch` behavior.
|
||||
* If true, properties in `search` that are explicitly `undefined` must NOT be present in the current URL search params for the link to be active.
|
||||
* @default false
|
||||
*/
|
||||
explicitUndefined?: boolean
|
||||
}
|
||||
|
||||
export interface LinkOptionsProps {
|
||||
/**
|
||||
* The standard anchor tag target attribute
|
||||
*/
|
||||
target?: HTMLAnchorElement['target']
|
||||
/**
|
||||
* Configurable options to determine if the link should be considered active or not
|
||||
* @default {exact:true,includeHash:true}
|
||||
*/
|
||||
activeOptions?: ActiveOptions
|
||||
/**
|
||||
* The preloading strategy for this link
|
||||
* - `false` - No preloading
|
||||
* - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.
|
||||
* - `'viewport'` - Preload the linked route when it enters the viewport
|
||||
*/
|
||||
preload?: false | 'intent' | 'viewport' | 'render'
|
||||
/**
|
||||
* When a preload strategy is set, this delays the preload by this many milliseconds.
|
||||
* If the user exits the link before this delay, the preload will be cancelled.
|
||||
*/
|
||||
preloadDelay?: number
|
||||
/**
|
||||
* Control whether the link should be disabled or not
|
||||
* If set to `true`, the link will be rendered without an `href` attribute
|
||||
* @default false
|
||||
*/
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
export type LinkOptions<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TFrom extends string = string,
|
||||
TTo extends string | undefined = '.',
|
||||
TMaskFrom extends string = TFrom,
|
||||
TMaskTo extends string = '.',
|
||||
> = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkOptionsProps
|
||||
|
||||
export type LinkCurrentTargetElement = {
|
||||
preloadTimeout?: null | ReturnType<typeof setTimeout>
|
||||
}
|
||||
|
||||
export const preloadWarning = 'Error preloading route! ☝️'
|
||||
Reference in New Issue
Block a user