create-ones-app 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1255 -1185
- package/dist/index.js +1320 -1250
- package/dist/types/actions/create/consts.d.ts +3 -0
- package/dist/types/actions/create/consts.d.ts.map +1 -0
- package/dist/types/actions/create/index.d.ts.map +1 -1
- package/dist/types/common/package/schema.d.ts +3 -0
- package/dist/types/common/package/schema.d.ts.map +1 -1
- package/dist/types/common/package/types.d.ts +1 -0
- package/dist/types/common/package/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/template/example/package.json +2 -3
- package/template/example/package-lock.json +0 -12696
package/dist/index.cjs
CHANGED
|
@@ -7,13 +7,13 @@ const node_path = require("node:path");
|
|
|
7
7
|
const fse = require("fs-extra");
|
|
8
8
|
const uuid = require("uuid");
|
|
9
9
|
const node_url = require("node:url");
|
|
10
|
-
const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
|
|
11
|
-
const chalk = require("chalk");
|
|
12
|
-
const lodashEs = require("lodash-es");
|
|
13
|
-
const node_fs = require("node:fs");
|
|
14
10
|
const node_process = require("node:process");
|
|
11
|
+
const node_fs = require("node:fs");
|
|
15
12
|
const zod = require("zod");
|
|
16
13
|
const addFormats = require("ajv-formats");
|
|
14
|
+
const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
|
|
15
|
+
const chalk = require("chalk");
|
|
16
|
+
const lodashEs = require("lodash-es");
|
|
17
17
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
18
18
|
const getPublicPath = () => {
|
|
19
19
|
const __dirname = node_path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
|
|
@@ -23,345 +23,54 @@ const PUBLIC_FILENAME = {
|
|
|
23
23
|
MANIFEST: "opkx.json",
|
|
24
24
|
RC: ".onesrc.json"
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
ErrorCode2["UNKNOWN_ERROR"] = "E00";
|
|
28
|
-
ErrorCode2["COMMAND_ERROR"] = "E01";
|
|
29
|
-
ErrorCode2["TEMPLATE_NOT_FOUND"] = "E02";
|
|
30
|
-
ErrorCode2["MISSING_PROJECT_PATH"] = "E03";
|
|
31
|
-
return ErrorCode2;
|
|
32
|
-
})(ErrorCode || {});
|
|
33
|
-
const throwError = (code2, message) => {
|
|
34
|
-
let $message = message.trim();
|
|
35
|
-
if (code2 === ErrorCode.COMMAND_ERROR) {
|
|
36
|
-
$message = $message.replace(/^error: /, "");
|
|
37
|
-
}
|
|
38
|
-
$message = $message.replace(/\s+$/, "");
|
|
39
|
-
const text = `${$message}[${code2}]`;
|
|
40
|
-
console.error(chalk.red(text));
|
|
41
|
-
process.exit(1);
|
|
42
|
-
};
|
|
43
|
-
const en = {
|
|
44
|
-
"desc.create": "Create a new ONES App",
|
|
45
|
-
"desc.create.projectPath": "Specify the project path",
|
|
46
|
-
"desc.create.templateName": "Specify the template name",
|
|
47
|
-
"desc.create.manifestOnly": "Only create the manifest file",
|
|
48
|
-
"success.create.gitInitialized": "Git repository initialized.",
|
|
49
|
-
"success.create.gitInitializedAndIgnoreStaged": 'Git repository initialized, and ".gitignore" has been staged.',
|
|
50
|
-
"success.create.fetchReferences": "To help your AI work on this app, fetch the app development references:",
|
|
51
|
-
"warn.create.gitInitSkipped": 'Warning: failed to initialize a Git repository automatically. You can run "git init" later. Reason: {reason}',
|
|
52
|
-
"warn.create.gitIgnoreStageSkipped": 'Warning: Git repository initialized, but failed to stage ".gitignore". You can run "git add .gitignore" later. Reason: {reason}',
|
|
53
|
-
"error.command.missingProjectPathFriendly": "Project path is required. Example: ones create hello-ones",
|
|
54
|
-
"error.create.templateNotFound": 'Template "{templateName}" not found',
|
|
55
|
-
"error.create.missingProjectPath": "Project path is required"
|
|
56
|
-
};
|
|
57
|
-
const map = {
|
|
58
|
-
en
|
|
59
|
-
};
|
|
60
|
-
const getCurrentLanguageList = () => {
|
|
61
|
-
return ["en"];
|
|
62
|
-
};
|
|
63
|
-
const translate = (key, params) => {
|
|
64
|
-
const list = getCurrentLanguageList();
|
|
65
|
-
for (let index = 0; index < list.length; index++) {
|
|
66
|
-
const language = list[index];
|
|
67
|
-
let value = lodashEs.get(map[language], key);
|
|
68
|
-
if (value) {
|
|
69
|
-
if (params && typeof value === "string") {
|
|
70
|
-
value = value.replace(/\{(\w+)\}/g, (match, paramKey) => {
|
|
71
|
-
var _params$paramKey;
|
|
72
|
-
const result = (_params$paramKey = params === null || params === void 0 ? void 0 : params[paramKey]) !== null && _params$paramKey !== void 0 ? _params$paramKey : match;
|
|
73
|
-
return String(result);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return key;
|
|
80
|
-
};
|
|
81
|
-
const i18n = {
|
|
82
|
-
t: translate
|
|
83
|
-
};
|
|
84
|
-
const getCommandOptions = (args, keys) => {
|
|
85
|
-
const $args = args.slice(-2);
|
|
86
|
-
const $list = args.slice(0, -2);
|
|
87
|
-
const [options, command] = $args;
|
|
88
|
-
const $options = options;
|
|
89
|
-
keys.forEach((key, index) => {
|
|
90
|
-
$options[key] = $list[index];
|
|
91
|
-
});
|
|
92
|
-
return {
|
|
93
|
-
options,
|
|
94
|
-
command
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
const getRawArguments = (cmd) => {
|
|
98
|
-
const $cmd = cmd;
|
|
99
|
-
return $cmd._args;
|
|
100
|
-
};
|
|
101
|
-
const getRawOptions = (cmd) => {
|
|
102
|
-
const $cmd = cmd;
|
|
103
|
-
return $cmd.options;
|
|
104
|
-
};
|
|
105
|
-
const addCommandUsage = (cmd, blackList2) => {
|
|
106
|
-
const args = getRawArguments(cmd);
|
|
107
|
-
const options = getRawOptions(cmd);
|
|
108
|
-
if (options.length || args.length) {
|
|
109
|
-
cmd.usage(_reduceInstanceProperty(args).call(args, (base, arg) => {
|
|
110
|
-
if (blackList2 !== null && blackList2 !== void 0 && _includesInstanceProperty(blackList2).call(blackList2, arg.name())) {
|
|
111
|
-
return base;
|
|
112
|
-
}
|
|
113
|
-
if (arg.required) {
|
|
114
|
-
return `${base} <${arg.name()}>`;
|
|
115
|
-
}
|
|
116
|
-
return `${base} [${arg.name()}]`;
|
|
117
|
-
}, "[options]"));
|
|
118
|
-
} else {
|
|
119
|
-
cmd.usage(" ");
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
const addCommandOutput = (cmd) => {
|
|
123
|
-
cmd.configureOutput({
|
|
124
|
-
outputError(str) {
|
|
125
|
-
const message = str.replace(/^error: /, "").trim();
|
|
126
|
-
if (message === "missing required argument 'project-path'") {
|
|
127
|
-
throwError(ErrorCode.COMMAND_ERROR, i18n.t("error.command.missingProjectPathFriendly"));
|
|
128
|
-
}
|
|
129
|
-
throwError(ErrorCode.COMMAND_ERROR, str);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
const getTemplatePath = () => {
|
|
26
|
+
const getPackageJSONPath = () => {
|
|
134
27
|
const __dirname = node_path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
|
|
135
|
-
return node_path.join(__dirname, "../
|
|
136
|
-
};
|
|
137
|
-
const getTemplateChoices = () => {
|
|
138
|
-
const path = getTemplatePath();
|
|
139
|
-
return node_fs.readdirSync(path);
|
|
140
|
-
};
|
|
141
|
-
const getTemplateDefault = () => {
|
|
142
|
-
return "example";
|
|
143
|
-
};
|
|
144
|
-
const defaultTemplateName = getTemplateDefault();
|
|
145
|
-
const normalize$1 = async (options) => {
|
|
146
|
-
const projectPathInput = options.projectPath;
|
|
147
|
-
if (projectPathInput)
|
|
148
|
-
;
|
|
149
|
-
else {
|
|
150
|
-
return throwError(ErrorCode.MISSING_PROJECT_PATH, i18n.t("error.create.missingProjectPath"));
|
|
151
|
-
}
|
|
152
|
-
const projectPath = node_path.resolve(node_process.cwd(), projectPathInput);
|
|
153
|
-
const templateName = defaultTemplateName;
|
|
154
|
-
const manifestOnly = Boolean(options.manifestOnly);
|
|
155
|
-
const templateChoices = getTemplateChoices();
|
|
156
|
-
const validTemplateName = _includesInstanceProperty(templateChoices).call(templateChoices, templateName);
|
|
157
|
-
if (validTemplateName)
|
|
158
|
-
;
|
|
159
|
-
else {
|
|
160
|
-
return throwError(ErrorCode.TEMPLATE_NOT_FOUND, i18n.t("error.create.templateNotFound", {
|
|
161
|
-
templateName
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
projectPath,
|
|
166
|
-
templateName,
|
|
167
|
-
manifestOnly
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
const {
|
|
171
|
-
existsSync,
|
|
172
|
-
copy,
|
|
173
|
-
moveSync,
|
|
174
|
-
readJSON,
|
|
175
|
-
writeJSON,
|
|
176
|
-
readdirSync,
|
|
177
|
-
readFile,
|
|
178
|
-
writeFile,
|
|
179
|
-
ensureDir
|
|
180
|
-
} = fse;
|
|
181
|
-
const getErrorMessage = (error2) => {
|
|
182
|
-
if (error2 instanceof Error && error2.message) {
|
|
183
|
-
return error2.message;
|
|
184
|
-
}
|
|
185
|
-
return "Unknown error";
|
|
28
|
+
return node_path.join(__dirname, "../package.json");
|
|
186
29
|
};
|
|
187
|
-
const
|
|
30
|
+
const getPackageJSON = () => {
|
|
31
|
+
const path = getPackageJSONPath();
|
|
32
|
+
const string = node_fs.readFileSync(path, {
|
|
33
|
+
encoding: "utf8"
|
|
34
|
+
});
|
|
188
35
|
try {
|
|
189
|
-
|
|
190
|
-
cwd: projectPath,
|
|
191
|
-
stdio: "ignore"
|
|
192
|
-
});
|
|
36
|
+
return JSON.parse(string);
|
|
193
37
|
} catch (error2) {
|
|
194
|
-
return {
|
|
195
|
-
status: "git-init-skipped",
|
|
196
|
-
reason: getErrorMessage(error2)
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
if (existsSync(node_path.join(projectPath, ".gitignore"))) {
|
|
200
|
-
try {
|
|
201
|
-
node_child_process.execFileSync("git", ["add", ".gitignore"], {
|
|
202
|
-
cwd: projectPath,
|
|
203
|
-
stdio: "ignore"
|
|
204
|
-
});
|
|
205
|
-
return {
|
|
206
|
-
status: "ignore-staged"
|
|
207
|
-
};
|
|
208
|
-
} catch (error2) {
|
|
209
|
-
return {
|
|
210
|
-
status: "gitignore-stage-skipped",
|
|
211
|
-
reason: getErrorMessage(error2)
|
|
212
|
-
};
|
|
213
|
-
}
|
|
38
|
+
return {};
|
|
214
39
|
}
|
|
215
|
-
return {
|
|
216
|
-
status: "initialized"
|
|
217
|
-
};
|
|
218
40
|
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
41
|
+
function getDefaultExportFromCjs(x) {
|
|
42
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
43
|
+
}
|
|
44
|
+
var _2020 = { exports: {} };
|
|
45
|
+
var core$3 = {};
|
|
46
|
+
var validate = {};
|
|
47
|
+
var boolSchema = {};
|
|
48
|
+
var errors = {};
|
|
49
|
+
var codegen = {};
|
|
50
|
+
var code$1 = {};
|
|
51
|
+
(function(exports2) {
|
|
52
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
53
|
+
exports2.regexpCode = exports2.getEsmExportName = exports2.getProperty = exports2.safeStringify = exports2.stringify = exports2.strConcat = exports2.addCodeArg = exports2.str = exports2._ = exports2.nil = exports2._Code = exports2.Name = exports2.IDENTIFIER = exports2._CodeOrName = void 0;
|
|
54
|
+
class _CodeOrName {
|
|
222
55
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const templatePath = node_path.join(getTemplatePath(), getTemplateDefault());
|
|
242
|
-
await copy(templatePath, projectPath);
|
|
243
|
-
const rename = [["_gitignore", ".gitignore"], ["_prettierignore", ".prettierignore"], ["_prettierrc", ".prettierrc"], ["_tsconfig.json", "tsconfig.json"], ["_eslint.config.mjs_", "eslint.config.mjs"], ["_husky_pre-commit", ".husky/pre-commit"]];
|
|
244
|
-
rename.forEach((_ref) => {
|
|
245
|
-
let [from, to] = _ref;
|
|
246
|
-
moveSync(node_path.join(projectPath, from), node_path.join(projectPath, to), {
|
|
247
|
-
overwrite: true
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
const logoDirPath = node_path.join(publicPath, "logos");
|
|
251
|
-
const logos = readdirSync(logoDirPath);
|
|
252
|
-
if (logos.length > 0) {
|
|
253
|
-
const index = Math.floor(Math.random() * logos.length);
|
|
254
|
-
const logo = logos[index];
|
|
255
|
-
const logoPath = node_path.join(logoDirPath, logo);
|
|
256
|
-
const logoContent = await readFile(logoPath, {
|
|
257
|
-
encoding: "utf-8"
|
|
258
|
-
});
|
|
259
|
-
await writeFile(node_path.join(projectPath, "public/logo.svg"), logoContent, {
|
|
260
|
-
encoding: "utf-8"
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
await ensureDir(projectPath);
|
|
265
|
-
let manifestJSONPath = "";
|
|
266
|
-
if (manifestOnly) {
|
|
267
|
-
manifestJSONPath = node_path.join(publicPath, PUBLIC_FILENAME.MANIFEST);
|
|
268
|
-
} else {
|
|
269
|
-
manifestJSONPath = node_path.join(projectPath, PUBLIC_FILENAME.MANIFEST);
|
|
270
|
-
}
|
|
271
|
-
const manifestJSON = await readJSON(manifestJSONPath);
|
|
272
|
-
manifestJSON.app.id = `app_${uuid.v4().replace(/-/g, "").slice(0, 16)}`;
|
|
273
|
-
manifestJSON.app.name = appName;
|
|
274
|
-
await writeJSON(node_path.join(projectPath, PUBLIC_FILENAME.MANIFEST), manifestJSON, {
|
|
275
|
-
spaces: 2
|
|
276
|
-
});
|
|
277
|
-
const rcJSONPath = node_path.join(publicPath, PUBLIC_FILENAME.RC);
|
|
278
|
-
const rcJSON = await readJSON(rcJSONPath);
|
|
279
|
-
await writeJSON(node_path.join(projectPath, PUBLIC_FILENAME.RC), rcJSON, {
|
|
280
|
-
spaces: 2
|
|
281
|
-
});
|
|
282
|
-
const gitSetupResult = initializeGitRepository(projectPath);
|
|
283
|
-
console.log(`App "${appName}" created successfully!`);
|
|
284
|
-
if (gitSetupResult.status === "ignore-staged") {
|
|
285
|
-
console.log(i18n.t("success.create.gitInitializedAndIgnoreStaged"));
|
|
286
|
-
} else if (gitSetupResult.status === "initialized") {
|
|
287
|
-
console.log(i18n.t("success.create.gitInitialized"));
|
|
288
|
-
} else if (gitSetupResult.status === "git-init-skipped") {
|
|
289
|
-
console.log(i18n.t("warn.create.gitInitSkipped", {
|
|
290
|
-
reason: gitSetupResult.reason
|
|
291
|
-
}));
|
|
292
|
-
} else if (gitSetupResult.status === "gitignore-stage-skipped") {
|
|
293
|
-
console.log(i18n.t("warn.create.gitIgnoreStageSkipped", {
|
|
294
|
-
reason: gitSetupResult.reason
|
|
295
|
-
}));
|
|
296
|
-
}
|
|
297
|
-
console.log("");
|
|
298
|
-
console.log(i18n.t("success.create.fetchReferences"));
|
|
299
|
-
console.log(`ones specs fetch --dir "${projectPath}"`);
|
|
300
|
-
};
|
|
301
|
-
const createCommandArguments = ["projectPath", "templateName"];
|
|
302
|
-
const blackList = ["template-name"];
|
|
303
|
-
const $create = new commander.Command("create").description(i18n.t("desc.create")).argument("<project-path>", i18n.t("desc.create.projectPath")).argument("[template-name]", i18n.t("desc.create.templateName")).option("-m, --manifest-only", i18n.t("desc.create.manifestOnly")).action(create).configureHelp({
|
|
304
|
-
visibleArguments: (cmd) => {
|
|
305
|
-
return getRawArguments(cmd).filter((arg) => !_includesInstanceProperty(blackList).call(blackList, arg.name()));
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
addCommandUsage($create, blackList);
|
|
309
|
-
addCommandOutput($create);
|
|
310
|
-
const context = {};
|
|
311
|
-
const getContext = (key) => {
|
|
312
|
-
return context[key];
|
|
313
|
-
};
|
|
314
|
-
const setContext = (key, value) => {
|
|
315
|
-
context[key] = value;
|
|
316
|
-
};
|
|
317
|
-
const getPackageJSONPath = () => {
|
|
318
|
-
const __dirname = node_path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
|
|
319
|
-
return node_path.join(__dirname, "../package.json");
|
|
320
|
-
};
|
|
321
|
-
const getPackageJSON = () => {
|
|
322
|
-
const path = getPackageJSONPath();
|
|
323
|
-
const string = node_fs.readFileSync(path, {
|
|
324
|
-
encoding: "utf8"
|
|
325
|
-
});
|
|
326
|
-
try {
|
|
327
|
-
return JSON.parse(string);
|
|
328
|
-
} catch (error2) {
|
|
329
|
-
return {};
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
function getDefaultExportFromCjs(x) {
|
|
333
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
334
|
-
}
|
|
335
|
-
var _2020 = { exports: {} };
|
|
336
|
-
var core$3 = {};
|
|
337
|
-
var validate = {};
|
|
338
|
-
var boolSchema = {};
|
|
339
|
-
var errors = {};
|
|
340
|
-
var codegen = {};
|
|
341
|
-
var code$1 = {};
|
|
342
|
-
(function(exports2) {
|
|
343
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
344
|
-
exports2.regexpCode = exports2.getEsmExportName = exports2.getProperty = exports2.safeStringify = exports2.stringify = exports2.strConcat = exports2.addCodeArg = exports2.str = exports2._ = exports2.nil = exports2._Code = exports2.Name = exports2.IDENTIFIER = exports2._CodeOrName = void 0;
|
|
345
|
-
class _CodeOrName {
|
|
346
|
-
}
|
|
347
|
-
exports2._CodeOrName = _CodeOrName;
|
|
348
|
-
exports2.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
|
|
349
|
-
class Name extends _CodeOrName {
|
|
350
|
-
constructor(s) {
|
|
351
|
-
super();
|
|
352
|
-
if (!exports2.IDENTIFIER.test(s))
|
|
353
|
-
throw new Error("CodeGen: name must be a valid identifier");
|
|
354
|
-
this.str = s;
|
|
355
|
-
}
|
|
356
|
-
toString() {
|
|
357
|
-
return this.str;
|
|
358
|
-
}
|
|
359
|
-
emptyStr() {
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
get names() {
|
|
363
|
-
return { [this.str]: 1 };
|
|
364
|
-
}
|
|
56
|
+
exports2._CodeOrName = _CodeOrName;
|
|
57
|
+
exports2.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
|
|
58
|
+
class Name extends _CodeOrName {
|
|
59
|
+
constructor(s) {
|
|
60
|
+
super();
|
|
61
|
+
if (!exports2.IDENTIFIER.test(s))
|
|
62
|
+
throw new Error("CodeGen: name must be a valid identifier");
|
|
63
|
+
this.str = s;
|
|
64
|
+
}
|
|
65
|
+
toString() {
|
|
66
|
+
return this.str;
|
|
67
|
+
}
|
|
68
|
+
emptyStr() {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
get names() {
|
|
72
|
+
return { [this.str]: 1 };
|
|
73
|
+
}
|
|
365
74
|
}
|
|
366
75
|
exports2.Name = Name;
|
|
367
76
|
class _Code extends _CodeOrName {
|
|
@@ -1347,8 +1056,8 @@ var scope = {};
|
|
|
1347
1056
|
var util = {};
|
|
1348
1057
|
Object.defineProperty(util, "__esModule", { value: true });
|
|
1349
1058
|
util.checkStrictMode = util.getErrorPath = util.Type = util.useFunc = util.setEvaluated = util.evaluatedPropsToName = util.mergeEvaluated = util.eachItem = util.unescapeJsonPointer = util.escapeJsonPointer = util.escapeFragment = util.unescapeFragment = util.schemaRefOrVal = util.schemaHasRulesButRef = util.schemaHasRules = util.checkUnknownRules = util.alwaysValidSchema = util.toHash = void 0;
|
|
1350
|
-
const codegen_1$
|
|
1351
|
-
const code_1$
|
|
1059
|
+
const codegen_1$t = codegen;
|
|
1060
|
+
const code_1$9 = code$1;
|
|
1352
1061
|
function toHash(arr) {
|
|
1353
1062
|
const hash = {};
|
|
1354
1063
|
for (const item of arr)
|
|
@@ -1401,9 +1110,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
|
|
|
1401
1110
|
if (typeof schema == "number" || typeof schema == "boolean")
|
|
1402
1111
|
return schema;
|
|
1403
1112
|
if (typeof schema == "string")
|
|
1404
|
-
return (0, codegen_1$
|
|
1113
|
+
return (0, codegen_1$t._)`${schema}`;
|
|
1405
1114
|
}
|
|
1406
|
-
return (0, codegen_1$
|
|
1115
|
+
return (0, codegen_1$t._)`${topSchemaRef}${schemaPath}${(0, codegen_1$t.getProperty)(keyword2)}`;
|
|
1407
1116
|
}
|
|
1408
1117
|
util.schemaRefOrVal = schemaRefOrVal;
|
|
1409
1118
|
function unescapeFragment(str) {
|
|
@@ -1435,20 +1144,20 @@ function eachItem(xs, f) {
|
|
|
1435
1144
|
util.eachItem = eachItem;
|
|
1436
1145
|
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
|
|
1437
1146
|
return (gen, from, to, toName) => {
|
|
1438
|
-
const res = to === void 0 ? from : to instanceof codegen_1$
|
|
1439
|
-
return toName === codegen_1$
|
|
1147
|
+
const res = to === void 0 ? from : to instanceof codegen_1$t.Name ? (from instanceof codegen_1$t.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$t.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
|
|
1148
|
+
return toName === codegen_1$t.Name && !(res instanceof codegen_1$t.Name) ? resultToName(gen, res) : res;
|
|
1440
1149
|
};
|
|
1441
1150
|
}
|
|
1442
1151
|
util.mergeEvaluated = {
|
|
1443
1152
|
props: makeMergeEvaluated({
|
|
1444
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1445
|
-
gen.if((0, codegen_1$
|
|
1153
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$t._)`${to} !== true && ${from} !== undefined`, () => {
|
|
1154
|
+
gen.if((0, codegen_1$t._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$t._)`${to} || {}`).code((0, codegen_1$t._)`Object.assign(${to}, ${from})`));
|
|
1446
1155
|
}),
|
|
1447
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1156
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$t._)`${to} !== true`, () => {
|
|
1448
1157
|
if (from === true) {
|
|
1449
1158
|
gen.assign(to, true);
|
|
1450
1159
|
} else {
|
|
1451
|
-
gen.assign(to, (0, codegen_1$
|
|
1160
|
+
gen.assign(to, (0, codegen_1$t._)`${to} || {}`);
|
|
1452
1161
|
setEvaluated(gen, to, from);
|
|
1453
1162
|
}
|
|
1454
1163
|
}),
|
|
@@ -1456,8 +1165,8 @@ util.mergeEvaluated = {
|
|
|
1456
1165
|
resultToName: evaluatedPropsToName
|
|
1457
1166
|
}),
|
|
1458
1167
|
items: makeMergeEvaluated({
|
|
1459
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1460
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1168
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$t._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$t._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
|
|
1169
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$t._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$t._)`${to} > ${from} ? ${to} : ${from}`)),
|
|
1461
1170
|
mergeValues: (from, to) => from === true ? true : Math.max(from, to),
|
|
1462
1171
|
resultToName: (gen, items2) => gen.var("items", items2)
|
|
1463
1172
|
})
|
|
@@ -1465,21 +1174,21 @@ util.mergeEvaluated = {
|
|
|
1465
1174
|
function evaluatedPropsToName(gen, ps) {
|
|
1466
1175
|
if (ps === true)
|
|
1467
1176
|
return gen.var("props", true);
|
|
1468
|
-
const props = gen.var("props", (0, codegen_1$
|
|
1177
|
+
const props = gen.var("props", (0, codegen_1$t._)`{}`);
|
|
1469
1178
|
if (ps !== void 0)
|
|
1470
1179
|
setEvaluated(gen, props, ps);
|
|
1471
1180
|
return props;
|
|
1472
1181
|
}
|
|
1473
1182
|
util.evaluatedPropsToName = evaluatedPropsToName;
|
|
1474
1183
|
function setEvaluated(gen, props, ps) {
|
|
1475
|
-
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$
|
|
1184
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$t._)`${props}${(0, codegen_1$t.getProperty)(p)}`, true));
|
|
1476
1185
|
}
|
|
1477
1186
|
util.setEvaluated = setEvaluated;
|
|
1478
1187
|
const snippets = {};
|
|
1479
1188
|
function useFunc(gen, f) {
|
|
1480
1189
|
return gen.scopeValue("func", {
|
|
1481
1190
|
ref: f,
|
|
1482
|
-
code: snippets[f.code] || (snippets[f.code] = new code_1$
|
|
1191
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1$9._Code(f.code))
|
|
1483
1192
|
});
|
|
1484
1193
|
}
|
|
1485
1194
|
util.useFunc = useFunc;
|
|
@@ -1489,11 +1198,11 @@ var Type;
|
|
|
1489
1198
|
Type2[Type2["Str"] = 1] = "Str";
|
|
1490
1199
|
})(Type || (util.Type = Type = {}));
|
|
1491
1200
|
function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
|
|
1492
|
-
if (dataProp instanceof codegen_1$
|
|
1201
|
+
if (dataProp instanceof codegen_1$t.Name) {
|
|
1493
1202
|
const isNumber = dataPropType === Type.Num;
|
|
1494
|
-
return jsPropertySyntax ? isNumber ? (0, codegen_1$
|
|
1203
|
+
return jsPropertySyntax ? isNumber ? (0, codegen_1$t._)`"[" + ${dataProp} + "]"` : (0, codegen_1$t._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$t._)`"/" + ${dataProp}` : (0, codegen_1$t._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
|
|
1495
1204
|
}
|
|
1496
|
-
return jsPropertySyntax ? (0, codegen_1$
|
|
1205
|
+
return jsPropertySyntax ? (0, codegen_1$t.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
|
|
1497
1206
|
}
|
|
1498
1207
|
util.getErrorPath = getErrorPath;
|
|
1499
1208
|
function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
@@ -1505,45 +1214,52 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
|
1505
1214
|
it.self.logger.warn(msg);
|
|
1506
1215
|
}
|
|
1507
1216
|
util.checkStrictMode = checkStrictMode;
|
|
1508
|
-
var names
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1217
|
+
var names = {};
|
|
1218
|
+
var hasRequiredNames;
|
|
1219
|
+
function requireNames() {
|
|
1220
|
+
if (hasRequiredNames)
|
|
1221
|
+
return names;
|
|
1222
|
+
hasRequiredNames = 1;
|
|
1223
|
+
Object.defineProperty(names, "__esModule", { value: true });
|
|
1224
|
+
const codegen_12 = codegen;
|
|
1225
|
+
const names$1 = {
|
|
1226
|
+
// validation function arguments
|
|
1227
|
+
data: new codegen_12.Name("data"),
|
|
1228
|
+
// data passed to validation function
|
|
1229
|
+
// args passed from referencing schema
|
|
1230
|
+
valCxt: new codegen_12.Name("valCxt"),
|
|
1231
|
+
// validation/data context - should not be used directly, it is destructured to the names below
|
|
1232
|
+
instancePath: new codegen_12.Name("instancePath"),
|
|
1233
|
+
parentData: new codegen_12.Name("parentData"),
|
|
1234
|
+
parentDataProperty: new codegen_12.Name("parentDataProperty"),
|
|
1235
|
+
rootData: new codegen_12.Name("rootData"),
|
|
1236
|
+
// root data - same as the data passed to the first/top validation function
|
|
1237
|
+
dynamicAnchors: new codegen_12.Name("dynamicAnchors"),
|
|
1238
|
+
// used to support recursiveRef and dynamicRef
|
|
1239
|
+
// function scoped variables
|
|
1240
|
+
vErrors: new codegen_12.Name("vErrors"),
|
|
1241
|
+
// null or array of validation errors
|
|
1242
|
+
errors: new codegen_12.Name("errors"),
|
|
1243
|
+
// counter of validation errors
|
|
1244
|
+
this: new codegen_12.Name("this"),
|
|
1245
|
+
// "globals"
|
|
1246
|
+
self: new codegen_12.Name("self"),
|
|
1247
|
+
scope: new codegen_12.Name("scope"),
|
|
1248
|
+
// JTD serialize/parse name for JSON string and position
|
|
1249
|
+
json: new codegen_12.Name("json"),
|
|
1250
|
+
jsonPos: new codegen_12.Name("jsonPos"),
|
|
1251
|
+
jsonLen: new codegen_12.Name("jsonLen"),
|
|
1252
|
+
jsonPart: new codegen_12.Name("jsonPart")
|
|
1253
|
+
};
|
|
1254
|
+
names.default = names$1;
|
|
1255
|
+
return names;
|
|
1256
|
+
}
|
|
1541
1257
|
(function(exports2) {
|
|
1542
1258
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1543
1259
|
exports2.extendErrors = exports2.resetErrorsCount = exports2.reportExtraError = exports2.reportError = exports2.keyword$DataError = exports2.keywordError = void 0;
|
|
1544
1260
|
const codegen_12 = codegen;
|
|
1545
1261
|
const util_12 = util;
|
|
1546
|
-
const names_12 =
|
|
1262
|
+
const names_12 = requireNames();
|
|
1547
1263
|
exports2.keywordError = {
|
|
1548
1264
|
message: ({ keyword: keyword2 }) => (0, codegen_12.str)`must pass "${keyword2}" keyword validation`
|
|
1549
1265
|
};
|
|
@@ -1655,49 +1371,56 @@ names$1.default = names;
|
|
|
1655
1371
|
keyValues.push([E.propertyName, propertyName]);
|
|
1656
1372
|
}
|
|
1657
1373
|
})(errors);
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
const
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1374
|
+
var hasRequiredBoolSchema;
|
|
1375
|
+
function requireBoolSchema() {
|
|
1376
|
+
if (hasRequiredBoolSchema)
|
|
1377
|
+
return boolSchema;
|
|
1378
|
+
hasRequiredBoolSchema = 1;
|
|
1379
|
+
Object.defineProperty(boolSchema, "__esModule", { value: true });
|
|
1380
|
+
boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
|
|
1381
|
+
const errors_12 = errors;
|
|
1382
|
+
const codegen_12 = codegen;
|
|
1383
|
+
const names_12 = requireNames();
|
|
1384
|
+
const boolError = {
|
|
1385
|
+
message: "boolean schema is false"
|
|
1386
|
+
};
|
|
1387
|
+
function topBoolOrEmptySchema(it) {
|
|
1388
|
+
const { gen, schema, validateName } = it;
|
|
1389
|
+
if (schema === false) {
|
|
1390
|
+
falseSchemaError(it, false);
|
|
1391
|
+
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1392
|
+
gen.return(names_12.default.data);
|
|
1393
|
+
} else {
|
|
1394
|
+
gen.assign((0, codegen_12._)`${validateName}.errors`, null);
|
|
1395
|
+
gen.return(true);
|
|
1396
|
+
}
|
|
1675
1397
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1398
|
+
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1399
|
+
function boolOrEmptySchema(it, valid) {
|
|
1400
|
+
const { gen, schema } = it;
|
|
1401
|
+
if (schema === false) {
|
|
1402
|
+
gen.var(valid, false);
|
|
1403
|
+
falseSchemaError(it);
|
|
1404
|
+
} else {
|
|
1405
|
+
gen.var(valid, true);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1409
|
+
function falseSchemaError(it, overrideAllErrors) {
|
|
1410
|
+
const { gen, data } = it;
|
|
1411
|
+
const cxt = {
|
|
1412
|
+
gen,
|
|
1413
|
+
keyword: "false schema",
|
|
1414
|
+
data,
|
|
1415
|
+
schema: false,
|
|
1416
|
+
schemaCode: false,
|
|
1417
|
+
schemaValue: false,
|
|
1418
|
+
params: {},
|
|
1419
|
+
it
|
|
1420
|
+
};
|
|
1421
|
+
(0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1685
1422
|
}
|
|
1686
|
-
|
|
1687
|
-
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1688
|
-
function falseSchemaError(it, overrideAllErrors) {
|
|
1689
|
-
const { gen, data } = it;
|
|
1690
|
-
const cxt = {
|
|
1691
|
-
gen,
|
|
1692
|
-
keyword: "false schema",
|
|
1693
|
-
data,
|
|
1694
|
-
schema: false,
|
|
1695
|
-
schemaCode: false,
|
|
1696
|
-
schemaValue: false,
|
|
1697
|
-
params: {},
|
|
1698
|
-
it
|
|
1699
|
-
};
|
|
1700
|
-
(0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1423
|
+
return boolSchema;
|
|
1701
1424
|
}
|
|
1702
1425
|
var dataType = {};
|
|
1703
1426
|
var rules = {};
|
|
@@ -1726,29 +1449,36 @@ function getRules() {
|
|
|
1726
1449
|
}
|
|
1727
1450
|
rules.getRules = getRules;
|
|
1728
1451
|
var applicability = {};
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
}
|
|
1735
|
-
applicability.schemaHasRulesForType =
|
|
1736
|
-
function
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1452
|
+
var hasRequiredApplicability;
|
|
1453
|
+
function requireApplicability() {
|
|
1454
|
+
if (hasRequiredApplicability)
|
|
1455
|
+
return applicability;
|
|
1456
|
+
hasRequiredApplicability = 1;
|
|
1457
|
+
Object.defineProperty(applicability, "__esModule", { value: true });
|
|
1458
|
+
applicability.shouldUseRule = applicability.shouldUseGroup = applicability.schemaHasRulesForType = void 0;
|
|
1459
|
+
function schemaHasRulesForType({ schema, self }, type2) {
|
|
1460
|
+
const group = self.RULES.types[type2];
|
|
1461
|
+
return group && group !== true && shouldUseGroup(schema, group);
|
|
1462
|
+
}
|
|
1463
|
+
applicability.schemaHasRulesForType = schemaHasRulesForType;
|
|
1464
|
+
function shouldUseGroup(schema, group) {
|
|
1465
|
+
return group.rules.some((rule) => shouldUseRule(schema, rule));
|
|
1466
|
+
}
|
|
1467
|
+
applicability.shouldUseGroup = shouldUseGroup;
|
|
1468
|
+
function shouldUseRule(schema, rule) {
|
|
1469
|
+
var _a;
|
|
1470
|
+
return schema[rule.keyword] !== void 0 || ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== void 0));
|
|
1471
|
+
}
|
|
1472
|
+
applicability.shouldUseRule = shouldUseRule;
|
|
1473
|
+
return applicability;
|
|
1743
1474
|
}
|
|
1744
|
-
applicability.shouldUseRule = shouldUseRule;
|
|
1745
1475
|
Object.defineProperty(dataType, "__esModule", { value: true });
|
|
1746
1476
|
dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
|
|
1747
1477
|
const rules_1 = rules;
|
|
1748
|
-
const applicability_1
|
|
1749
|
-
const errors_1
|
|
1750
|
-
const codegen_1$
|
|
1751
|
-
const util_1$
|
|
1478
|
+
const applicability_1 = requireApplicability();
|
|
1479
|
+
const errors_1 = errors;
|
|
1480
|
+
const codegen_1$s = codegen;
|
|
1481
|
+
const util_1$r = util;
|
|
1752
1482
|
var DataType;
|
|
1753
1483
|
(function(DataType2) {
|
|
1754
1484
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -1780,7 +1510,7 @@ dataType.getJSONTypes = getJSONTypes;
|
|
|
1780
1510
|
function coerceAndCheckDataType(it, types2) {
|
|
1781
1511
|
const { gen, data, opts } = it;
|
|
1782
1512
|
const coerceTo = coerceToTypes(types2, opts.coerceTypes);
|
|
1783
|
-
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1
|
|
1513
|
+
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
|
|
1784
1514
|
if (checkTypes) {
|
|
1785
1515
|
const wrongType = checkDataTypes(types2, data, opts.strictNumbers, DataType.Wrong);
|
|
1786
1516
|
gen.if(wrongType, () => {
|
|
@@ -1799,12 +1529,12 @@ function coerceToTypes(types2, coerceTypes) {
|
|
|
1799
1529
|
}
|
|
1800
1530
|
function coerceData(it, types2, coerceTo) {
|
|
1801
1531
|
const { gen, data, opts } = it;
|
|
1802
|
-
const dataType2 = gen.let("dataType", (0, codegen_1$
|
|
1803
|
-
const coerced = gen.let("coerced", (0, codegen_1$
|
|
1532
|
+
const dataType2 = gen.let("dataType", (0, codegen_1$s._)`typeof ${data}`);
|
|
1533
|
+
const coerced = gen.let("coerced", (0, codegen_1$s._)`undefined`);
|
|
1804
1534
|
if (opts.coerceTypes === "array") {
|
|
1805
|
-
gen.if((0, codegen_1$
|
|
1535
|
+
gen.if((0, codegen_1$s._)`${dataType2} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen.assign(data, (0, codegen_1$s._)`${data}[0]`).assign(dataType2, (0, codegen_1$s._)`typeof ${data}`).if(checkDataTypes(types2, data, opts.strictNumbers), () => gen.assign(coerced, data)));
|
|
1806
1536
|
}
|
|
1807
|
-
gen.if((0, codegen_1$
|
|
1537
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`);
|
|
1808
1538
|
for (const t of coerceTo) {
|
|
1809
1539
|
if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
|
|
1810
1540
|
coerceSpecificType(t);
|
|
@@ -1813,63 +1543,63 @@ function coerceData(it, types2, coerceTo) {
|
|
|
1813
1543
|
gen.else();
|
|
1814
1544
|
reportTypeError(it);
|
|
1815
1545
|
gen.endIf();
|
|
1816
|
-
gen.if((0, codegen_1$
|
|
1546
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`, () => {
|
|
1817
1547
|
gen.assign(data, coerced);
|
|
1818
1548
|
assignParentData(it, coerced);
|
|
1819
1549
|
});
|
|
1820
1550
|
function coerceSpecificType(t) {
|
|
1821
1551
|
switch (t) {
|
|
1822
1552
|
case "string":
|
|
1823
|
-
gen.elseIf((0, codegen_1$
|
|
1553
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$s._)`"" + ${data}`).elseIf((0, codegen_1$s._)`${data} === null`).assign(coerced, (0, codegen_1$s._)`""`);
|
|
1824
1554
|
return;
|
|
1825
1555
|
case "number":
|
|
1826
|
-
gen.elseIf((0, codegen_1$
|
|
1827
|
-
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$
|
|
1556
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "boolean" || ${data} === null
|
|
1557
|
+
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$s._)`+${data}`);
|
|
1828
1558
|
return;
|
|
1829
1559
|
case "integer":
|
|
1830
|
-
gen.elseIf((0, codegen_1$
|
|
1831
|
-
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$
|
|
1560
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "boolean" || ${data} === null
|
|
1561
|
+
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$s._)`+${data}`);
|
|
1832
1562
|
return;
|
|
1833
1563
|
case "boolean":
|
|
1834
|
-
gen.elseIf((0, codegen_1$
|
|
1564
|
+
gen.elseIf((0, codegen_1$s._)`${data} === "false" || ${data} === 0 || ${data} === null`).assign(coerced, false).elseIf((0, codegen_1$s._)`${data} === "true" || ${data} === 1`).assign(coerced, true);
|
|
1835
1565
|
return;
|
|
1836
1566
|
case "null":
|
|
1837
|
-
gen.elseIf((0, codegen_1$
|
|
1567
|
+
gen.elseIf((0, codegen_1$s._)`${data} === "" || ${data} === 0 || ${data} === false`);
|
|
1838
1568
|
gen.assign(coerced, null);
|
|
1839
1569
|
return;
|
|
1840
1570
|
case "array":
|
|
1841
|
-
gen.elseIf((0, codegen_1$
|
|
1842
|
-
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$
|
|
1571
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "string" || ${dataType2} === "number"
|
|
1572
|
+
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$s._)`[${data}]`);
|
|
1843
1573
|
}
|
|
1844
1574
|
}
|
|
1845
1575
|
}
|
|
1846
1576
|
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
|
|
1847
|
-
gen.if((0, codegen_1$
|
|
1577
|
+
gen.if((0, codegen_1$s._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$s._)`${parentData}[${parentDataProperty}]`, expr));
|
|
1848
1578
|
}
|
|
1849
1579
|
function checkDataType(dataType2, data, strictNums, correct = DataType.Correct) {
|
|
1850
|
-
const EQ = correct === DataType.Correct ? codegen_1$
|
|
1580
|
+
const EQ = correct === DataType.Correct ? codegen_1$s.operators.EQ : codegen_1$s.operators.NEQ;
|
|
1851
1581
|
let cond;
|
|
1852
1582
|
switch (dataType2) {
|
|
1853
1583
|
case "null":
|
|
1854
|
-
return (0, codegen_1$
|
|
1584
|
+
return (0, codegen_1$s._)`${data} ${EQ} null`;
|
|
1855
1585
|
case "array":
|
|
1856
|
-
cond = (0, codegen_1$
|
|
1586
|
+
cond = (0, codegen_1$s._)`Array.isArray(${data})`;
|
|
1857
1587
|
break;
|
|
1858
1588
|
case "object":
|
|
1859
|
-
cond = (0, codegen_1$
|
|
1589
|
+
cond = (0, codegen_1$s._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
|
|
1860
1590
|
break;
|
|
1861
1591
|
case "integer":
|
|
1862
|
-
cond = numCond((0, codegen_1$
|
|
1592
|
+
cond = numCond((0, codegen_1$s._)`!(${data} % 1) && !isNaN(${data})`);
|
|
1863
1593
|
break;
|
|
1864
1594
|
case "number":
|
|
1865
1595
|
cond = numCond();
|
|
1866
1596
|
break;
|
|
1867
1597
|
default:
|
|
1868
|
-
return (0, codegen_1$
|
|
1598
|
+
return (0, codegen_1$s._)`typeof ${data} ${EQ} ${dataType2}`;
|
|
1869
1599
|
}
|
|
1870
|
-
return correct === DataType.Correct ? cond : (0, codegen_1$
|
|
1871
|
-
function numCond(_cond = codegen_1$
|
|
1872
|
-
return (0, codegen_1$
|
|
1600
|
+
return correct === DataType.Correct ? cond : (0, codegen_1$s.not)(cond);
|
|
1601
|
+
function numCond(_cond = codegen_1$s.nil) {
|
|
1602
|
+
return (0, codegen_1$s.and)((0, codegen_1$s._)`typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1$s._)`isFinite(${data})` : codegen_1$s.nil);
|
|
1873
1603
|
}
|
|
1874
1604
|
}
|
|
1875
1605
|
dataType.checkDataType = checkDataType;
|
|
@@ -1878,35 +1608,35 @@ function checkDataTypes(dataTypes, data, strictNums, correct) {
|
|
|
1878
1608
|
return checkDataType(dataTypes[0], data, strictNums, correct);
|
|
1879
1609
|
}
|
|
1880
1610
|
let cond;
|
|
1881
|
-
const types2 = (0, util_1$
|
|
1611
|
+
const types2 = (0, util_1$r.toHash)(dataTypes);
|
|
1882
1612
|
if (types2.array && types2.object) {
|
|
1883
|
-
const notObj = (0, codegen_1$
|
|
1884
|
-
cond = types2.null ? notObj : (0, codegen_1$
|
|
1613
|
+
const notObj = (0, codegen_1$s._)`typeof ${data} != "object"`;
|
|
1614
|
+
cond = types2.null ? notObj : (0, codegen_1$s._)`!${data} || ${notObj}`;
|
|
1885
1615
|
delete types2.null;
|
|
1886
1616
|
delete types2.array;
|
|
1887
1617
|
delete types2.object;
|
|
1888
1618
|
} else {
|
|
1889
|
-
cond = codegen_1$
|
|
1619
|
+
cond = codegen_1$s.nil;
|
|
1890
1620
|
}
|
|
1891
1621
|
if (types2.number)
|
|
1892
1622
|
delete types2.integer;
|
|
1893
1623
|
for (const t in types2)
|
|
1894
|
-
cond = (0, codegen_1$
|
|
1624
|
+
cond = (0, codegen_1$s.and)(cond, checkDataType(t, data, strictNums, correct));
|
|
1895
1625
|
return cond;
|
|
1896
1626
|
}
|
|
1897
1627
|
dataType.checkDataTypes = checkDataTypes;
|
|
1898
1628
|
const typeError = {
|
|
1899
1629
|
message: ({ schema }) => `must be ${schema}`,
|
|
1900
|
-
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$
|
|
1630
|
+
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$s._)`{type: ${schema}}` : (0, codegen_1$s._)`{type: ${schemaValue}}`
|
|
1901
1631
|
};
|
|
1902
1632
|
function reportTypeError(it) {
|
|
1903
1633
|
const cxt = getTypeErrorContext(it);
|
|
1904
|
-
(0, errors_1
|
|
1634
|
+
(0, errors_1.reportError)(cxt, typeError);
|
|
1905
1635
|
}
|
|
1906
1636
|
dataType.reportTypeError = reportTypeError;
|
|
1907
1637
|
function getTypeErrorContext(it) {
|
|
1908
1638
|
const { gen, data, schema } = it;
|
|
1909
|
-
const schemaCode = (0, util_1$
|
|
1639
|
+
const schemaCode = (0, util_1$r.schemaRefOrVal)(it, schema, "type");
|
|
1910
1640
|
return {
|
|
1911
1641
|
gen,
|
|
1912
1642
|
keyword: "type",
|
|
@@ -1920,54 +1650,61 @@ function getTypeErrorContext(it) {
|
|
|
1920
1650
|
};
|
|
1921
1651
|
}
|
|
1922
1652
|
var defaults = {};
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
return;
|
|
1942
|
-
const childData = (0, codegen_1$v._)`${data}${(0, codegen_1$v.getProperty)(prop)}`;
|
|
1943
|
-
if (compositeRule) {
|
|
1944
|
-
(0, util_1$t.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1945
|
-
return;
|
|
1653
|
+
var hasRequiredDefaults;
|
|
1654
|
+
function requireDefaults() {
|
|
1655
|
+
if (hasRequiredDefaults)
|
|
1656
|
+
return defaults;
|
|
1657
|
+
hasRequiredDefaults = 1;
|
|
1658
|
+
Object.defineProperty(defaults, "__esModule", { value: true });
|
|
1659
|
+
defaults.assignDefaults = void 0;
|
|
1660
|
+
const codegen_12 = codegen;
|
|
1661
|
+
const util_12 = util;
|
|
1662
|
+
function assignDefaults(it, ty) {
|
|
1663
|
+
const { properties: properties2, items: items2 } = it.schema;
|
|
1664
|
+
if (ty === "object" && properties2) {
|
|
1665
|
+
for (const key in properties2) {
|
|
1666
|
+
assignDefault(it, key, properties2[key].default);
|
|
1667
|
+
}
|
|
1668
|
+
} else if (ty === "array" && Array.isArray(items2)) {
|
|
1669
|
+
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1670
|
+
}
|
|
1946
1671
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1672
|
+
defaults.assignDefaults = assignDefaults;
|
|
1673
|
+
function assignDefault(it, prop, defaultValue) {
|
|
1674
|
+
const { gen, compositeRule, data, opts } = it;
|
|
1675
|
+
if (defaultValue === void 0)
|
|
1676
|
+
return;
|
|
1677
|
+
const childData = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(prop)}`;
|
|
1678
|
+
if (compositeRule) {
|
|
1679
|
+
(0, util_12.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
let condition = (0, codegen_12._)`${childData} === undefined`;
|
|
1683
|
+
if (opts.useDefaults === "empty") {
|
|
1684
|
+
condition = (0, codegen_12._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
1685
|
+
}
|
|
1686
|
+
gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
|
|
1950
1687
|
}
|
|
1951
|
-
|
|
1688
|
+
return defaults;
|
|
1952
1689
|
}
|
|
1953
1690
|
var keyword = {};
|
|
1954
1691
|
var code = {};
|
|
1955
1692
|
Object.defineProperty(code, "__esModule", { value: true });
|
|
1956
1693
|
code.validateUnion = code.validateArray = code.usePattern = code.callValidateCode = code.schemaProperties = code.allSchemaProperties = code.noPropertyInData = code.propertyInData = code.isOwnProperty = code.hasPropFunc = code.reportMissingProp = code.checkMissingProp = code.checkReportMissingProp = void 0;
|
|
1957
|
-
const codegen_1$
|
|
1958
|
-
const util_1$
|
|
1959
|
-
const names_1$
|
|
1694
|
+
const codegen_1$r = codegen;
|
|
1695
|
+
const util_1$q = util;
|
|
1696
|
+
const names_1$6 = requireNames();
|
|
1960
1697
|
const util_2$1 = util;
|
|
1961
1698
|
function checkReportMissingProp(cxt, prop) {
|
|
1962
1699
|
const { gen, data, it } = cxt;
|
|
1963
1700
|
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
|
1964
|
-
cxt.setParams({ missingProperty: (0, codegen_1$
|
|
1701
|
+
cxt.setParams({ missingProperty: (0, codegen_1$r._)`${prop}` }, true);
|
|
1965
1702
|
cxt.error();
|
|
1966
1703
|
});
|
|
1967
1704
|
}
|
|
1968
1705
|
code.checkReportMissingProp = checkReportMissingProp;
|
|
1969
1706
|
function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
|
|
1970
|
-
return (0, codegen_1$
|
|
1707
|
+
return (0, codegen_1$r.or)(...properties2.map((prop) => (0, codegen_1$r.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1$r._)`${missing} = ${prop}`)));
|
|
1971
1708
|
}
|
|
1972
1709
|
code.checkMissingProp = checkMissingProp;
|
|
1973
1710
|
function reportMissingProp(cxt, missing) {
|
|
@@ -1979,22 +1716,22 @@ function hasPropFunc(gen) {
|
|
|
1979
1716
|
return gen.scopeValue("func", {
|
|
1980
1717
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1981
1718
|
ref: Object.prototype.hasOwnProperty,
|
|
1982
|
-
code: (0, codegen_1$
|
|
1719
|
+
code: (0, codegen_1$r._)`Object.prototype.hasOwnProperty`
|
|
1983
1720
|
});
|
|
1984
1721
|
}
|
|
1985
1722
|
code.hasPropFunc = hasPropFunc;
|
|
1986
1723
|
function isOwnProperty(gen, data, property) {
|
|
1987
|
-
return (0, codegen_1$
|
|
1724
|
+
return (0, codegen_1$r._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
|
|
1988
1725
|
}
|
|
1989
1726
|
code.isOwnProperty = isOwnProperty;
|
|
1990
1727
|
function propertyInData(gen, data, property, ownProperties) {
|
|
1991
|
-
const cond = (0, codegen_1$
|
|
1992
|
-
return ownProperties ? (0, codegen_1$
|
|
1728
|
+
const cond = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)(property)} !== undefined`;
|
|
1729
|
+
return ownProperties ? (0, codegen_1$r._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
|
1993
1730
|
}
|
|
1994
1731
|
code.propertyInData = propertyInData;
|
|
1995
1732
|
function noPropertyInData(gen, data, property, ownProperties) {
|
|
1996
|
-
const cond = (0, codegen_1$
|
|
1997
|
-
return ownProperties ? (0, codegen_1$
|
|
1733
|
+
const cond = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)(property)} === undefined`;
|
|
1734
|
+
return ownProperties ? (0, codegen_1$r.or)(cond, (0, codegen_1$r.not)(isOwnProperty(gen, data, property))) : cond;
|
|
1998
1735
|
}
|
|
1999
1736
|
code.noPropertyInData = noPropertyInData;
|
|
2000
1737
|
function allSchemaProperties(schemaMap) {
|
|
@@ -2002,24 +1739,24 @@ function allSchemaProperties(schemaMap) {
|
|
|
2002
1739
|
}
|
|
2003
1740
|
code.allSchemaProperties = allSchemaProperties;
|
|
2004
1741
|
function schemaProperties(it, schemaMap) {
|
|
2005
|
-
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$
|
|
1742
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$q.alwaysValidSchema)(it, schemaMap[p]));
|
|
2006
1743
|
}
|
|
2007
1744
|
code.schemaProperties = schemaProperties;
|
|
2008
1745
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context2, passSchema) {
|
|
2009
|
-
const dataAndSchema = passSchema ? (0, codegen_1$
|
|
1746
|
+
const dataAndSchema = passSchema ? (0, codegen_1$r._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
|
2010
1747
|
const valCxt = [
|
|
2011
|
-
[names_1$
|
|
2012
|
-
[names_1$
|
|
2013
|
-
[names_1$
|
|
2014
|
-
[names_1$
|
|
1748
|
+
[names_1$6.default.instancePath, (0, codegen_1$r.strConcat)(names_1$6.default.instancePath, errorPath)],
|
|
1749
|
+
[names_1$6.default.parentData, it.parentData],
|
|
1750
|
+
[names_1$6.default.parentDataProperty, it.parentDataProperty],
|
|
1751
|
+
[names_1$6.default.rootData, names_1$6.default.rootData]
|
|
2015
1752
|
];
|
|
2016
1753
|
if (it.opts.dynamicRef)
|
|
2017
|
-
valCxt.push([names_1$
|
|
2018
|
-
const args = (0, codegen_1$
|
|
2019
|
-
return context2 !== codegen_1$
|
|
1754
|
+
valCxt.push([names_1$6.default.dynamicAnchors, names_1$6.default.dynamicAnchors]);
|
|
1755
|
+
const args = (0, codegen_1$r._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
1756
|
+
return context2 !== codegen_1$r.nil ? (0, codegen_1$r._)`${func}.call(${context2}, ${args})` : (0, codegen_1$r._)`${func}(${args})`;
|
|
2020
1757
|
}
|
|
2021
1758
|
code.callValidateCode = callValidateCode;
|
|
2022
|
-
const newRegExp = (0, codegen_1$
|
|
1759
|
+
const newRegExp = (0, codegen_1$r._)`new RegExp`;
|
|
2023
1760
|
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
2024
1761
|
const u = opts.unicodeRegExp ? "u" : "";
|
|
2025
1762
|
const { regExp } = opts.code;
|
|
@@ -2027,7 +1764,7 @@ function usePattern({ gen, it: { opts } }, pattern2) {
|
|
|
2027
1764
|
return gen.scopeValue("pattern", {
|
|
2028
1765
|
key: rx.toString(),
|
|
2029
1766
|
ref: rx,
|
|
2030
|
-
code: (0, codegen_1$
|
|
1767
|
+
code: (0, codegen_1$r._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
2031
1768
|
});
|
|
2032
1769
|
}
|
|
2033
1770
|
code.usePattern = usePattern;
|
|
@@ -2043,14 +1780,14 @@ function validateArray(cxt) {
|
|
|
2043
1780
|
validateItems(() => gen.break());
|
|
2044
1781
|
return valid;
|
|
2045
1782
|
function validateItems(notValid) {
|
|
2046
|
-
const len = gen.const("len", (0, codegen_1$
|
|
1783
|
+
const len = gen.const("len", (0, codegen_1$r._)`${data}.length`);
|
|
2047
1784
|
gen.forRange("i", 0, len, (i) => {
|
|
2048
1785
|
cxt.subschema({
|
|
2049
1786
|
keyword: keyword2,
|
|
2050
1787
|
dataProp: i,
|
|
2051
|
-
dataPropType: util_1$
|
|
1788
|
+
dataPropType: util_1$q.Type.Num
|
|
2052
1789
|
}, valid);
|
|
2053
|
-
gen.if((0, codegen_1$
|
|
1790
|
+
gen.if((0, codegen_1$r.not)(valid), notValid);
|
|
2054
1791
|
});
|
|
2055
1792
|
}
|
|
2056
1793
|
}
|
|
@@ -2059,7 +1796,7 @@ function validateUnion(cxt) {
|
|
|
2059
1796
|
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
2060
1797
|
if (!Array.isArray(schema))
|
|
2061
1798
|
throw new Error("ajv implementation error");
|
|
2062
|
-
const alwaysValid = schema.some((sch) => (0, util_1$
|
|
1799
|
+
const alwaysValid = schema.some((sch) => (0, util_1$q.alwaysValidSchema)(it, sch));
|
|
2063
1800
|
if (alwaysValid && !it.opts.unevaluated)
|
|
2064
1801
|
return;
|
|
2065
1802
|
const valid = gen.let("valid", false);
|
|
@@ -2070,202 +1807,216 @@ function validateUnion(cxt) {
|
|
|
2070
1807
|
schemaProp: i,
|
|
2071
1808
|
compositeRule: true
|
|
2072
1809
|
}, schValid);
|
|
2073
|
-
gen.assign(valid, (0, codegen_1$
|
|
1810
|
+
gen.assign(valid, (0, codegen_1$r._)`${valid} || ${schValid}`);
|
|
2074
1811
|
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
2075
1812
|
if (!merged)
|
|
2076
|
-
gen.if((0, codegen_1$
|
|
1813
|
+
gen.if((0, codegen_1$r.not)(valid));
|
|
2077
1814
|
}));
|
|
2078
1815
|
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
2079
1816
|
}
|
|
2080
1817
|
code.validateUnion = validateUnion;
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
const
|
|
2089
|
-
const
|
|
2090
|
-
const
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
}
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
checkAsyncKeyword(it, def2);
|
|
2108
|
-
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
2109
|
-
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
2110
|
-
const valid = gen.let("valid");
|
|
2111
|
-
cxt.block$data(valid, validateKeyword);
|
|
2112
|
-
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
2113
|
-
function validateKeyword() {
|
|
2114
|
-
if (def2.errors === false) {
|
|
2115
|
-
assignValid();
|
|
2116
|
-
if (def2.modifying)
|
|
2117
|
-
modifyData(cxt);
|
|
2118
|
-
reportErrs(() => cxt.error());
|
|
2119
|
-
} else {
|
|
2120
|
-
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
2121
|
-
if (def2.modifying)
|
|
2122
|
-
modifyData(cxt);
|
|
2123
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
function validateAsync() {
|
|
2127
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
2128
|
-
gen.try(() => assignValid((0, codegen_1$t._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$t._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$t._)`${e}.errors`), () => gen.throw(e)));
|
|
2129
|
-
return ruleErrs;
|
|
2130
|
-
}
|
|
2131
|
-
function validateSync() {
|
|
2132
|
-
const validateErrs = (0, codegen_1$t._)`${validateRef}.errors`;
|
|
2133
|
-
gen.assign(validateErrs, null);
|
|
2134
|
-
assignValid(codegen_1$t.nil);
|
|
2135
|
-
return validateErrs;
|
|
2136
|
-
}
|
|
2137
|
-
function assignValid(_await = def2.async ? (0, codegen_1$t._)`await ` : codegen_1$t.nil) {
|
|
2138
|
-
const passCxt = it.opts.passContext ? names_1$7.default.this : names_1$7.default.self;
|
|
2139
|
-
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
2140
|
-
gen.assign(valid, (0, codegen_1$t._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
2141
|
-
}
|
|
2142
|
-
function reportErrs(errors2) {
|
|
2143
|
-
var _a2;
|
|
2144
|
-
gen.if((0, codegen_1$t.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
keyword.funcKeywordCode = funcKeywordCode;
|
|
2148
|
-
function modifyData(cxt) {
|
|
2149
|
-
const { gen, data, it } = cxt;
|
|
2150
|
-
gen.if(it.parentData, () => gen.assign(data, (0, codegen_1$t._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
2151
|
-
}
|
|
2152
|
-
function addErrs(cxt, errs) {
|
|
2153
|
-
const { gen } = cxt;
|
|
2154
|
-
gen.if((0, codegen_1$t._)`Array.isArray(${errs})`, () => {
|
|
2155
|
-
gen.assign(names_1$7.default.vErrors, (0, codegen_1$t._)`${names_1$7.default.vErrors} === null ? ${errs} : ${names_1$7.default.vErrors}.concat(${errs})`).assign(names_1$7.default.errors, (0, codegen_1$t._)`${names_1$7.default.vErrors}.length`);
|
|
2156
|
-
(0, errors_1$1.extendErrors)(cxt);
|
|
2157
|
-
}, () => cxt.error());
|
|
2158
|
-
}
|
|
2159
|
-
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
2160
|
-
if (def2.async && !schemaEnv.$async)
|
|
2161
|
-
throw new Error("async keyword in sync schema");
|
|
2162
|
-
}
|
|
2163
|
-
function useKeyword(gen, keyword2, result) {
|
|
2164
|
-
if (result === void 0)
|
|
2165
|
-
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
2166
|
-
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$t.stringify)(result) });
|
|
2167
|
-
}
|
|
2168
|
-
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
2169
|
-
return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
|
|
2170
|
-
}
|
|
2171
|
-
keyword.validSchemaType = validSchemaType;
|
|
2172
|
-
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
2173
|
-
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
2174
|
-
throw new Error("ajv implementation error");
|
|
1818
|
+
var hasRequiredKeyword;
|
|
1819
|
+
function requireKeyword() {
|
|
1820
|
+
if (hasRequiredKeyword)
|
|
1821
|
+
return keyword;
|
|
1822
|
+
hasRequiredKeyword = 1;
|
|
1823
|
+
Object.defineProperty(keyword, "__esModule", { value: true });
|
|
1824
|
+
keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
|
|
1825
|
+
const codegen_12 = codegen;
|
|
1826
|
+
const names_12 = requireNames();
|
|
1827
|
+
const code_12 = code;
|
|
1828
|
+
const errors_12 = errors;
|
|
1829
|
+
function macroKeywordCode(cxt, def2) {
|
|
1830
|
+
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
1831
|
+
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
1832
|
+
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
1833
|
+
if (it.opts.validateSchema !== false)
|
|
1834
|
+
it.self.validateSchema(macroSchema, true);
|
|
1835
|
+
const valid = gen.name("valid");
|
|
1836
|
+
cxt.subschema({
|
|
1837
|
+
schema: macroSchema,
|
|
1838
|
+
schemaPath: codegen_12.nil,
|
|
1839
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
1840
|
+
topSchemaRef: schemaRef,
|
|
1841
|
+
compositeRule: true
|
|
1842
|
+
}, valid);
|
|
1843
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
2175
1844
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
1845
|
+
keyword.macroKeywordCode = macroKeywordCode;
|
|
1846
|
+
function funcKeywordCode(cxt, def2) {
|
|
1847
|
+
var _a;
|
|
1848
|
+
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
1849
|
+
checkAsyncKeyword(it, def2);
|
|
1850
|
+
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
1851
|
+
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
1852
|
+
const valid = gen.let("valid");
|
|
1853
|
+
cxt.block$data(valid, validateKeyword);
|
|
1854
|
+
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
1855
|
+
function validateKeyword() {
|
|
1856
|
+
if (def2.errors === false) {
|
|
1857
|
+
assignValid();
|
|
1858
|
+
if (def2.modifying)
|
|
1859
|
+
modifyData(cxt);
|
|
1860
|
+
reportErrs(() => cxt.error());
|
|
1861
|
+
} else {
|
|
1862
|
+
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
1863
|
+
if (def2.modifying)
|
|
1864
|
+
modifyData(cxt);
|
|
1865
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
function validateAsync() {
|
|
1869
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
1870
|
+
gen.try(() => assignValid((0, codegen_12._)`await `), (e) => gen.assign(valid, false).if((0, codegen_12._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_12._)`${e}.errors`), () => gen.throw(e)));
|
|
1871
|
+
return ruleErrs;
|
|
1872
|
+
}
|
|
1873
|
+
function validateSync() {
|
|
1874
|
+
const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
|
|
1875
|
+
gen.assign(validateErrs, null);
|
|
1876
|
+
assignValid(codegen_12.nil);
|
|
1877
|
+
return validateErrs;
|
|
1878
|
+
}
|
|
1879
|
+
function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
|
|
1880
|
+
const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
|
|
1881
|
+
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
1882
|
+
gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
1883
|
+
}
|
|
1884
|
+
function reportErrs(errors2) {
|
|
1885
|
+
var _a2;
|
|
1886
|
+
gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
1887
|
+
}
|
|
2179
1888
|
}
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
1889
|
+
keyword.funcKeywordCode = funcKeywordCode;
|
|
1890
|
+
function modifyData(cxt) {
|
|
1891
|
+
const { gen, data, it } = cxt;
|
|
1892
|
+
gen.if(it.parentData, () => gen.assign(data, (0, codegen_12._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
1893
|
+
}
|
|
1894
|
+
function addErrs(cxt, errs) {
|
|
1895
|
+
const { gen } = cxt;
|
|
1896
|
+
gen.if((0, codegen_12._)`Array.isArray(${errs})`, () => {
|
|
1897
|
+
gen.assign(names_12.default.vErrors, (0, codegen_12._)`${names_12.default.vErrors} === null ? ${errs} : ${names_12.default.vErrors}.concat(${errs})`).assign(names_12.default.errors, (0, codegen_12._)`${names_12.default.vErrors}.length`);
|
|
1898
|
+
(0, errors_12.extendErrors)(cxt);
|
|
1899
|
+
}, () => cxt.error());
|
|
1900
|
+
}
|
|
1901
|
+
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
1902
|
+
if (def2.async && !schemaEnv.$async)
|
|
1903
|
+
throw new Error("async keyword in sync schema");
|
|
1904
|
+
}
|
|
1905
|
+
function useKeyword(gen, keyword2, result) {
|
|
1906
|
+
if (result === void 0)
|
|
1907
|
+
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
1908
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_12.stringify)(result) });
|
|
1909
|
+
}
|
|
1910
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
1911
|
+
return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
|
|
1912
|
+
}
|
|
1913
|
+
keyword.validSchemaType = validSchemaType;
|
|
1914
|
+
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
1915
|
+
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
1916
|
+
throw new Error("ajv implementation error");
|
|
1917
|
+
}
|
|
1918
|
+
const deps = def2.dependencies;
|
|
1919
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
1920
|
+
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
1921
|
+
}
|
|
1922
|
+
if (def2.validateSchema) {
|
|
1923
|
+
const valid = def2.validateSchema(schema[keyword2]);
|
|
1924
|
+
if (!valid) {
|
|
1925
|
+
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
|
|
1926
|
+
if (opts.validateSchema === "log")
|
|
1927
|
+
self.logger.error(msg);
|
|
1928
|
+
else
|
|
1929
|
+
throw new Error(msg);
|
|
1930
|
+
}
|
|
2188
1931
|
}
|
|
2189
1932
|
}
|
|
1933
|
+
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
1934
|
+
return keyword;
|
|
2190
1935
|
}
|
|
2191
|
-
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
2192
1936
|
var subschema = {};
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
schema
|
|
2205
|
-
schemaPath: (0, codegen_1$s._)`${it.schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}`,
|
|
2206
|
-
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
2207
|
-
} : {
|
|
2208
|
-
schema: sch[schemaProp],
|
|
2209
|
-
schemaPath: (0, codegen_1$s._)`${it.schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}${(0, codegen_1$s.getProperty)(schemaProp)}`,
|
|
2210
|
-
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$r.escapeFragment)(schemaProp)}`
|
|
2211
|
-
};
|
|
2212
|
-
}
|
|
2213
|
-
if (schema !== void 0) {
|
|
2214
|
-
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
2215
|
-
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
1937
|
+
var hasRequiredSubschema;
|
|
1938
|
+
function requireSubschema() {
|
|
1939
|
+
if (hasRequiredSubschema)
|
|
1940
|
+
return subschema;
|
|
1941
|
+
hasRequiredSubschema = 1;
|
|
1942
|
+
Object.defineProperty(subschema, "__esModule", { value: true });
|
|
1943
|
+
subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
|
|
1944
|
+
const codegen_12 = codegen;
|
|
1945
|
+
const util_12 = util;
|
|
1946
|
+
function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
1947
|
+
if (keyword2 !== void 0 && schema !== void 0) {
|
|
1948
|
+
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
2216
1949
|
}
|
|
2217
|
-
|
|
2218
|
-
schema
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
}
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
1950
|
+
if (keyword2 !== void 0) {
|
|
1951
|
+
const sch = it.schema[keyword2];
|
|
1952
|
+
return schemaProp === void 0 ? {
|
|
1953
|
+
schema: sch,
|
|
1954
|
+
schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}`,
|
|
1955
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
1956
|
+
} : {
|
|
1957
|
+
schema: sch[schemaProp],
|
|
1958
|
+
schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}${(0, codegen_12.getProperty)(schemaProp)}`,
|
|
1959
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_12.escapeFragment)(schemaProp)}`
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
if (schema !== void 0) {
|
|
1963
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
1964
|
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
1965
|
+
}
|
|
1966
|
+
return {
|
|
1967
|
+
schema,
|
|
1968
|
+
schemaPath,
|
|
1969
|
+
topSchemaRef,
|
|
1970
|
+
errSchemaPath
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
throw new Error('either "keyword" or "schema" must be passed');
|
|
1974
|
+
}
|
|
1975
|
+
subschema.getSubschema = getSubschema;
|
|
1976
|
+
function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
|
|
1977
|
+
if (data !== void 0 && dataProp !== void 0) {
|
|
1978
|
+
throw new Error('both "data" and "dataProp" passed, only one allowed');
|
|
1979
|
+
}
|
|
1980
|
+
const { gen } = it;
|
|
1981
|
+
if (dataProp !== void 0) {
|
|
1982
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
1983
|
+
const nextData = gen.let("data", (0, codegen_12._)`${it.data}${(0, codegen_12.getProperty)(dataProp)}`, true);
|
|
1984
|
+
dataContextProps(nextData);
|
|
1985
|
+
subschema2.errorPath = (0, codegen_12.str)`${errorPath}${(0, util_12.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
1986
|
+
subschema2.parentDataProperty = (0, codegen_12._)`${dataProp}`;
|
|
1987
|
+
subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
|
|
1988
|
+
}
|
|
1989
|
+
if (data !== void 0) {
|
|
1990
|
+
const nextData = data instanceof codegen_12.Name ? data : gen.let("data", data, true);
|
|
1991
|
+
dataContextProps(nextData);
|
|
1992
|
+
if (propertyName !== void 0)
|
|
1993
|
+
subschema2.propertyName = propertyName;
|
|
1994
|
+
}
|
|
1995
|
+
if (dataTypes)
|
|
1996
|
+
subschema2.dataTypes = dataTypes;
|
|
1997
|
+
function dataContextProps(_nextData) {
|
|
1998
|
+
subschema2.data = _nextData;
|
|
1999
|
+
subschema2.dataLevel = it.dataLevel + 1;
|
|
2000
|
+
subschema2.dataTypes = [];
|
|
2001
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
2002
|
+
subschema2.parentData = it.data;
|
|
2003
|
+
subschema2.dataNames = [...it.dataNames, _nextData];
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
subschema.extendSubschemaData = extendSubschemaData;
|
|
2007
|
+
function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
2008
|
+
if (compositeRule !== void 0)
|
|
2009
|
+
subschema2.compositeRule = compositeRule;
|
|
2010
|
+
if (createErrors !== void 0)
|
|
2011
|
+
subschema2.createErrors = createErrors;
|
|
2012
|
+
if (allErrors !== void 0)
|
|
2013
|
+
subschema2.allErrors = allErrors;
|
|
2014
|
+
subschema2.jtdDiscriminator = jtdDiscriminator;
|
|
2015
|
+
subschema2.jtdMetadata = jtdMetadata;
|
|
2016
|
+
}
|
|
2017
|
+
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
2018
|
+
return subschema;
|
|
2267
2019
|
}
|
|
2268
|
-
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
2269
2020
|
var resolve$2 = {};
|
|
2270
2021
|
var fastDeepEqual = function equal(a, b) {
|
|
2271
2022
|
if (a === b)
|
|
@@ -2390,7 +2141,7 @@ function escapeJsonPtr(str) {
|
|
|
2390
2141
|
var jsonSchemaTraverseExports = jsonSchemaTraverse.exports;
|
|
2391
2142
|
Object.defineProperty(resolve$2, "__esModule", { value: true });
|
|
2392
2143
|
resolve$2.getSchemaRefs = resolve$2.resolveUrl = resolve$2.normalizeId = resolve$2._getFullPath = resolve$2.getFullPath = resolve$2.inlineRef = void 0;
|
|
2393
|
-
const util_1$
|
|
2144
|
+
const util_1$p = util;
|
|
2394
2145
|
const equal$3 = fastDeepEqual;
|
|
2395
2146
|
const traverse = jsonSchemaTraverseExports;
|
|
2396
2147
|
const SIMPLE_INLINED = /* @__PURE__ */ new Set([
|
|
@@ -2449,7 +2200,7 @@ function countKeys(schema) {
|
|
|
2449
2200
|
if (SIMPLE_INLINED.has(key))
|
|
2450
2201
|
continue;
|
|
2451
2202
|
if (typeof schema[key] == "object") {
|
|
2452
|
-
(0, util_1$
|
|
2203
|
+
(0, util_1$p.eachItem)(schema[key], (sch) => count += countKeys(sch));
|
|
2453
2204
|
}
|
|
2454
2205
|
if (count === Infinity)
|
|
2455
2206
|
return Infinity;
|
|
@@ -2537,506 +2288,513 @@ function getSchemaRefs(schema, baseId) {
|
|
|
2537
2288
|
}
|
|
2538
2289
|
}
|
|
2539
2290
|
resolve$2.getSchemaRefs = getSchemaRefs;
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
const
|
|
2548
|
-
const
|
|
2549
|
-
const
|
|
2550
|
-
const
|
|
2551
|
-
const
|
|
2552
|
-
const
|
|
2553
|
-
const
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2291
|
+
var hasRequiredValidate;
|
|
2292
|
+
function requireValidate() {
|
|
2293
|
+
if (hasRequiredValidate)
|
|
2294
|
+
return validate;
|
|
2295
|
+
hasRequiredValidate = 1;
|
|
2296
|
+
Object.defineProperty(validate, "__esModule", { value: true });
|
|
2297
|
+
validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
|
|
2298
|
+
const boolSchema_1 = requireBoolSchema();
|
|
2299
|
+
const dataType_12 = dataType;
|
|
2300
|
+
const applicability_12 = requireApplicability();
|
|
2301
|
+
const dataType_2 = dataType;
|
|
2302
|
+
const defaults_1 = requireDefaults();
|
|
2303
|
+
const keyword_1 = requireKeyword();
|
|
2304
|
+
const subschema_1 = requireSubschema();
|
|
2305
|
+
const codegen_12 = codegen;
|
|
2306
|
+
const names_12 = requireNames();
|
|
2307
|
+
const resolve_12 = resolve$2;
|
|
2308
|
+
const util_12 = util;
|
|
2309
|
+
const errors_12 = errors;
|
|
2310
|
+
function validateFunctionCode(it) {
|
|
2311
|
+
if (isSchemaObj(it)) {
|
|
2312
|
+
checkKeywords(it);
|
|
2313
|
+
if (schemaCxtHasRules(it)) {
|
|
2314
|
+
topSchemaObjCode(it);
|
|
2315
|
+
return;
|
|
2316
|
+
}
|
|
2560
2317
|
}
|
|
2318
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2561
2319
|
}
|
|
2562
|
-
|
|
2563
|
-
}
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2320
|
+
validate.validateFunctionCode = validateFunctionCode;
|
|
2321
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
2322
|
+
if (opts.code.es5) {
|
|
2323
|
+
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${names_12.default.valCxt}`, schemaEnv.$async, () => {
|
|
2324
|
+
gen.code((0, codegen_12._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
2325
|
+
destructureValCxtES5(gen, opts);
|
|
2326
|
+
gen.code(body);
|
|
2327
|
+
});
|
|
2328
|
+
} else {
|
|
2329
|
+
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
function destructureValCxt(opts) {
|
|
2333
|
+
return (0, codegen_12._)`{${names_12.default.instancePath}="", ${names_12.default.parentData}, ${names_12.default.parentDataProperty}, ${names_12.default.rootData}=${names_12.default.data}${opts.dynamicRef ? (0, codegen_12._)`, ${names_12.default.dynamicAnchors}={}` : codegen_12.nil}}={}`;
|
|
2334
|
+
}
|
|
2335
|
+
function destructureValCxtES5(gen, opts) {
|
|
2336
|
+
gen.if(names_12.default.valCxt, () => {
|
|
2337
|
+
gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
|
|
2338
|
+
gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
|
|
2339
|
+
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
|
|
2340
|
+
gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
|
|
2341
|
+
if (opts.dynamicRef)
|
|
2342
|
+
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
|
|
2343
|
+
}, () => {
|
|
2344
|
+
gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
|
|
2345
|
+
gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
|
|
2346
|
+
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
|
|
2347
|
+
gen.var(names_12.default.rootData, names_12.default.data);
|
|
2348
|
+
if (opts.dynamicRef)
|
|
2349
|
+
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
|
|
2571
2350
|
});
|
|
2572
|
-
} else {
|
|
2573
|
-
gen.func(validateName, (0, codegen_1$r._)`${names_1$6.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2574
2351
|
}
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
gen
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
}
|
|
2596
|
-
function
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
returnResults(it);
|
|
2608
|
-
});
|
|
2609
|
-
return;
|
|
2610
|
-
}
|
|
2611
|
-
function resetEvaluated(it) {
|
|
2612
|
-
const { gen, validateName } = it;
|
|
2613
|
-
it.evaluated = gen.const("evaluated", (0, codegen_1$r._)`${validateName}.evaluated`);
|
|
2614
|
-
gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.props`, (0, codegen_1$r._)`undefined`));
|
|
2615
|
-
gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.items`, (0, codegen_1$r._)`undefined`));
|
|
2616
|
-
}
|
|
2617
|
-
function funcSourceUrl(schema, opts) {
|
|
2618
|
-
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2619
|
-
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$r._)`/*# sourceURL=${schId} */` : codegen_1$r.nil;
|
|
2620
|
-
}
|
|
2621
|
-
function subschemaCode(it, valid) {
|
|
2622
|
-
if (isSchemaObj(it)) {
|
|
2623
|
-
checkKeywords(it);
|
|
2624
|
-
if (schemaCxtHasRules(it)) {
|
|
2625
|
-
subSchemaObjCode(it, valid);
|
|
2626
|
-
return;
|
|
2352
|
+
function topSchemaObjCode(it) {
|
|
2353
|
+
const { schema, opts, gen } = it;
|
|
2354
|
+
validateFunction(it, () => {
|
|
2355
|
+
if (opts.$comment && schema.$comment)
|
|
2356
|
+
commentKeyword(it);
|
|
2357
|
+
checkNoDefault(it);
|
|
2358
|
+
gen.let(names_12.default.vErrors, null);
|
|
2359
|
+
gen.let(names_12.default.errors, 0);
|
|
2360
|
+
if (opts.unevaluated)
|
|
2361
|
+
resetEvaluated(it);
|
|
2362
|
+
typeAndKeywords(it);
|
|
2363
|
+
returnResults(it);
|
|
2364
|
+
});
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
function resetEvaluated(it) {
|
|
2368
|
+
const { gen, validateName } = it;
|
|
2369
|
+
it.evaluated = gen.const("evaluated", (0, codegen_12._)`${validateName}.evaluated`);
|
|
2370
|
+
gen.if((0, codegen_12._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_12._)`${it.evaluated}.props`, (0, codegen_12._)`undefined`));
|
|
2371
|
+
gen.if((0, codegen_12._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_12._)`${it.evaluated}.items`, (0, codegen_12._)`undefined`));
|
|
2372
|
+
}
|
|
2373
|
+
function funcSourceUrl(schema, opts) {
|
|
2374
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2375
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_12._)`/*# sourceURL=${schId} */` : codegen_12.nil;
|
|
2376
|
+
}
|
|
2377
|
+
function subschemaCode(it, valid) {
|
|
2378
|
+
if (isSchemaObj(it)) {
|
|
2379
|
+
checkKeywords(it);
|
|
2380
|
+
if (schemaCxtHasRules(it)) {
|
|
2381
|
+
subSchemaObjCode(it, valid);
|
|
2382
|
+
return;
|
|
2383
|
+
}
|
|
2627
2384
|
}
|
|
2385
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2628
2386
|
}
|
|
2629
|
-
(
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
return true;
|
|
2637
|
-
return false;
|
|
2638
|
-
}
|
|
2639
|
-
function isSchemaObj(it) {
|
|
2640
|
-
return typeof it.schema != "boolean";
|
|
2641
|
-
}
|
|
2642
|
-
function subSchemaObjCode(it, valid) {
|
|
2643
|
-
const { schema, gen, opts } = it;
|
|
2644
|
-
if (opts.$comment && schema.$comment)
|
|
2645
|
-
commentKeyword(it);
|
|
2646
|
-
updateContext(it);
|
|
2647
|
-
checkAsyncSchema(it);
|
|
2648
|
-
const errsCount = gen.const("_errs", names_1$6.default.errors);
|
|
2649
|
-
typeAndKeywords(it, errsCount);
|
|
2650
|
-
gen.var(valid, (0, codegen_1$r._)`${errsCount} === ${names_1$6.default.errors}`);
|
|
2651
|
-
}
|
|
2652
|
-
function checkKeywords(it) {
|
|
2653
|
-
(0, util_1$p.checkUnknownRules)(it);
|
|
2654
|
-
checkRefsAndKeywords(it);
|
|
2655
|
-
}
|
|
2656
|
-
function typeAndKeywords(it, errsCount) {
|
|
2657
|
-
if (it.opts.jtd)
|
|
2658
|
-
return schemaKeywords(it, [], false, errsCount);
|
|
2659
|
-
const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
|
|
2660
|
-
const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
|
|
2661
|
-
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2662
|
-
}
|
|
2663
|
-
function checkRefsAndKeywords(it) {
|
|
2664
|
-
const { schema, errSchemaPath, opts, self } = it;
|
|
2665
|
-
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$p.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2666
|
-
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2387
|
+
function schemaCxtHasRules({ schema, self }) {
|
|
2388
|
+
if (typeof schema == "boolean")
|
|
2389
|
+
return !schema;
|
|
2390
|
+
for (const key in schema)
|
|
2391
|
+
if (self.RULES.all[key])
|
|
2392
|
+
return true;
|
|
2393
|
+
return false;
|
|
2667
2394
|
}
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
const { schema, opts } = it;
|
|
2671
|
-
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
2672
|
-
(0, util_1$p.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2395
|
+
function isSchemaObj(it) {
|
|
2396
|
+
return typeof it.schema != "boolean";
|
|
2673
2397
|
}
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
}
|
|
2684
|
-
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2685
|
-
const msg = schema.$comment;
|
|
2686
|
-
if (opts.$comment === true) {
|
|
2687
|
-
gen.code((0, codegen_1$r._)`${names_1$6.default.self}.logger.log(${msg})`);
|
|
2688
|
-
} else if (typeof opts.$comment == "function") {
|
|
2689
|
-
const schemaPath = (0, codegen_1$r.str)`${errSchemaPath}/$comment`;
|
|
2690
|
-
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2691
|
-
gen.code((0, codegen_1$r._)`${names_1$6.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2398
|
+
function subSchemaObjCode(it, valid) {
|
|
2399
|
+
const { schema, gen, opts } = it;
|
|
2400
|
+
if (opts.$comment && schema.$comment)
|
|
2401
|
+
commentKeyword(it);
|
|
2402
|
+
updateContext(it);
|
|
2403
|
+
checkAsyncSchema(it);
|
|
2404
|
+
const errsCount = gen.const("_errs", names_12.default.errors);
|
|
2405
|
+
typeAndKeywords(it, errsCount);
|
|
2406
|
+
gen.var(valid, (0, codegen_12._)`${errsCount} === ${names_12.default.errors}`);
|
|
2692
2407
|
}
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
if (schemaEnv.$async) {
|
|
2697
|
-
gen.if((0, codegen_1$r._)`${names_1$6.default.errors} === 0`, () => gen.return(names_1$6.default.data), () => gen.throw((0, codegen_1$r._)`new ${ValidationError2}(${names_1$6.default.vErrors})`));
|
|
2698
|
-
} else {
|
|
2699
|
-
gen.assign((0, codegen_1$r._)`${validateName}.errors`, names_1$6.default.vErrors);
|
|
2700
|
-
if (opts.unevaluated)
|
|
2701
|
-
assignEvaluated(it);
|
|
2702
|
-
gen.return((0, codegen_1$r._)`${names_1$6.default.errors} === 0`);
|
|
2408
|
+
function checkKeywords(it) {
|
|
2409
|
+
(0, util_12.checkUnknownRules)(it);
|
|
2410
|
+
checkRefsAndKeywords(it);
|
|
2703
2411
|
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
}
|
|
2711
|
-
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2712
|
-
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2713
|
-
const { RULES } = self;
|
|
2714
|
-
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$p.schemaHasRulesButRef)(schema, RULES))) {
|
|
2715
|
-
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2716
|
-
return;
|
|
2412
|
+
function typeAndKeywords(it, errsCount) {
|
|
2413
|
+
if (it.opts.jtd)
|
|
2414
|
+
return schemaKeywords(it, [], false, errsCount);
|
|
2415
|
+
const types2 = (0, dataType_12.getSchemaTypes)(it.schema);
|
|
2416
|
+
const checkedTypes = (0, dataType_12.coerceAndCheckDataType)(it, types2);
|
|
2417
|
+
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2717
2418
|
}
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
if (
|
|
2419
|
+
function checkRefsAndKeywords(it) {
|
|
2420
|
+
const { schema, errSchemaPath, opts, self } = it;
|
|
2421
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_12.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2422
|
+
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
function checkNoDefault(it) {
|
|
2426
|
+
const { schema, opts } = it;
|
|
2427
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
2428
|
+
(0, util_12.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
function updateContext(it) {
|
|
2432
|
+
const schId = it.schema[it.opts.schemaId];
|
|
2433
|
+
if (schId)
|
|
2434
|
+
it.baseId = (0, resolve_12.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
2435
|
+
}
|
|
2436
|
+
function checkAsyncSchema(it) {
|
|
2437
|
+
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2438
|
+
throw new Error("async schema in sync schema");
|
|
2439
|
+
}
|
|
2440
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2441
|
+
const msg = schema.$comment;
|
|
2442
|
+
if (opts.$comment === true) {
|
|
2443
|
+
gen.code((0, codegen_12._)`${names_12.default.self}.logger.log(${msg})`);
|
|
2444
|
+
} else if (typeof opts.$comment == "function") {
|
|
2445
|
+
const schemaPath = (0, codegen_12.str)`${errSchemaPath}/$comment`;
|
|
2446
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2447
|
+
gen.code((0, codegen_12._)`${names_12.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
function returnResults(it) {
|
|
2451
|
+
const { gen, schemaEnv, validateName, ValidationError: ValidationError2, opts } = it;
|
|
2452
|
+
if (schemaEnv.$async) {
|
|
2453
|
+
gen.if((0, codegen_12._)`${names_12.default.errors} === 0`, () => gen.return(names_12.default.data), () => gen.throw((0, codegen_12._)`new ${ValidationError2}(${names_12.default.vErrors})`));
|
|
2454
|
+
} else {
|
|
2455
|
+
gen.assign((0, codegen_12._)`${validateName}.errors`, names_12.default.vErrors);
|
|
2456
|
+
if (opts.unevaluated)
|
|
2457
|
+
assignEvaluated(it);
|
|
2458
|
+
gen.return((0, codegen_12._)`${names_12.default.errors} === 0`);
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
2462
|
+
if (props instanceof codegen_12.Name)
|
|
2463
|
+
gen.assign((0, codegen_12._)`${evaluated}.props`, props);
|
|
2464
|
+
if (items2 instanceof codegen_12.Name)
|
|
2465
|
+
gen.assign((0, codegen_12._)`${evaluated}.items`, items2);
|
|
2466
|
+
}
|
|
2467
|
+
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2468
|
+
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2469
|
+
const { RULES } = self;
|
|
2470
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_12.schemaHasRulesButRef)(schema, RULES))) {
|
|
2471
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2727
2472
|
return;
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
(
|
|
2473
|
+
}
|
|
2474
|
+
if (!opts.jtd)
|
|
2475
|
+
checkStrictTypes(it, types2);
|
|
2476
|
+
gen.block(() => {
|
|
2477
|
+
for (const group of RULES.rules)
|
|
2478
|
+
groupKeywords(group);
|
|
2479
|
+
groupKeywords(RULES.post);
|
|
2480
|
+
});
|
|
2481
|
+
function groupKeywords(group) {
|
|
2482
|
+
if (!(0, applicability_12.shouldUseGroup)(schema, group))
|
|
2483
|
+
return;
|
|
2484
|
+
if (group.type) {
|
|
2485
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
2486
|
+
iterateKeywords(it, group);
|
|
2487
|
+
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2488
|
+
gen.else();
|
|
2489
|
+
(0, dataType_2.reportTypeError)(it);
|
|
2490
|
+
}
|
|
2491
|
+
gen.endIf();
|
|
2492
|
+
} else {
|
|
2493
|
+
iterateKeywords(it, group);
|
|
2734
2494
|
}
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
iterateKeywords(it, group);
|
|
2495
|
+
if (!allErrors)
|
|
2496
|
+
gen.if((0, codegen_12._)`${names_12.default.errors} === ${errsCount || 0}`);
|
|
2738
2497
|
}
|
|
2739
|
-
if (!allErrors)
|
|
2740
|
-
gen.if((0, codegen_1$r._)`${names_1$6.default.errors} === ${errsCount || 0}`);
|
|
2741
2498
|
}
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
(
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2499
|
+
function iterateKeywords(it, group) {
|
|
2500
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
2501
|
+
if (useDefaults)
|
|
2502
|
+
(0, defaults_1.assignDefaults)(it, group.type);
|
|
2503
|
+
gen.block(() => {
|
|
2504
|
+
for (const rule of group.rules) {
|
|
2505
|
+
if ((0, applicability_12.shouldUseRule)(schema, rule)) {
|
|
2506
|
+
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
2507
|
+
}
|
|
2751
2508
|
}
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
function checkStrictTypes(it, types2) {
|
|
2512
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2513
|
+
return;
|
|
2514
|
+
checkContextTypes(it, types2);
|
|
2515
|
+
if (!it.opts.allowUnionTypes)
|
|
2516
|
+
checkMultipleTypes(it, types2);
|
|
2517
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
2518
|
+
}
|
|
2519
|
+
function checkContextTypes(it, types2) {
|
|
2520
|
+
if (!types2.length)
|
|
2521
|
+
return;
|
|
2522
|
+
if (!it.dataTypes.length) {
|
|
2523
|
+
it.dataTypes = types2;
|
|
2524
|
+
return;
|
|
2752
2525
|
}
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
if (!it.opts.allowUnionTypes)
|
|
2760
|
-
checkMultipleTypes(it, types2);
|
|
2761
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
2762
|
-
}
|
|
2763
|
-
function checkContextTypes(it, types2) {
|
|
2764
|
-
if (!types2.length)
|
|
2765
|
-
return;
|
|
2766
|
-
if (!it.dataTypes.length) {
|
|
2767
|
-
it.dataTypes = types2;
|
|
2768
|
-
return;
|
|
2526
|
+
types2.forEach((t) => {
|
|
2527
|
+
if (!includesType(it.dataTypes, t)) {
|
|
2528
|
+
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
2529
|
+
}
|
|
2530
|
+
});
|
|
2531
|
+
narrowSchemaTypes(it, types2);
|
|
2769
2532
|
}
|
|
2770
|
-
|
|
2771
|
-
if (!
|
|
2772
|
-
strictTypesError(it,
|
|
2533
|
+
function checkMultipleTypes(it, ts) {
|
|
2534
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2535
|
+
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2773
2536
|
}
|
|
2774
|
-
});
|
|
2775
|
-
narrowSchemaTypes(it, types2);
|
|
2776
|
-
}
|
|
2777
|
-
function checkMultipleTypes(it, ts) {
|
|
2778
|
-
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2779
|
-
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2780
2537
|
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2538
|
+
function checkKeywordTypes(it, ts) {
|
|
2539
|
+
const rules2 = it.self.RULES.all;
|
|
2540
|
+
for (const keyword2 in rules2) {
|
|
2541
|
+
const rule = rules2[keyword2];
|
|
2542
|
+
if (typeof rule == "object" && (0, applicability_12.shouldUseRule)(it.schema, rule)) {
|
|
2543
|
+
const { type: type2 } = rule.definition;
|
|
2544
|
+
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
2545
|
+
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
2546
|
+
}
|
|
2790
2547
|
}
|
|
2791
2548
|
}
|
|
2792
2549
|
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2550
|
+
function hasApplicableType(schTs, kwdT) {
|
|
2551
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
2552
|
+
}
|
|
2553
|
+
function includesType(ts, t) {
|
|
2554
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
2555
|
+
}
|
|
2556
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
2557
|
+
const ts = [];
|
|
2558
|
+
for (const t of it.dataTypes) {
|
|
2559
|
+
if (includesType(withTypes, t))
|
|
2560
|
+
ts.push(t);
|
|
2561
|
+
else if (withTypes.includes("integer") && t === "number")
|
|
2562
|
+
ts.push("integer");
|
|
2563
|
+
}
|
|
2564
|
+
it.dataTypes = ts;
|
|
2565
|
+
}
|
|
2566
|
+
function strictTypesError(it, msg) {
|
|
2567
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
2568
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
2569
|
+
(0, util_12.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
2570
|
+
}
|
|
2571
|
+
class KeywordCxt {
|
|
2572
|
+
constructor(it, def2, keyword2) {
|
|
2573
|
+
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
2574
|
+
this.gen = it.gen;
|
|
2575
|
+
this.allErrors = it.allErrors;
|
|
2576
|
+
this.keyword = keyword2;
|
|
2577
|
+
this.data = it.data;
|
|
2578
|
+
this.schema = it.schema[keyword2];
|
|
2579
|
+
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
2580
|
+
this.schemaValue = (0, util_12.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
2581
|
+
this.schemaType = def2.schemaType;
|
|
2582
|
+
this.parentSchema = it.schema;
|
|
2583
|
+
this.params = {};
|
|
2584
|
+
this.it = it;
|
|
2585
|
+
this.def = def2;
|
|
2586
|
+
if (this.$data) {
|
|
2587
|
+
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
2588
|
+
} else {
|
|
2589
|
+
this.schemaCode = this.schemaValue;
|
|
2590
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
2591
|
+
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2595
|
+
this.errsCount = it.gen.const("_errs", names_12.default.errors);
|
|
2836
2596
|
}
|
|
2837
2597
|
}
|
|
2838
|
-
|
|
2839
|
-
this.
|
|
2598
|
+
result(condition, successAction, failAction) {
|
|
2599
|
+
this.failResult((0, codegen_12.not)(condition), successAction, failAction);
|
|
2840
2600
|
}
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2601
|
+
failResult(condition, successAction, failAction) {
|
|
2602
|
+
this.gen.if(condition);
|
|
2603
|
+
if (failAction)
|
|
2604
|
+
failAction();
|
|
2605
|
+
else
|
|
2606
|
+
this.error();
|
|
2607
|
+
if (successAction) {
|
|
2608
|
+
this.gen.else();
|
|
2609
|
+
successAction();
|
|
2610
|
+
if (this.allErrors)
|
|
2611
|
+
this.gen.endIf();
|
|
2612
|
+
} else {
|
|
2613
|
+
if (this.allErrors)
|
|
2614
|
+
this.gen.endIf();
|
|
2615
|
+
else
|
|
2616
|
+
this.gen.else();
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
pass(condition, failAction) {
|
|
2620
|
+
this.failResult((0, codegen_12.not)(condition), void 0, failAction);
|
|
2621
|
+
}
|
|
2622
|
+
fail(condition) {
|
|
2623
|
+
if (condition === void 0) {
|
|
2624
|
+
this.error();
|
|
2625
|
+
if (!this.allErrors)
|
|
2626
|
+
this.gen.if(false);
|
|
2627
|
+
return;
|
|
2628
|
+
}
|
|
2629
|
+
this.gen.if(condition);
|
|
2850
2630
|
this.error();
|
|
2851
|
-
if (successAction) {
|
|
2852
|
-
this.gen.else();
|
|
2853
|
-
successAction();
|
|
2854
|
-
if (this.allErrors)
|
|
2855
|
-
this.gen.endIf();
|
|
2856
|
-
} else {
|
|
2857
2631
|
if (this.allErrors)
|
|
2858
2632
|
this.gen.endIf();
|
|
2859
2633
|
else
|
|
2860
2634
|
this.gen.else();
|
|
2861
2635
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2636
|
+
fail$data(condition) {
|
|
2637
|
+
if (!this.$data)
|
|
2638
|
+
return this.fail(condition);
|
|
2639
|
+
const { schemaCode } = this;
|
|
2640
|
+
this.fail((0, codegen_12._)`${schemaCode} !== undefined && (${(0, codegen_12.or)(this.invalid$data(), condition)})`);
|
|
2641
|
+
}
|
|
2642
|
+
error(append, errorParams, errorPaths) {
|
|
2643
|
+
if (errorParams) {
|
|
2644
|
+
this.setParams(errorParams);
|
|
2645
|
+
this._error(append, errorPaths);
|
|
2646
|
+
this.setParams({});
|
|
2647
|
+
return;
|
|
2648
|
+
}
|
|
2649
|
+
this._error(append, errorPaths);
|
|
2650
|
+
}
|
|
2651
|
+
_error(append, errorPaths) {
|
|
2652
|
+
(append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
|
|
2653
|
+
}
|
|
2654
|
+
$dataError() {
|
|
2655
|
+
(0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
|
|
2656
|
+
}
|
|
2657
|
+
reset() {
|
|
2658
|
+
if (this.errsCount === void 0)
|
|
2659
|
+
throw new Error('add "trackErrors" to keyword definition');
|
|
2660
|
+
(0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
|
|
2661
|
+
}
|
|
2662
|
+
ok(cond) {
|
|
2869
2663
|
if (!this.allErrors)
|
|
2870
|
-
this.gen.if(
|
|
2871
|
-
return;
|
|
2664
|
+
this.gen.if(cond);
|
|
2872
2665
|
}
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
this.gen.else();
|
|
2879
|
-
}
|
|
2880
|
-
fail$data(condition) {
|
|
2881
|
-
if (!this.$data)
|
|
2882
|
-
return this.fail(condition);
|
|
2883
|
-
const { schemaCode } = this;
|
|
2884
|
-
this.fail((0, codegen_1$r._)`${schemaCode} !== undefined && (${(0, codegen_1$r.or)(this.invalid$data(), condition)})`);
|
|
2885
|
-
}
|
|
2886
|
-
error(append, errorParams, errorPaths) {
|
|
2887
|
-
if (errorParams) {
|
|
2888
|
-
this.setParams(errorParams);
|
|
2889
|
-
this._error(append, errorPaths);
|
|
2890
|
-
this.setParams({});
|
|
2891
|
-
return;
|
|
2666
|
+
setParams(obj, assign) {
|
|
2667
|
+
if (assign)
|
|
2668
|
+
Object.assign(this.params, obj);
|
|
2669
|
+
else
|
|
2670
|
+
this.params = obj;
|
|
2892
2671
|
}
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
$dataError() {
|
|
2899
|
-
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
2900
|
-
}
|
|
2901
|
-
reset() {
|
|
2902
|
-
if (this.errsCount === void 0)
|
|
2903
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
2904
|
-
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
2905
|
-
}
|
|
2906
|
-
ok(cond) {
|
|
2907
|
-
if (!this.allErrors)
|
|
2908
|
-
this.gen.if(cond);
|
|
2909
|
-
}
|
|
2910
|
-
setParams(obj, assign) {
|
|
2911
|
-
if (assign)
|
|
2912
|
-
Object.assign(this.params, obj);
|
|
2913
|
-
else
|
|
2914
|
-
this.params = obj;
|
|
2915
|
-
}
|
|
2916
|
-
block$data(valid, codeBlock, $dataValid = codegen_1$r.nil) {
|
|
2917
|
-
this.gen.block(() => {
|
|
2918
|
-
this.check$data(valid, $dataValid);
|
|
2919
|
-
codeBlock();
|
|
2920
|
-
});
|
|
2921
|
-
}
|
|
2922
|
-
check$data(valid = codegen_1$r.nil, $dataValid = codegen_1$r.nil) {
|
|
2923
|
-
if (!this.$data)
|
|
2924
|
-
return;
|
|
2925
|
-
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2926
|
-
gen.if((0, codegen_1$r.or)((0, codegen_1$r._)`${schemaCode} === undefined`, $dataValid));
|
|
2927
|
-
if (valid !== codegen_1$r.nil)
|
|
2928
|
-
gen.assign(valid, true);
|
|
2929
|
-
if (schemaType.length || def2.validateSchema) {
|
|
2930
|
-
gen.elseIf(this.invalid$data());
|
|
2931
|
-
this.$dataError();
|
|
2932
|
-
if (valid !== codegen_1$r.nil)
|
|
2933
|
-
gen.assign(valid, false);
|
|
2672
|
+
block$data(valid, codeBlock, $dataValid = codegen_12.nil) {
|
|
2673
|
+
this.gen.block(() => {
|
|
2674
|
+
this.check$data(valid, $dataValid);
|
|
2675
|
+
codeBlock();
|
|
2676
|
+
});
|
|
2934
2677
|
}
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2678
|
+
check$data(valid = codegen_12.nil, $dataValid = codegen_12.nil) {
|
|
2679
|
+
if (!this.$data)
|
|
2680
|
+
return;
|
|
2681
|
+
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2682
|
+
gen.if((0, codegen_12.or)((0, codegen_12._)`${schemaCode} === undefined`, $dataValid));
|
|
2683
|
+
if (valid !== codegen_12.nil)
|
|
2684
|
+
gen.assign(valid, true);
|
|
2685
|
+
if (schemaType.length || def2.validateSchema) {
|
|
2686
|
+
gen.elseIf(this.invalid$data());
|
|
2687
|
+
this.$dataError();
|
|
2688
|
+
if (valid !== codegen_12.nil)
|
|
2689
|
+
gen.assign(valid, false);
|
|
2946
2690
|
}
|
|
2947
|
-
|
|
2691
|
+
gen.else();
|
|
2948
2692
|
}
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2693
|
+
invalid$data() {
|
|
2694
|
+
const { gen, schemaCode, schemaType, def: def2, it } = this;
|
|
2695
|
+
return (0, codegen_12.or)(wrong$DataType(), invalid$DataSchema());
|
|
2696
|
+
function wrong$DataType() {
|
|
2697
|
+
if (schemaType.length) {
|
|
2698
|
+
if (!(schemaCode instanceof codegen_12.Name))
|
|
2699
|
+
throw new Error("ajv implementation error");
|
|
2700
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2701
|
+
return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2702
|
+
}
|
|
2703
|
+
return codegen_12.nil;
|
|
2704
|
+
}
|
|
2705
|
+
function invalid$DataSchema() {
|
|
2706
|
+
if (def2.validateSchema) {
|
|
2707
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2708
|
+
return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2709
|
+
}
|
|
2710
|
+
return codegen_12.nil;
|
|
2953
2711
|
}
|
|
2954
|
-
return codegen_1$r.nil;
|
|
2955
2712
|
}
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2713
|
+
subschema(appl, valid) {
|
|
2714
|
+
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
2715
|
+
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
2716
|
+
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
2717
|
+
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
2718
|
+
subschemaCode(nextContext, valid);
|
|
2719
|
+
return nextContext;
|
|
2720
|
+
}
|
|
2721
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
2722
|
+
const { it, gen } = this;
|
|
2723
|
+
if (!it.opts.unevaluated)
|
|
2724
|
+
return;
|
|
2725
|
+
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2726
|
+
it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2727
|
+
}
|
|
2728
|
+
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2729
|
+
it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2730
|
+
}
|
|
2971
2731
|
}
|
|
2972
|
-
|
|
2973
|
-
|
|
2732
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
2733
|
+
const { it, gen } = this;
|
|
2734
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
2735
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_12.Name));
|
|
2736
|
+
return true;
|
|
2737
|
+
}
|
|
2974
2738
|
}
|
|
2975
2739
|
}
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2740
|
+
validate.KeywordCxt = KeywordCxt;
|
|
2741
|
+
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2742
|
+
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2743
|
+
if ("code" in def2) {
|
|
2744
|
+
def2.code(cxt, ruleType);
|
|
2745
|
+
} else if (cxt.$data && def2.validate) {
|
|
2746
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2747
|
+
} else if ("macro" in def2) {
|
|
2748
|
+
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2749
|
+
} else if (def2.compile || def2.validate) {
|
|
2750
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2754
|
+
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2755
|
+
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2756
|
+
let jsonPointer;
|
|
2757
|
+
let data;
|
|
2758
|
+
if ($data === "")
|
|
2759
|
+
return names_12.default.rootData;
|
|
2760
|
+
if ($data[0] === "/") {
|
|
2761
|
+
if (!JSON_POINTER.test($data))
|
|
2762
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2763
|
+
jsonPointer = $data;
|
|
2764
|
+
data = names_12.default.rootData;
|
|
2765
|
+
} else {
|
|
2766
|
+
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
2767
|
+
if (!matches)
|
|
2768
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2769
|
+
const up = +matches[1];
|
|
2770
|
+
jsonPointer = matches[2];
|
|
2771
|
+
if (jsonPointer === "#") {
|
|
2772
|
+
if (up >= dataLevel)
|
|
2773
|
+
throw new Error(errorMsg("property/index", up));
|
|
2774
|
+
return dataPathArr[dataLevel - up];
|
|
2775
|
+
}
|
|
2776
|
+
if (up > dataLevel)
|
|
2777
|
+
throw new Error(errorMsg("data", up));
|
|
2778
|
+
data = dataNames[dataLevel - up];
|
|
2779
|
+
if (!jsonPointer)
|
|
2780
|
+
return data;
|
|
2781
|
+
}
|
|
2782
|
+
let expr = data;
|
|
2783
|
+
const segments = jsonPointer.split("/");
|
|
2784
|
+
for (const segment of segments) {
|
|
2785
|
+
if (segment) {
|
|
2786
|
+
data = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
|
|
2787
|
+
expr = (0, codegen_12._)`${expr} && ${data}`;
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
return expr;
|
|
2791
|
+
function errorMsg(pointerType, up) {
|
|
2792
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2981
2793
|
}
|
|
2982
2794
|
}
|
|
2795
|
+
validate.getData = getData;
|
|
2796
|
+
return validate;
|
|
2983
2797
|
}
|
|
2984
|
-
validate.KeywordCxt = KeywordCxt;
|
|
2985
|
-
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2986
|
-
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2987
|
-
if ("code" in def2) {
|
|
2988
|
-
def2.code(cxt, ruleType);
|
|
2989
|
-
} else if (cxt.$data && def2.validate) {
|
|
2990
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2991
|
-
} else if ("macro" in def2) {
|
|
2992
|
-
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2993
|
-
} else if (def2.compile || def2.validate) {
|
|
2994
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2995
|
-
}
|
|
2996
|
-
}
|
|
2997
|
-
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2998
|
-
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2999
|
-
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
3000
|
-
let jsonPointer;
|
|
3001
|
-
let data;
|
|
3002
|
-
if ($data === "")
|
|
3003
|
-
return names_1$6.default.rootData;
|
|
3004
|
-
if ($data[0] === "/") {
|
|
3005
|
-
if (!JSON_POINTER.test($data))
|
|
3006
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3007
|
-
jsonPointer = $data;
|
|
3008
|
-
data = names_1$6.default.rootData;
|
|
3009
|
-
} else {
|
|
3010
|
-
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
3011
|
-
if (!matches)
|
|
3012
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3013
|
-
const up = +matches[1];
|
|
3014
|
-
jsonPointer = matches[2];
|
|
3015
|
-
if (jsonPointer === "#") {
|
|
3016
|
-
if (up >= dataLevel)
|
|
3017
|
-
throw new Error(errorMsg("property/index", up));
|
|
3018
|
-
return dataPathArr[dataLevel - up];
|
|
3019
|
-
}
|
|
3020
|
-
if (up > dataLevel)
|
|
3021
|
-
throw new Error(errorMsg("data", up));
|
|
3022
|
-
data = dataNames[dataLevel - up];
|
|
3023
|
-
if (!jsonPointer)
|
|
3024
|
-
return data;
|
|
3025
|
-
}
|
|
3026
|
-
let expr = data;
|
|
3027
|
-
const segments = jsonPointer.split("/");
|
|
3028
|
-
for (const segment of segments) {
|
|
3029
|
-
if (segment) {
|
|
3030
|
-
data = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)((0, util_1$p.unescapeJsonPointer)(segment))}`;
|
|
3031
|
-
expr = (0, codegen_1$r._)`${expr} && ${data}`;
|
|
3032
|
-
}
|
|
3033
|
-
}
|
|
3034
|
-
return expr;
|
|
3035
|
-
function errorMsg(pointerType, up) {
|
|
3036
|
-
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
3037
|
-
}
|
|
3038
|
-
}
|
|
3039
|
-
validate.getData = getData;
|
|
3040
2798
|
var validation_error = {};
|
|
3041
2799
|
Object.defineProperty(validation_error, "__esModule", { value: true });
|
|
3042
2800
|
class ValidationError extends Error {
|
|
@@ -3063,10 +2821,10 @@ Object.defineProperty(compile, "__esModule", { value: true });
|
|
|
3063
2821
|
compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
|
|
3064
2822
|
const codegen_1$q = codegen;
|
|
3065
2823
|
const validation_error_1 = validation_error;
|
|
3066
|
-
const names_1$5 =
|
|
2824
|
+
const names_1$5 = requireNames();
|
|
3067
2825
|
const resolve_1 = resolve$2;
|
|
3068
2826
|
const util_1$o = util;
|
|
3069
|
-
const validate_1$1 =
|
|
2827
|
+
const validate_1$1 = requireValidate();
|
|
3070
2828
|
class SchemaEnv {
|
|
3071
2829
|
constructor(env) {
|
|
3072
2830
|
var _a;
|
|
@@ -3762,7 +3520,7 @@ var schemes = {
|
|
|
3762
3520
|
};
|
|
3763
3521
|
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = utils;
|
|
3764
3522
|
const { SCHEMES, getSchemeHandler } = schemes;
|
|
3765
|
-
function normalize(uri2, options) {
|
|
3523
|
+
function normalize$1(uri2, options) {
|
|
3766
3524
|
if (typeof uri2 === "string") {
|
|
3767
3525
|
uri2 = /** @type {T} */
|
|
3768
3526
|
serialize(parse(uri2, options), options);
|
|
@@ -3999,7 +3757,7 @@ function parse(uri2, opts) {
|
|
|
3999
3757
|
}
|
|
4000
3758
|
const fastUri = {
|
|
4001
3759
|
SCHEMES,
|
|
4002
|
-
normalize,
|
|
3760
|
+
normalize: normalize$1,
|
|
4003
3761
|
resolve,
|
|
4004
3762
|
resolveComponent,
|
|
4005
3763
|
equal: equal$2,
|
|
@@ -4017,7 +3775,7 @@ uri$1.default = uri;
|
|
|
4017
3775
|
(function(exports2) {
|
|
4018
3776
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
4019
3777
|
exports2.CodeGen = exports2.Name = exports2.nil = exports2.stringify = exports2.str = exports2._ = exports2.KeywordCxt = void 0;
|
|
4020
|
-
var validate_12 =
|
|
3778
|
+
var validate_12 = requireValidate();
|
|
4021
3779
|
Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
|
|
4022
3780
|
return validate_12.KeywordCxt;
|
|
4023
3781
|
} });
|
|
@@ -4637,7 +4395,7 @@ ref.callRef = ref.getValidate = void 0;
|
|
|
4637
4395
|
const ref_error_1$1 = ref_error;
|
|
4638
4396
|
const code_1$8 = code;
|
|
4639
4397
|
const codegen_1$p = codegen;
|
|
4640
|
-
const names_1$4 =
|
|
4398
|
+
const names_1$4 = requireNames();
|
|
4641
4399
|
const compile_1$2 = compile;
|
|
4642
4400
|
const util_1$n = util;
|
|
4643
4401
|
const def$A = {
|
|
@@ -5521,7 +5279,7 @@ var additionalProperties = {};
|
|
|
5521
5279
|
Object.defineProperty(additionalProperties, "__esModule", { value: true });
|
|
5522
5280
|
const code_1$3 = code;
|
|
5523
5281
|
const codegen_1$9 = codegen;
|
|
5524
|
-
const names_1$3 =
|
|
5282
|
+
const names_1$3 = requireNames();
|
|
5525
5283
|
const util_1$c = util;
|
|
5526
5284
|
const error$6 = {
|
|
5527
5285
|
message: "must NOT have additional properties",
|
|
@@ -5619,7 +5377,7 @@ const def$j = {
|
|
|
5619
5377
|
additionalProperties.default = def$j;
|
|
5620
5378
|
var properties$8 = {};
|
|
5621
5379
|
Object.defineProperty(properties$8, "__esModule", { value: true });
|
|
5622
|
-
const validate_1 =
|
|
5380
|
+
const validate_1 = requireValidate();
|
|
5623
5381
|
const code_1$2 = code;
|
|
5624
5382
|
const util_1$b = util;
|
|
5625
5383
|
const additionalProperties_1$1 = additionalProperties;
|
|
@@ -5967,7 +5725,7 @@ var dynamicAnchor$1 = {};
|
|
|
5967
5725
|
Object.defineProperty(dynamicAnchor$1, "__esModule", { value: true });
|
|
5968
5726
|
dynamicAnchor$1.dynamicAnchor = void 0;
|
|
5969
5727
|
const codegen_1$5 = codegen;
|
|
5970
|
-
const names_1$2 =
|
|
5728
|
+
const names_1$2 = requireNames();
|
|
5971
5729
|
const compile_1$1 = compile;
|
|
5972
5730
|
const ref_1$1 = ref;
|
|
5973
5731
|
const def$a = {
|
|
@@ -5996,7 +5754,7 @@ var dynamicRef$1 = {};
|
|
|
5996
5754
|
Object.defineProperty(dynamicRef$1, "__esModule", { value: true });
|
|
5997
5755
|
dynamicRef$1.dynamicRef = void 0;
|
|
5998
5756
|
const codegen_1$4 = codegen;
|
|
5999
|
-
const names_1$1 =
|
|
5757
|
+
const names_1$1 = requireNames();
|
|
6000
5758
|
const ref_1 = ref;
|
|
6001
5759
|
const def$9 = {
|
|
6002
5760
|
keyword: "$dynamicRef",
|
|
@@ -6110,7 +5868,7 @@ var unevaluatedProperties = {};
|
|
|
6110
5868
|
Object.defineProperty(unevaluatedProperties, "__esModule", { value: true });
|
|
6111
5869
|
const codegen_1$3 = codegen;
|
|
6112
5870
|
const util_1$2 = util;
|
|
6113
|
-
const names_1 =
|
|
5871
|
+
const names_1 = requireNames();
|
|
6114
5872
|
const error$3 = {
|
|
6115
5873
|
message: "must NOT have unevaluated properties",
|
|
6116
5874
|
params: ({ params }) => (0, codegen_1$3._)`{unevaluatedProperty: ${params.unevaluatedProperty}}`
|
|
@@ -7026,7 +6784,7 @@ jsonSchema202012.default = addMetaSchema2020;
|
|
|
7026
6784
|
module2.exports.Ajv2020 = Ajv20202;
|
|
7027
6785
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7028
6786
|
exports2.default = Ajv20202;
|
|
7029
|
-
var validate_12 =
|
|
6787
|
+
var validate_12 = requireValidate();
|
|
7030
6788
|
Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
|
|
7031
6789
|
return validate_12.KeywordCxt;
|
|
7032
6790
|
} });
|
|
@@ -7068,7 +6826,8 @@ const AppPackageJSONSchema = zod.z.object({
|
|
|
7068
6826
|
"build": zod.z.string().optional(),
|
|
7069
6827
|
"build:backend": zod.z.string().optional(),
|
|
7070
6828
|
"build:web": zod.z.string().optional()
|
|
7071
|
-
}).optional()
|
|
6829
|
+
}).optional(),
|
|
6830
|
+
dependencies: zod.z.record(zod.z.string()).optional()
|
|
7072
6831
|
});
|
|
7073
6832
|
const AppManifestJSONSchema = zod.z.object({
|
|
7074
6833
|
app: zod.z.object({
|
|
@@ -7160,6 +6919,317 @@ var HostedTokenScope = /* @__PURE__ */ ((HostedTokenScope2) => {
|
|
|
7160
6919
|
HostedTokenScope2["RELAY"] = "ones:hosted:relay";
|
|
7161
6920
|
return HostedTokenScope2;
|
|
7162
6921
|
})(HostedTokenScope || {});
|
|
6922
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
6923
|
+
ErrorCode2["UNKNOWN_ERROR"] = "E00";
|
|
6924
|
+
ErrorCode2["COMMAND_ERROR"] = "E01";
|
|
6925
|
+
ErrorCode2["TEMPLATE_NOT_FOUND"] = "E02";
|
|
6926
|
+
ErrorCode2["MISSING_PROJECT_PATH"] = "E03";
|
|
6927
|
+
return ErrorCode2;
|
|
6928
|
+
})(ErrorCode || {});
|
|
6929
|
+
const throwError = (code2, message) => {
|
|
6930
|
+
let $message = message.trim();
|
|
6931
|
+
if (code2 === ErrorCode.COMMAND_ERROR) {
|
|
6932
|
+
$message = $message.replace(/^error: /, "");
|
|
6933
|
+
}
|
|
6934
|
+
$message = $message.replace(/\s+$/, "");
|
|
6935
|
+
const text = `${$message}[${code2}]`;
|
|
6936
|
+
console.error(chalk.red(text));
|
|
6937
|
+
process.exit(1);
|
|
6938
|
+
};
|
|
6939
|
+
const en = {
|
|
6940
|
+
"desc.create": "Create a new ONES App",
|
|
6941
|
+
"desc.create.projectPath": "Specify the project path",
|
|
6942
|
+
"desc.create.templateName": "Specify the template name",
|
|
6943
|
+
"desc.create.manifestOnly": "Only create the manifest file",
|
|
6944
|
+
"success.create.gitInitialized": "Git repository initialized.",
|
|
6945
|
+
"success.create.gitInitializedAndIgnoreStaged": 'Git repository initialized, and ".gitignore" has been staged.',
|
|
6946
|
+
"success.create.fetchReferences": "To help your AI work on this app, fetch the app development references:",
|
|
6947
|
+
"warn.create.gitInitSkipped": 'Warning: failed to initialize a Git repository automatically. You can run "git init" later. Reason: {reason}',
|
|
6948
|
+
"warn.create.gitIgnoreStageSkipped": 'Warning: Git repository initialized, but failed to stage ".gitignore". You can run "git add .gitignore" later. Reason: {reason}',
|
|
6949
|
+
"error.command.missingProjectPathFriendly": "Project path is required. Example: ones create hello-ones",
|
|
6950
|
+
"error.create.templateNotFound": 'Template "{templateName}" not found',
|
|
6951
|
+
"error.create.missingProjectPath": "Project path is required"
|
|
6952
|
+
};
|
|
6953
|
+
const map = {
|
|
6954
|
+
en
|
|
6955
|
+
};
|
|
6956
|
+
const getCurrentLanguageList = () => {
|
|
6957
|
+
return ["en"];
|
|
6958
|
+
};
|
|
6959
|
+
const translate = (key, params) => {
|
|
6960
|
+
const list = getCurrentLanguageList();
|
|
6961
|
+
for (let index = 0; index < list.length; index++) {
|
|
6962
|
+
const language = list[index];
|
|
6963
|
+
let value = lodashEs.get(map[language], key);
|
|
6964
|
+
if (value) {
|
|
6965
|
+
if (params && typeof value === "string") {
|
|
6966
|
+
value = value.replace(/\{(\w+)\}/g, (match, paramKey) => {
|
|
6967
|
+
var _params$paramKey;
|
|
6968
|
+
const result = (_params$paramKey = params === null || params === void 0 ? void 0 : params[paramKey]) !== null && _params$paramKey !== void 0 ? _params$paramKey : match;
|
|
6969
|
+
return String(result);
|
|
6970
|
+
});
|
|
6971
|
+
}
|
|
6972
|
+
return value;
|
|
6973
|
+
}
|
|
6974
|
+
}
|
|
6975
|
+
return key;
|
|
6976
|
+
};
|
|
6977
|
+
const i18n = {
|
|
6978
|
+
t: translate
|
|
6979
|
+
};
|
|
6980
|
+
const getCommandOptions = (args, keys) => {
|
|
6981
|
+
const $args = args.slice(-2);
|
|
6982
|
+
const $list = args.slice(0, -2);
|
|
6983
|
+
const [options, command] = $args;
|
|
6984
|
+
const $options = options;
|
|
6985
|
+
keys.forEach((key, index) => {
|
|
6986
|
+
$options[key] = $list[index];
|
|
6987
|
+
});
|
|
6988
|
+
return {
|
|
6989
|
+
options,
|
|
6990
|
+
command
|
|
6991
|
+
};
|
|
6992
|
+
};
|
|
6993
|
+
const getRawArguments = (cmd) => {
|
|
6994
|
+
const $cmd = cmd;
|
|
6995
|
+
return $cmd._args;
|
|
6996
|
+
};
|
|
6997
|
+
const getRawOptions = (cmd) => {
|
|
6998
|
+
const $cmd = cmd;
|
|
6999
|
+
return $cmd.options;
|
|
7000
|
+
};
|
|
7001
|
+
const addCommandUsage = (cmd, blackList2) => {
|
|
7002
|
+
const args = getRawArguments(cmd);
|
|
7003
|
+
const options = getRawOptions(cmd);
|
|
7004
|
+
if (options.length || args.length) {
|
|
7005
|
+
cmd.usage(_reduceInstanceProperty(args).call(args, (base, arg) => {
|
|
7006
|
+
if (blackList2 !== null && blackList2 !== void 0 && _includesInstanceProperty(blackList2).call(blackList2, arg.name())) {
|
|
7007
|
+
return base;
|
|
7008
|
+
}
|
|
7009
|
+
if (arg.required) {
|
|
7010
|
+
return `${base} <${arg.name()}>`;
|
|
7011
|
+
}
|
|
7012
|
+
return `${base} [${arg.name()}]`;
|
|
7013
|
+
}, "[options]"));
|
|
7014
|
+
} else {
|
|
7015
|
+
cmd.usage(" ");
|
|
7016
|
+
}
|
|
7017
|
+
};
|
|
7018
|
+
const addCommandOutput = (cmd) => {
|
|
7019
|
+
cmd.configureOutput({
|
|
7020
|
+
outputError(str) {
|
|
7021
|
+
const message = str.replace(/^error: /, "").trim();
|
|
7022
|
+
if (message === "missing required argument 'project-path'") {
|
|
7023
|
+
throwError(ErrorCode.COMMAND_ERROR, i18n.t("error.command.missingProjectPathFriendly"));
|
|
7024
|
+
}
|
|
7025
|
+
throwError(ErrorCode.COMMAND_ERROR, str);
|
|
7026
|
+
}
|
|
7027
|
+
});
|
|
7028
|
+
};
|
|
7029
|
+
const getTemplatePath = () => {
|
|
7030
|
+
const __dirname = node_path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
|
|
7031
|
+
return node_path.join(__dirname, "../template");
|
|
7032
|
+
};
|
|
7033
|
+
const getTemplateChoices = () => {
|
|
7034
|
+
const path = getTemplatePath();
|
|
7035
|
+
return node_fs.readdirSync(path);
|
|
7036
|
+
};
|
|
7037
|
+
const getTemplateDefault = () => {
|
|
7038
|
+
return "example";
|
|
7039
|
+
};
|
|
7040
|
+
const defaultTemplateName = getTemplateDefault();
|
|
7041
|
+
const normalize = async (options) => {
|
|
7042
|
+
const projectPathInput = options.projectPath;
|
|
7043
|
+
if (projectPathInput)
|
|
7044
|
+
;
|
|
7045
|
+
else {
|
|
7046
|
+
return throwError(ErrorCode.MISSING_PROJECT_PATH, i18n.t("error.create.missingProjectPath"));
|
|
7047
|
+
}
|
|
7048
|
+
const projectPath = node_path.resolve(node_process.cwd(), projectPathInput);
|
|
7049
|
+
const templateName = defaultTemplateName;
|
|
7050
|
+
const manifestOnly = Boolean(options.manifestOnly);
|
|
7051
|
+
const templateChoices = getTemplateChoices();
|
|
7052
|
+
const validTemplateName = _includesInstanceProperty(templateChoices).call(templateChoices, templateName);
|
|
7053
|
+
if (validTemplateName)
|
|
7054
|
+
;
|
|
7055
|
+
else {
|
|
7056
|
+
return throwError(ErrorCode.TEMPLATE_NOT_FOUND, i18n.t("error.create.templateNotFound", {
|
|
7057
|
+
templateName
|
|
7058
|
+
}));
|
|
7059
|
+
}
|
|
7060
|
+
return {
|
|
7061
|
+
projectPath,
|
|
7062
|
+
templateName,
|
|
7063
|
+
manifestOnly
|
|
7064
|
+
};
|
|
7065
|
+
};
|
|
7066
|
+
const ONES_OPEN_NODE_SDK = "@ones-open/node-sdk";
|
|
7067
|
+
const ONES_OPEN_WEB_SDK = "@ones-open/web-sdk";
|
|
7068
|
+
const {
|
|
7069
|
+
existsSync,
|
|
7070
|
+
copy,
|
|
7071
|
+
moveSync,
|
|
7072
|
+
readJSON,
|
|
7073
|
+
writeJSON,
|
|
7074
|
+
readdirSync,
|
|
7075
|
+
readFile,
|
|
7076
|
+
writeFile,
|
|
7077
|
+
ensureDir
|
|
7078
|
+
} = fse;
|
|
7079
|
+
const getErrorMessage = (error2) => {
|
|
7080
|
+
if (error2 instanceof Error && error2.message) {
|
|
7081
|
+
return error2.message;
|
|
7082
|
+
}
|
|
7083
|
+
return "Unknown error";
|
|
7084
|
+
};
|
|
7085
|
+
const initializeGitRepository = (projectPath) => {
|
|
7086
|
+
try {
|
|
7087
|
+
node_child_process.execFileSync("git", ["init"], {
|
|
7088
|
+
cwd: projectPath,
|
|
7089
|
+
stdio: "ignore"
|
|
7090
|
+
});
|
|
7091
|
+
} catch (error2) {
|
|
7092
|
+
return {
|
|
7093
|
+
status: "git-init-skipped",
|
|
7094
|
+
reason: getErrorMessage(error2)
|
|
7095
|
+
};
|
|
7096
|
+
}
|
|
7097
|
+
if (existsSync(node_path.join(projectPath, ".gitignore"))) {
|
|
7098
|
+
try {
|
|
7099
|
+
node_child_process.execFileSync("git", ["add", ".gitignore"], {
|
|
7100
|
+
cwd: projectPath,
|
|
7101
|
+
stdio: "ignore"
|
|
7102
|
+
});
|
|
7103
|
+
return {
|
|
7104
|
+
status: "ignore-staged"
|
|
7105
|
+
};
|
|
7106
|
+
} catch (error2) {
|
|
7107
|
+
return {
|
|
7108
|
+
status: "gitignore-stage-skipped",
|
|
7109
|
+
reason: getErrorMessage(error2)
|
|
7110
|
+
};
|
|
7111
|
+
}
|
|
7112
|
+
}
|
|
7113
|
+
return {
|
|
7114
|
+
status: "initialized"
|
|
7115
|
+
};
|
|
7116
|
+
};
|
|
7117
|
+
const create = async function() {
|
|
7118
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7119
|
+
args[_key] = arguments[_key];
|
|
7120
|
+
}
|
|
7121
|
+
const {
|
|
7122
|
+
options
|
|
7123
|
+
} = getCommandOptions(args, createCommandArguments);
|
|
7124
|
+
const normalizedOptions = await normalize(options);
|
|
7125
|
+
const {
|
|
7126
|
+
manifestOnly,
|
|
7127
|
+
projectPath
|
|
7128
|
+
} = normalizedOptions;
|
|
7129
|
+
const publicPath = getPublicPath();
|
|
7130
|
+
const appName = node_path.basename(projectPath);
|
|
7131
|
+
const isExists = existsSync(node_path.join(projectPath, PUBLIC_FILENAME.MANIFEST));
|
|
7132
|
+
if (isExists) {
|
|
7133
|
+
console.log(`App "${appName}" already exists!`);
|
|
7134
|
+
process.exit(1);
|
|
7135
|
+
}
|
|
7136
|
+
if (manifestOnly)
|
|
7137
|
+
;
|
|
7138
|
+
else {
|
|
7139
|
+
const templatePath = node_path.join(getTemplatePath(), getTemplateDefault());
|
|
7140
|
+
await copy(templatePath, projectPath);
|
|
7141
|
+
const rename = [["_gitignore", ".gitignore"], ["_prettierignore", ".prettierignore"], ["_prettierrc", ".prettierrc"], ["_tsconfig.json", "tsconfig.json"], ["_eslint.config.mjs_", "eslint.config.mjs"], ["_husky_pre-commit", ".husky/pre-commit"]];
|
|
7142
|
+
rename.forEach((_ref) => {
|
|
7143
|
+
let [from, to] = _ref;
|
|
7144
|
+
moveSync(node_path.join(projectPath, from), node_path.join(projectPath, to), {
|
|
7145
|
+
overwrite: true
|
|
7146
|
+
});
|
|
7147
|
+
});
|
|
7148
|
+
const logoDirPath = node_path.join(publicPath, "logos");
|
|
7149
|
+
const logos = readdirSync(logoDirPath);
|
|
7150
|
+
if (logos.length > 0) {
|
|
7151
|
+
const index = Math.floor(Math.random() * logos.length);
|
|
7152
|
+
const logo = logos[index];
|
|
7153
|
+
const logoPath = node_path.join(logoDirPath, logo);
|
|
7154
|
+
const logoContent = await readFile(logoPath, {
|
|
7155
|
+
encoding: "utf-8"
|
|
7156
|
+
});
|
|
7157
|
+
await writeFile(node_path.join(projectPath, "public/logo.svg"), logoContent, {
|
|
7158
|
+
encoding: "utf-8"
|
|
7159
|
+
});
|
|
7160
|
+
}
|
|
7161
|
+
const appPackageJSONPath = node_path.join(projectPath, "package.json");
|
|
7162
|
+
const appPackageJSON = await readJSON(appPackageJSONPath);
|
|
7163
|
+
if (appPackageJSON.dependencies) {
|
|
7164
|
+
const packageJSON = getPackageJSON();
|
|
7165
|
+
if (packageJSON.dependencies) {
|
|
7166
|
+
const ONES_OPEN_NODE_SDK_VERSION = packageJSON.dependencies[ONES_OPEN_NODE_SDK];
|
|
7167
|
+
if (ONES_OPEN_NODE_SDK_VERSION) {
|
|
7168
|
+
appPackageJSON.dependencies[ONES_OPEN_NODE_SDK] = ONES_OPEN_NODE_SDK_VERSION;
|
|
7169
|
+
}
|
|
7170
|
+
const ONES_OPEN_WEB_SDK_VERSION = packageJSON.dependencies[ONES_OPEN_WEB_SDK];
|
|
7171
|
+
if (ONES_OPEN_WEB_SDK_VERSION) {
|
|
7172
|
+
appPackageJSON.dependencies[ONES_OPEN_WEB_SDK] = ONES_OPEN_WEB_SDK_VERSION;
|
|
7173
|
+
}
|
|
7174
|
+
}
|
|
7175
|
+
}
|
|
7176
|
+
await writeJSON(appPackageJSONPath, appPackageJSON, {
|
|
7177
|
+
spaces: 2
|
|
7178
|
+
});
|
|
7179
|
+
}
|
|
7180
|
+
await ensureDir(projectPath);
|
|
7181
|
+
let manifestJSONPath = "";
|
|
7182
|
+
if (manifestOnly) {
|
|
7183
|
+
manifestJSONPath = node_path.join(publicPath, PUBLIC_FILENAME.MANIFEST);
|
|
7184
|
+
} else {
|
|
7185
|
+
manifestJSONPath = node_path.join(projectPath, PUBLIC_FILENAME.MANIFEST);
|
|
7186
|
+
}
|
|
7187
|
+
const manifestJSON = await readJSON(manifestJSONPath);
|
|
7188
|
+
manifestJSON.app.id = `app_${uuid.v4().replace(/-/g, "").slice(0, 16)}`;
|
|
7189
|
+
manifestJSON.app.name = appName;
|
|
7190
|
+
await writeJSON(node_path.join(projectPath, PUBLIC_FILENAME.MANIFEST), manifestJSON, {
|
|
7191
|
+
spaces: 2
|
|
7192
|
+
});
|
|
7193
|
+
const rcJSONPath = node_path.join(publicPath, PUBLIC_FILENAME.RC);
|
|
7194
|
+
const rcJSON = await readJSON(rcJSONPath);
|
|
7195
|
+
await writeJSON(node_path.join(projectPath, PUBLIC_FILENAME.RC), rcJSON, {
|
|
7196
|
+
spaces: 2
|
|
7197
|
+
});
|
|
7198
|
+
const gitSetupResult = initializeGitRepository(projectPath);
|
|
7199
|
+
console.log(`App "${appName}" created successfully!`);
|
|
7200
|
+
if (gitSetupResult.status === "ignore-staged") {
|
|
7201
|
+
console.log(i18n.t("success.create.gitInitializedAndIgnoreStaged"));
|
|
7202
|
+
} else if (gitSetupResult.status === "initialized") {
|
|
7203
|
+
console.log(i18n.t("success.create.gitInitialized"));
|
|
7204
|
+
} else if (gitSetupResult.status === "git-init-skipped") {
|
|
7205
|
+
console.log(i18n.t("warn.create.gitInitSkipped", {
|
|
7206
|
+
reason: gitSetupResult.reason
|
|
7207
|
+
}));
|
|
7208
|
+
} else if (gitSetupResult.status === "gitignore-stage-skipped") {
|
|
7209
|
+
console.log(i18n.t("warn.create.gitIgnoreStageSkipped", {
|
|
7210
|
+
reason: gitSetupResult.reason
|
|
7211
|
+
}));
|
|
7212
|
+
}
|
|
7213
|
+
console.log("");
|
|
7214
|
+
console.log(i18n.t("success.create.fetchReferences"));
|
|
7215
|
+
console.log(`ones specs fetch --dir "${projectPath}"`);
|
|
7216
|
+
};
|
|
7217
|
+
const createCommandArguments = ["projectPath", "templateName"];
|
|
7218
|
+
const blackList = ["template-name"];
|
|
7219
|
+
const $create = new commander.Command("create").description(i18n.t("desc.create")).argument("<project-path>", i18n.t("desc.create.projectPath")).argument("[template-name]", i18n.t("desc.create.templateName")).option("-m, --manifest-only", i18n.t("desc.create.manifestOnly")).action(create).configureHelp({
|
|
7220
|
+
visibleArguments: (cmd) => {
|
|
7221
|
+
return getRawArguments(cmd).filter((arg) => !_includesInstanceProperty(blackList).call(blackList, arg.name()));
|
|
7222
|
+
}
|
|
7223
|
+
});
|
|
7224
|
+
addCommandUsage($create, blackList);
|
|
7225
|
+
addCommandOutput($create);
|
|
7226
|
+
const context = {};
|
|
7227
|
+
const getContext = (key) => {
|
|
7228
|
+
return context[key];
|
|
7229
|
+
};
|
|
7230
|
+
const setContext = (key, value) => {
|
|
7231
|
+
context[key] = value;
|
|
7232
|
+
};
|
|
7163
7233
|
const runCommandCreate = async () => {
|
|
7164
7234
|
const command = $create;
|
|
7165
7235
|
setContext("command", command);
|