ochre-sdk 0.20.1 → 0.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -648,8 +648,30 @@ type PropertyValueQueryItem = {
648
648
  */
649
649
  type Query = {
650
650
  target: "propertyValue";
651
- dataType: Exclude<PropertyValueContentType, "coordinate">;
651
+ dataType: Exclude<Exclude<PropertyValueContentType, "coordinate">, "date" | "dateTime">;
652
+ value: string;
653
+ from?: never;
654
+ to?: never;
655
+ matchMode: "includes" | "exact";
656
+ isCaseSensitive: boolean;
657
+ language: string;
658
+ operator?: "AND" | "OR";
659
+ } | {
660
+ target: "propertyValue";
661
+ dataType: "date" | "dateTime";
662
+ value: string;
663
+ from: string;
664
+ to?: string;
665
+ matchMode: "includes" | "exact";
666
+ isCaseSensitive: boolean;
667
+ language: string;
668
+ operator?: "AND" | "OR";
669
+ } | {
670
+ target: "propertyValue";
671
+ dataType: "date" | "dateTime";
652
672
  value: string;
673
+ from?: string;
674
+ to: string;
653
675
  matchMode: "includes" | "exact";
654
676
  isCaseSensitive: boolean;
655
677
  language: string;
package/dist/index.mjs CHANGED
@@ -772,37 +772,60 @@ const setItemsParamsSchema = z.object({
772
772
  setScopeUuids: z.array(uuidSchema).min(1, "At least one set scope UUID is required"),
773
773
  belongsToCollectionScopeUuids: z.array(uuidSchema).default([]),
774
774
  propertyVariableUuids: z.array(uuidSchema).default([]),
775
- queries: z.array(z.discriminatedUnion("target", [z.object({
776
- target: z.literal("propertyValue"),
777
- dataType: z.enum([
778
- "string",
779
- "integer",
780
- "decimal",
781
- "boolean",
782
- "date",
783
- "dateTime",
784
- "time",
785
- "IDREF"
786
- ]),
787
- value: z.string(),
788
- matchMode: z.enum(["includes", "exact"]),
789
- isCaseSensitive: z.boolean(),
790
- language: z.string().default("eng"),
791
- operator: z.enum(["AND", "OR"]).optional()
792
- }), z.object({
793
- target: z.enum([
794
- "title",
795
- "description",
796
- "image",
797
- "periods",
798
- "bibliography"
799
- ]),
800
- value: z.string(),
801
- matchMode: z.enum(["includes", "exact"]),
802
- isCaseSensitive: z.boolean(),
803
- language: z.string().default("eng"),
804
- operator: z.enum(["AND", "OR"]).optional()
805
- })])).default([]),
775
+ queries: z.array(z.union([
776
+ z.object({
777
+ target: z.literal("propertyValue"),
778
+ dataType: z.enum([
779
+ "string",
780
+ "integer",
781
+ "decimal",
782
+ "boolean",
783
+ "time",
784
+ "IDREF"
785
+ ]),
786
+ value: z.string(),
787
+ matchMode: z.enum(["includes", "exact"]),
788
+ isCaseSensitive: z.boolean(),
789
+ language: z.string().default("eng"),
790
+ operator: z.enum(["AND", "OR"]).optional()
791
+ }).strict(),
792
+ z.object({
793
+ target: z.literal("propertyValue"),
794
+ dataType: z.enum(["date", "dateTime"]),
795
+ value: z.string(),
796
+ from: z.string(),
797
+ to: z.string().optional(),
798
+ matchMode: z.enum(["includes", "exact"]),
799
+ isCaseSensitive: z.boolean(),
800
+ language: z.string().default("eng"),
801
+ operator: z.enum(["AND", "OR"]).optional()
802
+ }).strict(),
803
+ z.object({
804
+ target: z.literal("propertyValue"),
805
+ dataType: z.enum(["date", "dateTime"]),
806
+ value: z.string(),
807
+ from: z.string().optional(),
808
+ to: z.string(),
809
+ matchMode: z.enum(["includes", "exact"]),
810
+ isCaseSensitive: z.boolean(),
811
+ language: z.string().default("eng"),
812
+ operator: z.enum(["AND", "OR"]).optional()
813
+ }).strict(),
814
+ z.object({
815
+ target: z.enum([
816
+ "title",
817
+ "description",
818
+ "image",
819
+ "periods",
820
+ "bibliography"
821
+ ]),
822
+ value: z.string(),
823
+ matchMode: z.enum(["includes", "exact"]),
824
+ isCaseSensitive: z.boolean(),
825
+ language: z.string().default("eng"),
826
+ operator: z.enum(["AND", "OR"]).optional()
827
+ }).strict()
828
+ ])).default([]),
806
829
  page: z.number().min(1, "Page must be positive").default(1),
807
830
  pageSize: z.number().min(1, "Page size must be positive").default(DEFAULT_PAGE_SIZE)
808
831
  }).superRefine((value, ctx) => {
@@ -2089,13 +2112,27 @@ function buildStringMatchPredicate(params) {
2089
2112
  return `${comparedPath} = ${comparedValueLiteral}`;
2090
2113
  }
2091
2114
  /**
2115
+ * Build a date/dateTime range predicate for an XQuery string.
2116
+ */
2117
+ function buildDateRangePredicate(params) {
2118
+ const { from, to } = params;
2119
+ const conditions = [];
2120
+ if (from != null) conditions.push(`(value/@rawValue ge ${stringLiteral(from)})`);
2121
+ if (to != null) conditions.push(`(value/@rawValue le ${stringLiteral(to)})`);
2122
+ return conditions.join(" and ");
2123
+ }
2124
+ /**
2092
2125
  * Build a property value predicate for an XQuery string
2093
2126
  * @param query - The propertyValue query
2094
2127
  * @returns The property value predicate
2095
2128
  */
2096
2129
  function buildPropertyValuePredicate(query) {
2097
2130
  if (query.dataType === "IDREF") return `.//properties//property[value[@uuid=${stringLiteral(query.value)}]]`;
2098
- if (query.dataType === "date" || query.dataType === "dateTime" || query.dataType === "time" || query.dataType === "integer" || query.dataType === "decimal" || query.dataType === "boolean") return `.//properties//property[value[@rawValue=${stringLiteral(query.value)}]]`;
2131
+ if (query.dataType === "date" || query.dataType === "dateTime") return `.//properties//property[(label/@uuid=${stringLiteral(query.value)}) and ${buildDateRangePredicate({
2132
+ from: query.from,
2133
+ to: query.to
2134
+ })}]`;
2135
+ if (query.dataType === "time" || query.dataType === "integer" || query.dataType === "decimal" || query.dataType === "boolean") return `.//properties//property[value[@rawValue=${stringLiteral(query.value)}]]`;
2099
2136
  return `.//properties//property[${buildStringMatchPredicate({
2100
2137
  path: `string-join(value/content[@xml:lang="${query.language}"]/string, "")`,
2101
2138
  value: query.value,
@@ -2109,32 +2146,36 @@ function buildPropertyValuePredicate(query) {
2109
2146
  * @returns The query predicate
2110
2147
  */
2111
2148
  function buildQueryPredicate(query) {
2112
- const stringMatchParams = {
2113
- value: query.value,
2114
- matchMode: query.matchMode,
2115
- isCaseSensitive: query.isCaseSensitive,
2116
- language: query.language
2117
- };
2118
2149
  switch (query.target) {
2119
2150
  case "title": return buildStringMatchPredicate({
2120
2151
  path: `string-join(identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2121
- ...stringMatchParams
2152
+ value: query.value,
2153
+ matchMode: query.matchMode,
2154
+ isCaseSensitive: query.isCaseSensitive
2122
2155
  });
2123
2156
  case "description": return buildStringMatchPredicate({
2124
2157
  path: `string-join(description/content[@xml:lang="${query.language}"]/string, "")`,
2125
- ...stringMatchParams
2158
+ value: query.value,
2159
+ matchMode: query.matchMode,
2160
+ isCaseSensitive: query.isCaseSensitive
2126
2161
  });
2127
2162
  case "periods": return buildStringMatchPredicate({
2128
2163
  path: `string-join(periods/period/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2129
- ...stringMatchParams
2164
+ value: query.value,
2165
+ matchMode: query.matchMode,
2166
+ isCaseSensitive: query.isCaseSensitive
2130
2167
  });
2131
2168
  case "bibliography": return buildStringMatchPredicate({
2132
2169
  path: `string-join(bibliographies/bibliography/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2133
- ...stringMatchParams
2170
+ value: query.value,
2171
+ matchMode: query.matchMode,
2172
+ isCaseSensitive: query.isCaseSensitive
2134
2173
  });
2135
2174
  case "image": return buildStringMatchPredicate({
2136
2175
  path: `string-join(image/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2137
- ...stringMatchParams
2176
+ value: query.value,
2177
+ matchMode: query.matchMode,
2178
+ isCaseSensitive: query.isCaseSensitive
2138
2179
  });
2139
2180
  case "propertyValue": return buildPropertyValuePredicate(query);
2140
2181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "devDependencies": {
49
49
  "@antfu/eslint-config": "^7.6.1",
50
- "@types/node": "^24.10.13",
50
+ "@types/node": "^24.10.14",
51
51
  "bumpp": "^10.4.1",
52
52
  "eslint": "^10.0.2",
53
53
  "prettier": "^3.8.1",