nextjs-cms 0.9.37 → 0.9.39

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 (84) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +279 -279
  3. package/dist/api/actions/files.d.ts.map +1 -1
  4. package/dist/api/actions/pages.d.ts +28 -7
  5. package/dist/api/actions/pages.d.ts.map +1 -1
  6. package/dist/api/actions/pages.js +112 -27
  7. package/dist/api/trpc/root.d.ts +65 -10
  8. package/dist/api/trpc/root.d.ts.map +1 -1
  9. package/dist/api/trpc/routers/config.d.ts.map +1 -1
  10. package/dist/api/trpc/routers/hasItemsSection.d.ts +23 -2
  11. package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -1
  12. package/dist/api/trpc/routers/hasItemsSection.js +2 -1
  13. package/dist/api/trpc/routers/logs.d.ts +37 -4
  14. package/dist/api/trpc/routers/logs.d.ts.map +1 -1
  15. package/dist/api/trpc/routers/logs.js +92 -43
  16. package/dist/api/trpc/routers/navigation.d.ts +4 -3
  17. package/dist/api/trpc/routers/navigation.d.ts.map +1 -1
  18. package/dist/api/trpc/routers/simpleSection.d.ts +1 -1
  19. package/dist/api/trpc/routers/simpleSection.d.ts.map +1 -1
  20. package/dist/api/trpc/server.d.ts +195 -30
  21. package/dist/api/trpc/server.d.ts.map +1 -1
  22. package/dist/cli/lib/db-config.js +10 -10
  23. package/dist/cli/lib/update-sections.js +24 -24
  24. package/dist/core/config/config-loader.d.ts +2 -2
  25. package/dist/core/db/table-checker/MysqlTable.js +10 -10
  26. package/dist/core/factories/FieldFactory.d.ts +1 -6
  27. package/dist/core/factories/FieldFactory.d.ts.map +1 -1
  28. package/dist/core/factories/FieldFactory.js +3 -68
  29. package/dist/core/factories/section-factory-with-esbuild.js +9 -9
  30. package/dist/core/factories/section-factory-with-jiti.js +9 -9
  31. package/dist/core/fields/checkbox.d.ts +3 -3
  32. package/dist/core/fields/color.d.ts +3 -3
  33. package/dist/core/fields/date-range.d.ts +2 -2
  34. package/dist/core/fields/date.d.ts +3 -3
  35. package/dist/core/fields/document.d.ts +3 -3
  36. package/dist/core/fields/field.d.ts +25 -12
  37. package/dist/core/fields/field.d.ts.map +1 -1
  38. package/dist/core/fields/field.js +51 -23
  39. package/dist/core/fields/index.d.ts +1 -0
  40. package/dist/core/fields/index.d.ts.map +1 -1
  41. package/dist/core/fields/index.js +2 -0
  42. package/dist/core/fields/map.d.ts +3 -3
  43. package/dist/core/fields/number.d.ts +4 -4
  44. package/dist/core/fields/password.d.ts +3 -3
  45. package/dist/core/fields/photo.d.ts +9 -9
  46. package/dist/core/fields/richText.d.ts +12 -12
  47. package/dist/core/fields/select.d.ts +7 -7
  48. package/dist/core/fields/selectMultiple.d.ts +4 -4
  49. package/dist/core/fields/slug.d.ts +9 -9
  50. package/dist/core/fields/tags.d.ts +3 -3
  51. package/dist/core/fields/text.d.ts +2 -2
  52. package/dist/core/fields/textArea.d.ts +2 -2
  53. package/dist/core/fields/video.d.ts +3 -3
  54. package/dist/core/helpers/conditional-rules.d.ts +63 -0
  55. package/dist/core/helpers/conditional-rules.d.ts.map +1 -0
  56. package/dist/core/helpers/conditional-rules.js +113 -0
  57. package/dist/core/helpers/index.d.ts +1 -0
  58. package/dist/core/helpers/index.d.ts.map +1 -1
  59. package/dist/core/helpers/index.js +4 -0
  60. package/dist/core/sections/category.d.ts +50 -50
  61. package/dist/core/sections/hasItems.d.ts +74 -74
  62. package/dist/core/sections/section.d.ts +23 -23
  63. package/dist/core/sections/simple.d.ts +6 -6
  64. package/dist/core/submit/submit.d.ts +4 -1
  65. package/dist/core/submit/submit.d.ts.map +1 -1
  66. package/dist/core/submit/submit.js +9 -19
  67. package/dist/core/types/index.d.ts +30 -8
  68. package/dist/core/types/index.d.ts.map +1 -1
  69. package/dist/index.d.ts +1 -0
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +4 -0
  72. package/dist/logging/event-labels.d.ts +11 -0
  73. package/dist/logging/event-labels.d.ts.map +1 -0
  74. package/dist/logging/event-labels.js +14 -0
  75. package/dist/logging/log.d.ts +1 -1
  76. package/dist/logging/log.d.ts.map +1 -1
  77. package/dist/translations/base/en.d.ts +33 -0
  78. package/dist/translations/base/en.d.ts.map +1 -1
  79. package/dist/translations/base/en.js +33 -0
  80. package/dist/translations/client.d.ts +400 -4
  81. package/dist/translations/client.d.ts.map +1 -1
  82. package/dist/translations/server.d.ts +400 -4
  83. package/dist/translations/server.d.ts.map +1 -1
  84. package/package.json +7 -3
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Normalize a value to the string form used for comparison.
3
+ *
4
+ * Form values reach us as strings (`FormData`) on the server and as strings, numbers or booleans on
5
+ * the client, so every condition compares string representations. An absent value (`undefined`, or
6
+ * the `null` returned by `FormData.get()` for a missing key) normalizes to `undefined` so it is never
7
+ * confused with the literal string `'undefined'`.
8
+ */
9
+ function normalize(value) {
10
+ if (value === undefined || value === null)
11
+ return undefined;
12
+ return String(value);
13
+ }
14
+ /**
15
+ * Coerce a normalized value to a number for the ordering conditions.
16
+ *
17
+ * Returns `NaN` for absent, blank and non-numeric values so that every ordering comparison against
18
+ * them is false — an ordering condition is only met when both sides are real numbers.
19
+ */
20
+ function toComparableNumber(value) {
21
+ if (value === undefined || value.trim() === '')
22
+ return NaN;
23
+ return Number(value);
24
+ }
25
+ /**
26
+ * Evaluate a single conditional rule against the current value of its controlling field.
27
+ *
28
+ * This is the one place conditions are interpreted. It is shared by the admin UI (deciding whether to
29
+ * render a conditional field) and by submit (deciding whether to persist it), so a field can never be
30
+ * visible in the form but silently dropped on save.
31
+ *
32
+ * Notes on semantics:
33
+ * - `equals` / `notEquals` / `contains` / `notContains` compare string representations; `contains` is
34
+ * case sensitive.
35
+ * - The ordering conditions require both sides to be numeric, and are false otherwise.
36
+ * - When the controlling field has no value, negative conditions (`notEquals`, `notContains`) are met
37
+ * and every other condition is not.
38
+ *
39
+ * @param rule The rule to evaluate: the condition and the value it expects.
40
+ * @param actualValue The current value of the controlling field.
41
+ */
42
+ export function evaluateConditionalRule(rule, actualValue) {
43
+ const actual = normalize(actualValue);
44
+ const expected = normalize(rule.value);
45
+ switch (rule.condition) {
46
+ case 'equals':
47
+ return actual === expected;
48
+ case 'notEquals':
49
+ return actual !== expected;
50
+ case 'contains':
51
+ return actual !== undefined && expected !== undefined && actual.includes(expected);
52
+ case 'notContains':
53
+ return !(actual !== undefined && expected !== undefined && actual.includes(expected));
54
+ case 'greaterThan':
55
+ return toComparableNumber(actual) > toComparableNumber(expected);
56
+ case 'lessThan':
57
+ return toComparableNumber(actual) < toComparableNumber(expected);
58
+ case 'greaterThanOrEquals':
59
+ return toComparableNumber(actual) >= toComparableNumber(expected);
60
+ case 'lessThanOrEquals':
61
+ return toComparableNumber(actual) <= toComparableNumber(expected);
62
+ default:
63
+ return false;
64
+ }
65
+ }
66
+ /**
67
+ * Combine conditional rules with AND semantics — the dependent field is active only when every rule
68
+ * passes. Use in a field's `conditionalRules` when it declares two or more rules.
69
+ */
70
+ export function and(...rules) {
71
+ return { match: 'all', rules };
72
+ }
73
+ /**
74
+ * Combine conditional rules with OR semantics — the dependent field is active when at least one rule
75
+ * passes. Use in a field's `conditionalRules` when it declares two or more rules.
76
+ */
77
+ export function or(...rules) {
78
+ return { match: 'any', rules };
79
+ }
80
+ /**
81
+ * Normalize a field's `conditionalRules` config into a single {@link ConditionalRuleGroup}.
82
+ *
83
+ * A single-rule array (the no-wrapper form) becomes an `all` group; an `and()` / `or()` group passes
84
+ * through unchanged. Returns `undefined` when there are no rules, which callers treat as "not
85
+ * conditional". Accepts a bare multi-rule array at runtime for resilience, though the config type
86
+ * forbids it so authors are pushed to `and()` / `or()`.
87
+ */
88
+ export function normalizeConditionalRules(input) {
89
+ if (!input)
90
+ return undefined;
91
+ if (Array.isArray(input)) {
92
+ if (input.length === 0)
93
+ return undefined;
94
+ return { match: 'all', rules: input };
95
+ }
96
+ return input;
97
+ }
98
+ /**
99
+ * Evaluate a whole rule group against the current form state.
100
+ *
101
+ * Value resolution is delegated to `resolveValue` so this works on both layers: the server passes a
102
+ * resolver backed by submitted `FormData`, the client one backed by the live field values. Each rule
103
+ * is resolved against its own controlling field. An empty group never matches.
104
+ *
105
+ * @param group The group to evaluate, with its `all` / `any` combining operator.
106
+ * @param resolveValue Returns the current value of the field a given rule controls on.
107
+ */
108
+ export function evaluateConditionalRuleGroup(group, resolveValue) {
109
+ if (!group.rules || group.rules.length === 0)
110
+ return false;
111
+ const results = group.rules.map((rule) => evaluateConditionalRule(rule, resolveValue(rule)));
112
+ return group.match === 'any' ? results.some((result) => result) : results.every((result) => result);
113
+ }
@@ -2,4 +2,5 @@ export { is } from './entity.js';
2
2
  export { entityKind } from './entity.js';
3
3
  export type { LZEntity } from './entity.js';
4
4
  export { hasOwnEntityKind } from './entity.js';
5
+ export { evaluateConditionalRule, evaluateConditionalRuleGroup, normalizeConditionalRules } from './conditional-rules.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAI9C,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA"}
@@ -1,3 +1,7 @@
1
1
  export { is } from './entity.js';
2
2
  export { entityKind } from './entity.js';
3
3
  export { hasOwnEntityKind } from './entity.js';
4
+ // Note: the `and` / `or` authoring wrappers are re-exported from `core/fields` (alongside the field
5
+ // factories that section configs use), so they are intentionally not re-exported here to avoid a
6
+ // duplicate export when `core/index` merges both barrels.
7
+ export { evaluateConditionalRule, evaluateConditionalRuleGroup, normalizeConditionalRules } from './conditional-rules.js';