@projectdochelp/s3te 3.4.3 → 3.4.4

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/README.md CHANGED
@@ -724,7 +724,8 @@ Filter notes:
724
724
  - multiple clauses are combined with logical `AND`
725
725
  - `__typename` matches the content model, for example `article`
726
726
  - supported legacy value wrappers are `S`, `N`, `BOOL`, `NULL`, and `L`
727
- - results are sorted deterministically; numeric `order` comes first, then `contentId`, then `id`
727
+ - results are sorted deterministically; items with a numeric field `order` are rendered first in ascending order, then items without a numeric `order`, then `contentId`, then `id`
728
+ - this also works with mirrored Webiny content if the model contains a field with the exact field ID `order` and type `number`
728
729
 
729
730
  **Example**
730
731
 
@@ -1018,6 +1019,13 @@ That makes the option example above equivalent to a config that contains:
1018
1019
 
1019
1020
  Use this for every Webiny model whose entries should be available to S3TE template commands like `dbitem`, `dbmulti`, `dbmultifile`, `dbmultifileitem`, or `dbpart`.
1020
1021
 
1022
+ If a Webiny model should control the output order for `dbmulti` or `dbmultifile`, add a field with:
1023
+
1024
+ - field ID `order`
1025
+ - field type `number`
1026
+
1027
+ S3TE sorts matching items by that numeric `order` in ascending order. Items without a numeric `order` stay at the end.
1028
+
1021
1029
  If different environments should read from different Webiny installations or tenants, run the option command per environment:
1022
1030
 
1023
1031
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectdochelp/s3te",
3
- "version": "3.4.3",
3
+ "version": "3.4.4",
4
4
  "description": "CLI, render core, AWS adapter, and testkit for S3TemplateEngine projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -83,13 +83,42 @@ function compareFilter(actual, expected, filterType) {
83
83
  return actual === expected;
84
84
  }
85
85
 
86
+ function coerceNumericOrderValue(value) {
87
+ if (typeof value === "number") {
88
+ return Number.isFinite(value) ? value : null;
89
+ }
90
+
91
+ if (typeof value === "string") {
92
+ const trimmed = value.trim();
93
+ if (!trimmed) {
94
+ return null;
95
+ }
96
+ const parsed = Number(trimmed);
97
+ return Number.isFinite(parsed) ? parsed : null;
98
+ }
99
+
100
+ const legacyValue = legacyAttributeValueToPlain(value);
101
+ if (legacyValue !== undefined && legacyValue !== value) {
102
+ return coerceNumericOrderValue(legacyValue);
103
+ }
104
+
105
+ return null;
106
+ }
107
+
108
+ function readOrderValue(item) {
109
+ const candidate = item?.values?.order ?? item?.order;
110
+ return coerceNumericOrderValue(candidate);
111
+ }
112
+
86
113
  function compareOrder(a, b) {
87
- const aHasOrder = typeof a.values?.order === "number";
88
- const bHasOrder = typeof b.values?.order === "number";
114
+ const aOrder = readOrderValue(a);
115
+ const bOrder = readOrderValue(b);
116
+ const aHasOrder = aOrder !== null;
117
+ const bHasOrder = bOrder !== null;
89
118
 
90
119
  if (aHasOrder && bHasOrder) {
91
- if (a.values.order !== b.values.order) {
92
- return a.values.order - b.values.order;
120
+ if (aOrder !== bOrder) {
121
+ return aOrder - bOrder;
93
122
  }
94
123
  } else if (aHasOrder && !bHasOrder) {
95
124
  return -1;