@matreshka/bff 0.33.0 → 0.33.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.
@@ -25,14 +25,14 @@ function assertClientUpdateSchemaSupported(schema, path = "") {
25
25
  function assertClientUpdateFieldSupported(schema, path) {
26
26
  const unwrapped = unwrapOptionalNullable(schema);
27
27
  if (unwrapped instanceof zod_1.z.ZodPipe) {
28
- const inner = unwrapped._def.in;
28
+ const inner = unwrapped.in;
29
29
  if (inner instanceof zod_1.z.ZodObject) {
30
30
  throw new Error(`Context validation schema: object-level transform at "${formatPath(path)}" is not supported for dotted-path client updates. Use leaf-level transforms only.`);
31
31
  }
32
32
  return;
33
33
  }
34
34
  if (unwrapped instanceof zod_1.z.ZodObject) {
35
- const checks = unwrapped._def.checks;
35
+ const checks = unwrapped.def.checks;
36
36
  if (checks && checks.length > 0) {
37
37
  throw new Error(`Context validation schema: object-level refine at "${formatPath(path)}" is not supported for dotted-path client updates. Use leaf-level refinements only.`);
38
38
  }
@@ -4,11 +4,12 @@ import { z } from "zod";
4
4
  import type { SetContext } from "../actions/set-context";
5
5
  import { AnySchemaContextRef, ContextRef, ContextRefValueType } from "../context/context-ref";
6
6
  import type { ContextUpdateDelivery } from "./context-update-delivery";
7
- /** Общая часть ref-типов по значению: маркер типа и чтение. */
7
+ /** Общая часть ref-типов по значению: маркер типа, чтение и запись. */
8
8
  type ValueRefBase<ValueType> = {
9
9
  readonly __valueType?: ValueType;
10
10
  get(): ValueType;
11
11
  set(value: ValueType): Observable<ContextUpdateDelivery>;
12
+ update(updater: (current: ValueType) => ValueType): Observable<ContextUpdateDelivery>;
12
13
  };
13
14
  /**
14
15
  * Ссылка на поле контекста с известным типом значения.
@@ -1,2 +1,9 @@
1
1
  import { z } from "zod";
2
- export declare function zodDeepPick(schema: z.ZodTypeAny, propertyPath: string): z.ZodTypeAny;
2
+ /**
3
+ * Схема конечного поля по dotted-пути клиентского patch.
4
+ *
5
+ * Элемент массива адресуется числовым сегментом (`meters.0.zones.0.value`).
6
+ * Индексом он считается только если текущий узел — `ZodArray`; у `ZodObject`
7
+ * тот же сегмент остаётся строковым ключом (`{ "0": z.string() }`).
8
+ */
9
+ export declare function zodDeepPick(schema: z.ZodType, propertyPath: string): z.ZodType;
@@ -8,68 +8,72 @@ function isZodObject(schema) {
8
8
  function isZodArray(schema) {
9
9
  return schema instanceof zod_1.z.ZodArray;
10
10
  }
11
- /** Объектная shape для навигации по dotted-пути (без object-level pipe/transform). */
12
- function objectShapeForPick(schema) {
11
+ /**
12
+ * Узел схемы, по которому можно идти дальше по пути.
13
+ * Снимает optional/nullable и pipe к object/array (object-level transform).
14
+ */
15
+ function schemaForPathStep(schema) {
13
16
  let current = schema;
14
17
  for (;;) {
15
- if (isZodObject(current)) {
16
- return current;
17
- }
18
18
  if (current instanceof zod_1.z.ZodOptional || current instanceof zod_1.z.ZodNullable) {
19
19
  current = current.unwrap();
20
20
  continue;
21
21
  }
22
22
  if (current instanceof zod_1.z.ZodPipe) {
23
- const inner = current._def.in;
24
- if (isZodObject(inner)) {
25
- return inner;
23
+ const inner = current.in;
24
+ if (isZodObject(inner) || isZodArray(inner)) {
25
+ current = inner;
26
+ continue;
26
27
  }
27
28
  break;
28
29
  }
29
30
  break;
30
31
  }
32
+ return current;
33
+ }
34
+ /** Объектная shape для навигации по dotted-пути (без object-level pipe/transform). */
35
+ function objectShapeForPick(schema) {
36
+ const current = schemaForPathStep(schema);
37
+ if (isZodObject(current)) {
38
+ return current;
39
+ }
31
40
  throw Error("Not a zod object");
32
41
  }
33
42
  function pickObject(schema, path) {
34
43
  const objectSchema = objectShapeForPick(schema);
35
- const newSchema = objectSchema.shape?.[path];
44
+ const shape = objectSchema.shape;
45
+ const newSchema = shape[path];
36
46
  if (!newSchema)
37
47
  throw Error(
38
48
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
39
- `${path} does not exist on schema with keys: ${Object.keys(objectSchema.shape)}`);
49
+ `${path} does not exist on schema with keys: ${Object.keys(shape)}`);
40
50
  return newSchema;
41
51
  }
42
52
  function pickArray(schema) {
43
- if (!isZodArray(schema))
53
+ const current = schemaForPathStep(schema);
54
+ if (!isZodArray(current))
44
55
  throw Error("Not a Zod Array");
45
- const newSchema = schema?.element;
56
+ const newSchema = current.element;
46
57
  if (!newSchema)
47
58
  throw Error("No element on Zod Array");
48
59
  return newSchema;
49
60
  }
61
+ /**
62
+ * Схема конечного поля по dotted-пути клиентского patch.
63
+ *
64
+ * Элемент массива адресуется числовым сегментом (`meters.0.zones.0.value`).
65
+ * Индексом он считается только если текущий узел — `ZodArray`; у `ZodObject`
66
+ * тот же сегмент остаётся строковым ключом (`{ "0": z.string() }`).
67
+ */
50
68
  function zodDeepPick(schema, propertyPath) {
51
69
  if (propertyPath === "")
52
70
  return schema;
53
- const numberRegex = new RegExp("[[0-9]+]");
54
- const arrayIndex = propertyPath.search(numberRegex);
55
- const objectIndex = propertyPath.indexOf(".");
56
- const matchedArray = arrayIndex !== -1;
57
- const matchedObject = objectIndex !== -1;
58
- if ((matchedArray && matchedObject && arrayIndex < objectIndex) ||
59
- (matchedArray && !matchedObject)) {
60
- const arraySplit = propertyPath.split(numberRegex);
61
- const restArray = arraySplit.slice(1, arraySplit.length).join("[0]");
62
- if (arrayIndex !== 0) {
63
- return zodDeepPick(pickObject(schema, arraySplit[0]), `[0]${restArray}`);
64
- }
65
- return zodDeepPick(pickArray(schema), restArray.charAt(0) === "."
66
- ? restArray.slice(1, restArray.length)
67
- : restArray);
68
- }
69
- if (matchedObject) {
70
- const objectSplit = propertyPath.split(".");
71
- const restObject = objectSplit.slice(1, objectSplit.length).join(".");
72
- return zodDeepPick(pickObject(schema, objectSplit[0]), restObject);
71
+ const dot = propertyPath.indexOf(".");
72
+ const segment = dot === -1 ? propertyPath : propertyPath.slice(0, dot);
73
+ const rest = dot === -1 ? "" : propertyPath.slice(dot + 1);
74
+ const current = schemaForPathStep(schema);
75
+ if (isZodArray(current) && /^\d+$/.test(segment)) {
76
+ return zodDeepPick(pickArray(current), rest);
73
77
  }
74
- return pickObject(schema, propertyPath);
78
+ return zodDeepPick(pickObject(schema, segment), rest);
75
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matreshka/bff",
3
- "version": "0.33.0",
3
+ "version": "0.33.2",
4
4
  "description": "Matreshka BFF: server-driven UI runtime — routing, pages, context, component DSL, and platform APIs",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",