@flamework-experimental/transformer 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -0
- package/flamework-schema.json +76 -0
- package/flamework.config.schema.json +197 -0
- package/out/classes/buildInfo.js +467 -0
- package/out/classes/diagnostics.js +110 -0
- package/out/classes/logger.js +201 -0
- package/out/classes/nodeMetadata.js +232 -0
- package/out/classes/transformState.js +623 -0
- package/out/index.js +75 -0
- package/out/transformations/expressions/transformAccessExpression.js +35 -0
- package/out/transformations/expressions/transformBinaryExpression.js +57 -0
- package/out/transformations/expressions/transformCallExpression.js +33 -0
- package/out/transformations/expressions/transformDeleteExpression.js +22 -0
- package/out/transformations/expressions/transformNewExpression.js +17 -0
- package/out/transformations/expressions/transformUnaryExpression.js +63 -0
- package/out/transformations/macros/intrinsics/components.js +64 -0
- package/out/transformations/macros/intrinsics/env.js +31 -0
- package/out/transformations/macros/intrinsics/guards.js +43 -0
- package/out/transformations/macros/intrinsics/inlining.js +22 -0
- package/out/transformations/macros/intrinsics/networking.js +131 -0
- package/out/transformations/macros/intrinsics/parameters.js +81 -0
- package/out/transformations/macros/intrinsics/paths.js +42 -0
- package/out/transformations/macros/updateComponentConfig.js +409 -0
- package/out/transformations/plugins/nodeFactory.js +159 -0
- package/out/transformations/plugins/pluginHost.js +235 -0
- package/out/transformations/plugins/typeFacade.js +242 -0
- package/out/transformations/statements/transformClassDeclaration.js +282 -0
- package/out/transformations/transformExpression.js +34 -0
- package/out/transformations/transformFile.js +78 -0
- package/out/transformations/transformNetworkingCall.js +566 -0
- package/out/transformations/transformNode.js +27 -0
- package/out/transformations/transformStatement.js +57 -0
- package/out/transformations/transformStatementList.js +64 -0
- package/out/transformations/transformUserMacro.js +698 -0
- package/out/transformer.js +52 -0
- package/out/util/cache.js +10 -0
- package/out/util/constants.js +5 -0
- package/out/util/diagnosticsUtils.js +112 -0
- package/out/util/env.js +267 -0
- package/out/util/factory.js +583 -0
- package/out/util/functions/addLeadingComment.js +13 -0
- package/out/util/functions/arePathsEqual.js +14 -0
- package/out/util/functions/assert.js +17 -0
- package/out/util/functions/buildGuardFromType.js +713 -0
- package/out/util/functions/buildInstanceShape.js +156 -0
- package/out/util/functions/buildSerializerFromType.js +2309 -0
- package/out/util/functions/createPathTranslator.js +54 -0
- package/out/util/functions/emitTypescriptMismatch.js +80 -0
- package/out/util/functions/getDeclarationName.js +23 -0
- package/out/util/functions/getDeclarationOfType.js +7 -0
- package/out/util/functions/getIndexExpression.js +16 -0
- package/out/util/functions/getInstanceTypeFromType.js +75 -0
- package/out/util/functions/getNodeList.js +6 -0
- package/out/util/functions/getPackageJson.js +44 -0
- package/out/util/functions/getSuperClasses.js +51 -0
- package/out/util/functions/isAttributesAccess.js +23 -0
- package/out/util/functions/isCleanBuildDirectory.js +13 -0
- package/out/util/functions/isDefinedType.js +16 -0
- package/out/util/functions/isPathDescendantOf.js +25 -0
- package/out/util/functions/isTupleType.js +10 -0
- package/out/util/functions/parseCommandLine.js +31 -0
- package/out/util/functions/shuffle.js +39 -0
- package/out/util/functions/tryResolve.js +15 -0
- package/out/util/functions/validateConstraintMetadata.js +60 -0
- package/out/util/packages.js +12 -0
- package/out/util/projectConfig.js +221 -0
- package/out/util/schema.js +80 -0
- package/out/util/tsInternals.js +16 -0
- package/out/util/uid.js +227 -0
- package/package.json +45 -0
- package/rojo-schema.json +34 -0
- package/types.d.ts +4 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = default_1;
|
|
7
|
+
// internals declared locally in src/types/tsInternals.d.ts
|
|
8
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
var path_1 = __importDefault(require("path"));
|
|
10
|
+
var transformFile_1 = require("./transformations/transformFile");
|
|
11
|
+
var transformState_1 = require("./classes/transformState");
|
|
12
|
+
var logger_1 = require("./classes/logger");
|
|
13
|
+
var factory_1 = require("./util/factory");
|
|
14
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
15
|
+
var emitTypescriptMismatch_1 = require("./util/functions/emitTypescriptMismatch");
|
|
16
|
+
var constants_1 = require("./util/constants");
|
|
17
|
+
function default_1(program, config) {
|
|
18
|
+
return function (context) {
|
|
19
|
+
if (logger_1.Logger.verbose)
|
|
20
|
+
logger_1.Logger.write("\n");
|
|
21
|
+
factory_1.f.setFactory(context.factory);
|
|
22
|
+
var state = new transformState_1.TransformState(program, context, config !== null && config !== void 0 ? config : {});
|
|
23
|
+
var projectFlameworkVersion = state.buildInfo.getFlameworkVersion();
|
|
24
|
+
if (projectFlameworkVersion !== constants_1.PKG_VERSION) {
|
|
25
|
+
logger_1.Logger.writeLine("".concat(chalk_1.default.red("Project was compiled on different version of Flamework.")), "Please recompile by deleting the ".concat(path_1.default.relative(state.currentDirectory, state.outDir), " directory"), "Current Flamework Version: ".concat(chalk_1.default.yellow(constants_1.PKG_VERSION)), "Previous Flamework Version: ".concat(chalk_1.default.yellow(projectFlameworkVersion)));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
setTimeout(function () { return state.saveArtifacts(); });
|
|
29
|
+
return function (file) {
|
|
30
|
+
if (!typescript_1.default.isSourceFile(file)) {
|
|
31
|
+
(0, emitTypescriptMismatch_1.emitTypescriptMismatch)(state, chalk_1.default.red("Failed to load! TS version mismatch detected"));
|
|
32
|
+
}
|
|
33
|
+
if (state.config.noSemanticDiagnostics !== true) {
|
|
34
|
+
var originalFile = typescript_1.default.getParseTreeNode(file, typescript_1.default.isSourceFile);
|
|
35
|
+
if (originalFile) {
|
|
36
|
+
var preEmitDiagnostics = typescript_1.default.getPreEmitDiagnostics(program, originalFile);
|
|
37
|
+
if (preEmitDiagnostics.some(function (x) { return x.category === typescript_1.default.DiagnosticCategory.Error; })) {
|
|
38
|
+
preEmitDiagnostics
|
|
39
|
+
.filter(typescript_1.default.isDiagnosticWithLocation)
|
|
40
|
+
.forEach(function (diag) { return context.addDiagnostic(diag); });
|
|
41
|
+
return file;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
var relativeName = path_1.default.relative(state.srcDir, file.fileName);
|
|
46
|
+
logger_1.Logger.warn("Failed to validate '".concat(relativeName, "' due to lack of parse tree node."));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return (0, transformFile_1.transformFile)(state, file);
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
var __values = (this && this.__values) || function(o) {
|
|
28
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
+
if (m) return m.call(o);
|
|
30
|
+
if (o && typeof o.length === "number") return {
|
|
31
|
+
next: function () {
|
|
32
|
+
if (o && i >= o.length) o = void 0;
|
|
33
|
+
return { value: o && o[i++], done: !o };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.captureDiagnostic = captureDiagnostic;
|
|
43
|
+
exports.relocateDiagnostic = relocateDiagnostic;
|
|
44
|
+
exports.catchDiagnostic = catchDiagnostic;
|
|
45
|
+
exports.withDiagnosticContext = withDiagnosticContext;
|
|
46
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
47
|
+
var diagnostics_1 = require("../classes/diagnostics");
|
|
48
|
+
function captureDiagnostic(cb) {
|
|
49
|
+
var args = [];
|
|
50
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
51
|
+
args[_i - 1] = arguments[_i];
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return { success: true, value: cb.apply(void 0, __spreadArray([], __read(args), false)) };
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if ("diagnostic" in e) {
|
|
58
|
+
/// Temporary workaround for 1.1.1
|
|
59
|
+
if (typescript_1.default.version.startsWith("1.1.1") &&
|
|
60
|
+
!typescript_1.default.version.startsWith("1.1.1-dev") &&
|
|
61
|
+
!globalThis.RBXTSC_DEV) {
|
|
62
|
+
e.diagnostic = undefined;
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
return { success: false, diagnostic: e.diagnostic };
|
|
66
|
+
}
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function relocateDiagnostic(node, cb) {
|
|
71
|
+
var params = [];
|
|
72
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
73
|
+
params[_i - 2] = arguments[_i];
|
|
74
|
+
}
|
|
75
|
+
var result = captureDiagnostic.apply(void 0, __spreadArray([cb], __read(params), false));
|
|
76
|
+
if (result.success) {
|
|
77
|
+
return result.value;
|
|
78
|
+
}
|
|
79
|
+
diagnostics_1.Diagnostics.relocate(result.diagnostic, node);
|
|
80
|
+
}
|
|
81
|
+
function catchDiagnostic(fallback, cb) {
|
|
82
|
+
var _a;
|
|
83
|
+
var result = captureDiagnostic(cb);
|
|
84
|
+
if (!result.success) {
|
|
85
|
+
diagnostics_1.Diagnostics.addDiagnostic(result.diagnostic);
|
|
86
|
+
}
|
|
87
|
+
return (_a = result.value) !== null && _a !== void 0 ? _a : fallback;
|
|
88
|
+
}
|
|
89
|
+
function withDiagnosticContext(node, message, callback) {
|
|
90
|
+
var e_1, _a;
|
|
91
|
+
var _b;
|
|
92
|
+
var result = captureDiagnostic(callback);
|
|
93
|
+
if (!result.success) {
|
|
94
|
+
var newDiagnostic = diagnostics_1.Diagnostics.createDiagnostic(node, typescript_1.default.DiagnosticCategory.Error, typeof message === "string" ? message : message());
|
|
95
|
+
typescript_1.default.addRelatedInfo(newDiagnostic, result.diagnostic);
|
|
96
|
+
try {
|
|
97
|
+
for (var _c = __values((_b = result.diagnostic.relatedInformation) !== null && _b !== void 0 ? _b : []), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
98
|
+
var relatedInfo = _d.value;
|
|
99
|
+
typescript_1.default.addRelatedInfo(newDiagnostic, relatedInfo);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
103
|
+
finally {
|
|
104
|
+
try {
|
|
105
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
106
|
+
}
|
|
107
|
+
finally { if (e_1) throw e_1.error; }
|
|
108
|
+
}
|
|
109
|
+
throw new diagnostics_1.DiagnosticError(newDiagnostic);
|
|
110
|
+
}
|
|
111
|
+
return result.value;
|
|
112
|
+
}
|
package/out/util/env.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.ENV_FILES = void 0;
|
|
34
|
+
exports.parseEnvFile = parseEnvFile;
|
|
35
|
+
exports.loadEnv = loadEnv;
|
|
36
|
+
exports.substituteEnv = substituteEnv;
|
|
37
|
+
exports.coerceBySchema = coerceBySchema;
|
|
38
|
+
var fs_1 = __importDefault(require("fs"));
|
|
39
|
+
var path_1 = __importDefault(require("path"));
|
|
40
|
+
/** The files read next to `flamework.config.json`, in order; a later file overrides an earlier one. */
|
|
41
|
+
exports.ENV_FILES = [".env", ".env.local"];
|
|
42
|
+
/**
|
|
43
|
+
* Parses a dotenv file: one `KEY=value` per line, an optional `export ` prefix, `#` comments and
|
|
44
|
+
* blank lines. A value in double quotes honours `\n`, `\t`, `\r`, `\\` and `\"`; one in single
|
|
45
|
+
* quotes is taken as written; an unquoted value is trimmed and ends at a ` #` comment.
|
|
46
|
+
*/
|
|
47
|
+
function parseEnvFile(text) {
|
|
48
|
+
var e_1, _a;
|
|
49
|
+
var result = {};
|
|
50
|
+
try {
|
|
51
|
+
for (var _b = __values(text.split(/\r?\n/)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
52
|
+
var rawLine = _c.value;
|
|
53
|
+
var line = rawLine.trim();
|
|
54
|
+
if (line === "" || line.startsWith("#")) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
var match = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
|
|
58
|
+
if (!match) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
var _d = __read(match, 3), key = _d[1], rest = _d[2];
|
|
62
|
+
result[key] = parseEnvValue(rest);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
66
|
+
finally {
|
|
67
|
+
try {
|
|
68
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
69
|
+
}
|
|
70
|
+
finally { if (e_1) throw e_1.error; }
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
function parseEnvValue(rest) {
|
|
75
|
+
var quote = rest[0];
|
|
76
|
+
if (quote === '"' || quote === "'") {
|
|
77
|
+
var value = "";
|
|
78
|
+
for (var i = 1; i < rest.length; i++) {
|
|
79
|
+
var char = rest[i];
|
|
80
|
+
if (char === quote) {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
if (quote === '"' && char === "\\" && i + 1 < rest.length) {
|
|
84
|
+
var next = rest[++i];
|
|
85
|
+
value += next === "n" ? "\n" : next === "t" ? "\t" : next === "r" ? "\r" : next;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
value += char;
|
|
89
|
+
}
|
|
90
|
+
// No closing quote: the rest of the line is the value, quote included, as dotenv does.
|
|
91
|
+
return rest;
|
|
92
|
+
}
|
|
93
|
+
var comment = rest.search(/\s#/);
|
|
94
|
+
return (comment === -1 ? rest : rest.slice(0, comment)).trim();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The environment a config file is substituted from: `.env`, then `.env.local` on top, both from
|
|
98
|
+
* the given directory, with the process environment on top of both.
|
|
99
|
+
*/
|
|
100
|
+
function loadEnv(directory, processEnv) {
|
|
101
|
+
var e_2, _a, e_3, _b;
|
|
102
|
+
if (processEnv === void 0) { processEnv = process.env; }
|
|
103
|
+
var env = {};
|
|
104
|
+
try {
|
|
105
|
+
for (var ENV_FILES_1 = __values(exports.ENV_FILES), ENV_FILES_1_1 = ENV_FILES_1.next(); !ENV_FILES_1_1.done; ENV_FILES_1_1 = ENV_FILES_1.next()) {
|
|
106
|
+
var file = ENV_FILES_1_1.value;
|
|
107
|
+
var envPath = path_1.default.join(directory, file);
|
|
108
|
+
if (fs_1.default.existsSync(envPath)) {
|
|
109
|
+
Object.assign(env, parseEnvFile(fs_1.default.readFileSync(envPath, "utf8")));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
114
|
+
finally {
|
|
115
|
+
try {
|
|
116
|
+
if (ENV_FILES_1_1 && !ENV_FILES_1_1.done && (_a = ENV_FILES_1.return)) _a.call(ENV_FILES_1);
|
|
117
|
+
}
|
|
118
|
+
finally { if (e_2) throw e_2.error; }
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
for (var _c = __values(Object.entries(processEnv)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
122
|
+
var _e = __read(_d.value, 2), key = _e[0], value = _e[1];
|
|
123
|
+
if (value !== undefined) {
|
|
124
|
+
env[key] = value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
129
|
+
finally {
|
|
130
|
+
try {
|
|
131
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
132
|
+
}
|
|
133
|
+
finally { if (e_3) throw e_3.error; }
|
|
134
|
+
}
|
|
135
|
+
return env;
|
|
136
|
+
}
|
|
137
|
+
var PLACEHOLDER = /\$\$|\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
|
|
138
|
+
/**
|
|
139
|
+
* Replaces `${NAME}` and `${NAME:-fallback}` in every string of a parsed config with the variable's
|
|
140
|
+
* value, and `$$` with a literal dollar. Keys are left alone.
|
|
141
|
+
*
|
|
142
|
+
* A variable that is not set and has no fallback raises, naming the variable and where it was used.
|
|
143
|
+
*/
|
|
144
|
+
function substituteEnv(value, env, describe) {
|
|
145
|
+
var substituted = new Set();
|
|
146
|
+
var visit = function (current, pointer) {
|
|
147
|
+
var e_4, _a;
|
|
148
|
+
if (typeof current === "string") {
|
|
149
|
+
// `replace` with a global pattern starts from the beginning every time; `test` would not.
|
|
150
|
+
var matched_1 = false;
|
|
151
|
+
var replaced = current.replace(PLACEHOLDER, function (match, name, fallback) {
|
|
152
|
+
matched_1 = true;
|
|
153
|
+
if (match === "$$") {
|
|
154
|
+
return "$";
|
|
155
|
+
}
|
|
156
|
+
var found = env[name];
|
|
157
|
+
if (found !== undefined) {
|
|
158
|
+
return found;
|
|
159
|
+
}
|
|
160
|
+
if (fallback !== undefined) {
|
|
161
|
+
return fallback;
|
|
162
|
+
}
|
|
163
|
+
throw new Error("".concat(describe(pointer), " uses $").concat(name, ", which is not set in the environment, .env or .env.local ") +
|
|
164
|
+
"and has no fallback. Set it, or write ${".concat(name, ":-value} to give it one."));
|
|
165
|
+
});
|
|
166
|
+
if (matched_1) {
|
|
167
|
+
substituted.add(pointer);
|
|
168
|
+
}
|
|
169
|
+
return replaced;
|
|
170
|
+
}
|
|
171
|
+
if (Array.isArray(current)) {
|
|
172
|
+
return current.map(function (item, index) { return visit(item, "".concat(pointer, "/").concat(index)); });
|
|
173
|
+
}
|
|
174
|
+
if (current !== null && typeof current === "object") {
|
|
175
|
+
var result = {};
|
|
176
|
+
try {
|
|
177
|
+
for (var _b = __values(Object.entries(current)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
178
|
+
var _d = __read(_c.value, 2), key = _d[0], item = _d[1];
|
|
179
|
+
result[key] = visit(item, "".concat(pointer, "/").concat(key));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
183
|
+
finally {
|
|
184
|
+
try {
|
|
185
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
186
|
+
}
|
|
187
|
+
finally { if (e_4) throw e_4.error; }
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
return current;
|
|
192
|
+
};
|
|
193
|
+
return { value: visit(value, ""), substituted: substituted };
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Converts strings sitting where a JSON schema expects a boolean, a number or a list of strings. A
|
|
197
|
+
* value from the environment is always a string, so `"obfuscation": "${OBFUSCATE:-false}"` has to
|
|
198
|
+
* become a boolean before the schema sees it.
|
|
199
|
+
*
|
|
200
|
+
* Booleans accept `true`/`false`/`1`/`0`, case-insensitively. A list splits on commas, trims, and
|
|
201
|
+
* drops empty entries, so an empty string is an empty list. A string that does not parse raises.
|
|
202
|
+
*/
|
|
203
|
+
function coerceBySchema(value, schema, describe) {
|
|
204
|
+
var visit = function (current, node, pointer) {
|
|
205
|
+
var e_5, _a;
|
|
206
|
+
if (node === undefined) {
|
|
207
|
+
return current;
|
|
208
|
+
}
|
|
209
|
+
if (typeof current === "string") {
|
|
210
|
+
return coerceString(current, node, function () { return describe(pointer); });
|
|
211
|
+
}
|
|
212
|
+
if (Array.isArray(current)) {
|
|
213
|
+
return current.map(function (item, index) { return visit(item, node.items, "".concat(pointer, "/").concat(index)); });
|
|
214
|
+
}
|
|
215
|
+
if (current !== null && typeof current === "object" && node.properties) {
|
|
216
|
+
var result = {};
|
|
217
|
+
try {
|
|
218
|
+
for (var _b = __values(Object.entries(current)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
219
|
+
var _d = __read(_c.value, 2), key = _d[0], item = _d[1];
|
|
220
|
+
result[key] = visit(item, node.properties[key], "".concat(pointer, "/").concat(key));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
224
|
+
finally {
|
|
225
|
+
try {
|
|
226
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
227
|
+
}
|
|
228
|
+
finally { if (e_5) throw e_5.error; }
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
return current;
|
|
233
|
+
};
|
|
234
|
+
return visit(value, schema, "");
|
|
235
|
+
}
|
|
236
|
+
function coerceString(value, node, where) {
|
|
237
|
+
var _a;
|
|
238
|
+
switch (node.type) {
|
|
239
|
+
case "boolean": {
|
|
240
|
+
var lowered = value.trim().toLowerCase();
|
|
241
|
+
if (lowered === "true" || lowered === "1")
|
|
242
|
+
return true;
|
|
243
|
+
if (lowered === "false" || lowered === "0")
|
|
244
|
+
return false;
|
|
245
|
+
throw new Error("".concat(where(), " is \"").concat(value, "\", which is not a boolean (true, false, 1 or 0)."));
|
|
246
|
+
}
|
|
247
|
+
case "number":
|
|
248
|
+
case "integer": {
|
|
249
|
+
var parsed = Number(value.trim());
|
|
250
|
+
if (value.trim() === "" || Number.isNaN(parsed)) {
|
|
251
|
+
throw new Error("".concat(where(), " is \"").concat(value, "\", which is not a number."));
|
|
252
|
+
}
|
|
253
|
+
return parsed;
|
|
254
|
+
}
|
|
255
|
+
case "array": {
|
|
256
|
+
if (((_a = node.items) === null || _a === void 0 ? void 0 : _a.type) !== "string") {
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
return value
|
|
260
|
+
.split(",")
|
|
261
|
+
.map(function (entry) { return entry.trim(); })
|
|
262
|
+
.filter(function (entry) { return entry !== ""; });
|
|
263
|
+
}
|
|
264
|
+
default:
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
}
|