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.
Files changed (51) hide show
  1. package/dist/constants.d.mts +17 -0
  2. package/dist/constants.mjs +85 -0
  3. package/dist/fetchers/gallery.d.mts +38 -0
  4. package/dist/fetchers/gallery.mjs +91 -0
  5. package/dist/fetchers/item-links.d.mts +32 -0
  6. package/dist/fetchers/item-links.mjs +120 -0
  7. package/dist/fetchers/item.d.mts +74 -0
  8. package/dist/fetchers/item.mjs +146 -0
  9. package/dist/fetchers/set/items.d.mts +48 -0
  10. package/dist/fetchers/set/items.mjs +268 -0
  11. package/dist/fetchers/set/property-values.d.mts +46 -0
  12. package/dist/fetchers/set/property-values.mjs +514 -0
  13. package/dist/fetchers/website.d.mts +25 -0
  14. package/dist/fetchers/website.mjs +38 -0
  15. package/dist/getters.d.mts +193 -0
  16. package/dist/getters.mjs +341 -0
  17. package/dist/helpers.d.mts +18 -0
  18. package/dist/helpers.mjs +33 -0
  19. package/dist/index.d.mts +12 -1971
  20. package/dist/index.mjs +9 -7236
  21. package/dist/parsers/helpers.d.mts +27 -0
  22. package/dist/parsers/helpers.mjs +53 -0
  23. package/dist/parsers/index.d.mts +65 -0
  24. package/dist/parsers/index.mjs +1338 -0
  25. package/dist/parsers/mdx.d.mts +4 -0
  26. package/dist/parsers/mdx.mjs +9 -0
  27. package/dist/parsers/multilingual.d.mts +189 -0
  28. package/dist/parsers/multilingual.mjs +410 -0
  29. package/dist/parsers/string.d.mts +29 -0
  30. package/dist/parsers/string.mjs +477 -0
  31. package/dist/parsers/website/index.d.mts +20 -0
  32. package/dist/parsers/website/index.mjs +1245 -0
  33. package/dist/parsers/website/reader.d.mts +29 -0
  34. package/dist/parsers/website/reader.mjs +75 -0
  35. package/dist/query.d.mts +13 -0
  36. package/dist/query.mjs +827 -0
  37. package/dist/schemas.d.mts +84 -0
  38. package/dist/schemas.mjs +232 -0
  39. package/dist/types/index.d.mts +840 -0
  40. package/dist/types/index.mjs +1 -0
  41. package/dist/types/website.d.mts +501 -0
  42. package/dist/types/website.mjs +1 -0
  43. package/dist/utils.d.mts +34 -0
  44. package/dist/utils.mjs +172 -0
  45. package/dist/xml/metadata.d.mts +5 -0
  46. package/dist/xml/metadata.mjs +30 -0
  47. package/dist/xml/schemas.d.mts +13 -0
  48. package/dist/xml/schemas.mjs +849 -0
  49. package/dist/xml/types.d.mts +901 -0
  50. package/dist/xml/types.mjs +1 -0
  51. package/package.json +19 -17
@@ -0,0 +1,84 @@
1
+ import { Query } from "./types/index.mjs";
2
+ import * as v from "valibot";
3
+
4
+ //#region src/schemas.d.ts
5
+ /**
6
+ * Schema for validating UUIDs
7
+ * @internal
8
+ */
9
+ declare const uuidSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Invalid pseudo-UUID">]>;
10
+ /**
11
+ * Schema for validating language codes
12
+ * @internal
13
+ */
14
+ declare const iso639_3Schema: v.SchemaWithPipe<readonly [v.StringSchema<"Language code must be a string">, v.LengthAction<string, 3, "Language code must be exactly 3 characters">, v.RegexAction<string, "Language code must be exactly 3 lowercase letters">]>;
15
+ /**
16
+ * Valid component types for web elements
17
+ * @internal
18
+ */
19
+ declare const componentSchema: v.PicklistSchema<readonly ["3d-viewer", "advanced-search", "annotated-document", "annotated-image", "audio-player", "bibliography", "button", "collection", "empty-space", "entries", "iframe", "iiif-viewer", "image", "image-gallery", "map", "query", "search-bar", "table", "text", "timeline", "video"], "Invalid/unknown web element component">;
20
+ /**
21
+ * Schema for validating gallery parameters
22
+ * @internal
23
+ */
24
+ declare const gallerySchema: v.ObjectSchema<{
25
+ readonly uuid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Invalid pseudo-UUID">]>;
26
+ readonly filter: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
27
+ readonly page: v.SchemaWithPipe<readonly [v.NumberSchema<"Page must be positive">, v.CheckAction<number, "Page must be positive">]>;
28
+ readonly perPage: v.SchemaWithPipe<readonly [v.NumberSchema<"Per page must be positive">, v.CheckAction<number, "Per page must be positive">]>;
29
+ }, undefined>;
30
+ /**
31
+ * Schema for validating and parsing render options
32
+ * @internal
33
+ */
34
+ declare const renderOptionsSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string[]>, v.ArraySchema<v.PicklistSchema<["bold", "italic", "underline"], undefined>, undefined>]>;
35
+ /**
36
+ * Schema for validating and parsing whitespace options
37
+ * @internal
38
+ */
39
+ declare const whitespaceSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string[]>, v.ArraySchema<v.PicklistSchema<["newline", "trailing", "leading"], undefined>, undefined>]>;
40
+ /**
41
+ * Schema for validating the parameters for the Set property values fetching function
42
+ * @internal
43
+ */
44
+ declare const setPropertyValuesParamsSchema: v.ObjectSchema<{
45
+ readonly setScopeUuids: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Invalid pseudo-UUID">]>, undefined>, v.MinLengthAction<string[], 1, "At least one set scope UUID is required">]>;
46
+ readonly belongsToCollectionScopeUuids: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Invalid pseudo-UUID">]>, undefined>, readonly []>;
47
+ readonly queries: v.OptionalSchema<v.NullableSchema<v.GenericSchema<unknown, Query>, undefined>, null>;
48
+ readonly attributes: v.OptionalSchema<v.ObjectSchema<{
49
+ readonly bibliographies: v.GenericSchema<unknown, boolean>;
50
+ readonly periods: v.GenericSchema<unknown, boolean>;
51
+ }, undefined>, {
52
+ readonly bibliographies: false;
53
+ readonly periods: false;
54
+ }>;
55
+ readonly isLimitedToLeafPropertyValues: v.GenericSchema<unknown, boolean>;
56
+ }, undefined>;
57
+ /**
58
+ * Schema for validating Set items parameters
59
+ * @internal
60
+ */
61
+ declare const setItemsParamsSchema: v.ObjectSchema<{
62
+ readonly setScopeUuids: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Invalid pseudo-UUID">]>, undefined>, v.MinLengthAction<string[], 1, "At least one set scope UUID is required">]>;
63
+ readonly belongsToCollectionScopeUuids: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Invalid pseudo-UUID">]>, undefined>, readonly []>;
64
+ readonly queries: v.OptionalSchema<v.NullableSchema<v.GenericSchema<unknown, Query>, undefined>, null>;
65
+ readonly sort: v.OptionalSchema<v.VariantSchema<"target", [v.StrictObjectSchema<{
66
+ readonly target: v.LiteralSchema<"none", undefined>;
67
+ }, undefined>, v.StrictObjectSchema<{
68
+ readonly target: v.LiteralSchema<"title", undefined>;
69
+ readonly direction: v.OptionalSchema<v.PicklistSchema<["asc", "desc"], undefined>, "asc">;
70
+ readonly language: v.GenericSchema<unknown, string>;
71
+ }, undefined>, v.StrictObjectSchema<{
72
+ readonly target: v.LiteralSchema<"propertyValue", undefined>;
73
+ readonly propertyVariableUuid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Invalid pseudo-UUID">]>;
74
+ readonly dataType: v.PicklistSchema<readonly ["string", "integer", "decimal", "boolean", "date", "dateTime", "time", "IDREF"], undefined>;
75
+ readonly direction: v.OptionalSchema<v.PicklistSchema<["asc", "desc"], undefined>, "asc">;
76
+ readonly language: v.GenericSchema<unknown, string>;
77
+ }, undefined>], undefined>, {
78
+ readonly target: "none";
79
+ }>;
80
+ readonly page: v.OptionalSchema<v.GenericSchema<unknown, number>, 1>;
81
+ readonly pageSize: v.OptionalSchema<v.GenericSchema<unknown, number>, 48>;
82
+ }, undefined>;
83
+ //#endregion
84
+ export { componentSchema, gallerySchema, iso639_3Schema, renderOptionsSchema, setItemsParamsSchema, setPropertyValuesParamsSchema, uuidSchema, whitespaceSchema };
@@ -0,0 +1,232 @@
1
+ import { isPseudoUuid } from "./utils.mjs";
2
+ import "./helpers.mjs";
3
+ import * as v from "valibot";
4
+ //#region src/schemas.ts
5
+ const positiveNumber = (message) => v.pipe(v.number(), v.minValue(1, message));
6
+ const defaultString = (value) => v.optional(v.string(), value);
7
+ const defaultBoolean = (value) => v.optional(v.boolean(), value);
8
+ const sortDirectionSchema = v.optional(v.picklist(["asc", "desc"]), "asc");
9
+ /**
10
+ * Schema for validating UUIDs
11
+ * @internal
12
+ */
13
+ const uuidSchema = v.pipe(v.string(), v.check(isPseudoUuid, "Invalid pseudo-UUID"));
14
+ /**
15
+ * Schema for validating language codes
16
+ * @internal
17
+ */
18
+ const iso639_3Schema = v.pipe(v.string("Language code must be a string"), v.length(3, "Language code must be exactly 3 characters"), v.regex(/^[a-z]{3}$/, "Language code must be exactly 3 lowercase letters"));
19
+ /**
20
+ * Valid component types for web elements
21
+ * @internal
22
+ */
23
+ const componentSchema = v.picklist([
24
+ "3d-viewer",
25
+ "advanced-search",
26
+ "annotated-document",
27
+ "annotated-image",
28
+ "audio-player",
29
+ "bibliography",
30
+ "button",
31
+ "collection",
32
+ "empty-space",
33
+ "entries",
34
+ "iframe",
35
+ "iiif-viewer",
36
+ "image",
37
+ "image-gallery",
38
+ "map",
39
+ "query",
40
+ "search-bar",
41
+ "table",
42
+ "text",
43
+ "timeline",
44
+ "video"
45
+ ], "Invalid/unknown web element component");
46
+ /**
47
+ * Schema for validating gallery parameters
48
+ * @internal
49
+ */
50
+ const gallerySchema = v.object({
51
+ uuid: v.pipe(v.string(), v.check(isPseudoUuid, "Invalid pseudo-UUID")),
52
+ filter: v.optional(v.string()),
53
+ page: v.pipe(v.number("Page must be positive"), v.check((n) => n > 0, "Page must be positive")),
54
+ perPage: v.pipe(v.number("Per page must be positive"), v.check((n) => n > 0, "Per page must be positive"))
55
+ });
56
+ /**
57
+ * Schema for validating and parsing render options
58
+ * @internal
59
+ */
60
+ const renderOptionsSchema = v.pipe(v.string(), v.transform((str) => str.split(" ")), v.array(v.picklist([
61
+ "bold",
62
+ "italic",
63
+ "underline"
64
+ ])));
65
+ /**
66
+ * Schema for validating and parsing whitespace options
67
+ * @internal
68
+ */
69
+ const whitespaceSchema = v.pipe(v.string(), v.transform((str) => str.split(" ")), v.array(v.picklist([
70
+ "newline",
71
+ "trailing",
72
+ "leading"
73
+ ])));
74
+ /**
75
+ * Schema for validating date data types
76
+ * @internal
77
+ */
78
+ const dateDataTypeSchema = v.picklist(["date", "dateTime"]);
79
+ /**
80
+ * Shared schema for query fields
81
+ * @internal
82
+ */
83
+ const standardQueryFields = {
84
+ matchMode: v.picklist(["includes", "exact"]),
85
+ isCaseSensitive: v.boolean(),
86
+ language: defaultString("eng"),
87
+ isNegated: defaultBoolean(false)
88
+ };
89
+ /**
90
+ * Shared schema for Set queries
91
+ * @internal
92
+ */
93
+ const setQueryLeafSchema = v.union([
94
+ v.pipe(v.strictObject({
95
+ target: v.literal("property"),
96
+ propertyVariable: v.optional(uuidSchema),
97
+ dataType: v.picklist([
98
+ "string",
99
+ "integer",
100
+ "decimal",
101
+ "boolean",
102
+ "time",
103
+ "IDREF"
104
+ ]),
105
+ value: v.optional(v.string()),
106
+ ...standardQueryFields
107
+ }), v.check((value) => value.propertyVariable != null || value.value != null, "Property queries must include at least one propertyVariable or value")),
108
+ v.strictObject({
109
+ target: v.literal("property"),
110
+ propertyVariable: uuidSchema,
111
+ dataType: dateDataTypeSchema,
112
+ value: v.string(),
113
+ from: v.optional(v.never()),
114
+ to: v.optional(v.never()),
115
+ ...standardQueryFields
116
+ }),
117
+ v.strictObject({
118
+ target: v.literal("property"),
119
+ propertyVariable: uuidSchema,
120
+ dataType: dateDataTypeSchema,
121
+ value: v.optional(v.never()),
122
+ from: v.string(),
123
+ to: v.optional(v.string()),
124
+ ...standardQueryFields
125
+ }),
126
+ v.strictObject({
127
+ target: v.literal("property"),
128
+ propertyVariable: uuidSchema,
129
+ dataType: dateDataTypeSchema,
130
+ value: v.optional(v.never()),
131
+ from: v.optional(v.string()),
132
+ to: v.string(),
133
+ ...standardQueryFields
134
+ }),
135
+ v.strictObject({
136
+ target: v.literal("property"),
137
+ propertyVariable: v.optional(uuidSchema),
138
+ dataType: v.literal("all"),
139
+ value: v.string(),
140
+ ...standardQueryFields
141
+ }),
142
+ v.strictObject({
143
+ target: v.literal("string"),
144
+ value: v.string(),
145
+ ...standardQueryFields
146
+ }),
147
+ v.strictObject({
148
+ target: v.picklist([
149
+ "title",
150
+ "description",
151
+ "image",
152
+ "periods",
153
+ "bibliography",
154
+ "notes"
155
+ ]),
156
+ value: v.string(),
157
+ ...standardQueryFields
158
+ })
159
+ ]);
160
+ /**
161
+ * Schema for validating Set queries
162
+ * @internal
163
+ */
164
+ const setQuerySchema = v.lazy(() => v.union([
165
+ setQueryLeafSchema,
166
+ v.strictObject({ and: v.pipe(v.array(setQuerySchema), v.minLength(1, "AND groups must contain at least one query")) }),
167
+ v.strictObject({ or: v.pipe(v.array(setQuerySchema), v.minLength(1, "OR groups must contain at least one query")) })
168
+ ]));
169
+ /**
170
+ * Schema for validating Set queries
171
+ * @internal
172
+ */
173
+ const setQueriesSchema = v.optional(v.nullable(setQuerySchema), null);
174
+ /**
175
+ * Schema for validating Set items sort
176
+ * @internal
177
+ */
178
+ const setItemsSortSchema = v.optional(v.variant("target", [
179
+ v.strictObject({ target: v.literal("none") }),
180
+ v.strictObject({
181
+ target: v.literal("title"),
182
+ direction: sortDirectionSchema,
183
+ language: defaultString("eng")
184
+ }),
185
+ v.strictObject({
186
+ target: v.literal("propertyValue"),
187
+ propertyVariableUuid: uuidSchema,
188
+ dataType: v.picklist([
189
+ "string",
190
+ "integer",
191
+ "decimal",
192
+ "boolean",
193
+ "date",
194
+ "dateTime",
195
+ "time",
196
+ "IDREF"
197
+ ]),
198
+ direction: sortDirectionSchema,
199
+ language: defaultString("eng")
200
+ })
201
+ ]), { target: "none" });
202
+ /**
203
+ * Schema for validating the parameters for the Set property values fetching function
204
+ * @internal
205
+ */
206
+ const setPropertyValuesParamsSchema = v.object({
207
+ setScopeUuids: v.pipe(v.array(uuidSchema), v.minLength(1, "At least one set scope UUID is required")),
208
+ belongsToCollectionScopeUuids: v.optional(v.array(uuidSchema), []),
209
+ queries: setQueriesSchema,
210
+ attributes: v.optional(v.object({
211
+ bibliographies: defaultBoolean(false),
212
+ periods: defaultBoolean(false)
213
+ }), {
214
+ bibliographies: false,
215
+ periods: false
216
+ }),
217
+ isLimitedToLeafPropertyValues: defaultBoolean(false)
218
+ });
219
+ /**
220
+ * Schema for validating Set items parameters
221
+ * @internal
222
+ */
223
+ const setItemsParamsSchema = v.object({
224
+ setScopeUuids: v.pipe(v.array(uuidSchema), v.minLength(1, "At least one set scope UUID is required")),
225
+ belongsToCollectionScopeUuids: v.optional(v.array(uuidSchema), []),
226
+ queries: setQueriesSchema,
227
+ sort: setItemsSortSchema,
228
+ page: v.optional(positiveNumber("Page must be positive"), 1),
229
+ pageSize: v.optional(positiveNumber("Page size must be positive"), 48)
230
+ });
231
+ //#endregion
232
+ export { componentSchema, gallerySchema, iso639_3Schema, renderOptionsSchema, setItemsParamsSchema, setPropertyValuesParamsSchema, uuidSchema, whitespaceSchema };