@matreshka/bff 0.12.0 → 0.14.0
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/components/component.d.ts +1 -1
- package/dist/components/component.js +19 -16
- package/dist/components/for-each.d.ts +1 -1
- package/dist/core/actions/action.d.ts +0 -2
- package/dist/core/actions/action.js +0 -9
- package/dist/core/client.js +1 -0
- package/dist/core/conditions/condition-operand.d.ts +27 -10
- package/dist/core/conditions/context-array-includes.d.ts +9 -11
- package/dist/core/conditions/context-array-length.d.ts +17 -20
- package/dist/core/conditions/context-value-equal.d.ts +2 -2
- package/dist/core/conditions/context-value-in.d.ts +3 -6
- package/dist/core/conditions/context-value-not-equal.d.ts +2 -2
- package/dist/core/context/context-ref.d.ts +7 -2
- package/dist/core/context/context-ref.js +10 -0
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/types/context-value-ref.d.ts +2 -1
- package/package.json +2 -2
- package/dist/core/types/context-ref-primitive-value.d.ts +0 -5
- package/dist/core/types/context-ref-primitive-value.js +0 -2
- package/dist/core/types/native-picker-context-ref.d.ts +0 -8
- package/dist/core/types/native-picker-context-ref.js +0 -2
|
@@ -127,7 +127,7 @@ export declare abstract class Component<InitConfigType extends ComponentInitConf
|
|
|
127
127
|
/** Рассылка сообщения всем подписанным клиентам данного компонента */
|
|
128
128
|
protected broadcast(message: ComponentCommandMessage): void;
|
|
129
129
|
/** Обработка взаимодействия */
|
|
130
|
-
protected emitInteraction(type: string, payload: unknown, instance: ComponentInstance<this
|
|
130
|
+
protected emitInteraction(type: string, payload: unknown, instance: ComponentInstance<this>, handlers: number[]): void;
|
|
131
131
|
/** Выполняет server-only cleanup перед окончательным release instance. */
|
|
132
132
|
protected emitOnDestroy(instance: ComponentInstance<this>): void;
|
|
133
133
|
/** Добавление обработчика на взаимодействие */
|
|
@@ -132,16 +132,21 @@ class Component {
|
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
/** Обработка взаимодействия */
|
|
135
|
-
emitInteraction(type, payload, instance) {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
emitInteraction(type, payload, instance, handlers) {
|
|
136
|
+
const eventHandlers = this.interactions.get(type);
|
|
137
|
+
if (!eventHandlers) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
for (const index of handlers) {
|
|
141
|
+
const handler = eventHandlers[index];
|
|
142
|
+
if (!(handler instanceof server_action_1.ServerAction)) {
|
|
143
|
+
continue;
|
|
143
144
|
}
|
|
144
|
-
|
|
145
|
+
handler.execute({
|
|
146
|
+
instance,
|
|
147
|
+
payload,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
145
150
|
}
|
|
146
151
|
/** Выполняет server-only cleanup перед окончательным release instance. */
|
|
147
152
|
emitOnDestroy(instance) {
|
|
@@ -154,12 +159,10 @@ class Component {
|
|
|
154
159
|
}
|
|
155
160
|
(0, core_1.runWithClient)(client, () => {
|
|
156
161
|
this.destroyHandlers.forEach((handler) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
162
|
-
}
|
|
162
|
+
handler.execute({
|
|
163
|
+
instance,
|
|
164
|
+
payload: undefined,
|
|
165
|
+
});
|
|
163
166
|
});
|
|
164
167
|
});
|
|
165
168
|
}
|
|
@@ -326,7 +329,7 @@ class Component {
|
|
|
326
329
|
client.error$.next("Component interaction call, component are not using for this client");
|
|
327
330
|
return;
|
|
328
331
|
}
|
|
329
|
-
this.emitInteraction(message.eventType, message.payload, instance);
|
|
332
|
+
this.emitInteraction(message.eventType, message.payload, instance, message.getHandlers());
|
|
330
333
|
})));
|
|
331
334
|
this.clientSubscriptions.set(client, sub);
|
|
332
335
|
}
|
|
@@ -35,7 +35,7 @@ export type ForEachGeneratorProperties<RefType extends ContextRef<any, any>, Com
|
|
|
35
35
|
* @property ref Ссылка в контексте, по которой хранятся данные списка.
|
|
36
36
|
*/
|
|
37
37
|
export type ForEachProperties = {
|
|
38
|
-
ref: ContextRef
|
|
38
|
+
ref: ContextRef;
|
|
39
39
|
componentContext: Context<any>;
|
|
40
40
|
components?: (ComponentTreeNode | ComponentTreeNode[])[];
|
|
41
41
|
divider?: ComponentTreeNode[];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Condition as SerializedCondition } from "@matreshka/shared/types/condition";
|
|
2
|
-
import type { Client } from "../client";
|
|
3
2
|
import { Condition } from "../conditions/condition";
|
|
4
3
|
export type ActionConditions = Condition[] | (() => Condition[]);
|
|
5
4
|
export type ActionConfig = {
|
|
@@ -29,7 +28,6 @@ export declare abstract class Action {
|
|
|
29
28
|
payload: object;
|
|
30
29
|
conditions?: SerializedCondition[];
|
|
31
30
|
};
|
|
32
|
-
canExecute(client: Client): boolean;
|
|
33
31
|
private resolveConditions;
|
|
34
32
|
private serializeConditions;
|
|
35
33
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Action = void 0;
|
|
4
|
-
const shared_1 = require("@matreshka/shared");
|
|
5
4
|
/**
|
|
6
5
|
* Абстрактный класс действия, которое может быть сериализовано для клиента.
|
|
7
6
|
*/
|
|
@@ -25,14 +24,6 @@ class Action {
|
|
|
25
24
|
}
|
|
26
25
|
return result;
|
|
27
26
|
}
|
|
28
|
-
canExecute(client) {
|
|
29
|
-
const conditions = this.resolveConditions().map((condition) => condition.toJSON());
|
|
30
|
-
const evaluateActionConditions = shared_1.evaluateConditions;
|
|
31
|
-
return evaluateActionConditions(conditions, {
|
|
32
|
-
getContextValue: (ref) => ref.value(),
|
|
33
|
-
getDeviceType: () => client.deviceType(),
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
27
|
resolveConditions() {
|
|
37
28
|
return typeof this.conditions === "function"
|
|
38
29
|
? this.conditions()
|
package/dist/core/client.js
CHANGED
|
@@ -152,6 +152,7 @@ class Client {
|
|
|
152
152
|
target: v4_1.z.string().optional(),
|
|
153
153
|
id: v4_1.z.string().optional(),
|
|
154
154
|
attempt: v4_1.z.number().int().positive().optional(),
|
|
155
|
+
handlers: v4_1.z.array(v4_1.z.number().int().nonnegative()).optional(),
|
|
155
156
|
});
|
|
156
157
|
const message = abstractMessageSchema.parse(JSON.parse(messageString));
|
|
157
158
|
(0, client_context_1.runWithClient)(this, () => {
|
|
@@ -1,16 +1,32 @@
|
|
|
1
|
-
import type { JsonPrimitive } from "@matreshka/shared/types/json";
|
|
1
|
+
import type { JsonObject, JsonPrimitive } from "@matreshka/shared/types/json";
|
|
2
2
|
import type { SerializedOperand } from "@matreshka/shared/types/serialized-operand";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { Paths, PathValue } from "ts-essentials";
|
|
4
|
+
import { ContextRef, ContextRefValue } from "../context/context-ref";
|
|
5
|
+
import type { CompatibleContextValueRef } from "../types/context-value-ref";
|
|
6
|
+
type ContextArrayValue = readonly unknown[] | unknown[];
|
|
7
|
+
/** Элемент массива по значению `ContextRef`. */
|
|
8
|
+
export type ContextRefArrayElement<R extends ContextRef> = Extract<ContextRefValue<R>, ContextArrayValue>[number];
|
|
9
|
+
/** Ref на массив в контексте (значение по ref — массив или readonly-массив). */
|
|
10
|
+
export type CompatibleArrayContextRef<R extends ContextRef> = [
|
|
11
|
+
Extract<ContextRefValue<R>, ContextArrayValue>
|
|
12
|
+
] extends [never] ? never : R;
|
|
5
13
|
/**
|
|
6
|
-
* Операнд
|
|
7
|
-
* либо другая `ContextRef` (сравнение в рантайме через `===`).
|
|
14
|
+
* Операнд сравнения по известному типу значения: JSON-примитив или совместимая `ContextRef`.
|
|
8
15
|
*/
|
|
9
|
-
export type
|
|
10
|
-
/**
|
|
11
|
-
|
|
16
|
+
export type ConditionOperandFor<ValueType> = (ValueType & JsonPrimitive) | CompatibleContextValueRef<ValueType | undefined, ContextRef>;
|
|
17
|
+
/**
|
|
18
|
+
* Операнд условия на BFF: JSON-примитив того же типа, что значение по `ref`,
|
|
19
|
+
* либо другая ссылка с совместимым типом значения (сравнение в рантайме через `===`).
|
|
20
|
+
*/
|
|
21
|
+
export type ConditionOperand<R extends ContextRef> = ConditionOperandFor<ContextRefValue<R>>;
|
|
22
|
+
/** Значение поля элемента массива по `itemPath` (пустой путь — сам элемент). */
|
|
23
|
+
export type ArrayIncludesItemValue<Item, P extends string> = P extends "" ? Item : Item extends JsonObject ? PathValue<Item, P & Paths<Item>> : never;
|
|
24
|
+
/** Операнд {@link ContextArrayIncludes} / {@link ContextArrayNotIncludes}. */
|
|
25
|
+
export type ArrayIncludesOperand<R extends ContextRef, P extends string> = ConditionOperandFor<ArrayIncludesItemValue<ContextRefArrayElement<R>, P>>;
|
|
12
26
|
/** Операнд длины массива: число или ссылка на число в контексте. */
|
|
13
|
-
export type ConditionLengthOperand = number
|
|
27
|
+
export type ConditionLengthOperand = ConditionOperandFor<number>;
|
|
28
|
+
/** Операнд без привязки к конкретному `ref` (сериализация на wire). */
|
|
29
|
+
export type UntypedConditionOperand = JsonPrimitive | ContextRef;
|
|
14
30
|
/**
|
|
15
31
|
* До JSON-сериализации в `kind: "ref"` лежит `ContextRef`;
|
|
16
32
|
* после stringify `ref` становится строкой `contextId.path`.
|
|
@@ -20,8 +36,9 @@ export type BffSerializedOperand = {
|
|
|
20
36
|
value: JsonPrimitive;
|
|
21
37
|
} | {
|
|
22
38
|
kind: "ref";
|
|
23
|
-
ref: ContextRef
|
|
39
|
+
ref: ContextRef;
|
|
24
40
|
};
|
|
25
41
|
export declare function toSerializedOperand(value: UntypedConditionOperand): BffSerializedOperand;
|
|
26
42
|
/** Для payload, который уходит в `Condition` и затем кастится к wire-типу. */
|
|
27
43
|
export declare function toWireOperand(value: UntypedConditionOperand): SerializedOperand;
|
|
44
|
+
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Paths } from "ts-essentials";
|
|
2
|
+
import { ContextRef } from "../context/context-ref";
|
|
2
3
|
import { Condition } from "./condition";
|
|
3
|
-
import {
|
|
4
|
-
type ContextArrayValue = readonly unknown[] | unknown[];
|
|
5
|
-
type CompatibleArrayContextRef<R extends ContextRef<any, any>> = Extract<ContextRefValue<R>, ContextArrayValue> extends never ? never : R;
|
|
4
|
+
import { ArrayIncludesOperand, CompatibleArrayContextRef, ContextRefArrayElement } from "./condition-operand";
|
|
6
5
|
/**
|
|
7
6
|
* Условие: в массиве из контекста есть элемент, у которого значение по
|
|
8
7
|
* `itemPath` равно операнду (литерал или `ContextRef`).
|
|
@@ -11,11 +10,11 @@ type CompatibleArrayContextRef<R extends ContextRef<any, any>> = Extract<Context
|
|
|
11
10
|
*
|
|
12
11
|
* @internal Используйте {@link contextArrayIncludes} / {@link when.includes}.
|
|
13
12
|
*/
|
|
14
|
-
export declare class ContextArrayIncludes<R extends ContextRef
|
|
15
|
-
constructor(ref: CompatibleArrayContextRef<R>, itemPath:
|
|
13
|
+
export declare class ContextArrayIncludes<R extends ContextRef, P extends Paths<ContextRefArrayElement<R>> | "" = ""> extends Condition {
|
|
14
|
+
constructor(ref: CompatibleArrayContextRef<R>, itemPath: P, value: ArrayIncludesOperand<R, P>);
|
|
16
15
|
}
|
|
17
16
|
/** Функциональная форма {@link ContextArrayIncludes}. */
|
|
18
|
-
export declare function contextArrayIncludes<R extends ContextRef
|
|
17
|
+
export declare function contextArrayIncludes<R extends ContextRef, P extends Paths<ContextRefArrayElement<R>> | "" = "">(ref: CompatibleArrayContextRef<R>, itemPath: P, value: ArrayIncludesOperand<R, P>): ContextArrayIncludes<R, P>;
|
|
19
18
|
/**
|
|
20
19
|
* Условие: в массиве из контекста нет элемента, у которого значение по
|
|
21
20
|
* `itemPath` равно операнду (литерал или `ContextRef`).
|
|
@@ -24,9 +23,8 @@ export declare function contextArrayIncludes<R extends ContextRef<any, any>>(ref
|
|
|
24
23
|
*
|
|
25
24
|
* @internal Используйте {@link contextArrayNotIncludes} / {@link when.excludes}.
|
|
26
25
|
*/
|
|
27
|
-
export declare class ContextArrayNotIncludes<R extends ContextRef
|
|
28
|
-
constructor(ref: CompatibleArrayContextRef<R>, itemPath:
|
|
26
|
+
export declare class ContextArrayNotIncludes<R extends ContextRef, P extends Paths<ContextRefArrayElement<R>> | "" = ""> extends Condition {
|
|
27
|
+
constructor(ref: CompatibleArrayContextRef<R>, itemPath: P, value: ArrayIncludesOperand<R, P>);
|
|
29
28
|
}
|
|
30
29
|
/** Функциональная форма {@link ContextArrayNotIncludes}. */
|
|
31
|
-
export declare function contextArrayNotIncludes<R extends ContextRef
|
|
32
|
-
export {};
|
|
30
|
+
export declare function contextArrayNotIncludes<R extends ContextRef, P extends Paths<ContextRefArrayElement<R>> | "" = "">(ref: CompatibleArrayContextRef<R>, itemPath: P, value: ArrayIncludesOperand<R, P>): ContextArrayNotIncludes<R, P>;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { ArrayLengthCompare } from "@matreshka/shared/enums/array-length-compare";
|
|
2
|
-
import { ContextRef
|
|
2
|
+
import { ContextRef } from "../context/context-ref";
|
|
3
3
|
import { Condition } from "./condition";
|
|
4
|
-
import { ConditionLengthOperand } from "./condition-operand";
|
|
5
|
-
type ContextArrayValue = readonly unknown[] | unknown[];
|
|
6
|
-
type CompatibleArrayContextRef<R extends ContextRef<any, any>> = Extract<ContextRefValue<R>, ContextArrayValue> extends never ? never : R;
|
|
4
|
+
import { CompatibleArrayContextRef, ConditionLengthOperand } from "./condition-operand";
|
|
7
5
|
/**
|
|
8
6
|
* Условие сравнения длины массива в контексте с операндом
|
|
9
7
|
* (число или значение по `ContextRef`).
|
|
10
8
|
*
|
|
11
9
|
* @internal Используйте фабрики длины массива ({@link contextArrayLengthEqual} и др.).
|
|
12
10
|
*/
|
|
13
|
-
export declare abstract class ContextArrayLength<R extends ContextRef
|
|
11
|
+
export declare abstract class ContextArrayLength<R extends ContextRef> extends Condition {
|
|
14
12
|
constructor(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand, operator: ArrayLengthCompare);
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
@@ -18,69 +16,68 @@ export declare abstract class ContextArrayLength<R extends ContextRef<any, any>>
|
|
|
18
16
|
*
|
|
19
17
|
* @internal Используйте {@link contextArrayLengthEqual} / {@link when.lengthEquals}.
|
|
20
18
|
*/
|
|
21
|
-
export declare class ContextArrayLengthEqual<R extends ContextRef
|
|
19
|
+
export declare class ContextArrayLengthEqual<R extends ContextRef> extends Condition {
|
|
22
20
|
constructor(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand);
|
|
23
21
|
}
|
|
24
22
|
/** Функциональная форма {@link ContextArrayLengthEqual}. */
|
|
25
|
-
export declare function contextArrayLengthEqual<R extends ContextRef
|
|
23
|
+
export declare function contextArrayLengthEqual<R extends ContextRef>(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand): ContextArrayLengthEqual<R>;
|
|
26
24
|
/**
|
|
27
25
|
* Алиас: длина массива в контексте строго меньше операнда (`<`).
|
|
28
26
|
*
|
|
29
27
|
* @internal Используйте {@link contextArrayLengthLessThan} / {@link when.lengthLessThan}.
|
|
30
28
|
*/
|
|
31
|
-
export declare class ContextArrayLengthLessThan<R extends ContextRef
|
|
29
|
+
export declare class ContextArrayLengthLessThan<R extends ContextRef> extends Condition {
|
|
32
30
|
constructor(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand);
|
|
33
31
|
}
|
|
34
32
|
/** Функциональная форма {@link ContextArrayLengthLessThan}. */
|
|
35
|
-
export declare function contextArrayLengthLessThan<R extends ContextRef
|
|
33
|
+
export declare function contextArrayLengthLessThan<R extends ContextRef>(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand): ContextArrayLengthLessThan<R>;
|
|
36
34
|
/**
|
|
37
35
|
* Алиас: длина массива в контексте меньше или равна операнду (`<=`).
|
|
38
36
|
*
|
|
39
37
|
* @internal Используйте {@link contextArrayLengthLessOrEqual} / {@link when.lengthAtMost}.
|
|
40
38
|
*/
|
|
41
|
-
export declare class ContextArrayLengthLessOrEqual<R extends ContextRef
|
|
39
|
+
export declare class ContextArrayLengthLessOrEqual<R extends ContextRef> extends Condition {
|
|
42
40
|
constructor(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand);
|
|
43
41
|
}
|
|
44
42
|
/** Функциональная форма {@link ContextArrayLengthLessOrEqual}. */
|
|
45
|
-
export declare function contextArrayLengthLessOrEqual<R extends ContextRef
|
|
43
|
+
export declare function contextArrayLengthLessOrEqual<R extends ContextRef>(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand): ContextArrayLengthLessOrEqual<R>;
|
|
46
44
|
/**
|
|
47
45
|
* Алиас: длина массива в контексте строго больше операнда (`>`).
|
|
48
46
|
*
|
|
49
47
|
* @internal Используйте {@link contextArrayLengthGreaterThan} / {@link when.lengthGreaterThan}.
|
|
50
48
|
*/
|
|
51
|
-
export declare class ContextArrayLengthGreaterThan<R extends ContextRef
|
|
49
|
+
export declare class ContextArrayLengthGreaterThan<R extends ContextRef> extends Condition {
|
|
52
50
|
constructor(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand);
|
|
53
51
|
}
|
|
54
52
|
/** Функциональная форма {@link ContextArrayLengthGreaterThan}. */
|
|
55
|
-
export declare function contextArrayLengthGreaterThan<R extends ContextRef
|
|
53
|
+
export declare function contextArrayLengthGreaterThan<R extends ContextRef>(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand): ContextArrayLengthGreaterThan<R>;
|
|
56
54
|
/**
|
|
57
55
|
* Алиас: длина массива в контексте больше или равна операнду (`>=`).
|
|
58
56
|
*
|
|
59
57
|
* @internal Используйте {@link contextArrayLengthGreaterOrEqual} / {@link when.lengthAtLeast}.
|
|
60
58
|
*/
|
|
61
|
-
export declare class ContextArrayLengthGreaterOrEqual<R extends ContextRef
|
|
59
|
+
export declare class ContextArrayLengthGreaterOrEqual<R extends ContextRef> extends Condition {
|
|
62
60
|
constructor(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand);
|
|
63
61
|
}
|
|
64
62
|
/** Функциональная форма {@link ContextArrayLengthGreaterOrEqual}. */
|
|
65
|
-
export declare function contextArrayLengthGreaterOrEqual<R extends ContextRef
|
|
63
|
+
export declare function contextArrayLengthGreaterOrEqual<R extends ContextRef>(ref: CompatibleArrayContextRef<R>, length: ConditionLengthOperand): ContextArrayLengthGreaterOrEqual<R>;
|
|
66
64
|
/**
|
|
67
65
|
* Алиас: массив в контексте пуст (длина равна 0).
|
|
68
66
|
*
|
|
69
67
|
* @internal Используйте {@link contextValueEmpty} / {@link when.isEmpty}.
|
|
70
68
|
*/
|
|
71
|
-
export declare class ContextValueEmpty<R extends ContextRef
|
|
69
|
+
export declare class ContextValueEmpty<R extends ContextRef> extends ContextArrayLengthEqual<R> {
|
|
72
70
|
constructor(ref: CompatibleArrayContextRef<R>);
|
|
73
71
|
}
|
|
74
72
|
/** Функциональная форма {@link ContextValueEmpty}. */
|
|
75
|
-
export declare function contextValueEmpty<R extends ContextRef
|
|
73
|
+
export declare function contextValueEmpty<R extends ContextRef>(ref: CompatibleArrayContextRef<R>): ContextValueEmpty<R>;
|
|
76
74
|
/**
|
|
77
75
|
* Алиас: массив в контексте непуст (длина строго больше 0).
|
|
78
76
|
*
|
|
79
77
|
* @internal Используйте {@link contextValueNotEmpty} / {@link when.notEmpty}.
|
|
80
78
|
*/
|
|
81
|
-
export declare class ContextValueNotEmpty<R extends ContextRef
|
|
79
|
+
export declare class ContextValueNotEmpty<R extends ContextRef> extends ContextArrayLengthGreaterThan<R> {
|
|
82
80
|
constructor(ref: CompatibleArrayContextRef<R>);
|
|
83
81
|
}
|
|
84
82
|
/** Функциональная форма {@link ContextValueNotEmpty}. */
|
|
85
|
-
export declare function contextValueNotEmpty<R extends ContextRef
|
|
86
|
-
export {};
|
|
83
|
+
export declare function contextValueNotEmpty<R extends ContextRef>(ref: CompatibleArrayContextRef<R>): ContextValueNotEmpty<R>;
|
|
@@ -7,8 +7,8 @@ import { ConditionOperand } from "./condition-operand";
|
|
|
7
7
|
*
|
|
8
8
|
* @internal Используйте {@link contextValueEqual} / {@link when.equals}.
|
|
9
9
|
*/
|
|
10
|
-
export declare class ContextValueEqual<R extends ContextRef
|
|
10
|
+
export declare class ContextValueEqual<R extends ContextRef> extends Condition {
|
|
11
11
|
constructor(ref: R, value: ConditionOperand<R>);
|
|
12
12
|
}
|
|
13
13
|
/** Функциональная форма {@link ContextValueEqual}. */
|
|
14
|
-
export declare function contextValueEqual<R extends ContextRef
|
|
14
|
+
export declare function contextValueEqual<R extends ContextRef>(ref: R, value: ConditionOperand<R>): ContextValueEqual<R>;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { ContextRef } from "../context/context-ref";
|
|
2
|
-
import { ContextRefPrimitiveValue } from "../types/context-ref-primitive-value";
|
|
3
2
|
import { Condition } from "./condition";
|
|
4
3
|
import { ConditionOperand } from "./condition-operand";
|
|
5
|
-
type CompatiblePrimitiveContextRef<R extends ContextRef<any, any>> = ContextRefPrimitiveValue<R> extends never ? never : R;
|
|
6
4
|
/**
|
|
7
5
|
* Условие: значение по `ref` входит в список операндов
|
|
8
6
|
* (каждый элемент — литерал или `ContextRef`).
|
|
9
7
|
*
|
|
10
8
|
* @internal Используйте {@link contextValueIn} / {@link when.oneOf}.
|
|
11
9
|
*/
|
|
12
|
-
export declare class ContextValueIn<R extends ContextRef
|
|
13
|
-
constructor(ref:
|
|
10
|
+
export declare class ContextValueIn<R extends ContextRef> extends Condition {
|
|
11
|
+
constructor(ref: R, value: ConditionOperand<R>[]);
|
|
14
12
|
}
|
|
15
13
|
/** Функциональная форма {@link ContextValueIn}. */
|
|
16
|
-
export declare function contextValueIn<R extends ContextRef
|
|
17
|
-
export {};
|
|
14
|
+
export declare function contextValueIn<R extends ContextRef>(ref: R, value: ConditionOperand<R>[]): ContextValueIn<R>;
|
|
@@ -7,8 +7,8 @@ import { ConditionOperand } from "./condition-operand";
|
|
|
7
7
|
*
|
|
8
8
|
* @internal Используйте {@link contextValueNotEqual} / {@link when.notEquals}.
|
|
9
9
|
*/
|
|
10
|
-
export declare class ContextValueNotEqual<R extends ContextRef
|
|
10
|
+
export declare class ContextValueNotEqual<R extends ContextRef> extends Condition {
|
|
11
11
|
constructor(ref: R, value: ConditionOperand<R>);
|
|
12
12
|
}
|
|
13
13
|
/** Функциональная форма {@link ContextValueNotEqual}. */
|
|
14
|
-
export declare function contextValueNotEqual<R extends ContextRef
|
|
14
|
+
export declare function contextValueNotEqual<R extends ContextRef>(ref: R, value: ConditionOperand<R>): ContextValueNotEqual<R>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { JsonObject } from "@matreshka/shared/types/json";
|
|
2
2
|
import { Paths, PathValue } from "ts-essentials";
|
|
3
3
|
import { Context } from "./context";
|
|
4
|
-
export type ContextRefValue<R extends ContextRef
|
|
4
|
+
export type ContextRefValue<R extends ContextRef> = R extends {
|
|
5
5
|
readonly __valueType?: infer ValueType;
|
|
6
6
|
} ? Exclude<ValueType, undefined> : R extends ContextRef<infer ContextType, infer PathType> ? PathValue<ContextType, PathType> : never;
|
|
7
|
-
export declare class ContextRef<ContextType extends JsonObject =
|
|
7
|
+
export declare class ContextRef<ContextType extends JsonObject = JsonObject, PathType extends string = string> {
|
|
8
8
|
readonly context: Context<any>;
|
|
9
9
|
readonly path: PathType;
|
|
10
10
|
constructor(context: Context<any>, path: PathType);
|
|
@@ -43,6 +43,11 @@ export declare class ContextRef<ContextType extends JsonObject = any, PathType e
|
|
|
43
43
|
*/
|
|
44
44
|
strictRef<OtherContextType extends JsonObject, OtherPathType extends Paths<OtherContextType>>(other: ContextRef<OtherContextType, OtherPathType>): ContextRef<ContextType, `${PathType}.${PathValue<OtherContextType, OtherPathType> & string}`>;
|
|
45
45
|
value(): PathValue<ContextType, PathType>;
|
|
46
|
+
/**
|
|
47
|
+
* Запись значения по текущему пути через {@link Context.setValue}.
|
|
48
|
+
* Если контекст уже уничтожен, вызов игнорируется (без исключения).
|
|
49
|
+
*/
|
|
50
|
+
setValue(value: PathValue<ContextType, PathType>): void;
|
|
46
51
|
toString(): string;
|
|
47
52
|
toJSON(): string;
|
|
48
53
|
}
|
|
@@ -47,6 +47,16 @@ class ContextRef {
|
|
|
47
47
|
// Явно выбираем перегрузку Context.value(string): unknown и приводим к ожидаемому типу
|
|
48
48
|
return this.context.value(this.path);
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Запись значения по текущему пути через {@link Context.setValue}.
|
|
52
|
+
* Если контекст уже уничтожен, вызов игнорируется (без исключения).
|
|
53
|
+
*/
|
|
54
|
+
setValue(value) {
|
|
55
|
+
if (this.context.isDestroyed()) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.context.setValue(this.path, value);
|
|
59
|
+
}
|
|
50
60
|
toString() {
|
|
51
61
|
return `@{${this.context.id}.${this.path}}`;
|
|
52
62
|
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -27,7 +27,6 @@ export * from "./types/componentable";
|
|
|
27
27
|
export * from "./types/context-value-ref";
|
|
28
28
|
export * from "./types/message";
|
|
29
29
|
export * from "./types/mixed-with-callbacks-array";
|
|
30
|
-
export * from "./types/native-picker-context-ref";
|
|
31
30
|
export * from "./types/pageable";
|
|
32
31
|
export * from "./types/standalone-component";
|
|
33
32
|
export * from "./types/status-code";
|
package/dist/core/index.js
CHANGED
|
@@ -43,7 +43,6 @@ __exportStar(require("./types/componentable"), exports);
|
|
|
43
43
|
__exportStar(require("./types/context-value-ref"), exports);
|
|
44
44
|
__exportStar(require("./types/message"), exports);
|
|
45
45
|
__exportStar(require("./types/mixed-with-callbacks-array"), exports);
|
|
46
|
-
__exportStar(require("./types/native-picker-context-ref"), exports);
|
|
47
46
|
__exportStar(require("./types/pageable"), exports);
|
|
48
47
|
__exportStar(require("./types/standalone-component"), exports);
|
|
49
48
|
__exportStar(require("./types/status-code"), exports);
|
|
@@ -18,11 +18,12 @@ import { ContextRef, ContextRefValue } from "../context/context-ref";
|
|
|
18
18
|
export type ContextValueRef<ValueType> = ContextRef<any, any> & {
|
|
19
19
|
readonly __valueType?: ValueType;
|
|
20
20
|
value(): ValueType;
|
|
21
|
+
setValue(value: ValueType): void;
|
|
21
22
|
};
|
|
22
23
|
/**
|
|
23
24
|
* Ref `R` совместим с ожидаемым типом значения `ValueType` (проверка на call site).
|
|
24
25
|
*/
|
|
25
|
-
export type CompatibleContextValueRef<ValueType, R extends ContextRef
|
|
26
|
+
export type CompatibleContextValueRef<ValueType, R extends ContextRef> = ValueType extends ContextRefValue<R> ? R : never;
|
|
26
27
|
/**
|
|
27
28
|
* Ссылка на массив элементов в контексте (`ItemType[] | undefined`).
|
|
28
29
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matreshka/bff",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
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",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vitest": "^4.1.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@matreshka/shared": "^0.
|
|
65
|
+
"@matreshka/shared": "^0.13.0",
|
|
66
66
|
"@simplewebauthn/server": "^13.1.1",
|
|
67
67
|
"@simplewebauthn/types": "^12.0.0",
|
|
68
68
|
"fast-xml-parser": "^5.3.3",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { JsonPrimitive } from "@matreshka/shared/types/json";
|
|
2
|
-
import { ContextRef, ContextRefValue } from "../context/context-ref";
|
|
3
|
-
export type ContextRefPrimitiveValue<R extends ContextRef<any, any>> = R extends {
|
|
4
|
-
readonly __valueType?: infer ValueType;
|
|
5
|
-
} ? Extract<ValueType, JsonPrimitive> : Extract<ContextRefValue<R>, JsonPrimitive>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { JsonPrimitive } from "@matreshka/shared/types/json";
|
|
2
|
-
import { ContextRef } from "../context/context-ref";
|
|
3
|
-
import { CompatibleContextValueRef } from "./context-value-ref";
|
|
4
|
-
/**
|
|
5
|
-
* Ссылка на поле контекста, тип значения которого совместим с `ValueType`
|
|
6
|
-
* для соответствующего native picker.
|
|
7
|
-
*/
|
|
8
|
-
export type NativePickerContextRef<ValueType extends JsonPrimitive, R extends ContextRef<any, any> = ContextRef<any, any>> = CompatibleContextValueRef<ValueType, R>;
|