@thatopen/services 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/built-in/index.d.ts +59 -1
- package/dist/cli.js +1382 -904
- package/dist/cli.js.map +1 -1
- package/dist/core/client.d.ts +14 -0
- package/dist/core/examples/history.d.ts +4 -0
- package/dist/core/history.d.ts +204 -0
- package/dist/core/recipes.d.ts +98 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +1635 -1205
- package/dist/index.es.js.map +1 -1
- package/docs/ai-quickstart.md +5 -2
- package/docs/client/paths.json +4 -0
- package/package.json +1 -1
- package/src/built-in/GISManager/example.ts +29 -0
- package/src/built-in/UIManager/src/settings-panel/example.ts +4 -1
- package/src/built-in/index.ts +59 -3
- package/src/core/examples/history.ts +103 -0
package/dist/cli.js
CHANGED
|
@@ -6795,6 +6795,501 @@ Object.assign(lookup, {
|
|
|
6795
6795
|
io: lookup,
|
|
6796
6796
|
connect: lookup
|
|
6797
6797
|
});
|
|
6798
|
+
class StaleHistoryError extends Error {
|
|
6799
|
+
constructor(expectedGuid, actualGuid) {
|
|
6800
|
+
super(
|
|
6801
|
+
`The document history advanced while this version was being prepared: expected head ${expectedGuid}, found ${actualGuid ?? "none"}. Read the timeline again and rebuild on the new head.`
|
|
6802
|
+
);
|
|
6803
|
+
this.expectedGuid = expectedGuid;
|
|
6804
|
+
this.actualGuid = actualGuid;
|
|
6805
|
+
this.name = "StaleHistoryError";
|
|
6806
|
+
}
|
|
6807
|
+
}
|
|
6808
|
+
const ROOT_FOLDER = "bimterop";
|
|
6809
|
+
const HISTORY_FILE = "revitflow_history.json";
|
|
6810
|
+
const OPS_FILE = "revitflow_ops.json";
|
|
6811
|
+
const OPS_SCHEMA = "revitflow/ops@1";
|
|
6812
|
+
const LEGACY_MODEL_FILE = "revitflow_model.frag";
|
|
6813
|
+
const INTERNAL_PREFIX = "revitflow_";
|
|
6814
|
+
const versionTag = () => `v-${Date.now()}`;
|
|
6815
|
+
function idOf(item) {
|
|
6816
|
+
return String(item._id ?? item.id ?? "");
|
|
6817
|
+
}
|
|
6818
|
+
class ProjectHistory {
|
|
6819
|
+
constructor(client, projectId) {
|
|
6820
|
+
this.client = client;
|
|
6821
|
+
this.projectId = projectId;
|
|
6822
|
+
}
|
|
6823
|
+
#rootFolderId;
|
|
6824
|
+
/** The project's connected documents. */
|
|
6825
|
+
async docs() {
|
|
6826
|
+
const root = await this.#root();
|
|
6827
|
+
if (!root) return [];
|
|
6828
|
+
const folders = await this.client.listFolders({
|
|
6829
|
+
parentFolderId: root,
|
|
6830
|
+
projectId: this.projectId
|
|
6831
|
+
});
|
|
6832
|
+
const docs = [];
|
|
6833
|
+
for (const folder of folders) {
|
|
6834
|
+
const name = String(folder.name ?? "");
|
|
6835
|
+
const dash = name.indexOf("-");
|
|
6836
|
+
if (dash <= 0) continue;
|
|
6837
|
+
docs.push({
|
|
6838
|
+
source: name.slice(0, dash),
|
|
6839
|
+
docId: name.slice(dash + 1),
|
|
6840
|
+
modelName: void 0
|
|
6841
|
+
});
|
|
6842
|
+
}
|
|
6843
|
+
return docs;
|
|
6844
|
+
}
|
|
6845
|
+
/** One document's history. `source` and `docId` as {@link docs} lists them. */
|
|
6846
|
+
doc(source, docId) {
|
|
6847
|
+
return new FlowDoc(this.client, this, source, docId);
|
|
6848
|
+
}
|
|
6849
|
+
/** @internal The `bimterop` folder id, resolved once. */
|
|
6850
|
+
async rootFolderId(create = false) {
|
|
6851
|
+
if (this.#rootFolderId) return this.#rootFolderId;
|
|
6852
|
+
const found = await this.#root();
|
|
6853
|
+
if (found) return found;
|
|
6854
|
+
if (!create) return void 0;
|
|
6855
|
+
const made = await this.client.createFolder(
|
|
6856
|
+
ROOT_FOLDER,
|
|
6857
|
+
void 0,
|
|
6858
|
+
this.projectId
|
|
6859
|
+
);
|
|
6860
|
+
this.#rootFolderId = idOf(made);
|
|
6861
|
+
return this.#rootFolderId;
|
|
6862
|
+
}
|
|
6863
|
+
async #root() {
|
|
6864
|
+
if (this.#rootFolderId) return this.#rootFolderId;
|
|
6865
|
+
const folders = await this.client.listFolders({
|
|
6866
|
+
projectId: this.projectId
|
|
6867
|
+
});
|
|
6868
|
+
const root = folders.find(
|
|
6869
|
+
(f) => String(f.name ?? "") === ROOT_FOLDER && !f.parentId
|
|
6870
|
+
);
|
|
6871
|
+
if (root) this.#rootFolderId = idOf(root);
|
|
6872
|
+
return this.#rootFolderId;
|
|
6873
|
+
}
|
|
6874
|
+
}
|
|
6875
|
+
class FlowDoc {
|
|
6876
|
+
constructor(client, project, source, docId) {
|
|
6877
|
+
this.client = client;
|
|
6878
|
+
this.project = project;
|
|
6879
|
+
this.source = source;
|
|
6880
|
+
this.docId = docId;
|
|
6881
|
+
}
|
|
6882
|
+
#folderId;
|
|
6883
|
+
// ─── Reading ───────────────────────────────────────────────────────────────
|
|
6884
|
+
/**
|
|
6885
|
+
* The document's versions, oldest first, ordered by the parent graph (not
|
|
6886
|
+
* by array position, which concurrent writers do not keep meaningful).
|
|
6887
|
+
* Each version gets its `ordinal` filled in.
|
|
6888
|
+
*/
|
|
6889
|
+
async timeline() {
|
|
6890
|
+
const history = await this.#readHistory();
|
|
6891
|
+
return orderByGraph(history?.commits ?? []);
|
|
6892
|
+
}
|
|
6893
|
+
/** The head of the timeline, or null before the first sync. */
|
|
6894
|
+
async latest() {
|
|
6895
|
+
const timeline = await this.timeline();
|
|
6896
|
+
return timeline.length ? timeline[timeline.length - 1] : null;
|
|
6897
|
+
}
|
|
6898
|
+
/**
|
|
6899
|
+
* A version's delta geometry as a .frag. The baseline (`full`) versions have
|
|
6900
|
+
* no delta: their geometry IS the model file — use {@link model}.
|
|
6901
|
+
*/
|
|
6902
|
+
async delta(version2) {
|
|
6903
|
+
if (!version2.deltaId) {
|
|
6904
|
+
throw new Error(
|
|
6905
|
+
`Version ${version2.guid} carries no delta: it is a full export — read model() instead.`
|
|
6906
|
+
);
|
|
6907
|
+
}
|
|
6908
|
+
const response = await this.client.downloadHiddenFile(version2.deltaId);
|
|
6909
|
+
return await response.blob();
|
|
6910
|
+
}
|
|
6911
|
+
/** The visible model .frag as last fully exported. */
|
|
6912
|
+
async model() {
|
|
6913
|
+
const file = await this.#modelFile();
|
|
6914
|
+
if (!file) {
|
|
6915
|
+
throw new Error(
|
|
6916
|
+
`Document ${this.source}-${this.docId} has no model file yet.`
|
|
6917
|
+
);
|
|
6918
|
+
}
|
|
6919
|
+
const response = await this.client.downloadFile(file.id);
|
|
6920
|
+
return await response.blob();
|
|
6921
|
+
}
|
|
6922
|
+
// ─── Writing versions ─────────────────────────────────────────────────────
|
|
6923
|
+
/**
|
|
6924
|
+
* Appends one version: uploads the geometry it carries, then the updated
|
|
6925
|
+
* history. Give `expectedLatestGuid` whenever you built on a head you read,
|
|
6926
|
+
* so a concurrent writer surfaces as {@link StaleHistoryError} instead of a
|
|
6927
|
+
* silent fork.
|
|
6928
|
+
*/
|
|
6929
|
+
async sync(input) {
|
|
6930
|
+
const folderId = await this.#folder(true);
|
|
6931
|
+
let history = await this.#readHistory() ?? {
|
|
6932
|
+
model: this.docId,
|
|
6933
|
+
commits: []
|
|
6934
|
+
};
|
|
6935
|
+
const head = lastByGraph(history.commits);
|
|
6936
|
+
if (input.expectedLatestGuid !== void 0 && head?.guid !== input.expectedLatestGuid) {
|
|
6937
|
+
throw new StaleHistoryError(input.expectedLatestGuid, head?.guid);
|
|
6938
|
+
}
|
|
6939
|
+
const version2 = {
|
|
6940
|
+
guid: cryptoRandomGuid(),
|
|
6941
|
+
...head ? { parents: [head.guid] } : {},
|
|
6942
|
+
author: input.author,
|
|
6943
|
+
source: input.source,
|
|
6944
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6945
|
+
...input.message ? { message: input.message } : {},
|
|
6946
|
+
...input.userId ? { userId: input.userId } : {},
|
|
6947
|
+
...input.appliedOps?.length ? { appliedOps: input.appliedOps } : {},
|
|
6948
|
+
changes: input.changes,
|
|
6949
|
+
counts: tally(input.changes)
|
|
6950
|
+
};
|
|
6951
|
+
if (input.model) {
|
|
6952
|
+
await this.#writeModel(folderId, input.model);
|
|
6953
|
+
version2.full = true;
|
|
6954
|
+
}
|
|
6955
|
+
if (input.delta) {
|
|
6956
|
+
const modelFile = await this.#modelFile();
|
|
6957
|
+
if (!modelFile) {
|
|
6958
|
+
throw new Error(
|
|
6959
|
+
"A delta needs the model file to hang from: sync a full model first."
|
|
6960
|
+
);
|
|
6961
|
+
}
|
|
6962
|
+
const hidden = await this.client.createHiddenFile(
|
|
6963
|
+
input.delta,
|
|
6964
|
+
modelFile.id
|
|
6965
|
+
);
|
|
6966
|
+
version2.deltaId = String(
|
|
6967
|
+
hidden._id ?? hidden.id
|
|
6968
|
+
);
|
|
6969
|
+
}
|
|
6970
|
+
const fresh = await this.#readHistory();
|
|
6971
|
+
if (fresh) {
|
|
6972
|
+
history = fresh;
|
|
6973
|
+
const freshHead = lastByGraph(history.commits);
|
|
6974
|
+
if (input.expectedLatestGuid !== void 0 && freshHead?.guid !== input.expectedLatestGuid) {
|
|
6975
|
+
throw new StaleHistoryError(input.expectedLatestGuid, freshHead?.guid);
|
|
6976
|
+
}
|
|
6977
|
+
if (freshHead && !version2.parents) version2.parents = [freshHead.guid];
|
|
6978
|
+
}
|
|
6979
|
+
history.commits.push(version2);
|
|
6980
|
+
await this.#writeJson(folderId, HISTORY_FILE, history);
|
|
6981
|
+
return version2;
|
|
6982
|
+
}
|
|
6983
|
+
// ─── Suggestions (change requests) ────────────────────────────────────────
|
|
6984
|
+
/** Every suggestion in the document's queue, pending or resolved. */
|
|
6985
|
+
async suggestions() {
|
|
6986
|
+
const ops2 = await this.#readOps();
|
|
6987
|
+
return ops2?.ops ?? [];
|
|
6988
|
+
}
|
|
6989
|
+
/** The suggestions still waiting for the owner, oldest first. */
|
|
6990
|
+
async pendingSuggestions() {
|
|
6991
|
+
return (await this.suggestions()).filter((op) => op.state === "pending");
|
|
6992
|
+
}
|
|
6993
|
+
/**
|
|
6994
|
+
* Queues a change request for this document. The payload, when given, is
|
|
6995
|
+
* uploaded as a hidden file under the suggestions index.
|
|
6996
|
+
*/
|
|
6997
|
+
async suggest(input) {
|
|
6998
|
+
const folderId = await this.#folder(true);
|
|
6999
|
+
const index = await this.#readOps() ?? { schema: OPS_SCHEMA, ops: [] };
|
|
7000
|
+
const indexFile = await this.#file(OPS_FILE);
|
|
7001
|
+
const suggestion = {
|
|
7002
|
+
opId: cryptoRandomGuid(),
|
|
7003
|
+
title: input.title,
|
|
7004
|
+
verb: input.verb,
|
|
7005
|
+
author: input.author,
|
|
7006
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7007
|
+
state: "pending",
|
|
7008
|
+
...input.targets !== void 0 ? { targets: input.targets } : {},
|
|
7009
|
+
...input.batchId ? { batchId: input.batchId } : {},
|
|
7010
|
+
...input.userId ? { userId: input.userId } : {},
|
|
7011
|
+
...input.baseCommitGuid ? { baseCommitGuid: input.baseCommitGuid } : {}
|
|
7012
|
+
};
|
|
7013
|
+
if (input.payload) {
|
|
7014
|
+
const holder = indexFile ?? await this.#createJson(folderId, OPS_FILE, index);
|
|
7015
|
+
const hidden = await this.client.createHiddenFile(
|
|
7016
|
+
input.payload,
|
|
7017
|
+
holder.id
|
|
7018
|
+
);
|
|
7019
|
+
suggestion.fragId = String(
|
|
7020
|
+
hidden._id ?? hidden.id
|
|
7021
|
+
);
|
|
7022
|
+
}
|
|
7023
|
+
const fresh = await this.#readOps() ?? index;
|
|
7024
|
+
fresh.schema ??= OPS_SCHEMA;
|
|
7025
|
+
fresh.ops.push(suggestion);
|
|
7026
|
+
await this.#writeJson(folderId, OPS_FILE, fresh);
|
|
7027
|
+
return suggestion;
|
|
7028
|
+
}
|
|
7029
|
+
/** A suggestion's .frag payload. */
|
|
7030
|
+
async suggestionPayload(suggestion) {
|
|
7031
|
+
if (!suggestion.fragId) {
|
|
7032
|
+
throw new Error(`Suggestion ${suggestion.opId} carries no payload.`);
|
|
7033
|
+
}
|
|
7034
|
+
const response = await this.client.downloadHiddenFile(suggestion.fragId);
|
|
7035
|
+
return await response.blob();
|
|
7036
|
+
}
|
|
7037
|
+
/**
|
|
7038
|
+
* Marks a suggestion applied (naming the version that materialised it) or
|
|
7039
|
+
* discarded. The native plugins do this themselves when they apply; apps
|
|
7040
|
+
* use it for `discarded`.
|
|
7041
|
+
*/
|
|
7042
|
+
async resolveSuggestion(opId, outcome) {
|
|
7043
|
+
const folderId = await this.#folder(false);
|
|
7044
|
+
if (!folderId) throw new Error("This document has no suggestion queue.");
|
|
7045
|
+
const index = await this.#readOps();
|
|
7046
|
+
const suggestion = index?.ops.find((op) => op.opId === opId);
|
|
7047
|
+
if (!index || !suggestion) {
|
|
7048
|
+
throw new Error(`No suggestion ${opId} in this document's queue.`);
|
|
7049
|
+
}
|
|
7050
|
+
Object.assign(suggestion, outcome);
|
|
7051
|
+
await this.#writeJson(folderId, OPS_FILE, index);
|
|
7052
|
+
return suggestion;
|
|
7053
|
+
}
|
|
7054
|
+
// ─── The layout, below the surface ────────────────────────────────────────
|
|
7055
|
+
get #folderName() {
|
|
7056
|
+
return `${this.source}-${this.docId}`;
|
|
7057
|
+
}
|
|
7058
|
+
async #folder(create) {
|
|
7059
|
+
if (this.#folderId) return this.#folderId;
|
|
7060
|
+
const rootId = await this.project.rootFolderId(create);
|
|
7061
|
+
if (!rootId) {
|
|
7062
|
+
throw new Error(
|
|
7063
|
+
`Project ${this.project.projectId} has no connected documents yet.`
|
|
7064
|
+
);
|
|
7065
|
+
}
|
|
7066
|
+
const folders = await this.client.listFolders({
|
|
7067
|
+
parentFolderId: rootId,
|
|
7068
|
+
projectId: this.project.projectId
|
|
7069
|
+
});
|
|
7070
|
+
const found = folders.find(
|
|
7071
|
+
(f) => String(f.name ?? "") === this.#folderName
|
|
7072
|
+
);
|
|
7073
|
+
if (found) {
|
|
7074
|
+
this.#folderId = idOf(found);
|
|
7075
|
+
return this.#folderId;
|
|
7076
|
+
}
|
|
7077
|
+
if (!create) {
|
|
7078
|
+
throw new Error(
|
|
7079
|
+
`Document ${this.#folderName} does not exist in this project.`
|
|
7080
|
+
);
|
|
7081
|
+
}
|
|
7082
|
+
const made = await this.client.createFolder(
|
|
7083
|
+
this.#folderName,
|
|
7084
|
+
rootId,
|
|
7085
|
+
this.project.projectId
|
|
7086
|
+
);
|
|
7087
|
+
this.#folderId = idOf(made);
|
|
7088
|
+
return this.#folderId;
|
|
7089
|
+
}
|
|
7090
|
+
async #files() {
|
|
7091
|
+
const folderId = await this.#folder(false);
|
|
7092
|
+
const items2 = await this.client.listFiles({ folderId });
|
|
7093
|
+
return items2.map((item) => ({
|
|
7094
|
+
id: idOf(item),
|
|
7095
|
+
name: String(item.name ?? "")
|
|
7096
|
+
}));
|
|
7097
|
+
}
|
|
7098
|
+
async #file(name) {
|
|
7099
|
+
try {
|
|
7100
|
+
return (await this.#files()).find((f) => f.name === name);
|
|
7101
|
+
} catch {
|
|
7102
|
+
return void 0;
|
|
7103
|
+
}
|
|
7104
|
+
}
|
|
7105
|
+
async #modelFile() {
|
|
7106
|
+
try {
|
|
7107
|
+
const files = await this.#files();
|
|
7108
|
+
return files.find((f) => f.name === LEGACY_MODEL_FILE) ?? files.find(
|
|
7109
|
+
(f) => f.name.endsWith(".frag") && !f.name.startsWith(INTERNAL_PREFIX)
|
|
7110
|
+
);
|
|
7111
|
+
} catch {
|
|
7112
|
+
return void 0;
|
|
7113
|
+
}
|
|
7114
|
+
}
|
|
7115
|
+
async #readJson(name) {
|
|
7116
|
+
const file = await this.#file(name);
|
|
7117
|
+
if (!file) return void 0;
|
|
7118
|
+
const response = await this.client.downloadFile(file.id);
|
|
7119
|
+
const text2 = await response.text();
|
|
7120
|
+
if (!text2.trim()) return void 0;
|
|
7121
|
+
return JSON.parse(text2);
|
|
7122
|
+
}
|
|
7123
|
+
#readHistory() {
|
|
7124
|
+
return this.#readJson(HISTORY_FILE);
|
|
7125
|
+
}
|
|
7126
|
+
#readOps() {
|
|
7127
|
+
return this.#readJson(OPS_FILE);
|
|
7128
|
+
}
|
|
7129
|
+
async #writeJson(folderId, name, value2) {
|
|
7130
|
+
const blob = new Blob([JSON.stringify(value2)], {
|
|
7131
|
+
type: "application/json"
|
|
7132
|
+
});
|
|
7133
|
+
const existing = await this.#file(name);
|
|
7134
|
+
if (existing) {
|
|
7135
|
+
await this.client.updateFile(existing.id, {
|
|
7136
|
+
file: blob,
|
|
7137
|
+
versionTag: versionTag()
|
|
7138
|
+
});
|
|
7139
|
+
return existing;
|
|
7140
|
+
}
|
|
7141
|
+
return await this.#createJson(folderId, name, value2);
|
|
7142
|
+
}
|
|
7143
|
+
async #createJson(folderId, name, value2) {
|
|
7144
|
+
const blob = new Blob([JSON.stringify(value2)], {
|
|
7145
|
+
type: "application/json"
|
|
7146
|
+
});
|
|
7147
|
+
const created = await this.client.createFile({
|
|
7148
|
+
file: blob,
|
|
7149
|
+
name,
|
|
7150
|
+
versionTag: versionTag(),
|
|
7151
|
+
parentFolderId: folderId,
|
|
7152
|
+
projectId: this.project.projectId
|
|
7153
|
+
});
|
|
7154
|
+
const item = created.item;
|
|
7155
|
+
return { id: idOf(item ?? created), name };
|
|
7156
|
+
}
|
|
7157
|
+
async #writeModel(folderId, model) {
|
|
7158
|
+
const existing = await this.#modelFile();
|
|
7159
|
+
if (existing) {
|
|
7160
|
+
await this.client.updateFile(existing.id, {
|
|
7161
|
+
file: model,
|
|
7162
|
+
versionTag: versionTag()
|
|
7163
|
+
});
|
|
7164
|
+
return existing;
|
|
7165
|
+
}
|
|
7166
|
+
const name = `${this.#folderName}.frag`;
|
|
7167
|
+
const created = await this.client.createFile({
|
|
7168
|
+
file: model,
|
|
7169
|
+
name,
|
|
7170
|
+
versionTag: versionTag(),
|
|
7171
|
+
parentFolderId: folderId,
|
|
7172
|
+
projectId: this.project.projectId
|
|
7173
|
+
});
|
|
7174
|
+
const item = created.item;
|
|
7175
|
+
return { id: idOf(item ?? created), name };
|
|
7176
|
+
}
|
|
7177
|
+
}
|
|
7178
|
+
function tally(changes) {
|
|
7179
|
+
const counts = { added: 0, modified: 0, removed: 0 };
|
|
7180
|
+
for (const change of changes) {
|
|
7181
|
+
if (change.type === "create") counts.added++;
|
|
7182
|
+
else if (change.type === "delete") counts.removed++;
|
|
7183
|
+
else counts.modified++;
|
|
7184
|
+
}
|
|
7185
|
+
return counts;
|
|
7186
|
+
}
|
|
7187
|
+
function orderByGraph(versions) {
|
|
7188
|
+
if (versions.length <= 1) {
|
|
7189
|
+
versions.forEach((v, i) => v.ordinal = i);
|
|
7190
|
+
return [...versions];
|
|
7191
|
+
}
|
|
7192
|
+
const byGuid = new Map(versions.map((v) => [v.guid, v]));
|
|
7193
|
+
const children = /* @__PURE__ */ new Map();
|
|
7194
|
+
const roots = [];
|
|
7195
|
+
for (const version2 of versions) {
|
|
7196
|
+
const parent = version2.parents?.[0];
|
|
7197
|
+
if (parent && byGuid.has(parent)) {
|
|
7198
|
+
const list = children.get(parent) ?? [];
|
|
7199
|
+
list.push(version2);
|
|
7200
|
+
children.set(parent, list);
|
|
7201
|
+
} else {
|
|
7202
|
+
roots.push(version2);
|
|
7203
|
+
}
|
|
7204
|
+
}
|
|
7205
|
+
const byTime = (a, b) => String(a.timestamp).localeCompare(String(b.timestamp));
|
|
7206
|
+
roots.sort(byTime);
|
|
7207
|
+
const ordered = [];
|
|
7208
|
+
const stack = [...roots].reverse();
|
|
7209
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7210
|
+
while (stack.length) {
|
|
7211
|
+
const version2 = stack.pop();
|
|
7212
|
+
if (seen.has(version2.guid)) continue;
|
|
7213
|
+
seen.add(version2.guid);
|
|
7214
|
+
ordered.push(version2);
|
|
7215
|
+
const next = (children.get(version2.guid) ?? []).sort(byTime);
|
|
7216
|
+
for (let i = next.length - 1; i >= 0; i--) stack.push(next[i]);
|
|
7217
|
+
}
|
|
7218
|
+
for (const version2 of versions) {
|
|
7219
|
+
if (!seen.has(version2.guid)) ordered.push(version2);
|
|
7220
|
+
}
|
|
7221
|
+
ordered.forEach((v, i) => v.ordinal = i);
|
|
7222
|
+
return ordered;
|
|
7223
|
+
}
|
|
7224
|
+
function lastByGraph(versions) {
|
|
7225
|
+
const ordered = orderByGraph(versions);
|
|
7226
|
+
return ordered[ordered.length - 1];
|
|
7227
|
+
}
|
|
7228
|
+
function cryptoRandomGuid() {
|
|
7229
|
+
const anyCrypto = globalThis.crypto;
|
|
7230
|
+
if (anyCrypto?.randomUUID) return anyCrypto.randomUUID();
|
|
7231
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
7232
|
+
const r = Math.random() * 16 | 0;
|
|
7233
|
+
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
7234
|
+
});
|
|
7235
|
+
}
|
|
7236
|
+
class Recipes {
|
|
7237
|
+
constructor(client) {
|
|
7238
|
+
this.client = client;
|
|
7239
|
+
}
|
|
7240
|
+
#registry = /* @__PURE__ */ new Map();
|
|
7241
|
+
/** Registers a recipe. One per name; a second with the same name throws. */
|
|
7242
|
+
register(recipe) {
|
|
7243
|
+
if (this.#registry.has(recipe.name)) {
|
|
7244
|
+
throw new Error(`A recipe named "${recipe.name}" is already registered.`);
|
|
7245
|
+
}
|
|
7246
|
+
this.#registry.set(recipe.name, recipe);
|
|
7247
|
+
}
|
|
7248
|
+
/** The registered recipes, optionally filtered by target application. */
|
|
7249
|
+
list(filter) {
|
|
7250
|
+
const all = [...this.#registry.values()];
|
|
7251
|
+
return all.filter(
|
|
7252
|
+
(recipe) => (!filter?.to || recipe.to === filter.to) && (!filter?.input || recipe.inputs.includes(filter.input))
|
|
7253
|
+
);
|
|
7254
|
+
}
|
|
7255
|
+
/** A registered recipe by name, or undefined. */
|
|
7256
|
+
get(name) {
|
|
7257
|
+
return this.#registry.get(name);
|
|
7258
|
+
}
|
|
7259
|
+
/**
|
|
7260
|
+
* Runs a recipe and queues its suggestion on the target document. Safe to
|
|
7261
|
+
* call freely: nothing touches the native application until its owner
|
|
7262
|
+
* accepts the suggestion there.
|
|
7263
|
+
*/
|
|
7264
|
+
async run(name, options) {
|
|
7265
|
+
const recipe = this.#registry.get(name);
|
|
7266
|
+
if (!recipe) throw new Error(`No recipe named "${name}" is registered.`);
|
|
7267
|
+
if (recipe.to !== options.target.source) {
|
|
7268
|
+
throw new Error(
|
|
7269
|
+
`Recipe "${name}" writes ${recipe.to}, but the target document belongs to ${options.target.source}.`
|
|
7270
|
+
);
|
|
7271
|
+
}
|
|
7272
|
+
const targetDoc = this.client.history(options.projectId).doc(options.target.source, options.target.docId);
|
|
7273
|
+
const base = await targetDoc.latest();
|
|
7274
|
+
const result = await recipe.run({
|
|
7275
|
+
client: this.client,
|
|
7276
|
+
projectId: options.projectId,
|
|
7277
|
+
targetDoc,
|
|
7278
|
+
input: options.input,
|
|
7279
|
+
settings: options.settings ?? {}
|
|
7280
|
+
});
|
|
7281
|
+
const suggestion = await targetDoc.suggest({
|
|
7282
|
+
title: result.title,
|
|
7283
|
+
verb: result.verb,
|
|
7284
|
+
author: options.author,
|
|
7285
|
+
payload: result.payload,
|
|
7286
|
+
targets: result.targets,
|
|
7287
|
+
userId: options.userId,
|
|
7288
|
+
baseCommitGuid: base?.guid
|
|
7289
|
+
});
|
|
7290
|
+
return { suggestion, result };
|
|
7291
|
+
}
|
|
7292
|
+
}
|
|
6798
7293
|
const STORAGE_BATCH_MAX = 100;
|
|
6799
7294
|
function parseErrorBody(body) {
|
|
6800
7295
|
try {
|
|
@@ -7171,11 +7666,11 @@ class EngineServicesClient {
|
|
|
7171
7666
|
* @param versionTag - The version tag (e.g. "v1").
|
|
7172
7667
|
* @param params - Optional flags such as `withDraft`.
|
|
7173
7668
|
*/
|
|
7174
|
-
async getFileVersionMetadata(fileId,
|
|
7669
|
+
async getFileVersionMetadata(fileId, versionTag2, params) {
|
|
7175
7670
|
const { withDraft } = params || {};
|
|
7176
7671
|
return await this.#requestApi(
|
|
7177
7672
|
"GET",
|
|
7178
|
-
`${ITEM_PATH}/${encodeURIComponent(fileId)}/version/${encodeURIComponent(
|
|
7673
|
+
`${ITEM_PATH}/${encodeURIComponent(fileId)}/version/${encodeURIComponent(versionTag2)}/metadata`,
|
|
7179
7674
|
{
|
|
7180
7675
|
query: {
|
|
7181
7676
|
...withDraft && { withDraft: "true" }
|
|
@@ -7189,10 +7684,10 @@ class EngineServicesClient {
|
|
|
7189
7684
|
* @param versionTag - The version tag.
|
|
7190
7685
|
* @param metadata - Free-JSON object (max 200 fields, 50-char keys/values).
|
|
7191
7686
|
*/
|
|
7192
|
-
async updateFileVersionMetadata(fileId,
|
|
7687
|
+
async updateFileVersionMetadata(fileId, versionTag2, metadata2) {
|
|
7193
7688
|
return await this.#requestApi(
|
|
7194
7689
|
"PUT",
|
|
7195
|
-
`${ITEM_PATH}/${encodeURIComponent(fileId)}/version/${encodeURIComponent(
|
|
7690
|
+
`${ITEM_PATH}/${encodeURIComponent(fileId)}/version/${encodeURIComponent(versionTag2)}/metadata`,
|
|
7196
7691
|
{
|
|
7197
7692
|
body: JSON.stringify({ metadata: metadata2 }),
|
|
7198
7693
|
contentType: "application/json"
|
|
@@ -7204,10 +7699,10 @@ class EngineServicesClient {
|
|
|
7204
7699
|
* @param fileId - The file's unique identifier.
|
|
7205
7700
|
* @param versionTag - The version tag.
|
|
7206
7701
|
*/
|
|
7207
|
-
async deleteFileVersionMetadata(fileId,
|
|
7702
|
+
async deleteFileVersionMetadata(fileId, versionTag2) {
|
|
7208
7703
|
return await this.#requestApi(
|
|
7209
7704
|
"DELETE",
|
|
7210
|
-
`${ITEM_PATH}/${encodeURIComponent(fileId)}/version/${encodeURIComponent(
|
|
7705
|
+
`${ITEM_PATH}/${encodeURIComponent(fileId)}/version/${encodeURIComponent(versionTag2)}/metadata`
|
|
7211
7706
|
);
|
|
7212
7707
|
}
|
|
7213
7708
|
/**
|
|
@@ -7436,12 +7931,12 @@ class EngineServicesClient {
|
|
|
7436
7931
|
* @returns A fetch Response containing the bundle JavaScript text.
|
|
7437
7932
|
*/
|
|
7438
7933
|
async downloadComponentBundle(componentId, params) {
|
|
7439
|
-
const { versionTag, withDraft } = params || {};
|
|
7934
|
+
const { versionTag: versionTag2, withDraft } = params || {};
|
|
7440
7935
|
return await this.#requestFile(
|
|
7441
7936
|
`${ITEM_PATH}/${componentId}/download/bundle`,
|
|
7442
7937
|
{
|
|
7443
7938
|
query: {
|
|
7444
|
-
...
|
|
7939
|
+
...versionTag2 && { versionTag: versionTag2 },
|
|
7445
7940
|
...withDraft && { withDraft }
|
|
7446
7941
|
}
|
|
7447
7942
|
}
|
|
@@ -7633,10 +8128,10 @@ return main;`);
|
|
|
7633
8128
|
* @returns A fetch Response containing the bundle JavaScript text.
|
|
7634
8129
|
*/
|
|
7635
8130
|
async downloadAppBundle(appId, params) {
|
|
7636
|
-
const { versionTag, withDraft } = params || {};
|
|
8131
|
+
const { versionTag: versionTag2, withDraft } = params || {};
|
|
7637
8132
|
return await this.#requestFile(`${ITEM_PATH}/${appId}/download/bundle`, {
|
|
7638
8133
|
query: {
|
|
7639
|
-
...
|
|
8134
|
+
...versionTag2 && { versionTag: versionTag2 },
|
|
7640
8135
|
...withDraft && { withDraft }
|
|
7641
8136
|
}
|
|
7642
8137
|
});
|
|
@@ -7678,7 +8173,7 @@ return main;`);
|
|
|
7678
8173
|
* @param versionTag - Optional version to execute (defaults to latest).
|
|
7679
8174
|
* @returns An object containing the `executionId` to track progress.
|
|
7680
8175
|
*/
|
|
7681
|
-
async executeComponent(componentId, executionParams,
|
|
8176
|
+
async executeComponent(componentId, executionParams, versionTag2) {
|
|
7682
8177
|
if (this.localServerUrl) {
|
|
7683
8178
|
const url2 = `${this.localServerUrl}/api/${PROCESS_PATH}/${componentId}/execute`;
|
|
7684
8179
|
const response = await fetch(url2, {
|
|
@@ -7699,7 +8194,7 @@ return main;`);
|
|
|
7699
8194
|
`${PROCESS_PATH}/${componentId}/execute`,
|
|
7700
8195
|
{
|
|
7701
8196
|
body: JSON.stringify(executionParams),
|
|
7702
|
-
query: { ...
|
|
8197
|
+
query: { ...versionTag2 && { versionTag: versionTag2 } },
|
|
7703
8198
|
contentType: "application/json"
|
|
7704
8199
|
}
|
|
7705
8200
|
);
|
|
@@ -7801,6 +8296,25 @@ return main;`);
|
|
|
7801
8296
|
console.log(e);
|
|
7802
8297
|
});
|
|
7803
8298
|
}
|
|
8299
|
+
// ─── History & Recipes ───────────────────────────────────────────
|
|
8300
|
+
/**
|
|
8301
|
+
* A project's history of connected documents (Revit models, AutoCAD
|
|
8302
|
+
* drawings…): their version timelines and their change requests. See
|
|
8303
|
+
* `src/core/history.ts` — this surface is the only supported way to read
|
|
8304
|
+
* or write it; the storage underneath is private and will move.
|
|
8305
|
+
*/
|
|
8306
|
+
history(projectId) {
|
|
8307
|
+
return new ProjectHistory(this, projectId);
|
|
8308
|
+
}
|
|
8309
|
+
#recipes;
|
|
8310
|
+
/**
|
|
8311
|
+
* The recipe registry and runner: scripts that write change requests in a
|
|
8312
|
+
* native application's language. See `src/core/recipes.ts`.
|
|
8313
|
+
*/
|
|
8314
|
+
get recipes() {
|
|
8315
|
+
this.#recipes ??= new Recipes(this);
|
|
8316
|
+
return this.#recipes;
|
|
8317
|
+
}
|
|
7804
8318
|
// ─── Hidden Files ────────────────────────────────────────────────
|
|
7805
8319
|
/**
|
|
7806
8320
|
* Creates a hidden file attached to a parent item (e.g., dependencies, assets).
|
|
@@ -8017,10 +8531,10 @@ return main;`);
|
|
|
8017
8531
|
* @param metadata - Optional free-JSON metadata to store on the new version.
|
|
8018
8532
|
* @returns The created version.
|
|
8019
8533
|
*/
|
|
8020
|
-
async createVersion(itemId, file,
|
|
8534
|
+
async createVersion(itemId, file, versionTag2, extraProps, metadata2) {
|
|
8021
8535
|
const formData = new FormData();
|
|
8022
8536
|
formData.append("file", file);
|
|
8023
|
-
formData.append("versionTag",
|
|
8537
|
+
formData.append("versionTag", versionTag2);
|
|
8024
8538
|
extraProps && formData.append("extraProps", JSON.stringify(extraProps));
|
|
8025
8539
|
metadata2 && formData.append("metadata", JSON.stringify(metadata2));
|
|
8026
8540
|
return await this.#requestApi(
|
|
@@ -8084,10 +8598,10 @@ return main;`);
|
|
|
8084
8598
|
* @param versionTag - The version's tag (e.g. "v2").
|
|
8085
8599
|
* @returns The archived version.
|
|
8086
8600
|
*/
|
|
8087
|
-
async archiveVersion(itemId,
|
|
8601
|
+
async archiveVersion(itemId, versionTag2) {
|
|
8088
8602
|
return await this.#requestApi(
|
|
8089
8603
|
"PUT",
|
|
8090
|
-
`${ITEM_PATH}/${encodeURIComponent(itemId)}/version/${encodeURIComponent(
|
|
8604
|
+
`${ITEM_PATH}/${encodeURIComponent(itemId)}/version/${encodeURIComponent(versionTag2)}/archive`
|
|
8091
8605
|
);
|
|
8092
8606
|
}
|
|
8093
8607
|
/**
|
|
@@ -8096,10 +8610,10 @@ return main;`);
|
|
|
8096
8610
|
* @param versionTag - The version's tag (e.g. "v2").
|
|
8097
8611
|
* @returns The recovered version.
|
|
8098
8612
|
*/
|
|
8099
|
-
async recoverVersion(itemId,
|
|
8613
|
+
async recoverVersion(itemId, versionTag2) {
|
|
8100
8614
|
return await this.#requestApi(
|
|
8101
8615
|
"PUT",
|
|
8102
|
-
`${ITEM_PATH}/${encodeURIComponent(itemId)}/version/${encodeURIComponent(
|
|
8616
|
+
`${ITEM_PATH}/${encodeURIComponent(itemId)}/version/${encodeURIComponent(versionTag2)}/recover`
|
|
8103
8617
|
);
|
|
8104
8618
|
}
|
|
8105
8619
|
/**
|
|
@@ -8108,10 +8622,10 @@ return main;`);
|
|
|
8108
8622
|
* @param itemId - The item's unique identifier.
|
|
8109
8623
|
* @param versionTag - The version's tag (e.g. "v2").
|
|
8110
8624
|
*/
|
|
8111
|
-
async deleteVersion(itemId,
|
|
8625
|
+
async deleteVersion(itemId, versionTag2) {
|
|
8112
8626
|
return await this.#requestApi(
|
|
8113
8627
|
"DELETE",
|
|
8114
|
-
`${ITEM_PATH}/${encodeURIComponent(itemId)}/version/${encodeURIComponent(
|
|
8628
|
+
`${ITEM_PATH}/${encodeURIComponent(itemId)}/version/${encodeURIComponent(versionTag2)}`
|
|
8115
8629
|
);
|
|
8116
8630
|
}
|
|
8117
8631
|
// Project-scoped listings happen via the main list methods — e.g.
|
|
@@ -8142,20 +8656,20 @@ return main;`);
|
|
|
8142
8656
|
return responses.flat();
|
|
8143
8657
|
}
|
|
8144
8658
|
async #downloadItem(itemId, params) {
|
|
8145
|
-
const { versionTag, withDraft } = params || {};
|
|
8659
|
+
const { versionTag: versionTag2, withDraft } = params || {};
|
|
8146
8660
|
return await this.#requestFile(`${ITEM_PATH}/${itemId}/download`, {
|
|
8147
8661
|
query: {
|
|
8148
|
-
...
|
|
8662
|
+
...versionTag2 && { versionTag: versionTag2 },
|
|
8149
8663
|
...withDraft && { withDraft }
|
|
8150
8664
|
}
|
|
8151
8665
|
});
|
|
8152
8666
|
}
|
|
8153
8667
|
async #createItem(fileData, itemType, extraProps) {
|
|
8154
|
-
const { name, versionTag, parentFolderId, projectId, file, metadata: metadata2 } = fileData;
|
|
8668
|
+
const { name, versionTag: versionTag2, parentFolderId, projectId, file, metadata: metadata2 } = fileData;
|
|
8155
8669
|
const formData = new FormData();
|
|
8156
8670
|
formData.append("file", file);
|
|
8157
8671
|
formData.append("name", name);
|
|
8158
|
-
formData.append("versionTag",
|
|
8672
|
+
formData.append("versionTag", versionTag2);
|
|
8159
8673
|
formData.append("itemType", itemType);
|
|
8160
8674
|
parentFolderId && formData.append("folderId", parentFolderId);
|
|
8161
8675
|
projectId && formData.append("projectId", projectId);
|
|
@@ -8166,13 +8680,13 @@ return main;`);
|
|
|
8166
8680
|
});
|
|
8167
8681
|
}
|
|
8168
8682
|
async #updateItem(itemId, fileData, extraProps) {
|
|
8169
|
-
const { name, versionTag, parentFolderId, file, metadata: metadata2 } = fileData;
|
|
8683
|
+
const { name, versionTag: versionTag2, parentFolderId, file, metadata: metadata2 } = fileData;
|
|
8170
8684
|
let item;
|
|
8171
8685
|
let version2;
|
|
8172
8686
|
if (file) {
|
|
8173
8687
|
const formData = new FormData();
|
|
8174
8688
|
formData.append("file", file);
|
|
8175
|
-
|
|
8689
|
+
versionTag2 && formData.append("versionTag", versionTag2);
|
|
8176
8690
|
extraProps && formData.append("extraProps", JSON.stringify(extraProps));
|
|
8177
8691
|
metadata2 && formData.append("metadata", JSON.stringify(metadata2));
|
|
8178
8692
|
version2 = await this.#requestApi(
|
|
@@ -10877,15 +11391,15 @@ const publishCommand = new Command2("publish").description("Build and publish th
|
|
|
10877
11391
|
}
|
|
10878
11392
|
const pkg2 = JSON.parse(require$$3$1.readFileSync(pkgPath, "utf-8"));
|
|
10879
11393
|
const projectName = opts.name || pkg2.name || require$$2.basename(cwd);
|
|
10880
|
-
const
|
|
11394
|
+
const versionTag2 = opts.versionTag || pkg2.version || "1.0.0";
|
|
10881
11395
|
const projectId = opts.projectId || localConfig?.projectId;
|
|
10882
11396
|
const client = cliClient(config2.accessToken, config2.apiUrl);
|
|
10883
11397
|
if (existingId) {
|
|
10884
11398
|
try {
|
|
10885
11399
|
const versions = await client.listVersions(existingId);
|
|
10886
|
-
if (versions.some((v) => v.tag ===
|
|
11400
|
+
if (versions.some((v) => v.tag === versionTag2)) {
|
|
10887
11401
|
console.error(
|
|
10888
|
-
`Version ${
|
|
11402
|
+
`Version ${versionTag2} already exists for this ${isComponent ? "component" : "app"}. Bump the version in package.json or pass --version-tag.`
|
|
10889
11403
|
);
|
|
10890
11404
|
process.exit(1);
|
|
10891
11405
|
}
|
|
@@ -10944,7 +11458,7 @@ const publishCommand = new Command2("publish").description("Build and publish th
|
|
|
10944
11458
|
existingId,
|
|
10945
11459
|
zipFile,
|
|
10946
11460
|
projectName,
|
|
10947
|
-
|
|
11461
|
+
versionTag2,
|
|
10948
11462
|
cwd,
|
|
10949
11463
|
projectId
|
|
10950
11464
|
);
|
|
@@ -10954,7 +11468,7 @@ const publishCommand = new Command2("publish").description("Build and publish th
|
|
|
10954
11468
|
existingId,
|
|
10955
11469
|
zipFile,
|
|
10956
11470
|
projectName,
|
|
10957
|
-
|
|
11471
|
+
versionTag2,
|
|
10958
11472
|
cwd,
|
|
10959
11473
|
projectId
|
|
10960
11474
|
);
|
|
@@ -10991,7 +11505,7 @@ const publishCommand = new Command2("publish").description("Build and publish th
|
|
|
10991
11505
|
}
|
|
10992
11506
|
}
|
|
10993
11507
|
);
|
|
10994
|
-
async function publishApp(client, appId, zipFile, name,
|
|
11508
|
+
async function publishApp(client, appId, zipFile, name, versionTag2, cwd, projectId) {
|
|
10995
11509
|
if (appId) {
|
|
10996
11510
|
const existing = await client.getFile(appId);
|
|
10997
11511
|
if (existing.archived) {
|
|
@@ -10999,23 +11513,23 @@ async function publishApp(client, appId, zipFile, name, versionTag, cwd, project
|
|
|
10999
11513
|
await client.recoverFile(appId);
|
|
11000
11514
|
}
|
|
11001
11515
|
console.log(
|
|
11002
|
-
`Publishing new version (${
|
|
11516
|
+
`Publishing new version (${versionTag2}) for app ${appId}...`
|
|
11003
11517
|
);
|
|
11004
11518
|
const result = await client.createVersion(
|
|
11005
11519
|
appId,
|
|
11006
11520
|
zipFile,
|
|
11007
|
-
|
|
11521
|
+
versionTag2,
|
|
11008
11522
|
{}
|
|
11009
11523
|
// extraProps required by backend for APP items
|
|
11010
11524
|
);
|
|
11011
11525
|
console.log("Version created:", JSON.stringify(result, null, 2));
|
|
11012
11526
|
return appId;
|
|
11013
11527
|
} else {
|
|
11014
|
-
console.log(`Publishing new app "${name}" (${
|
|
11528
|
+
console.log(`Publishing new app "${name}" (${versionTag2})...`);
|
|
11015
11529
|
const result = await client.createApp({
|
|
11016
11530
|
file: zipFile,
|
|
11017
11531
|
name,
|
|
11018
|
-
versionTag,
|
|
11532
|
+
versionTag: versionTag2,
|
|
11019
11533
|
// The API has always accepted it; the CLI just never sent it, so a CI
|
|
11020
11534
|
// publish could not land an app inside a project.
|
|
11021
11535
|
...projectId && { projectId }
|
|
@@ -11029,7 +11543,7 @@ async function publishApp(client, appId, zipFile, name, versionTag, cwd, project
|
|
|
11029
11543
|
return newAppId ? String(newAppId) : void 0;
|
|
11030
11544
|
}
|
|
11031
11545
|
}
|
|
11032
|
-
async function publishComponent(client, componentId, zipFile, name,
|
|
11546
|
+
async function publishComponent(client, componentId, zipFile, name, versionTag2, cwd, projectId) {
|
|
11033
11547
|
const componentProps = {
|
|
11034
11548
|
type: "CLOUD",
|
|
11035
11549
|
tier: "FREE",
|
|
@@ -11042,23 +11556,23 @@ async function publishComponent(client, componentId, zipFile, name, versionTag,
|
|
|
11042
11556
|
await client.recoverComponent(componentId);
|
|
11043
11557
|
}
|
|
11044
11558
|
console.log(
|
|
11045
|
-
`Publishing new version (${
|
|
11559
|
+
`Publishing new version (${versionTag2}) for component ${componentId}...`
|
|
11046
11560
|
);
|
|
11047
11561
|
const result = await client.updateComponent(componentId, {
|
|
11048
11562
|
file: zipFile,
|
|
11049
|
-
versionTag,
|
|
11563
|
+
versionTag: versionTag2,
|
|
11050
11564
|
componentProps
|
|
11051
11565
|
});
|
|
11052
11566
|
console.log("Version created:", JSON.stringify(result, null, 2));
|
|
11053
11567
|
return componentId;
|
|
11054
11568
|
} else {
|
|
11055
11569
|
console.log(
|
|
11056
|
-
`Publishing new cloud component "${name}" (${
|
|
11570
|
+
`Publishing new cloud component "${name}" (${versionTag2})...`
|
|
11057
11571
|
);
|
|
11058
11572
|
const result = await client.createComponent({
|
|
11059
11573
|
file: zipFile,
|
|
11060
11574
|
name,
|
|
11061
|
-
versionTag,
|
|
11575
|
+
versionTag: versionTag2,
|
|
11062
11576
|
componentProps,
|
|
11063
11577
|
...projectId && { projectId }
|
|
11064
11578
|
});
|
|
@@ -25070,8 +25584,8 @@ var scope = {};
|
|
|
25070
25584
|
var util = {};
|
|
25071
25585
|
Object.defineProperty(util, "__esModule", { value: true });
|
|
25072
25586
|
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;
|
|
25073
|
-
const codegen_1$
|
|
25074
|
-
const code_1$
|
|
25587
|
+
const codegen_1$v = codegen;
|
|
25588
|
+
const code_1$a = code$1;
|
|
25075
25589
|
function toHash(arr) {
|
|
25076
25590
|
const hash = {};
|
|
25077
25591
|
for (const item of arr)
|
|
@@ -25124,9 +25638,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
|
|
|
25124
25638
|
if (typeof schema == "number" || typeof schema == "boolean")
|
|
25125
25639
|
return schema;
|
|
25126
25640
|
if (typeof schema == "string")
|
|
25127
|
-
return (0, codegen_1$
|
|
25641
|
+
return (0, codegen_1$v._)`${schema}`;
|
|
25128
25642
|
}
|
|
25129
|
-
return (0, codegen_1$
|
|
25643
|
+
return (0, codegen_1$v._)`${topSchemaRef}${schemaPath}${(0, codegen_1$v.getProperty)(keyword2)}`;
|
|
25130
25644
|
}
|
|
25131
25645
|
util.schemaRefOrVal = schemaRefOrVal;
|
|
25132
25646
|
function unescapeFragment(str) {
|
|
@@ -25158,20 +25672,20 @@ function eachItem(xs, f) {
|
|
|
25158
25672
|
util.eachItem = eachItem;
|
|
25159
25673
|
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues: mergeValues2, resultToName }) {
|
|
25160
25674
|
return (gen, from, to, toName) => {
|
|
25161
|
-
const res = to === void 0 ? from : to instanceof codegen_1$
|
|
25162
|
-
return toName === codegen_1$
|
|
25675
|
+
const res = to === void 0 ? from : to instanceof codegen_1$v.Name ? (from instanceof codegen_1$v.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$v.Name ? (mergeToName(gen, to, from), from) : mergeValues2(from, to);
|
|
25676
|
+
return toName === codegen_1$v.Name && !(res instanceof codegen_1$v.Name) ? resultToName(gen, res) : res;
|
|
25163
25677
|
};
|
|
25164
25678
|
}
|
|
25165
25679
|
util.mergeEvaluated = {
|
|
25166
25680
|
props: makeMergeEvaluated({
|
|
25167
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
25168
|
-
gen.if((0, codegen_1$
|
|
25681
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true && ${from} !== undefined`, () => {
|
|
25682
|
+
gen.if((0, codegen_1$v._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$v._)`${to} || {}`).code((0, codegen_1$v._)`Object.assign(${to}, ${from})`));
|
|
25169
25683
|
}),
|
|
25170
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
25684
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true`, () => {
|
|
25171
25685
|
if (from === true) {
|
|
25172
25686
|
gen.assign(to, true);
|
|
25173
25687
|
} else {
|
|
25174
|
-
gen.assign(to, (0, codegen_1$
|
|
25688
|
+
gen.assign(to, (0, codegen_1$v._)`${to} || {}`);
|
|
25175
25689
|
setEvaluated(gen, to, from);
|
|
25176
25690
|
}
|
|
25177
25691
|
}),
|
|
@@ -25179,8 +25693,8 @@ util.mergeEvaluated = {
|
|
|
25179
25693
|
resultToName: evaluatedPropsToName
|
|
25180
25694
|
}),
|
|
25181
25695
|
items: makeMergeEvaluated({
|
|
25182
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
25183
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
25696
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$v._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
|
|
25697
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$v._)`${to} > ${from} ? ${to} : ${from}`)),
|
|
25184
25698
|
mergeValues: (from, to) => from === true ? true : Math.max(from, to),
|
|
25185
25699
|
resultToName: (gen, items2) => gen.var("items", items2)
|
|
25186
25700
|
})
|
|
@@ -25188,21 +25702,21 @@ util.mergeEvaluated = {
|
|
|
25188
25702
|
function evaluatedPropsToName(gen, ps) {
|
|
25189
25703
|
if (ps === true)
|
|
25190
25704
|
return gen.var("props", true);
|
|
25191
|
-
const props = gen.var("props", (0, codegen_1$
|
|
25705
|
+
const props = gen.var("props", (0, codegen_1$v._)`{}`);
|
|
25192
25706
|
if (ps !== void 0)
|
|
25193
25707
|
setEvaluated(gen, props, ps);
|
|
25194
25708
|
return props;
|
|
25195
25709
|
}
|
|
25196
25710
|
util.evaluatedPropsToName = evaluatedPropsToName;
|
|
25197
25711
|
function setEvaluated(gen, props, ps) {
|
|
25198
|
-
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$
|
|
25712
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$v._)`${props}${(0, codegen_1$v.getProperty)(p)}`, true));
|
|
25199
25713
|
}
|
|
25200
25714
|
util.setEvaluated = setEvaluated;
|
|
25201
25715
|
const snippets = {};
|
|
25202
25716
|
function useFunc(gen, f) {
|
|
25203
25717
|
return gen.scopeValue("func", {
|
|
25204
25718
|
ref: f,
|
|
25205
|
-
code: snippets[f.code] || (snippets[f.code] = new code_1$
|
|
25719
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1$a._Code(f.code))
|
|
25206
25720
|
});
|
|
25207
25721
|
}
|
|
25208
25722
|
util.useFunc = useFunc;
|
|
@@ -25212,11 +25726,11 @@ var Type;
|
|
|
25212
25726
|
Type2[Type2["Str"] = 1] = "Str";
|
|
25213
25727
|
})(Type || (util.Type = Type = {}));
|
|
25214
25728
|
function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
|
|
25215
|
-
if (dataProp instanceof codegen_1$
|
|
25729
|
+
if (dataProp instanceof codegen_1$v.Name) {
|
|
25216
25730
|
const isNumber = dataPropType === Type.Num;
|
|
25217
|
-
return jsPropertySyntax ? isNumber ? (0, codegen_1$
|
|
25731
|
+
return jsPropertySyntax ? isNumber ? (0, codegen_1$v._)`"[" + ${dataProp} + "]"` : (0, codegen_1$v._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$v._)`"/" + ${dataProp}` : (0, codegen_1$v._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
|
|
25218
25732
|
}
|
|
25219
|
-
return jsPropertySyntax ? (0, codegen_1$
|
|
25733
|
+
return jsPropertySyntax ? (0, codegen_1$v.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
|
|
25220
25734
|
}
|
|
25221
25735
|
util.getErrorPath = getErrorPath;
|
|
25222
25736
|
function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
@@ -25230,35 +25744,35 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
|
25230
25744
|
util.checkStrictMode = checkStrictMode;
|
|
25231
25745
|
var names$1 = {};
|
|
25232
25746
|
Object.defineProperty(names$1, "__esModule", { value: true });
|
|
25233
|
-
const codegen_1$
|
|
25747
|
+
const codegen_1$u = codegen;
|
|
25234
25748
|
const names = {
|
|
25235
25749
|
// validation function arguments
|
|
25236
|
-
data: new codegen_1$
|
|
25750
|
+
data: new codegen_1$u.Name("data"),
|
|
25237
25751
|
// data passed to validation function
|
|
25238
25752
|
// args passed from referencing schema
|
|
25239
|
-
valCxt: new codegen_1$
|
|
25753
|
+
valCxt: new codegen_1$u.Name("valCxt"),
|
|
25240
25754
|
// validation/data context - should not be used directly, it is destructured to the names below
|
|
25241
|
-
instancePath: new codegen_1$
|
|
25242
|
-
parentData: new codegen_1$
|
|
25243
|
-
parentDataProperty: new codegen_1$
|
|
25244
|
-
rootData: new codegen_1$
|
|
25755
|
+
instancePath: new codegen_1$u.Name("instancePath"),
|
|
25756
|
+
parentData: new codegen_1$u.Name("parentData"),
|
|
25757
|
+
parentDataProperty: new codegen_1$u.Name("parentDataProperty"),
|
|
25758
|
+
rootData: new codegen_1$u.Name("rootData"),
|
|
25245
25759
|
// root data - same as the data passed to the first/top validation function
|
|
25246
|
-
dynamicAnchors: new codegen_1$
|
|
25760
|
+
dynamicAnchors: new codegen_1$u.Name("dynamicAnchors"),
|
|
25247
25761
|
// used to support recursiveRef and dynamicRef
|
|
25248
25762
|
// function scoped variables
|
|
25249
|
-
vErrors: new codegen_1$
|
|
25763
|
+
vErrors: new codegen_1$u.Name("vErrors"),
|
|
25250
25764
|
// null or array of validation errors
|
|
25251
|
-
errors: new codegen_1$
|
|
25765
|
+
errors: new codegen_1$u.Name("errors"),
|
|
25252
25766
|
// counter of validation errors
|
|
25253
|
-
this: new codegen_1$
|
|
25767
|
+
this: new codegen_1$u.Name("this"),
|
|
25254
25768
|
// "globals"
|
|
25255
|
-
self: new codegen_1$
|
|
25256
|
-
scope: new codegen_1$
|
|
25769
|
+
self: new codegen_1$u.Name("self"),
|
|
25770
|
+
scope: new codegen_1$u.Name("scope"),
|
|
25257
25771
|
// JTD serialize/parse name for JSON string and position
|
|
25258
|
-
json: new codegen_1$
|
|
25259
|
-
jsonPos: new codegen_1$
|
|
25260
|
-
jsonLen: new codegen_1$
|
|
25261
|
-
jsonPart: new codegen_1$
|
|
25772
|
+
json: new codegen_1$u.Name("json"),
|
|
25773
|
+
jsonPos: new codegen_1$u.Name("jsonPos"),
|
|
25774
|
+
jsonLen: new codegen_1$u.Name("jsonLen"),
|
|
25775
|
+
jsonPart: new codegen_1$u.Name("jsonPart")
|
|
25262
25776
|
};
|
|
25263
25777
|
names$1.default = names;
|
|
25264
25778
|
(function(exports) {
|
|
@@ -25378,55 +25892,49 @@ names$1.default = names;
|
|
|
25378
25892
|
keyValues.push([E.propertyName, propertyName]);
|
|
25379
25893
|
}
|
|
25380
25894
|
})(errors);
|
|
25381
|
-
|
|
25382
|
-
|
|
25383
|
-
|
|
25384
|
-
|
|
25385
|
-
|
|
25386
|
-
|
|
25387
|
-
|
|
25388
|
-
|
|
25389
|
-
|
|
25390
|
-
const
|
|
25391
|
-
|
|
25392
|
-
|
|
25393
|
-
|
|
25394
|
-
|
|
25395
|
-
|
|
25396
|
-
|
|
25397
|
-
|
|
25398
|
-
gen.return(names_12.default.data);
|
|
25399
|
-
} else {
|
|
25400
|
-
gen.assign((0, codegen_12._)`${validateName}.errors`, null);
|
|
25401
|
-
gen.return(true);
|
|
25402
|
-
}
|
|
25403
|
-
}
|
|
25404
|
-
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
25405
|
-
function boolOrEmptySchema(it, valid) {
|
|
25406
|
-
const { gen, schema } = it;
|
|
25407
|
-
if (schema === false) {
|
|
25408
|
-
gen.var(valid, false);
|
|
25409
|
-
falseSchemaError(it);
|
|
25410
|
-
} else {
|
|
25411
|
-
gen.var(valid, true);
|
|
25412
|
-
}
|
|
25895
|
+
Object.defineProperty(boolSchema, "__esModule", { value: true });
|
|
25896
|
+
boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
|
|
25897
|
+
const errors_1$3 = errors;
|
|
25898
|
+
const codegen_1$t = codegen;
|
|
25899
|
+
const names_1$6 = names$1;
|
|
25900
|
+
const boolError = {
|
|
25901
|
+
message: "boolean schema is false"
|
|
25902
|
+
};
|
|
25903
|
+
function topBoolOrEmptySchema(it) {
|
|
25904
|
+
const { gen, schema, validateName } = it;
|
|
25905
|
+
if (schema === false) {
|
|
25906
|
+
falseSchemaError(it, false);
|
|
25907
|
+
} else if (typeof schema == "object" && schema.$async === true) {
|
|
25908
|
+
gen.return(names_1$6.default.data);
|
|
25909
|
+
} else {
|
|
25910
|
+
gen.assign((0, codegen_1$t._)`${validateName}.errors`, null);
|
|
25911
|
+
gen.return(true);
|
|
25413
25912
|
}
|
|
25414
|
-
|
|
25415
|
-
|
|
25416
|
-
|
|
25417
|
-
|
|
25418
|
-
|
|
25419
|
-
|
|
25420
|
-
|
|
25421
|
-
|
|
25422
|
-
|
|
25423
|
-
schemaValue: false,
|
|
25424
|
-
params: {},
|
|
25425
|
-
it
|
|
25426
|
-
};
|
|
25427
|
-
(0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
25913
|
+
}
|
|
25914
|
+
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
25915
|
+
function boolOrEmptySchema(it, valid) {
|
|
25916
|
+
const { gen, schema } = it;
|
|
25917
|
+
if (schema === false) {
|
|
25918
|
+
gen.var(valid, false);
|
|
25919
|
+
falseSchemaError(it);
|
|
25920
|
+
} else {
|
|
25921
|
+
gen.var(valid, true);
|
|
25428
25922
|
}
|
|
25429
|
-
|
|
25923
|
+
}
|
|
25924
|
+
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
25925
|
+
function falseSchemaError(it, overrideAllErrors) {
|
|
25926
|
+
const { gen, data } = it;
|
|
25927
|
+
const cxt = {
|
|
25928
|
+
gen,
|
|
25929
|
+
keyword: "false schema",
|
|
25930
|
+
data,
|
|
25931
|
+
schema: false,
|
|
25932
|
+
schemaCode: false,
|
|
25933
|
+
schemaValue: false,
|
|
25934
|
+
params: {},
|
|
25935
|
+
it
|
|
25936
|
+
};
|
|
25937
|
+
(0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
25430
25938
|
}
|
|
25431
25939
|
var dataType = {};
|
|
25432
25940
|
var rules = {};
|
|
@@ -25474,10 +25982,10 @@ applicability.shouldUseRule = shouldUseRule;
|
|
|
25474
25982
|
Object.defineProperty(dataType, "__esModule", { value: true });
|
|
25475
25983
|
dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
|
|
25476
25984
|
const rules_1 = rules;
|
|
25477
|
-
const applicability_1 = applicability;
|
|
25478
|
-
const errors_1 = errors;
|
|
25479
|
-
const codegen_1$
|
|
25480
|
-
const util_1$
|
|
25985
|
+
const applicability_1$1 = applicability;
|
|
25986
|
+
const errors_1$2 = errors;
|
|
25987
|
+
const codegen_1$s = codegen;
|
|
25988
|
+
const util_1$r = util;
|
|
25481
25989
|
var DataType;
|
|
25482
25990
|
(function(DataType2) {
|
|
25483
25991
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -25509,7 +26017,7 @@ dataType.getJSONTypes = getJSONTypes;
|
|
|
25509
26017
|
function coerceAndCheckDataType(it, types2) {
|
|
25510
26018
|
const { gen, data, opts } = it;
|
|
25511
26019
|
const coerceTo = coerceToTypes(types2, opts.coerceTypes);
|
|
25512
|
-
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
|
|
26020
|
+
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1$1.schemaHasRulesForType)(it, types2[0]));
|
|
25513
26021
|
if (checkTypes) {
|
|
25514
26022
|
const wrongType = checkDataTypes(types2, data, opts.strictNumbers, DataType.Wrong);
|
|
25515
26023
|
gen.if(wrongType, () => {
|
|
@@ -25528,12 +26036,12 @@ function coerceToTypes(types2, coerceTypes) {
|
|
|
25528
26036
|
}
|
|
25529
26037
|
function coerceData(it, types2, coerceTo) {
|
|
25530
26038
|
const { gen, data, opts } = it;
|
|
25531
|
-
const dataType2 = gen.let("dataType", (0, codegen_1$
|
|
25532
|
-
const coerced = gen.let("coerced", (0, codegen_1$
|
|
26039
|
+
const dataType2 = gen.let("dataType", (0, codegen_1$s._)`typeof ${data}`);
|
|
26040
|
+
const coerced = gen.let("coerced", (0, codegen_1$s._)`undefined`);
|
|
25533
26041
|
if (opts.coerceTypes === "array") {
|
|
25534
|
-
gen.if((0, codegen_1$
|
|
26042
|
+
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)));
|
|
25535
26043
|
}
|
|
25536
|
-
gen.if((0, codegen_1$
|
|
26044
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`);
|
|
25537
26045
|
for (const t of coerceTo) {
|
|
25538
26046
|
if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
|
|
25539
26047
|
coerceSpecificType(t);
|
|
@@ -25542,63 +26050,63 @@ function coerceData(it, types2, coerceTo) {
|
|
|
25542
26050
|
gen.else();
|
|
25543
26051
|
reportTypeError(it);
|
|
25544
26052
|
gen.endIf();
|
|
25545
|
-
gen.if((0, codegen_1$
|
|
26053
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`, () => {
|
|
25546
26054
|
gen.assign(data, coerced);
|
|
25547
26055
|
assignParentData(it, coerced);
|
|
25548
26056
|
});
|
|
25549
26057
|
function coerceSpecificType(t) {
|
|
25550
26058
|
switch (t) {
|
|
25551
26059
|
case "string":
|
|
25552
|
-
gen.elseIf((0, codegen_1$
|
|
26060
|
+
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._)`""`);
|
|
25553
26061
|
return;
|
|
25554
26062
|
case "number":
|
|
25555
|
-
gen.elseIf((0, codegen_1$
|
|
25556
|
-
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$
|
|
26063
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "boolean" || ${data} === null
|
|
26064
|
+
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$s._)`+${data}`);
|
|
25557
26065
|
return;
|
|
25558
26066
|
case "integer":
|
|
25559
|
-
gen.elseIf((0, codegen_1$
|
|
25560
|
-
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$
|
|
26067
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "boolean" || ${data} === null
|
|
26068
|
+
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$s._)`+${data}`);
|
|
25561
26069
|
return;
|
|
25562
26070
|
case "boolean":
|
|
25563
|
-
gen.elseIf((0, codegen_1$
|
|
26071
|
+
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);
|
|
25564
26072
|
return;
|
|
25565
26073
|
case "null":
|
|
25566
|
-
gen.elseIf((0, codegen_1$
|
|
26074
|
+
gen.elseIf((0, codegen_1$s._)`${data} === "" || ${data} === 0 || ${data} === false`);
|
|
25567
26075
|
gen.assign(coerced, null);
|
|
25568
26076
|
return;
|
|
25569
26077
|
case "array":
|
|
25570
|
-
gen.elseIf((0, codegen_1$
|
|
25571
|
-
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$
|
|
26078
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "string" || ${dataType2} === "number"
|
|
26079
|
+
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$s._)`[${data}]`);
|
|
25572
26080
|
}
|
|
25573
26081
|
}
|
|
25574
26082
|
}
|
|
25575
26083
|
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
|
|
25576
|
-
gen.if((0, codegen_1$
|
|
26084
|
+
gen.if((0, codegen_1$s._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$s._)`${parentData}[${parentDataProperty}]`, expr));
|
|
25577
26085
|
}
|
|
25578
26086
|
function checkDataType(dataType2, data, strictNums, correct = DataType.Correct) {
|
|
25579
|
-
const EQ = correct === DataType.Correct ? codegen_1$
|
|
26087
|
+
const EQ = correct === DataType.Correct ? codegen_1$s.operators.EQ : codegen_1$s.operators.NEQ;
|
|
25580
26088
|
let cond;
|
|
25581
26089
|
switch (dataType2) {
|
|
25582
26090
|
case "null":
|
|
25583
|
-
return (0, codegen_1$
|
|
26091
|
+
return (0, codegen_1$s._)`${data} ${EQ} null`;
|
|
25584
26092
|
case "array":
|
|
25585
|
-
cond = (0, codegen_1$
|
|
26093
|
+
cond = (0, codegen_1$s._)`Array.isArray(${data})`;
|
|
25586
26094
|
break;
|
|
25587
26095
|
case "object":
|
|
25588
|
-
cond = (0, codegen_1$
|
|
26096
|
+
cond = (0, codegen_1$s._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
|
|
25589
26097
|
break;
|
|
25590
26098
|
case "integer":
|
|
25591
|
-
cond = numCond((0, codegen_1$
|
|
26099
|
+
cond = numCond((0, codegen_1$s._)`!(${data} % 1) && !isNaN(${data})`);
|
|
25592
26100
|
break;
|
|
25593
26101
|
case "number":
|
|
25594
26102
|
cond = numCond();
|
|
25595
26103
|
break;
|
|
25596
26104
|
default:
|
|
25597
|
-
return (0, codegen_1$
|
|
26105
|
+
return (0, codegen_1$s._)`typeof ${data} ${EQ} ${dataType2}`;
|
|
25598
26106
|
}
|
|
25599
|
-
return correct === DataType.Correct ? cond : (0, codegen_1$
|
|
25600
|
-
function numCond(_cond = codegen_1$
|
|
25601
|
-
return (0, codegen_1$
|
|
26107
|
+
return correct === DataType.Correct ? cond : (0, codegen_1$s.not)(cond);
|
|
26108
|
+
function numCond(_cond = codegen_1$s.nil) {
|
|
26109
|
+
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);
|
|
25602
26110
|
}
|
|
25603
26111
|
}
|
|
25604
26112
|
dataType.checkDataType = checkDataType;
|
|
@@ -25607,35 +26115,35 @@ function checkDataTypes(dataTypes, data, strictNums, correct) {
|
|
|
25607
26115
|
return checkDataType(dataTypes[0], data, strictNums, correct);
|
|
25608
26116
|
}
|
|
25609
26117
|
let cond;
|
|
25610
|
-
const types2 = (0, util_1$
|
|
26118
|
+
const types2 = (0, util_1$r.toHash)(dataTypes);
|
|
25611
26119
|
if (types2.array && types2.object) {
|
|
25612
|
-
const notObj = (0, codegen_1$
|
|
25613
|
-
cond = types2.null ? notObj : (0, codegen_1$
|
|
26120
|
+
const notObj = (0, codegen_1$s._)`typeof ${data} != "object"`;
|
|
26121
|
+
cond = types2.null ? notObj : (0, codegen_1$s._)`!${data} || ${notObj}`;
|
|
25614
26122
|
delete types2.null;
|
|
25615
26123
|
delete types2.array;
|
|
25616
26124
|
delete types2.object;
|
|
25617
26125
|
} else {
|
|
25618
|
-
cond = codegen_1$
|
|
26126
|
+
cond = codegen_1$s.nil;
|
|
25619
26127
|
}
|
|
25620
26128
|
if (types2.number)
|
|
25621
26129
|
delete types2.integer;
|
|
25622
26130
|
for (const t in types2)
|
|
25623
|
-
cond = (0, codegen_1$
|
|
26131
|
+
cond = (0, codegen_1$s.and)(cond, checkDataType(t, data, strictNums, correct));
|
|
25624
26132
|
return cond;
|
|
25625
26133
|
}
|
|
25626
26134
|
dataType.checkDataTypes = checkDataTypes;
|
|
25627
26135
|
const typeError = {
|
|
25628
26136
|
message: ({ schema }) => `must be ${schema}`,
|
|
25629
|
-
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$
|
|
26137
|
+
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$s._)`{type: ${schema}}` : (0, codegen_1$s._)`{type: ${schemaValue}}`
|
|
25630
26138
|
};
|
|
25631
26139
|
function reportTypeError(it) {
|
|
25632
26140
|
const cxt = getTypeErrorContext(it);
|
|
25633
|
-
(0, errors_1.reportError)(cxt, typeError);
|
|
26141
|
+
(0, errors_1$2.reportError)(cxt, typeError);
|
|
25634
26142
|
}
|
|
25635
26143
|
dataType.reportTypeError = reportTypeError;
|
|
25636
26144
|
function getTypeErrorContext(it) {
|
|
25637
26145
|
const { gen, data, schema } = it;
|
|
25638
|
-
const schemaCode = (0, util_1$
|
|
26146
|
+
const schemaCode = (0, util_1$r.schemaRefOrVal)(it, schema, "type");
|
|
25639
26147
|
return {
|
|
25640
26148
|
gen,
|
|
25641
26149
|
keyword: "type",
|
|
@@ -25649,60 +26157,54 @@ function getTypeErrorContext(it) {
|
|
|
25649
26157
|
};
|
|
25650
26158
|
}
|
|
25651
26159
|
var defaults = {};
|
|
25652
|
-
|
|
25653
|
-
|
|
25654
|
-
|
|
25655
|
-
|
|
25656
|
-
|
|
25657
|
-
|
|
25658
|
-
|
|
25659
|
-
|
|
25660
|
-
|
|
25661
|
-
|
|
25662
|
-
|
|
25663
|
-
|
|
25664
|
-
|
|
25665
|
-
|
|
25666
|
-
|
|
25667
|
-
|
|
25668
|
-
|
|
26160
|
+
Object.defineProperty(defaults, "__esModule", { value: true });
|
|
26161
|
+
defaults.assignDefaults = void 0;
|
|
26162
|
+
const codegen_1$r = codegen;
|
|
26163
|
+
const util_1$q = util;
|
|
26164
|
+
function assignDefaults(it, ty) {
|
|
26165
|
+
const { properties: properties2, items: items2 } = it.schema;
|
|
26166
|
+
if (ty === "object" && properties2) {
|
|
26167
|
+
for (const key in properties2) {
|
|
26168
|
+
assignDefault(it, key, properties2[key].default);
|
|
26169
|
+
}
|
|
26170
|
+
} else if (ty === "array" && Array.isArray(items2)) {
|
|
26171
|
+
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
26172
|
+
}
|
|
26173
|
+
}
|
|
26174
|
+
defaults.assignDefaults = assignDefaults;
|
|
26175
|
+
function assignDefault(it, prop, defaultValue) {
|
|
26176
|
+
const { gen, compositeRule, data, opts } = it;
|
|
26177
|
+
if (defaultValue === void 0)
|
|
26178
|
+
return;
|
|
26179
|
+
const childData = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)(prop)}`;
|
|
26180
|
+
if (compositeRule) {
|
|
26181
|
+
(0, util_1$q.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
26182
|
+
return;
|
|
25669
26183
|
}
|
|
25670
|
-
|
|
25671
|
-
|
|
25672
|
-
|
|
25673
|
-
if (defaultValue === void 0)
|
|
25674
|
-
return;
|
|
25675
|
-
const childData = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(prop)}`;
|
|
25676
|
-
if (compositeRule) {
|
|
25677
|
-
(0, util_12.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
25678
|
-
return;
|
|
25679
|
-
}
|
|
25680
|
-
let condition = (0, codegen_12._)`${childData} === undefined`;
|
|
25681
|
-
if (opts.useDefaults === "empty") {
|
|
25682
|
-
condition = (0, codegen_12._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
25683
|
-
}
|
|
25684
|
-
gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
|
|
26184
|
+
let condition = (0, codegen_1$r._)`${childData} === undefined`;
|
|
26185
|
+
if (opts.useDefaults === "empty") {
|
|
26186
|
+
condition = (0, codegen_1$r._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
25685
26187
|
}
|
|
25686
|
-
|
|
26188
|
+
gen.if(condition, (0, codegen_1$r._)`${childData} = ${(0, codegen_1$r.stringify)(defaultValue)}`);
|
|
25687
26189
|
}
|
|
25688
26190
|
var keyword = {};
|
|
25689
26191
|
var code = {};
|
|
25690
26192
|
Object.defineProperty(code, "__esModule", { value: true });
|
|
25691
26193
|
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;
|
|
25692
|
-
const codegen_1$
|
|
25693
|
-
const util_1$
|
|
25694
|
-
const names_1$
|
|
26194
|
+
const codegen_1$q = codegen;
|
|
26195
|
+
const util_1$p = util;
|
|
26196
|
+
const names_1$5 = names$1;
|
|
25695
26197
|
const util_2$1 = util;
|
|
25696
26198
|
function checkReportMissingProp(cxt, prop) {
|
|
25697
26199
|
const { gen, data, it } = cxt;
|
|
25698
26200
|
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
|
25699
|
-
cxt.setParams({ missingProperty: (0, codegen_1$
|
|
26201
|
+
cxt.setParams({ missingProperty: (0, codegen_1$q._)`${prop}` }, true);
|
|
25700
26202
|
cxt.error();
|
|
25701
26203
|
});
|
|
25702
26204
|
}
|
|
25703
26205
|
code.checkReportMissingProp = checkReportMissingProp;
|
|
25704
26206
|
function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
|
|
25705
|
-
return (0, codegen_1$
|
|
26207
|
+
return (0, codegen_1$q.or)(...properties2.map((prop) => (0, codegen_1$q.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1$q._)`${missing} = ${prop}`)));
|
|
25706
26208
|
}
|
|
25707
26209
|
code.checkMissingProp = checkMissingProp;
|
|
25708
26210
|
function reportMissingProp(cxt, missing) {
|
|
@@ -25714,22 +26216,22 @@ function hasPropFunc(gen) {
|
|
|
25714
26216
|
return gen.scopeValue("func", {
|
|
25715
26217
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
25716
26218
|
ref: Object.prototype.hasOwnProperty,
|
|
25717
|
-
code: (0, codegen_1$
|
|
26219
|
+
code: (0, codegen_1$q._)`Object.prototype.hasOwnProperty`
|
|
25718
26220
|
});
|
|
25719
26221
|
}
|
|
25720
26222
|
code.hasPropFunc = hasPropFunc;
|
|
25721
26223
|
function isOwnProperty(gen, data, property) {
|
|
25722
|
-
return (0, codegen_1$
|
|
26224
|
+
return (0, codegen_1$q._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
|
|
25723
26225
|
}
|
|
25724
26226
|
code.isOwnProperty = isOwnProperty;
|
|
25725
26227
|
function propertyInData(gen, data, property, ownProperties) {
|
|
25726
|
-
const cond = (0, codegen_1$
|
|
25727
|
-
return ownProperties ? (0, codegen_1$
|
|
26228
|
+
const cond = (0, codegen_1$q._)`${data}${(0, codegen_1$q.getProperty)(property)} !== undefined`;
|
|
26229
|
+
return ownProperties ? (0, codegen_1$q._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
|
25728
26230
|
}
|
|
25729
26231
|
code.propertyInData = propertyInData;
|
|
25730
26232
|
function noPropertyInData(gen, data, property, ownProperties) {
|
|
25731
|
-
const cond = (0, codegen_1$
|
|
25732
|
-
return ownProperties ? (0, codegen_1$
|
|
26233
|
+
const cond = (0, codegen_1$q._)`${data}${(0, codegen_1$q.getProperty)(property)} === undefined`;
|
|
26234
|
+
return ownProperties ? (0, codegen_1$q.or)(cond, (0, codegen_1$q.not)(isOwnProperty(gen, data, property))) : cond;
|
|
25733
26235
|
}
|
|
25734
26236
|
code.noPropertyInData = noPropertyInData;
|
|
25735
26237
|
function allSchemaProperties(schemaMap) {
|
|
@@ -25737,24 +26239,24 @@ function allSchemaProperties(schemaMap) {
|
|
|
25737
26239
|
}
|
|
25738
26240
|
code.allSchemaProperties = allSchemaProperties;
|
|
25739
26241
|
function schemaProperties(it, schemaMap) {
|
|
25740
|
-
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$
|
|
26242
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$p.alwaysValidSchema)(it, schemaMap[p]));
|
|
25741
26243
|
}
|
|
25742
26244
|
code.schemaProperties = schemaProperties;
|
|
25743
26245
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
|
|
25744
|
-
const dataAndSchema = passSchema ? (0, codegen_1$
|
|
26246
|
+
const dataAndSchema = passSchema ? (0, codegen_1$q._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
|
25745
26247
|
const valCxt = [
|
|
25746
|
-
[names_1$
|
|
25747
|
-
[names_1$
|
|
25748
|
-
[names_1$
|
|
25749
|
-
[names_1$
|
|
26248
|
+
[names_1$5.default.instancePath, (0, codegen_1$q.strConcat)(names_1$5.default.instancePath, errorPath)],
|
|
26249
|
+
[names_1$5.default.parentData, it.parentData],
|
|
26250
|
+
[names_1$5.default.parentDataProperty, it.parentDataProperty],
|
|
26251
|
+
[names_1$5.default.rootData, names_1$5.default.rootData]
|
|
25750
26252
|
];
|
|
25751
26253
|
if (it.opts.dynamicRef)
|
|
25752
|
-
valCxt.push([names_1$
|
|
25753
|
-
const args = (0, codegen_1$
|
|
25754
|
-
return context !== codegen_1$
|
|
26254
|
+
valCxt.push([names_1$5.default.dynamicAnchors, names_1$5.default.dynamicAnchors]);
|
|
26255
|
+
const args = (0, codegen_1$q._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
26256
|
+
return context !== codegen_1$q.nil ? (0, codegen_1$q._)`${func}.call(${context}, ${args})` : (0, codegen_1$q._)`${func}(${args})`;
|
|
25755
26257
|
}
|
|
25756
26258
|
code.callValidateCode = callValidateCode;
|
|
25757
|
-
const newRegExp = (0, codegen_1$
|
|
26259
|
+
const newRegExp = (0, codegen_1$q._)`new RegExp`;
|
|
25758
26260
|
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
25759
26261
|
const u = opts.unicodeRegExp ? "u" : "";
|
|
25760
26262
|
const { regExp } = opts.code;
|
|
@@ -25762,7 +26264,7 @@ function usePattern({ gen, it: { opts } }, pattern2) {
|
|
|
25762
26264
|
return gen.scopeValue("pattern", {
|
|
25763
26265
|
key: rx.toString(),
|
|
25764
26266
|
ref: rx,
|
|
25765
|
-
code: (0, codegen_1$
|
|
26267
|
+
code: (0, codegen_1$q._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
25766
26268
|
});
|
|
25767
26269
|
}
|
|
25768
26270
|
code.usePattern = usePattern;
|
|
@@ -25778,14 +26280,14 @@ function validateArray(cxt) {
|
|
|
25778
26280
|
validateItems(() => gen.break());
|
|
25779
26281
|
return valid;
|
|
25780
26282
|
function validateItems(notValid) {
|
|
25781
|
-
const len = gen.const("len", (0, codegen_1$
|
|
26283
|
+
const len = gen.const("len", (0, codegen_1$q._)`${data}.length`);
|
|
25782
26284
|
gen.forRange("i", 0, len, (i) => {
|
|
25783
26285
|
cxt.subschema({
|
|
25784
26286
|
keyword: keyword2,
|
|
25785
26287
|
dataProp: i,
|
|
25786
|
-
dataPropType: util_1$
|
|
26288
|
+
dataPropType: util_1$p.Type.Num
|
|
25787
26289
|
}, valid);
|
|
25788
|
-
gen.if((0, codegen_1$
|
|
26290
|
+
gen.if((0, codegen_1$q.not)(valid), notValid);
|
|
25789
26291
|
});
|
|
25790
26292
|
}
|
|
25791
26293
|
}
|
|
@@ -25794,7 +26296,7 @@ function validateUnion(cxt) {
|
|
|
25794
26296
|
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
25795
26297
|
if (!Array.isArray(schema))
|
|
25796
26298
|
throw new Error("ajv implementation error");
|
|
25797
|
-
const alwaysValid = schema.some((sch) => (0, util_1$
|
|
26299
|
+
const alwaysValid = schema.some((sch) => (0, util_1$p.alwaysValidSchema)(it, sch));
|
|
25798
26300
|
if (alwaysValid && !it.opts.unevaluated)
|
|
25799
26301
|
return;
|
|
25800
26302
|
const valid = gen.let("valid", false);
|
|
@@ -25805,214 +26307,202 @@ function validateUnion(cxt) {
|
|
|
25805
26307
|
schemaProp: i,
|
|
25806
26308
|
compositeRule: true
|
|
25807
26309
|
}, schValid);
|
|
25808
|
-
gen.assign(valid, (0, codegen_1$
|
|
26310
|
+
gen.assign(valid, (0, codegen_1$q._)`${valid} || ${schValid}`);
|
|
25809
26311
|
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
25810
26312
|
if (!merged)
|
|
25811
|
-
gen.if((0, codegen_1$
|
|
26313
|
+
gen.if((0, codegen_1$q.not)(valid));
|
|
25812
26314
|
}));
|
|
25813
26315
|
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
25814
26316
|
}
|
|
25815
26317
|
code.validateUnion = validateUnion;
|
|
25816
|
-
|
|
25817
|
-
|
|
25818
|
-
|
|
25819
|
-
|
|
25820
|
-
|
|
25821
|
-
|
|
25822
|
-
|
|
25823
|
-
const
|
|
25824
|
-
const
|
|
25825
|
-
const
|
|
25826
|
-
|
|
25827
|
-
|
|
25828
|
-
|
|
25829
|
-
|
|
25830
|
-
|
|
25831
|
-
|
|
25832
|
-
|
|
25833
|
-
|
|
25834
|
-
|
|
25835
|
-
|
|
25836
|
-
|
|
25837
|
-
|
|
25838
|
-
|
|
25839
|
-
|
|
25840
|
-
|
|
25841
|
-
}
|
|
25842
|
-
|
|
25843
|
-
|
|
25844
|
-
|
|
25845
|
-
|
|
25846
|
-
|
|
25847
|
-
|
|
25848
|
-
|
|
25849
|
-
|
|
25850
|
-
|
|
25851
|
-
|
|
25852
|
-
|
|
25853
|
-
|
|
25854
|
-
|
|
25855
|
-
|
|
25856
|
-
|
|
25857
|
-
|
|
25858
|
-
|
|
25859
|
-
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
25860
|
-
if (def2.modifying)
|
|
25861
|
-
modifyData(cxt);
|
|
25862
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
25863
|
-
}
|
|
25864
|
-
}
|
|
25865
|
-
function validateAsync() {
|
|
25866
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
25867
|
-
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)));
|
|
25868
|
-
return ruleErrs;
|
|
25869
|
-
}
|
|
25870
|
-
function validateSync() {
|
|
25871
|
-
const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
|
|
25872
|
-
gen.assign(validateErrs, null);
|
|
25873
|
-
assignValid(codegen_12.nil);
|
|
25874
|
-
return validateErrs;
|
|
25875
|
-
}
|
|
25876
|
-
function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
|
|
25877
|
-
const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
|
|
25878
|
-
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
25879
|
-
gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
25880
|
-
}
|
|
25881
|
-
function reportErrs(errors2) {
|
|
25882
|
-
var _a2;
|
|
25883
|
-
gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
26318
|
+
Object.defineProperty(keyword, "__esModule", { value: true });
|
|
26319
|
+
keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
|
|
26320
|
+
const codegen_1$p = codegen;
|
|
26321
|
+
const names_1$4 = names$1;
|
|
26322
|
+
const code_1$9 = code;
|
|
26323
|
+
const errors_1$1 = errors;
|
|
26324
|
+
function macroKeywordCode(cxt, def2) {
|
|
26325
|
+
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
26326
|
+
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
26327
|
+
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
26328
|
+
if (it.opts.validateSchema !== false)
|
|
26329
|
+
it.self.validateSchema(macroSchema, true);
|
|
26330
|
+
const valid = gen.name("valid");
|
|
26331
|
+
cxt.subschema({
|
|
26332
|
+
schema: macroSchema,
|
|
26333
|
+
schemaPath: codegen_1$p.nil,
|
|
26334
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
26335
|
+
topSchemaRef: schemaRef,
|
|
26336
|
+
compositeRule: true
|
|
26337
|
+
}, valid);
|
|
26338
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
26339
|
+
}
|
|
26340
|
+
keyword.macroKeywordCode = macroKeywordCode;
|
|
26341
|
+
function funcKeywordCode(cxt, def2) {
|
|
26342
|
+
var _a;
|
|
26343
|
+
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
26344
|
+
checkAsyncKeyword(it, def2);
|
|
26345
|
+
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
26346
|
+
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
26347
|
+
const valid = gen.let("valid");
|
|
26348
|
+
cxt.block$data(valid, validateKeyword);
|
|
26349
|
+
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
26350
|
+
function validateKeyword() {
|
|
26351
|
+
if (def2.errors === false) {
|
|
26352
|
+
assignValid();
|
|
26353
|
+
if (def2.modifying)
|
|
26354
|
+
modifyData(cxt);
|
|
26355
|
+
reportErrs(() => cxt.error());
|
|
26356
|
+
} else {
|
|
26357
|
+
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
26358
|
+
if (def2.modifying)
|
|
26359
|
+
modifyData(cxt);
|
|
26360
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
25884
26361
|
}
|
|
25885
26362
|
}
|
|
25886
|
-
|
|
25887
|
-
|
|
25888
|
-
|
|
25889
|
-
|
|
25890
|
-
}
|
|
25891
|
-
function
|
|
25892
|
-
const
|
|
25893
|
-
gen.
|
|
25894
|
-
|
|
25895
|
-
|
|
25896
|
-
|
|
25897
|
-
|
|
25898
|
-
|
|
25899
|
-
|
|
25900
|
-
|
|
25901
|
-
}
|
|
25902
|
-
function
|
|
25903
|
-
|
|
25904
|
-
|
|
25905
|
-
|
|
25906
|
-
|
|
25907
|
-
|
|
25908
|
-
|
|
25909
|
-
}
|
|
25910
|
-
|
|
25911
|
-
|
|
25912
|
-
|
|
25913
|
-
|
|
25914
|
-
|
|
25915
|
-
|
|
25916
|
-
|
|
25917
|
-
|
|
25918
|
-
|
|
25919
|
-
|
|
25920
|
-
|
|
25921
|
-
|
|
25922
|
-
|
|
25923
|
-
|
|
25924
|
-
|
|
25925
|
-
|
|
25926
|
-
|
|
25927
|
-
|
|
26363
|
+
function validateAsync() {
|
|
26364
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
26365
|
+
gen.try(() => assignValid((0, codegen_1$p._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$p._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$p._)`${e}.errors`), () => gen.throw(e)));
|
|
26366
|
+
return ruleErrs;
|
|
26367
|
+
}
|
|
26368
|
+
function validateSync() {
|
|
26369
|
+
const validateErrs = (0, codegen_1$p._)`${validateRef}.errors`;
|
|
26370
|
+
gen.assign(validateErrs, null);
|
|
26371
|
+
assignValid(codegen_1$p.nil);
|
|
26372
|
+
return validateErrs;
|
|
26373
|
+
}
|
|
26374
|
+
function assignValid(_await = def2.async ? (0, codegen_1$p._)`await ` : codegen_1$p.nil) {
|
|
26375
|
+
const passCxt = it.opts.passContext ? names_1$4.default.this : names_1$4.default.self;
|
|
26376
|
+
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
26377
|
+
gen.assign(valid, (0, codegen_1$p._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
26378
|
+
}
|
|
26379
|
+
function reportErrs(errors2) {
|
|
26380
|
+
var _a2;
|
|
26381
|
+
gen.if((0, codegen_1$p.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
26382
|
+
}
|
|
26383
|
+
}
|
|
26384
|
+
keyword.funcKeywordCode = funcKeywordCode;
|
|
26385
|
+
function modifyData(cxt) {
|
|
26386
|
+
const { gen, data, it } = cxt;
|
|
26387
|
+
gen.if(it.parentData, () => gen.assign(data, (0, codegen_1$p._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
26388
|
+
}
|
|
26389
|
+
function addErrs(cxt, errs) {
|
|
26390
|
+
const { gen } = cxt;
|
|
26391
|
+
gen.if((0, codegen_1$p._)`Array.isArray(${errs})`, () => {
|
|
26392
|
+
gen.assign(names_1$4.default.vErrors, (0, codegen_1$p._)`${names_1$4.default.vErrors} === null ? ${errs} : ${names_1$4.default.vErrors}.concat(${errs})`).assign(names_1$4.default.errors, (0, codegen_1$p._)`${names_1$4.default.vErrors}.length`);
|
|
26393
|
+
(0, errors_1$1.extendErrors)(cxt);
|
|
26394
|
+
}, () => cxt.error());
|
|
26395
|
+
}
|
|
26396
|
+
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
26397
|
+
if (def2.async && !schemaEnv.$async)
|
|
26398
|
+
throw new Error("async keyword in sync schema");
|
|
26399
|
+
}
|
|
26400
|
+
function useKeyword(gen, keyword2, result) {
|
|
26401
|
+
if (result === void 0)
|
|
26402
|
+
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
26403
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$p.stringify)(result) });
|
|
26404
|
+
}
|
|
26405
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
26406
|
+
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");
|
|
26407
|
+
}
|
|
26408
|
+
keyword.validSchemaType = validSchemaType;
|
|
26409
|
+
function validateKeywordUsage({ schema, opts, self: self2, errSchemaPath }, def2, keyword2) {
|
|
26410
|
+
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
26411
|
+
throw new Error("ajv implementation error");
|
|
26412
|
+
}
|
|
26413
|
+
const deps = def2.dependencies;
|
|
26414
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
26415
|
+
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
26416
|
+
}
|
|
26417
|
+
if (def2.validateSchema) {
|
|
26418
|
+
const valid = def2.validateSchema(schema[keyword2]);
|
|
26419
|
+
if (!valid) {
|
|
26420
|
+
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self2.errorsText(def2.validateSchema.errors);
|
|
26421
|
+
if (opts.validateSchema === "log")
|
|
26422
|
+
self2.logger.error(msg);
|
|
26423
|
+
else
|
|
26424
|
+
throw new Error(msg);
|
|
25928
26425
|
}
|
|
25929
26426
|
}
|
|
25930
|
-
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
25931
|
-
return keyword;
|
|
25932
26427
|
}
|
|
26428
|
+
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
25933
26429
|
var subschema = {};
|
|
25934
|
-
|
|
25935
|
-
|
|
25936
|
-
|
|
25937
|
-
|
|
25938
|
-
|
|
25939
|
-
|
|
25940
|
-
|
|
25941
|
-
|
|
25942
|
-
|
|
25943
|
-
|
|
25944
|
-
|
|
25945
|
-
|
|
25946
|
-
|
|
25947
|
-
|
|
25948
|
-
|
|
25949
|
-
|
|
25950
|
-
|
|
25951
|
-
|
|
25952
|
-
|
|
25953
|
-
|
|
25954
|
-
|
|
25955
|
-
|
|
25956
|
-
|
|
25957
|
-
}
|
|
25958
|
-
if (schema !== void 0) {
|
|
25959
|
-
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
25960
|
-
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
25961
|
-
}
|
|
25962
|
-
return {
|
|
25963
|
-
schema,
|
|
25964
|
-
schemaPath,
|
|
25965
|
-
topSchemaRef,
|
|
25966
|
-
errSchemaPath
|
|
25967
|
-
};
|
|
26430
|
+
Object.defineProperty(subschema, "__esModule", { value: true });
|
|
26431
|
+
subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
|
|
26432
|
+
const codegen_1$o = codegen;
|
|
26433
|
+
const util_1$o = util;
|
|
26434
|
+
function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
26435
|
+
if (keyword2 !== void 0 && schema !== void 0) {
|
|
26436
|
+
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
26437
|
+
}
|
|
26438
|
+
if (keyword2 !== void 0) {
|
|
26439
|
+
const sch = it.schema[keyword2];
|
|
26440
|
+
return schemaProp === void 0 ? {
|
|
26441
|
+
schema: sch,
|
|
26442
|
+
schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}`,
|
|
26443
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
26444
|
+
} : {
|
|
26445
|
+
schema: sch[schemaProp],
|
|
26446
|
+
schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}${(0, codegen_1$o.getProperty)(schemaProp)}`,
|
|
26447
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$o.escapeFragment)(schemaProp)}`
|
|
26448
|
+
};
|
|
26449
|
+
}
|
|
26450
|
+
if (schema !== void 0) {
|
|
26451
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
26452
|
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
25968
26453
|
}
|
|
25969
|
-
|
|
25970
|
-
|
|
25971
|
-
|
|
25972
|
-
|
|
25973
|
-
|
|
25974
|
-
|
|
25975
|
-
|
|
25976
|
-
|
|
25977
|
-
|
|
25978
|
-
|
|
25979
|
-
|
|
25980
|
-
|
|
25981
|
-
|
|
25982
|
-
|
|
25983
|
-
|
|
25984
|
-
|
|
25985
|
-
|
|
25986
|
-
|
|
25987
|
-
|
|
25988
|
-
|
|
25989
|
-
|
|
25990
|
-
|
|
25991
|
-
|
|
25992
|
-
|
|
25993
|
-
|
|
25994
|
-
|
|
25995
|
-
|
|
25996
|
-
subschema2.
|
|
25997
|
-
|
|
25998
|
-
|
|
25999
|
-
|
|
26000
|
-
|
|
26001
|
-
|
|
26002
|
-
|
|
26003
|
-
|
|
26004
|
-
|
|
26005
|
-
|
|
26006
|
-
|
|
26007
|
-
|
|
26008
|
-
|
|
26009
|
-
|
|
26010
|
-
|
|
26011
|
-
|
|
26012
|
-
|
|
26013
|
-
|
|
26014
|
-
|
|
26015
|
-
|
|
26454
|
+
return {
|
|
26455
|
+
schema,
|
|
26456
|
+
schemaPath,
|
|
26457
|
+
topSchemaRef,
|
|
26458
|
+
errSchemaPath
|
|
26459
|
+
};
|
|
26460
|
+
}
|
|
26461
|
+
throw new Error('either "keyword" or "schema" must be passed');
|
|
26462
|
+
}
|
|
26463
|
+
subschema.getSubschema = getSubschema;
|
|
26464
|
+
function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
|
|
26465
|
+
if (data !== void 0 && dataProp !== void 0) {
|
|
26466
|
+
throw new Error('both "data" and "dataProp" passed, only one allowed');
|
|
26467
|
+
}
|
|
26468
|
+
const { gen } = it;
|
|
26469
|
+
if (dataProp !== void 0) {
|
|
26470
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
26471
|
+
const nextData = gen.let("data", (0, codegen_1$o._)`${it.data}${(0, codegen_1$o.getProperty)(dataProp)}`, true);
|
|
26472
|
+
dataContextProps(nextData);
|
|
26473
|
+
subschema2.errorPath = (0, codegen_1$o.str)`${errorPath}${(0, util_1$o.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
26474
|
+
subschema2.parentDataProperty = (0, codegen_1$o._)`${dataProp}`;
|
|
26475
|
+
subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
|
|
26476
|
+
}
|
|
26477
|
+
if (data !== void 0) {
|
|
26478
|
+
const nextData = data instanceof codegen_1$o.Name ? data : gen.let("data", data, true);
|
|
26479
|
+
dataContextProps(nextData);
|
|
26480
|
+
if (propertyName !== void 0)
|
|
26481
|
+
subschema2.propertyName = propertyName;
|
|
26482
|
+
}
|
|
26483
|
+
if (dataTypes)
|
|
26484
|
+
subschema2.dataTypes = dataTypes;
|
|
26485
|
+
function dataContextProps(_nextData) {
|
|
26486
|
+
subschema2.data = _nextData;
|
|
26487
|
+
subschema2.dataLevel = it.dataLevel + 1;
|
|
26488
|
+
subschema2.dataTypes = [];
|
|
26489
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
26490
|
+
subschema2.parentData = it.data;
|
|
26491
|
+
subschema2.dataNames = [...it.dataNames, _nextData];
|
|
26492
|
+
}
|
|
26493
|
+
}
|
|
26494
|
+
subschema.extendSubschemaData = extendSubschemaData;
|
|
26495
|
+
function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
26496
|
+
if (compositeRule !== void 0)
|
|
26497
|
+
subschema2.compositeRule = compositeRule;
|
|
26498
|
+
if (createErrors !== void 0)
|
|
26499
|
+
subschema2.createErrors = createErrors;
|
|
26500
|
+
if (allErrors !== void 0)
|
|
26501
|
+
subschema2.allErrors = allErrors;
|
|
26502
|
+
subschema2.jtdDiscriminator = jtdDiscriminator;
|
|
26503
|
+
subschema2.jtdMetadata = jtdMetadata;
|
|
26504
|
+
}
|
|
26505
|
+
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
26016
26506
|
var resolve$2 = {};
|
|
26017
26507
|
var fastDeepEqual = function equal(a, b) {
|
|
26018
26508
|
if (a === b) return true;
|
|
@@ -26127,7 +26617,7 @@ function escapeJsonPtr(str) {
|
|
|
26127
26617
|
var jsonSchemaTraverseExports = jsonSchemaTraverse.exports;
|
|
26128
26618
|
Object.defineProperty(resolve$2, "__esModule", { value: true });
|
|
26129
26619
|
resolve$2.getSchemaRefs = resolve$2.resolveUrl = resolve$2.normalizeId = resolve$2._getFullPath = resolve$2.getFullPath = resolve$2.inlineRef = void 0;
|
|
26130
|
-
const util_1$
|
|
26620
|
+
const util_1$n = util;
|
|
26131
26621
|
const equal$3 = fastDeepEqual;
|
|
26132
26622
|
const traverse = jsonSchemaTraverseExports;
|
|
26133
26623
|
const SIMPLE_INLINED = /* @__PURE__ */ new Set([
|
|
@@ -26186,7 +26676,7 @@ function countKeys(schema) {
|
|
|
26186
26676
|
if (SIMPLE_INLINED.has(key))
|
|
26187
26677
|
continue;
|
|
26188
26678
|
if (typeof schema[key] == "object") {
|
|
26189
|
-
(0, util_1$
|
|
26679
|
+
(0, util_1$n.eachItem)(schema[key], (sch) => count += countKeys(sch));
|
|
26190
26680
|
}
|
|
26191
26681
|
if (count === Infinity)
|
|
26192
26682
|
return Infinity;
|
|
@@ -26274,528 +26764,516 @@ function getSchemaRefs(schema, baseId) {
|
|
|
26274
26764
|
}
|
|
26275
26765
|
}
|
|
26276
26766
|
resolve$2.getSchemaRefs = getSchemaRefs;
|
|
26277
|
-
|
|
26278
|
-
|
|
26279
|
-
|
|
26280
|
-
|
|
26281
|
-
|
|
26282
|
-
|
|
26283
|
-
|
|
26284
|
-
|
|
26285
|
-
|
|
26286
|
-
|
|
26287
|
-
|
|
26288
|
-
|
|
26289
|
-
|
|
26290
|
-
|
|
26291
|
-
|
|
26292
|
-
|
|
26293
|
-
|
|
26294
|
-
|
|
26295
|
-
|
|
26296
|
-
|
|
26297
|
-
checkKeywords(it);
|
|
26298
|
-
if (schemaCxtHasRules(it)) {
|
|
26299
|
-
topSchemaObjCode(it);
|
|
26300
|
-
return;
|
|
26301
|
-
}
|
|
26767
|
+
Object.defineProperty(validate, "__esModule", { value: true });
|
|
26768
|
+
validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
|
|
26769
|
+
const boolSchema_1 = boolSchema;
|
|
26770
|
+
const dataType_1$1 = dataType;
|
|
26771
|
+
const applicability_1 = applicability;
|
|
26772
|
+
const dataType_2 = dataType;
|
|
26773
|
+
const defaults_1 = defaults;
|
|
26774
|
+
const keyword_1 = keyword;
|
|
26775
|
+
const subschema_1 = subschema;
|
|
26776
|
+
const codegen_1$n = codegen;
|
|
26777
|
+
const names_1$3 = names$1;
|
|
26778
|
+
const resolve_1$2 = resolve$2;
|
|
26779
|
+
const util_1$m = util;
|
|
26780
|
+
const errors_1 = errors;
|
|
26781
|
+
function validateFunctionCode(it) {
|
|
26782
|
+
if (isSchemaObj(it)) {
|
|
26783
|
+
checkKeywords(it);
|
|
26784
|
+
if (schemaCxtHasRules(it)) {
|
|
26785
|
+
topSchemaObjCode(it);
|
|
26786
|
+
return;
|
|
26302
26787
|
}
|
|
26303
|
-
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
26304
|
-
}
|
|
26305
|
-
validate.validateFunctionCode = validateFunctionCode;
|
|
26306
|
-
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
26307
|
-
if (opts.code.es5) {
|
|
26308
|
-
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${names_12.default.valCxt}`, schemaEnv.$async, () => {
|
|
26309
|
-
gen.code((0, codegen_12._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
26310
|
-
destructureValCxtES5(gen, opts);
|
|
26311
|
-
gen.code(body);
|
|
26312
|
-
});
|
|
26313
|
-
} else {
|
|
26314
|
-
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
26315
|
-
}
|
|
26316
|
-
}
|
|
26317
|
-
function destructureValCxt(opts) {
|
|
26318
|
-
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}}={}`;
|
|
26319
|
-
}
|
|
26320
|
-
function destructureValCxtES5(gen, opts) {
|
|
26321
|
-
gen.if(names_12.default.valCxt, () => {
|
|
26322
|
-
gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
|
|
26323
|
-
gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
|
|
26324
|
-
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
|
|
26325
|
-
gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
|
|
26326
|
-
if (opts.dynamicRef)
|
|
26327
|
-
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
|
|
26328
|
-
}, () => {
|
|
26329
|
-
gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
|
|
26330
|
-
gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
|
|
26331
|
-
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
|
|
26332
|
-
gen.var(names_12.default.rootData, names_12.default.data);
|
|
26333
|
-
if (opts.dynamicRef)
|
|
26334
|
-
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
|
|
26335
|
-
});
|
|
26336
26788
|
}
|
|
26337
|
-
|
|
26338
|
-
|
|
26339
|
-
|
|
26340
|
-
|
|
26341
|
-
|
|
26342
|
-
|
|
26343
|
-
gen.
|
|
26344
|
-
gen
|
|
26345
|
-
|
|
26346
|
-
resetEvaluated(it);
|
|
26347
|
-
typeAndKeywords(it);
|
|
26348
|
-
returnResults(it);
|
|
26789
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
26790
|
+
}
|
|
26791
|
+
validate.validateFunctionCode = validateFunctionCode;
|
|
26792
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
26793
|
+
if (opts.code.es5) {
|
|
26794
|
+
gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${names_1$3.default.valCxt}`, schemaEnv.$async, () => {
|
|
26795
|
+
gen.code((0, codegen_1$n._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
26796
|
+
destructureValCxtES5(gen, opts);
|
|
26797
|
+
gen.code(body);
|
|
26349
26798
|
});
|
|
26350
|
-
|
|
26351
|
-
|
|
26352
|
-
|
|
26353
|
-
|
|
26354
|
-
|
|
26355
|
-
|
|
26356
|
-
|
|
26357
|
-
|
|
26358
|
-
|
|
26359
|
-
|
|
26360
|
-
|
|
26361
|
-
|
|
26362
|
-
|
|
26363
|
-
if (
|
|
26364
|
-
|
|
26365
|
-
|
|
26366
|
-
|
|
26367
|
-
|
|
26368
|
-
|
|
26369
|
-
|
|
26370
|
-
(
|
|
26371
|
-
|
|
26372
|
-
|
|
26373
|
-
|
|
26374
|
-
|
|
26375
|
-
|
|
26376
|
-
|
|
26377
|
-
return true;
|
|
26378
|
-
return false;
|
|
26379
|
-
}
|
|
26380
|
-
function isSchemaObj(it) {
|
|
26381
|
-
return typeof it.schema != "boolean";
|
|
26382
|
-
}
|
|
26383
|
-
function subSchemaObjCode(it, valid) {
|
|
26384
|
-
const { schema, gen, opts } = it;
|
|
26799
|
+
} else {
|
|
26800
|
+
gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
26801
|
+
}
|
|
26802
|
+
}
|
|
26803
|
+
function destructureValCxt(opts) {
|
|
26804
|
+
return (0, codegen_1$n._)`{${names_1$3.default.instancePath}="", ${names_1$3.default.parentData}, ${names_1$3.default.parentDataProperty}, ${names_1$3.default.rootData}=${names_1$3.default.data}${opts.dynamicRef ? (0, codegen_1$n._)`, ${names_1$3.default.dynamicAnchors}={}` : codegen_1$n.nil}}={}`;
|
|
26805
|
+
}
|
|
26806
|
+
function destructureValCxtES5(gen, opts) {
|
|
26807
|
+
gen.if(names_1$3.default.valCxt, () => {
|
|
26808
|
+
gen.var(names_1$3.default.instancePath, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.instancePath}`);
|
|
26809
|
+
gen.var(names_1$3.default.parentData, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.parentData}`);
|
|
26810
|
+
gen.var(names_1$3.default.parentDataProperty, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.parentDataProperty}`);
|
|
26811
|
+
gen.var(names_1$3.default.rootData, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.rootData}`);
|
|
26812
|
+
if (opts.dynamicRef)
|
|
26813
|
+
gen.var(names_1$3.default.dynamicAnchors, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.dynamicAnchors}`);
|
|
26814
|
+
}, () => {
|
|
26815
|
+
gen.var(names_1$3.default.instancePath, (0, codegen_1$n._)`""`);
|
|
26816
|
+
gen.var(names_1$3.default.parentData, (0, codegen_1$n._)`undefined`);
|
|
26817
|
+
gen.var(names_1$3.default.parentDataProperty, (0, codegen_1$n._)`undefined`);
|
|
26818
|
+
gen.var(names_1$3.default.rootData, names_1$3.default.data);
|
|
26819
|
+
if (opts.dynamicRef)
|
|
26820
|
+
gen.var(names_1$3.default.dynamicAnchors, (0, codegen_1$n._)`{}`);
|
|
26821
|
+
});
|
|
26822
|
+
}
|
|
26823
|
+
function topSchemaObjCode(it) {
|
|
26824
|
+
const { schema, opts, gen } = it;
|
|
26825
|
+
validateFunction(it, () => {
|
|
26385
26826
|
if (opts.$comment && schema.$comment)
|
|
26386
26827
|
commentKeyword(it);
|
|
26387
|
-
|
|
26388
|
-
|
|
26389
|
-
|
|
26390
|
-
|
|
26391
|
-
|
|
26392
|
-
|
|
26393
|
-
|
|
26394
|
-
|
|
26395
|
-
|
|
26396
|
-
|
|
26397
|
-
|
|
26398
|
-
|
|
26399
|
-
|
|
26400
|
-
|
|
26401
|
-
|
|
26402
|
-
|
|
26403
|
-
|
|
26404
|
-
|
|
26405
|
-
|
|
26406
|
-
|
|
26407
|
-
|
|
26408
|
-
|
|
26409
|
-
|
|
26410
|
-
|
|
26411
|
-
|
|
26412
|
-
|
|
26413
|
-
(0, util_12.checkStrictMode)(it, "default is ignored in the schema root");
|
|
26828
|
+
checkNoDefault(it);
|
|
26829
|
+
gen.let(names_1$3.default.vErrors, null);
|
|
26830
|
+
gen.let(names_1$3.default.errors, 0);
|
|
26831
|
+
if (opts.unevaluated)
|
|
26832
|
+
resetEvaluated(it);
|
|
26833
|
+
typeAndKeywords(it);
|
|
26834
|
+
returnResults(it);
|
|
26835
|
+
});
|
|
26836
|
+
return;
|
|
26837
|
+
}
|
|
26838
|
+
function resetEvaluated(it) {
|
|
26839
|
+
const { gen, validateName } = it;
|
|
26840
|
+
it.evaluated = gen.const("evaluated", (0, codegen_1$n._)`${validateName}.evaluated`);
|
|
26841
|
+
gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.props`, (0, codegen_1$n._)`undefined`));
|
|
26842
|
+
gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.items`, (0, codegen_1$n._)`undefined`));
|
|
26843
|
+
}
|
|
26844
|
+
function funcSourceUrl(schema, opts) {
|
|
26845
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
26846
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$n._)`/*# sourceURL=${schId} */` : codegen_1$n.nil;
|
|
26847
|
+
}
|
|
26848
|
+
function subschemaCode(it, valid) {
|
|
26849
|
+
if (isSchemaObj(it)) {
|
|
26850
|
+
checkKeywords(it);
|
|
26851
|
+
if (schemaCxtHasRules(it)) {
|
|
26852
|
+
subSchemaObjCode(it, valid);
|
|
26853
|
+
return;
|
|
26414
26854
|
}
|
|
26415
26855
|
}
|
|
26416
|
-
|
|
26417
|
-
|
|
26418
|
-
|
|
26419
|
-
|
|
26420
|
-
|
|
26421
|
-
|
|
26422
|
-
if (
|
|
26423
|
-
|
|
26424
|
-
|
|
26425
|
-
|
|
26426
|
-
|
|
26427
|
-
|
|
26428
|
-
|
|
26429
|
-
|
|
26430
|
-
|
|
26431
|
-
|
|
26432
|
-
|
|
26433
|
-
|
|
26856
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
26857
|
+
}
|
|
26858
|
+
function schemaCxtHasRules({ schema, self: self2 }) {
|
|
26859
|
+
if (typeof schema == "boolean")
|
|
26860
|
+
return !schema;
|
|
26861
|
+
for (const key in schema)
|
|
26862
|
+
if (self2.RULES.all[key])
|
|
26863
|
+
return true;
|
|
26864
|
+
return false;
|
|
26865
|
+
}
|
|
26866
|
+
function isSchemaObj(it) {
|
|
26867
|
+
return typeof it.schema != "boolean";
|
|
26868
|
+
}
|
|
26869
|
+
function subSchemaObjCode(it, valid) {
|
|
26870
|
+
const { schema, gen, opts } = it;
|
|
26871
|
+
if (opts.$comment && schema.$comment)
|
|
26872
|
+
commentKeyword(it);
|
|
26873
|
+
updateContext(it);
|
|
26874
|
+
checkAsyncSchema(it);
|
|
26875
|
+
const errsCount = gen.const("_errs", names_1$3.default.errors);
|
|
26876
|
+
typeAndKeywords(it, errsCount);
|
|
26877
|
+
gen.var(valid, (0, codegen_1$n._)`${errsCount} === ${names_1$3.default.errors}`);
|
|
26878
|
+
}
|
|
26879
|
+
function checkKeywords(it) {
|
|
26880
|
+
(0, util_1$m.checkUnknownRules)(it);
|
|
26881
|
+
checkRefsAndKeywords(it);
|
|
26882
|
+
}
|
|
26883
|
+
function typeAndKeywords(it, errsCount) {
|
|
26884
|
+
if (it.opts.jtd)
|
|
26885
|
+
return schemaKeywords(it, [], false, errsCount);
|
|
26886
|
+
const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
|
|
26887
|
+
const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
|
|
26888
|
+
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
26889
|
+
}
|
|
26890
|
+
function checkRefsAndKeywords(it) {
|
|
26891
|
+
const { schema, errSchemaPath, opts, self: self2 } = it;
|
|
26892
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$m.schemaHasRulesButRef)(schema, self2.RULES)) {
|
|
26893
|
+
self2.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
26894
|
+
}
|
|
26895
|
+
}
|
|
26896
|
+
function checkNoDefault(it) {
|
|
26897
|
+
const { schema, opts } = it;
|
|
26898
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
26899
|
+
(0, util_1$m.checkStrictMode)(it, "default is ignored in the schema root");
|
|
26900
|
+
}
|
|
26901
|
+
}
|
|
26902
|
+
function updateContext(it) {
|
|
26903
|
+
const schId = it.schema[it.opts.schemaId];
|
|
26904
|
+
if (schId)
|
|
26905
|
+
it.baseId = (0, resolve_1$2.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
26906
|
+
}
|
|
26907
|
+
function checkAsyncSchema(it) {
|
|
26908
|
+
if (it.schema.$async && !it.schemaEnv.$async)
|
|
26909
|
+
throw new Error("async schema in sync schema");
|
|
26910
|
+
}
|
|
26911
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
26912
|
+
const msg = schema.$comment;
|
|
26913
|
+
if (opts.$comment === true) {
|
|
26914
|
+
gen.code((0, codegen_1$n._)`${names_1$3.default.self}.logger.log(${msg})`);
|
|
26915
|
+
} else if (typeof opts.$comment == "function") {
|
|
26916
|
+
const schemaPath = (0, codegen_1$n.str)`${errSchemaPath}/$comment`;
|
|
26917
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
26918
|
+
gen.code((0, codegen_1$n._)`${names_1$3.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
26919
|
+
}
|
|
26920
|
+
}
|
|
26921
|
+
function returnResults(it) {
|
|
26922
|
+
const { gen, schemaEnv, validateName, ValidationError: ValidationError2, opts } = it;
|
|
26923
|
+
if (schemaEnv.$async) {
|
|
26924
|
+
gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === 0`, () => gen.return(names_1$3.default.data), () => gen.throw((0, codegen_1$n._)`new ${ValidationError2}(${names_1$3.default.vErrors})`));
|
|
26925
|
+
} else {
|
|
26926
|
+
gen.assign((0, codegen_1$n._)`${validateName}.errors`, names_1$3.default.vErrors);
|
|
26927
|
+
if (opts.unevaluated)
|
|
26928
|
+
assignEvaluated(it);
|
|
26929
|
+
gen.return((0, codegen_1$n._)`${names_1$3.default.errors} === 0`);
|
|
26930
|
+
}
|
|
26931
|
+
}
|
|
26932
|
+
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
26933
|
+
if (props instanceof codegen_1$n.Name)
|
|
26934
|
+
gen.assign((0, codegen_1$n._)`${evaluated}.props`, props);
|
|
26935
|
+
if (items2 instanceof codegen_1$n.Name)
|
|
26936
|
+
gen.assign((0, codegen_1$n._)`${evaluated}.items`, items2);
|
|
26937
|
+
}
|
|
26938
|
+
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
26939
|
+
const { gen, schema, data, allErrors, opts, self: self2 } = it;
|
|
26940
|
+
const { RULES } = self2;
|
|
26941
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$m.schemaHasRulesButRef)(schema, RULES))) {
|
|
26942
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
26943
|
+
return;
|
|
26434
26944
|
}
|
|
26435
|
-
|
|
26436
|
-
|
|
26437
|
-
|
|
26438
|
-
|
|
26439
|
-
|
|
26440
|
-
|
|
26441
|
-
|
|
26442
|
-
|
|
26443
|
-
|
|
26444
|
-
}
|
|
26445
|
-
}
|
|
26446
|
-
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
26447
|
-
if (props instanceof codegen_12.Name)
|
|
26448
|
-
gen.assign((0, codegen_12._)`${evaluated}.props`, props);
|
|
26449
|
-
if (items2 instanceof codegen_12.Name)
|
|
26450
|
-
gen.assign((0, codegen_12._)`${evaluated}.items`, items2);
|
|
26451
|
-
}
|
|
26452
|
-
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
26453
|
-
const { gen, schema, data, allErrors, opts, self: self2 } = it;
|
|
26454
|
-
const { RULES } = self2;
|
|
26455
|
-
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_12.schemaHasRulesButRef)(schema, RULES))) {
|
|
26456
|
-
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
26945
|
+
if (!opts.jtd)
|
|
26946
|
+
checkStrictTypes(it, types2);
|
|
26947
|
+
gen.block(() => {
|
|
26948
|
+
for (const group of RULES.rules)
|
|
26949
|
+
groupKeywords(group);
|
|
26950
|
+
groupKeywords(RULES.post);
|
|
26951
|
+
});
|
|
26952
|
+
function groupKeywords(group) {
|
|
26953
|
+
if (!(0, applicability_1.shouldUseGroup)(schema, group))
|
|
26457
26954
|
return;
|
|
26458
|
-
|
|
26459
|
-
|
|
26460
|
-
|
|
26461
|
-
|
|
26462
|
-
|
|
26463
|
-
|
|
26464
|
-
groupKeywords(RULES.post);
|
|
26465
|
-
});
|
|
26466
|
-
function groupKeywords(group) {
|
|
26467
|
-
if (!(0, applicability_12.shouldUseGroup)(schema, group))
|
|
26468
|
-
return;
|
|
26469
|
-
if (group.type) {
|
|
26470
|
-
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
26471
|
-
iterateKeywords(it, group);
|
|
26472
|
-
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
26473
|
-
gen.else();
|
|
26474
|
-
(0, dataType_2.reportTypeError)(it);
|
|
26475
|
-
}
|
|
26476
|
-
gen.endIf();
|
|
26477
|
-
} else {
|
|
26478
|
-
iterateKeywords(it, group);
|
|
26955
|
+
if (group.type) {
|
|
26956
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
26957
|
+
iterateKeywords(it, group);
|
|
26958
|
+
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
26959
|
+
gen.else();
|
|
26960
|
+
(0, dataType_2.reportTypeError)(it);
|
|
26479
26961
|
}
|
|
26480
|
-
|
|
26481
|
-
|
|
26962
|
+
gen.endIf();
|
|
26963
|
+
} else {
|
|
26964
|
+
iterateKeywords(it, group);
|
|
26482
26965
|
}
|
|
26966
|
+
if (!allErrors)
|
|
26967
|
+
gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === ${errsCount || 0}`);
|
|
26483
26968
|
}
|
|
26484
|
-
|
|
26485
|
-
|
|
26486
|
-
|
|
26487
|
-
|
|
26488
|
-
|
|
26489
|
-
|
|
26490
|
-
|
|
26491
|
-
|
|
26492
|
-
|
|
26493
|
-
}
|
|
26494
|
-
});
|
|
26495
|
-
}
|
|
26496
|
-
function checkStrictTypes(it, types2) {
|
|
26497
|
-
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
26498
|
-
return;
|
|
26499
|
-
checkContextTypes(it, types2);
|
|
26500
|
-
if (!it.opts.allowUnionTypes)
|
|
26501
|
-
checkMultipleTypes(it, types2);
|
|
26502
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
26503
|
-
}
|
|
26504
|
-
function checkContextTypes(it, types2) {
|
|
26505
|
-
if (!types2.length)
|
|
26506
|
-
return;
|
|
26507
|
-
if (!it.dataTypes.length) {
|
|
26508
|
-
it.dataTypes = types2;
|
|
26509
|
-
return;
|
|
26510
|
-
}
|
|
26511
|
-
types2.forEach((t) => {
|
|
26512
|
-
if (!includesType(it.dataTypes, t)) {
|
|
26513
|
-
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
26514
|
-
}
|
|
26515
|
-
});
|
|
26516
|
-
narrowSchemaTypes(it, types2);
|
|
26517
|
-
}
|
|
26518
|
-
function checkMultipleTypes(it, ts) {
|
|
26519
|
-
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
26520
|
-
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
26521
|
-
}
|
|
26522
|
-
}
|
|
26523
|
-
function checkKeywordTypes(it, ts) {
|
|
26524
|
-
const rules2 = it.self.RULES.all;
|
|
26525
|
-
for (const keyword2 in rules2) {
|
|
26526
|
-
const rule = rules2[keyword2];
|
|
26527
|
-
if (typeof rule == "object" && (0, applicability_12.shouldUseRule)(it.schema, rule)) {
|
|
26528
|
-
const { type: type2 } = rule.definition;
|
|
26529
|
-
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
26530
|
-
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
26531
|
-
}
|
|
26532
|
-
}
|
|
26533
|
-
}
|
|
26534
|
-
}
|
|
26535
|
-
function hasApplicableType(schTs, kwdT) {
|
|
26536
|
-
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
26537
|
-
}
|
|
26538
|
-
function includesType(ts, t) {
|
|
26539
|
-
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
26540
|
-
}
|
|
26541
|
-
function narrowSchemaTypes(it, withTypes) {
|
|
26542
|
-
const ts = [];
|
|
26543
|
-
for (const t of it.dataTypes) {
|
|
26544
|
-
if (includesType(withTypes, t))
|
|
26545
|
-
ts.push(t);
|
|
26546
|
-
else if (withTypes.includes("integer") && t === "number")
|
|
26547
|
-
ts.push("integer");
|
|
26548
|
-
}
|
|
26549
|
-
it.dataTypes = ts;
|
|
26550
|
-
}
|
|
26551
|
-
function strictTypesError(it, msg) {
|
|
26552
|
-
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
26553
|
-
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
26554
|
-
(0, util_12.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
26555
|
-
}
|
|
26556
|
-
class KeywordCxt {
|
|
26557
|
-
constructor(it, def2, keyword2) {
|
|
26558
|
-
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
26559
|
-
this.gen = it.gen;
|
|
26560
|
-
this.allErrors = it.allErrors;
|
|
26561
|
-
this.keyword = keyword2;
|
|
26562
|
-
this.data = it.data;
|
|
26563
|
-
this.schema = it.schema[keyword2];
|
|
26564
|
-
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
26565
|
-
this.schemaValue = (0, util_12.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
26566
|
-
this.schemaType = def2.schemaType;
|
|
26567
|
-
this.parentSchema = it.schema;
|
|
26568
|
-
this.params = {};
|
|
26569
|
-
this.it = it;
|
|
26570
|
-
this.def = def2;
|
|
26571
|
-
if (this.$data) {
|
|
26572
|
-
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
26573
|
-
} else {
|
|
26574
|
-
this.schemaCode = this.schemaValue;
|
|
26575
|
-
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
26576
|
-
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
26577
|
-
}
|
|
26578
|
-
}
|
|
26579
|
-
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
26580
|
-
this.errsCount = it.gen.const("_errs", names_12.default.errors);
|
|
26969
|
+
}
|
|
26970
|
+
function iterateKeywords(it, group) {
|
|
26971
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
26972
|
+
if (useDefaults)
|
|
26973
|
+
(0, defaults_1.assignDefaults)(it, group.type);
|
|
26974
|
+
gen.block(() => {
|
|
26975
|
+
for (const rule of group.rules) {
|
|
26976
|
+
if ((0, applicability_1.shouldUseRule)(schema, rule)) {
|
|
26977
|
+
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
26581
26978
|
}
|
|
26582
26979
|
}
|
|
26583
|
-
|
|
26584
|
-
|
|
26980
|
+
});
|
|
26981
|
+
}
|
|
26982
|
+
function checkStrictTypes(it, types2) {
|
|
26983
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
26984
|
+
return;
|
|
26985
|
+
checkContextTypes(it, types2);
|
|
26986
|
+
if (!it.opts.allowUnionTypes)
|
|
26987
|
+
checkMultipleTypes(it, types2);
|
|
26988
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
26989
|
+
}
|
|
26990
|
+
function checkContextTypes(it, types2) {
|
|
26991
|
+
if (!types2.length)
|
|
26992
|
+
return;
|
|
26993
|
+
if (!it.dataTypes.length) {
|
|
26994
|
+
it.dataTypes = types2;
|
|
26995
|
+
return;
|
|
26996
|
+
}
|
|
26997
|
+
types2.forEach((t) => {
|
|
26998
|
+
if (!includesType(it.dataTypes, t)) {
|
|
26999
|
+
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
26585
27000
|
}
|
|
26586
|
-
|
|
26587
|
-
|
|
26588
|
-
|
|
26589
|
-
|
|
26590
|
-
|
|
26591
|
-
|
|
26592
|
-
|
|
26593
|
-
|
|
26594
|
-
|
|
26595
|
-
|
|
26596
|
-
|
|
26597
|
-
|
|
26598
|
-
|
|
26599
|
-
|
|
26600
|
-
|
|
26601
|
-
|
|
27001
|
+
});
|
|
27002
|
+
narrowSchemaTypes(it, types2);
|
|
27003
|
+
}
|
|
27004
|
+
function checkMultipleTypes(it, ts) {
|
|
27005
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
27006
|
+
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
27007
|
+
}
|
|
27008
|
+
}
|
|
27009
|
+
function checkKeywordTypes(it, ts) {
|
|
27010
|
+
const rules2 = it.self.RULES.all;
|
|
27011
|
+
for (const keyword2 in rules2) {
|
|
27012
|
+
const rule = rules2[keyword2];
|
|
27013
|
+
if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
|
|
27014
|
+
const { type: type2 } = rule.definition;
|
|
27015
|
+
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
27016
|
+
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
27017
|
+
}
|
|
27018
|
+
}
|
|
27019
|
+
}
|
|
27020
|
+
}
|
|
27021
|
+
function hasApplicableType(schTs, kwdT) {
|
|
27022
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
27023
|
+
}
|
|
27024
|
+
function includesType(ts, t) {
|
|
27025
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
27026
|
+
}
|
|
27027
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
27028
|
+
const ts = [];
|
|
27029
|
+
for (const t of it.dataTypes) {
|
|
27030
|
+
if (includesType(withTypes, t))
|
|
27031
|
+
ts.push(t);
|
|
27032
|
+
else if (withTypes.includes("integer") && t === "number")
|
|
27033
|
+
ts.push("integer");
|
|
27034
|
+
}
|
|
27035
|
+
it.dataTypes = ts;
|
|
27036
|
+
}
|
|
27037
|
+
function strictTypesError(it, msg) {
|
|
27038
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
27039
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
27040
|
+
(0, util_1$m.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
27041
|
+
}
|
|
27042
|
+
class KeywordCxt {
|
|
27043
|
+
constructor(it, def2, keyword2) {
|
|
27044
|
+
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
27045
|
+
this.gen = it.gen;
|
|
27046
|
+
this.allErrors = it.allErrors;
|
|
27047
|
+
this.keyword = keyword2;
|
|
27048
|
+
this.data = it.data;
|
|
27049
|
+
this.schema = it.schema[keyword2];
|
|
27050
|
+
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
27051
|
+
this.schemaValue = (0, util_1$m.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
27052
|
+
this.schemaType = def2.schemaType;
|
|
27053
|
+
this.parentSchema = it.schema;
|
|
27054
|
+
this.params = {};
|
|
27055
|
+
this.it = it;
|
|
27056
|
+
this.def = def2;
|
|
27057
|
+
if (this.$data) {
|
|
27058
|
+
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
27059
|
+
} else {
|
|
27060
|
+
this.schemaCode = this.schemaValue;
|
|
27061
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
27062
|
+
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
26602
27063
|
}
|
|
26603
27064
|
}
|
|
26604
|
-
|
|
26605
|
-
this.
|
|
27065
|
+
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
27066
|
+
this.errsCount = it.gen.const("_errs", names_1$3.default.errors);
|
|
26606
27067
|
}
|
|
26607
|
-
|
|
26608
|
-
|
|
26609
|
-
|
|
26610
|
-
|
|
26611
|
-
|
|
26612
|
-
|
|
26613
|
-
|
|
26614
|
-
|
|
27068
|
+
}
|
|
27069
|
+
result(condition, successAction, failAction) {
|
|
27070
|
+
this.failResult((0, codegen_1$n.not)(condition), successAction, failAction);
|
|
27071
|
+
}
|
|
27072
|
+
failResult(condition, successAction, failAction) {
|
|
27073
|
+
this.gen.if(condition);
|
|
27074
|
+
if (failAction)
|
|
27075
|
+
failAction();
|
|
27076
|
+
else
|
|
26615
27077
|
this.error();
|
|
27078
|
+
if (successAction) {
|
|
27079
|
+
this.gen.else();
|
|
27080
|
+
successAction();
|
|
27081
|
+
if (this.allErrors)
|
|
27082
|
+
this.gen.endIf();
|
|
27083
|
+
} else {
|
|
26616
27084
|
if (this.allErrors)
|
|
26617
27085
|
this.gen.endIf();
|
|
26618
27086
|
else
|
|
26619
27087
|
this.gen.else();
|
|
26620
27088
|
}
|
|
26621
|
-
|
|
26622
|
-
|
|
26623
|
-
|
|
26624
|
-
|
|
26625
|
-
|
|
26626
|
-
|
|
26627
|
-
|
|
26628
|
-
if (errorParams) {
|
|
26629
|
-
this.setParams(errorParams);
|
|
26630
|
-
this._error(append, errorPaths);
|
|
26631
|
-
this.setParams({});
|
|
26632
|
-
return;
|
|
26633
|
-
}
|
|
26634
|
-
this._error(append, errorPaths);
|
|
26635
|
-
}
|
|
26636
|
-
_error(append, errorPaths) {
|
|
26637
|
-
(append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
|
|
26638
|
-
}
|
|
26639
|
-
$dataError() {
|
|
26640
|
-
(0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
|
|
26641
|
-
}
|
|
26642
|
-
reset() {
|
|
26643
|
-
if (this.errsCount === void 0)
|
|
26644
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
26645
|
-
(0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
|
|
26646
|
-
}
|
|
26647
|
-
ok(cond) {
|
|
27089
|
+
}
|
|
27090
|
+
pass(condition, failAction) {
|
|
27091
|
+
this.failResult((0, codegen_1$n.not)(condition), void 0, failAction);
|
|
27092
|
+
}
|
|
27093
|
+
fail(condition) {
|
|
27094
|
+
if (condition === void 0) {
|
|
27095
|
+
this.error();
|
|
26648
27096
|
if (!this.allErrors)
|
|
26649
|
-
this.gen.if(
|
|
26650
|
-
|
|
26651
|
-
setParams(obj, assign) {
|
|
26652
|
-
if (assign)
|
|
26653
|
-
Object.assign(this.params, obj);
|
|
26654
|
-
else
|
|
26655
|
-
this.params = obj;
|
|
27097
|
+
this.gen.if(false);
|
|
27098
|
+
return;
|
|
26656
27099
|
}
|
|
26657
|
-
|
|
26658
|
-
|
|
26659
|
-
|
|
26660
|
-
|
|
26661
|
-
|
|
27100
|
+
this.gen.if(condition);
|
|
27101
|
+
this.error();
|
|
27102
|
+
if (this.allErrors)
|
|
27103
|
+
this.gen.endIf();
|
|
27104
|
+
else
|
|
27105
|
+
this.gen.else();
|
|
27106
|
+
}
|
|
27107
|
+
fail$data(condition) {
|
|
27108
|
+
if (!this.$data)
|
|
27109
|
+
return this.fail(condition);
|
|
27110
|
+
const { schemaCode } = this;
|
|
27111
|
+
this.fail((0, codegen_1$n._)`${schemaCode} !== undefined && (${(0, codegen_1$n.or)(this.invalid$data(), condition)})`);
|
|
27112
|
+
}
|
|
27113
|
+
error(append, errorParams, errorPaths) {
|
|
27114
|
+
if (errorParams) {
|
|
27115
|
+
this.setParams(errorParams);
|
|
27116
|
+
this._error(append, errorPaths);
|
|
27117
|
+
this.setParams({});
|
|
27118
|
+
return;
|
|
26662
27119
|
}
|
|
26663
|
-
|
|
26664
|
-
|
|
26665
|
-
|
|
26666
|
-
|
|
26667
|
-
|
|
26668
|
-
|
|
26669
|
-
|
|
26670
|
-
|
|
26671
|
-
|
|
26672
|
-
|
|
26673
|
-
|
|
26674
|
-
|
|
26675
|
-
|
|
26676
|
-
|
|
27120
|
+
this._error(append, errorPaths);
|
|
27121
|
+
}
|
|
27122
|
+
_error(append, errorPaths) {
|
|
27123
|
+
(append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
|
|
27124
|
+
}
|
|
27125
|
+
$dataError() {
|
|
27126
|
+
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
27127
|
+
}
|
|
27128
|
+
reset() {
|
|
27129
|
+
if (this.errsCount === void 0)
|
|
27130
|
+
throw new Error('add "trackErrors" to keyword definition');
|
|
27131
|
+
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
27132
|
+
}
|
|
27133
|
+
ok(cond) {
|
|
27134
|
+
if (!this.allErrors)
|
|
27135
|
+
this.gen.if(cond);
|
|
27136
|
+
}
|
|
27137
|
+
setParams(obj, assign) {
|
|
27138
|
+
if (assign)
|
|
27139
|
+
Object.assign(this.params, obj);
|
|
27140
|
+
else
|
|
27141
|
+
this.params = obj;
|
|
27142
|
+
}
|
|
27143
|
+
block$data(valid, codeBlock, $dataValid = codegen_1$n.nil) {
|
|
27144
|
+
this.gen.block(() => {
|
|
27145
|
+
this.check$data(valid, $dataValid);
|
|
27146
|
+
codeBlock();
|
|
27147
|
+
});
|
|
27148
|
+
}
|
|
27149
|
+
check$data(valid = codegen_1$n.nil, $dataValid = codegen_1$n.nil) {
|
|
27150
|
+
if (!this.$data)
|
|
27151
|
+
return;
|
|
27152
|
+
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
27153
|
+
gen.if((0, codegen_1$n.or)((0, codegen_1$n._)`${schemaCode} === undefined`, $dataValid));
|
|
27154
|
+
if (valid !== codegen_1$n.nil)
|
|
27155
|
+
gen.assign(valid, true);
|
|
27156
|
+
if (schemaType.length || def2.validateSchema) {
|
|
27157
|
+
gen.elseIf(this.invalid$data());
|
|
27158
|
+
this.$dataError();
|
|
27159
|
+
if (valid !== codegen_1$n.nil)
|
|
27160
|
+
gen.assign(valid, false);
|
|
26677
27161
|
}
|
|
26678
|
-
|
|
26679
|
-
|
|
26680
|
-
|
|
26681
|
-
|
|
26682
|
-
|
|
26683
|
-
|
|
26684
|
-
|
|
26685
|
-
|
|
26686
|
-
|
|
26687
|
-
|
|
26688
|
-
return
|
|
26689
|
-
}
|
|
26690
|
-
function invalid$DataSchema() {
|
|
26691
|
-
if (def2.validateSchema) {
|
|
26692
|
-
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
26693
|
-
return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
|
|
26694
|
-
}
|
|
26695
|
-
return codegen_12.nil;
|
|
26696
|
-
}
|
|
26697
|
-
}
|
|
26698
|
-
subschema(appl, valid) {
|
|
26699
|
-
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
26700
|
-
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
26701
|
-
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
26702
|
-
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
26703
|
-
subschemaCode(nextContext, valid);
|
|
26704
|
-
return nextContext;
|
|
26705
|
-
}
|
|
26706
|
-
mergeEvaluated(schemaCxt, toName) {
|
|
26707
|
-
const { it, gen } = this;
|
|
26708
|
-
if (!it.opts.unevaluated)
|
|
26709
|
-
return;
|
|
26710
|
-
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
26711
|
-
it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
26712
|
-
}
|
|
26713
|
-
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
26714
|
-
it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
27162
|
+
gen.else();
|
|
27163
|
+
}
|
|
27164
|
+
invalid$data() {
|
|
27165
|
+
const { gen, schemaCode, schemaType, def: def2, it } = this;
|
|
27166
|
+
return (0, codegen_1$n.or)(wrong$DataType(), invalid$DataSchema());
|
|
27167
|
+
function wrong$DataType() {
|
|
27168
|
+
if (schemaType.length) {
|
|
27169
|
+
if (!(schemaCode instanceof codegen_1$n.Name))
|
|
27170
|
+
throw new Error("ajv implementation error");
|
|
27171
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
27172
|
+
return (0, codegen_1$n._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
26715
27173
|
}
|
|
27174
|
+
return codegen_1$n.nil;
|
|
26716
27175
|
}
|
|
26717
|
-
|
|
26718
|
-
|
|
26719
|
-
|
|
26720
|
-
|
|
26721
|
-
return true;
|
|
27176
|
+
function invalid$DataSchema() {
|
|
27177
|
+
if (def2.validateSchema) {
|
|
27178
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
27179
|
+
return (0, codegen_1$n._)`!${validateSchemaRef}(${schemaCode})`;
|
|
26722
27180
|
}
|
|
27181
|
+
return codegen_1$n.nil;
|
|
26723
27182
|
}
|
|
26724
27183
|
}
|
|
26725
|
-
|
|
26726
|
-
|
|
26727
|
-
|
|
26728
|
-
|
|
26729
|
-
|
|
26730
|
-
|
|
26731
|
-
|
|
26732
|
-
|
|
26733
|
-
|
|
26734
|
-
|
|
26735
|
-
|
|
26736
|
-
|
|
26737
|
-
|
|
26738
|
-
|
|
26739
|
-
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
26740
|
-
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
26741
|
-
let jsonPointer;
|
|
26742
|
-
let data;
|
|
26743
|
-
if ($data === "")
|
|
26744
|
-
return names_12.default.rootData;
|
|
26745
|
-
if ($data[0] === "/") {
|
|
26746
|
-
if (!JSON_POINTER.test($data))
|
|
26747
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
26748
|
-
jsonPointer = $data;
|
|
26749
|
-
data = names_12.default.rootData;
|
|
26750
|
-
} else {
|
|
26751
|
-
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
26752
|
-
if (!matches)
|
|
26753
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
26754
|
-
const up = +matches[1];
|
|
26755
|
-
jsonPointer = matches[2];
|
|
26756
|
-
if (jsonPointer === "#") {
|
|
26757
|
-
if (up >= dataLevel)
|
|
26758
|
-
throw new Error(errorMsg("property/index", up));
|
|
26759
|
-
return dataPathArr[dataLevel - up];
|
|
26760
|
-
}
|
|
26761
|
-
if (up > dataLevel)
|
|
26762
|
-
throw new Error(errorMsg("data", up));
|
|
26763
|
-
data = dataNames[dataLevel - up];
|
|
26764
|
-
if (!jsonPointer)
|
|
26765
|
-
return data;
|
|
27184
|
+
subschema(appl, valid) {
|
|
27185
|
+
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
27186
|
+
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
27187
|
+
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
27188
|
+
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
27189
|
+
subschemaCode(nextContext, valid);
|
|
27190
|
+
return nextContext;
|
|
27191
|
+
}
|
|
27192
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
27193
|
+
const { it, gen } = this;
|
|
27194
|
+
if (!it.opts.unevaluated)
|
|
27195
|
+
return;
|
|
27196
|
+
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
27197
|
+
it.props = util_1$m.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
26766
27198
|
}
|
|
26767
|
-
|
|
26768
|
-
|
|
26769
|
-
for (const segment of segments) {
|
|
26770
|
-
if (segment) {
|
|
26771
|
-
data = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
|
|
26772
|
-
expr = (0, codegen_12._)`${expr} && ${data}`;
|
|
26773
|
-
}
|
|
27199
|
+
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
27200
|
+
it.items = util_1$m.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
26774
27201
|
}
|
|
26775
|
-
|
|
26776
|
-
|
|
26777
|
-
|
|
27202
|
+
}
|
|
27203
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
27204
|
+
const { it, gen } = this;
|
|
27205
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
27206
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1$n.Name));
|
|
27207
|
+
return true;
|
|
26778
27208
|
}
|
|
26779
27209
|
}
|
|
26780
|
-
validate.getData = getData;
|
|
26781
|
-
return validate;
|
|
26782
27210
|
}
|
|
26783
|
-
|
|
26784
|
-
|
|
26785
|
-
|
|
26786
|
-
if (
|
|
26787
|
-
|
|
26788
|
-
|
|
26789
|
-
|
|
26790
|
-
|
|
26791
|
-
|
|
26792
|
-
|
|
26793
|
-
|
|
27211
|
+
validate.KeywordCxt = KeywordCxt;
|
|
27212
|
+
function keywordCode(it, keyword2, def2, ruleType) {
|
|
27213
|
+
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
27214
|
+
if ("code" in def2) {
|
|
27215
|
+
def2.code(cxt, ruleType);
|
|
27216
|
+
} else if (cxt.$data && def2.validate) {
|
|
27217
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
27218
|
+
} else if ("macro" in def2) {
|
|
27219
|
+
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
27220
|
+
} else if (def2.compile || def2.validate) {
|
|
27221
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
27222
|
+
}
|
|
27223
|
+
}
|
|
27224
|
+
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
27225
|
+
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
27226
|
+
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
27227
|
+
let jsonPointer;
|
|
27228
|
+
let data;
|
|
27229
|
+
if ($data === "")
|
|
27230
|
+
return names_1$3.default.rootData;
|
|
27231
|
+
if ($data[0] === "/") {
|
|
27232
|
+
if (!JSON_POINTER.test($data))
|
|
27233
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
27234
|
+
jsonPointer = $data;
|
|
27235
|
+
data = names_1$3.default.rootData;
|
|
27236
|
+
} else {
|
|
27237
|
+
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
27238
|
+
if (!matches)
|
|
27239
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
27240
|
+
const up = +matches[1];
|
|
27241
|
+
jsonPointer = matches[2];
|
|
27242
|
+
if (jsonPointer === "#") {
|
|
27243
|
+
if (up >= dataLevel)
|
|
27244
|
+
throw new Error(errorMsg("property/index", up));
|
|
27245
|
+
return dataPathArr[dataLevel - up];
|
|
27246
|
+
}
|
|
27247
|
+
if (up > dataLevel)
|
|
27248
|
+
throw new Error(errorMsg("data", up));
|
|
27249
|
+
data = dataNames[dataLevel - up];
|
|
27250
|
+
if (!jsonPointer)
|
|
27251
|
+
return data;
|
|
27252
|
+
}
|
|
27253
|
+
let expr = data;
|
|
27254
|
+
const segments = jsonPointer.split("/");
|
|
27255
|
+
for (const segment of segments) {
|
|
27256
|
+
if (segment) {
|
|
27257
|
+
data = (0, codegen_1$n._)`${data}${(0, codegen_1$n.getProperty)((0, util_1$m.unescapeJsonPointer)(segment))}`;
|
|
27258
|
+
expr = (0, codegen_1$n._)`${expr} && ${data}`;
|
|
26794
27259
|
}
|
|
26795
27260
|
}
|
|
26796
|
-
|
|
26797
|
-
|
|
27261
|
+
return expr;
|
|
27262
|
+
function errorMsg(pointerType, up) {
|
|
27263
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
27264
|
+
}
|
|
27265
|
+
}
|
|
27266
|
+
validate.getData = getData;
|
|
27267
|
+
var validation_error = {};
|
|
27268
|
+
Object.defineProperty(validation_error, "__esModule", { value: true });
|
|
27269
|
+
class ValidationError extends Error {
|
|
27270
|
+
constructor(errors2) {
|
|
27271
|
+
super("validation failed");
|
|
27272
|
+
this.errors = errors2;
|
|
27273
|
+
this.ajv = this.validation = true;
|
|
27274
|
+
}
|
|
26798
27275
|
}
|
|
27276
|
+
validation_error.default = ValidationError;
|
|
26799
27277
|
var ref_error = {};
|
|
26800
27278
|
Object.defineProperty(ref_error, "__esModule", { value: true });
|
|
26801
27279
|
const resolve_1$1 = resolve$2;
|
|
@@ -26811,11 +27289,11 @@ var compile = {};
|
|
|
26811
27289
|
Object.defineProperty(compile, "__esModule", { value: true });
|
|
26812
27290
|
compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
|
|
26813
27291
|
const codegen_1$m = codegen;
|
|
26814
|
-
const validation_error_1 =
|
|
27292
|
+
const validation_error_1 = validation_error;
|
|
26815
27293
|
const names_1$2 = names$1;
|
|
26816
27294
|
const resolve_1 = resolve$2;
|
|
26817
27295
|
const util_1$l = util;
|
|
26818
|
-
const validate_1$1 =
|
|
27296
|
+
const validate_1$1 = validate;
|
|
26819
27297
|
class SchemaEnv {
|
|
26820
27298
|
constructor(env) {
|
|
26821
27299
|
var _a;
|
|
@@ -28100,7 +28578,7 @@ uri$1.default = uri;
|
|
|
28100
28578
|
(function(exports) {
|
|
28101
28579
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28102
28580
|
exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = void 0;
|
|
28103
|
-
var validate_12 =
|
|
28581
|
+
var validate_12 = validate;
|
|
28104
28582
|
Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
|
|
28105
28583
|
return validate_12.KeywordCxt;
|
|
28106
28584
|
} });
|
|
@@ -28123,7 +28601,7 @@ uri$1.default = uri;
|
|
|
28123
28601
|
Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
|
|
28124
28602
|
return codegen_12.CodeGen;
|
|
28125
28603
|
} });
|
|
28126
|
-
const validation_error_12 =
|
|
28604
|
+
const validation_error_12 = validation_error;
|
|
28127
28605
|
const ref_error_12 = ref_error;
|
|
28128
28606
|
const rules_12 = rules;
|
|
28129
28607
|
const compile_12 = compile;
|
|
@@ -29711,7 +30189,7 @@ const def$a = {
|
|
|
29711
30189
|
additionalProperties.default = def$a;
|
|
29712
30190
|
var properties$1 = {};
|
|
29713
30191
|
Object.defineProperty(properties$1, "__esModule", { value: true });
|
|
29714
|
-
const validate_1 =
|
|
30192
|
+
const validate_1 = validate;
|
|
29715
30193
|
const code_1$2 = code;
|
|
29716
30194
|
const util_1$7 = util;
|
|
29717
30195
|
const additionalProperties_1$1 = additionalProperties;
|
|
@@ -30562,7 +31040,7 @@ const require$$3 = {
|
|
|
30562
31040
|
module2.exports.Ajv = Ajv2;
|
|
30563
31041
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30564
31042
|
exports.default = Ajv2;
|
|
30565
|
-
var validate_12 =
|
|
31043
|
+
var validate_12 = validate;
|
|
30566
31044
|
Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
|
|
30567
31045
|
return validate_12.KeywordCxt;
|
|
30568
31046
|
} });
|
|
@@ -30585,7 +31063,7 @@ const require$$3 = {
|
|
|
30585
31063
|
Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
|
|
30586
31064
|
return codegen_12.CodeGen;
|
|
30587
31065
|
} });
|
|
30588
|
-
var validation_error_12 =
|
|
31066
|
+
var validation_error_12 = validation_error;
|
|
30589
31067
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
|
|
30590
31068
|
return validation_error_12.default;
|
|
30591
31069
|
} });
|