ochre-sdk 1.0.13 → 1.0.14
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/constants.d.mts +17 -0
- package/dist/constants.mjs +85 -0
- package/dist/fetchers/gallery.d.mts +38 -0
- package/dist/fetchers/gallery.mjs +91 -0
- package/dist/fetchers/item-links.d.mts +32 -0
- package/dist/fetchers/item-links.mjs +120 -0
- package/dist/fetchers/item.d.mts +74 -0
- package/dist/fetchers/item.mjs +146 -0
- package/dist/fetchers/set/items.d.mts +48 -0
- package/dist/fetchers/set/items.mjs +268 -0
- package/dist/fetchers/set/property-values.d.mts +46 -0
- package/dist/fetchers/set/property-values.mjs +514 -0
- package/dist/fetchers/website.d.mts +25 -0
- package/dist/fetchers/website.mjs +38 -0
- package/dist/getters.d.mts +193 -0
- package/dist/getters.mjs +341 -0
- package/dist/helpers.d.mts +18 -0
- package/dist/helpers.mjs +33 -0
- package/dist/index.d.mts +12 -1971
- package/dist/index.mjs +9 -7236
- package/dist/parsers/helpers.d.mts +27 -0
- package/dist/parsers/helpers.mjs +53 -0
- package/dist/parsers/index.d.mts +65 -0
- package/dist/parsers/index.mjs +1338 -0
- package/dist/parsers/mdx.d.mts +4 -0
- package/dist/parsers/mdx.mjs +9 -0
- package/dist/parsers/multilingual.d.mts +189 -0
- package/dist/parsers/multilingual.mjs +410 -0
- package/dist/parsers/string.d.mts +29 -0
- package/dist/parsers/string.mjs +477 -0
- package/dist/parsers/website/index.d.mts +20 -0
- package/dist/parsers/website/index.mjs +1245 -0
- package/dist/parsers/website/reader.d.mts +29 -0
- package/dist/parsers/website/reader.mjs +75 -0
- package/dist/query.d.mts +13 -0
- package/dist/query.mjs +827 -0
- package/dist/schemas.d.mts +84 -0
- package/dist/schemas.mjs +232 -0
- package/dist/types/index.d.mts +840 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/website.d.mts +501 -0
- package/dist/types/website.mjs +1 -0
- package/dist/utils.d.mts +34 -0
- package/dist/utils.mjs +172 -0
- package/dist/xml/metadata.d.mts +5 -0
- package/dist/xml/metadata.mjs +30 -0
- package/dist/xml/schemas.d.mts +13 -0
- package/dist/xml/schemas.mjs +849 -0
- package/dist/xml/types.d.mts +901 -0
- package/dist/xml/types.mjs +1 -0
- package/package.json +19 -17
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
const PSEUDO_UUID_REGEX = /^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === "object" && value != null;
|
|
6
|
+
}
|
|
7
|
+
function isSchemaValidationIssue(value) {
|
|
8
|
+
if (!isRecord(value)) return false;
|
|
9
|
+
return typeof value.kind === "string" && typeof value.type === "string" && typeof value.message === "string";
|
|
10
|
+
}
|
|
11
|
+
function isSchemaValidationIssues(value) {
|
|
12
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
13
|
+
for (const item of value) if (!isSchemaValidationIssue(item)) return false;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
function getIssuePath(issue) {
|
|
17
|
+
const path = v.getDotPath(issue);
|
|
18
|
+
return path != null && path.length > 0 ? path : "(root)";
|
|
19
|
+
}
|
|
20
|
+
function formatPrimitiveValue(value) {
|
|
21
|
+
if (value == null) return String(value);
|
|
22
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
23
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || typeof value === "symbol") return String(value);
|
|
24
|
+
if (value instanceof Date) return value.toISOString();
|
|
25
|
+
if (value instanceof RegExp) return String(value);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function appendSchemaValidationIssues(lines, issues, depth = 0, prefix = "") {
|
|
29
|
+
let index = 0;
|
|
30
|
+
for (const issue of issues) {
|
|
31
|
+
index += 1;
|
|
32
|
+
const number = prefix.length > 0 ? `${prefix}.${index}` : String(index);
|
|
33
|
+
const indent = " ".repeat(depth);
|
|
34
|
+
lines.push(`${indent}${number}. ${getIssuePath(issue)}`, `${indent} Message: ${issue.message}`, `${indent} Type: ${issue.kind}:${issue.type}`);
|
|
35
|
+
if (issue.expected != null) lines.push(`${indent} Expected: ${issue.expected}`);
|
|
36
|
+
if (issue.received.length > 0) lines.push(`${indent} Received: ${issue.received}`);
|
|
37
|
+
const input = formatPrimitiveValue(issue.input);
|
|
38
|
+
if (input != null) lines.push(`${indent} Input: ${input}`);
|
|
39
|
+
const requirement = formatPrimitiveValue(issue.requirement);
|
|
40
|
+
if (requirement != null) lines.push(`${indent} Requirement: ${requirement}`);
|
|
41
|
+
if (issue.issues != null && issue.issues.length > 0) {
|
|
42
|
+
lines.push(`${indent} Nested issues:`);
|
|
43
|
+
appendSchemaValidationIssues(lines, issue.issues, depth + 1, number);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function formatCauseValue(value) {
|
|
48
|
+
if (typeof value === "string") return value.length > 0 ? value : null;
|
|
49
|
+
const primitiveValue = formatPrimitiveValue(value);
|
|
50
|
+
if (primitiveValue != null) return primitiveValue;
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
const values = [];
|
|
53
|
+
for (const item of value) {
|
|
54
|
+
const formattedItem = typeof item === "string" && item.length > 0 ? item : formatPrimitiveValue(item);
|
|
55
|
+
if (formattedItem != null && formattedItem.length > 0) values.push(formattedItem);
|
|
56
|
+
}
|
|
57
|
+
return values.length > 0 ? values.join(", ") : null;
|
|
58
|
+
}
|
|
59
|
+
if (isRecord(value)) {
|
|
60
|
+
const values = [];
|
|
61
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
62
|
+
const formattedEntryValue = formatPrimitiveValue(entryValue);
|
|
63
|
+
if (formattedEntryValue != null) values.push(`${key}: ${formattedEntryValue}`);
|
|
64
|
+
}
|
|
65
|
+
return values.length > 0 ? values.join("; ") : null;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
function appendDetailedError(lines, error, fallbackMessage, depth, seenErrors) {
|
|
70
|
+
const indent = " ".repeat(depth);
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
if (seenErrors.has(error)) {
|
|
73
|
+
lines.push(`${indent}Error: [Circular cause]`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
seenErrors.add(error);
|
|
77
|
+
lines.push(`${indent}Error`);
|
|
78
|
+
if (error.name !== "Error") lines.push(`${indent}Name: ${error.name}`);
|
|
79
|
+
lines.push(`${indent}Message: ${error.message}`);
|
|
80
|
+
if (error instanceof AggregateError && error.errors.length > 0) {
|
|
81
|
+
lines.push("", `${indent}Contained errors`);
|
|
82
|
+
let index = 0;
|
|
83
|
+
for (const containedError of error.errors) {
|
|
84
|
+
index += 1;
|
|
85
|
+
lines.push(`${indent}${index}.`);
|
|
86
|
+
appendDetailedError(lines, containedError, "Unknown error", depth + 1, seenErrors);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (error.cause != null) {
|
|
90
|
+
const causeLines = [];
|
|
91
|
+
if (appendDetailedCause(causeLines, error.cause, depth, seenErrors)) lines.push("", ...causeLines);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
lines.push(`${indent}Error`, `${indent}Message: ${fallbackMessage}`);
|
|
96
|
+
const value = formatCauseValue(error);
|
|
97
|
+
if (value != null) lines.push(`${indent}Value: ${value}`);
|
|
98
|
+
}
|
|
99
|
+
function appendDetailedCause(lines, cause, depth, seenErrors) {
|
|
100
|
+
const indent = " ".repeat(depth);
|
|
101
|
+
if (isSchemaValidationIssues(cause)) {
|
|
102
|
+
lines.push(`${indent}Schema validation`);
|
|
103
|
+
appendSchemaValidationIssues(lines, cause, depth);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
if (cause instanceof Error) {
|
|
107
|
+
lines.push(`${indent}Cause`);
|
|
108
|
+
appendDetailedError(lines, cause, cause.message, depth + 1, seenErrors);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
const formattedCause = formatCauseValue(cause);
|
|
112
|
+
if (formattedCause != null) {
|
|
113
|
+
lines.push(`${indent}Cause`, `${indent}${formattedCause}`);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
function getErrorMessage(error, fallbackMessage) {
|
|
119
|
+
return error instanceof Error ? error.message : fallbackMessage;
|
|
120
|
+
}
|
|
121
|
+
function getDetailedError(error, fallbackMessage = "Unknown error") {
|
|
122
|
+
const lines = [];
|
|
123
|
+
appendDetailedError(lines, error, fallbackMessage, 0, /* @__PURE__ */ new Set());
|
|
124
|
+
return lines.join("\n");
|
|
125
|
+
}
|
|
126
|
+
function getErrorOutput(error, fallbackMessage) {
|
|
127
|
+
const message = getErrorMessage(error, fallbackMessage);
|
|
128
|
+
return {
|
|
129
|
+
error: message,
|
|
130
|
+
detailedError: getDetailedError(error, message)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function createSchemaValidationError(message, issues) {
|
|
134
|
+
return new Error(message, { cause: issues });
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Validates a pseudo-UUID string
|
|
138
|
+
* @param value - The string to validate
|
|
139
|
+
* @returns True if the string is a valid pseudo-UUID, false otherwise
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
function isPseudoUuid(value) {
|
|
143
|
+
return PSEUDO_UUID_REGEX.test(value);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Build a string literal for an XQuery string
|
|
147
|
+
* @param value - The string value to escape
|
|
148
|
+
* @returns The escaped string literal
|
|
149
|
+
*/
|
|
150
|
+
function stringLiteral(value) {
|
|
151
|
+
return `"${value.replaceAll("\"", "\"\"")}"`;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Flatten a properties array
|
|
155
|
+
* @param properties - The properties to flatten
|
|
156
|
+
* @returns The flattened properties
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
function flattenProperties(properties) {
|
|
160
|
+
const result = [];
|
|
161
|
+
for (const property of properties) {
|
|
162
|
+
result.push({
|
|
163
|
+
variable: property.variable,
|
|
164
|
+
values: property.values,
|
|
165
|
+
comment: property.comment
|
|
166
|
+
});
|
|
167
|
+
if ("properties" in property) result.push(...flattenProperties(property.properties));
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { createSchemaValidationError, flattenProperties, getDetailedError, getErrorMessage, getErrorOutput, isPseudoUuid, stringLiteral };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { XMLParser } from "fast-xml-parser";
|
|
2
|
+
//#region src/xml/metadata.ts
|
|
3
|
+
const XML_METADATA_SYMBOL = XMLParser.getMetaDataSymbol();
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === "object" && value != null;
|
|
6
|
+
}
|
|
7
|
+
function getXMLMetadata(value) {
|
|
8
|
+
if (!isRecord(value)) return null;
|
|
9
|
+
return value[XML_METADATA_SYMBOL] ?? null;
|
|
10
|
+
}
|
|
11
|
+
function getXMLSourceIndex(value) {
|
|
12
|
+
const startIndex = getXMLMetadata(value)?.startIndex;
|
|
13
|
+
return typeof startIndex === "number" ? startIndex : null;
|
|
14
|
+
}
|
|
15
|
+
function restoreXMLMetadata(output, input) {
|
|
16
|
+
if (!isRecord(output) || !isRecord(input)) return;
|
|
17
|
+
const metadata = getXMLMetadata(input);
|
|
18
|
+
if (metadata != null) Object.defineProperty(output, XML_METADATA_SYMBOL, {
|
|
19
|
+
value: metadata,
|
|
20
|
+
enumerable: false,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
23
|
+
if (Array.isArray(output) && Array.isArray(input)) {
|
|
24
|
+
for (const [index, outputValue] of output.entries()) restoreXMLMetadata(outputValue, input[index]);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const [key, outputValue] of Object.entries(output)) restoreXMLMetadata(outputValue, input[key]);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { getXMLSourceIndex, restoreXMLMetadata };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { XMLData as XMLData$1, XMLDataItem as XMLDataItem$1, XMLGalleryData as XMLGalleryData$1, XMLItemLinksData as XMLItemLinksData$1, XMLLink as XMLLink$1, XMLSetItemsData as XMLSetItemsData$1, XMLWebsiteData as XMLWebsiteData$1 } from "./types.mjs";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
|
|
4
|
+
//#region src/xml/schemas.d.ts
|
|
5
|
+
declare const XMLLink: v.GenericSchema<unknown, XMLLink$1>;
|
|
6
|
+
declare const XMLDataItem: v.GenericSchema<unknown, XMLDataItem$1>;
|
|
7
|
+
declare const XMLItemLinksData: v.GenericSchema<unknown, XMLItemLinksData$1>;
|
|
8
|
+
declare const XMLGalleryData: v.GenericSchema<unknown, XMLGalleryData$1>;
|
|
9
|
+
declare const XMLSetItemsData: v.GenericSchema<unknown, XMLSetItemsData$1>;
|
|
10
|
+
declare const XMLData: v.GenericSchema<unknown, XMLData$1>;
|
|
11
|
+
declare const XMLWebsiteData: v.GenericSchema<unknown, XMLWebsiteData$1>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { XMLData, XMLDataItem, XMLGalleryData, XMLItemLinksData, XMLLink, XMLSetItemsData, XMLWebsiteData };
|