@olovyannikov/effector-models 1.0.0-alpha.2 → 1.0.0-alpha.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0-alpha.3
4
+
5
+ ### Added
6
+
7
+ - **Aliases in the core.** Every model has `$aliases`, `alias` and `unalias`.
8
+ `update`, `upsert`, `delete`, `rename` and instance events accept an alias
9
+ wherever they accept an id; so do `useInstance`, `useInstanceEvents`,
10
+ `useChildIds`, `useChildren` and `useUnionInstance`.
11
+ - **Facts**: `model.deleted` (real ids of the deleted instances followed by
12
+ their aliases) and `model.renamed` (`{ from, to }` with the real `from`).
13
+ They fire only when something was actually deleted or moved.
14
+ - Relations see through aliases: a child or a reference that stores an alias
15
+ of its target is cascaded and cleaned up like one that stores the real id.
16
+ `$idsByParent` is always keyed by the real parent id.
17
+ - `union.$aliases`; `Child` has a `parent` field.
18
+
19
+ ### Changed
20
+
21
+ - `upsert` with an alias id extends the aliased instance instead of creating
22
+ a new one. `create` still displaces the alias.
23
+ - `rename` to the instance's own id is a no-op. It used to delete the
24
+ instance.
25
+ - `ModelLike` also requires `$aliases`, `deleted` and `renamed`.
26
+ - `useUnionInstance` returns the real id when the reference holds an alias.
27
+
28
+ ### Deprecated
29
+
30
+ - `aliases(model)` is a thin wrapper over the model now: `add` is
31
+ `model.alias`, `remove` is `model.unalias`, `resolved(event)` returns the
32
+ event itself. The sid of the alias store did not change, so serialized
33
+ state from alpha.2 hydrates as is.
34
+
3
35
  ## 1.0.0-alpha.2
4
36
 
5
37
  ### Added
package/README.md CHANGED
@@ -16,7 +16,7 @@ Fork of [`@effector-kit/models`](https://github.com/movpushmov/effector-kit) by
16
16
  | Write to missing instance | silent `Promise.reject` | ignored and reported via `missed` |
17
17
  | React `useModel(lens)` | re-renders on any instance change, new object every render | subscribed to its own instance, stable reference, selector |
18
18
 
19
- `child`, `ref` and `union` are available as [relations](#relations) between models: plain data plus integrity rules. Aliases are an opt-in helper, [`aliases`](#aliases--one-instance-several-ids). Not carried over: `fn` with arbitrary graphs inside an instance — side effects stay outside, as usual in Effector.
19
+ `child`, `ref` and `union` are available as [relations](#relations) between models: plain data plus integrity rules. Aliases are built into the model: see [aliases](#aliases--one-instance-several-ids). Not carried over: `fn` with arbitrary graphs inside an instance — side effects stay outside, as usual in Effector.
20
20
 
21
21
  Documentation, a step-by-step tutorial and live examples: <https://olovyannikov.github.io/effector-kit/guide/keyed-models> (also in Russian).
22
22
 
@@ -59,18 +59,23 @@ A reducer returning the same object means "nothing changed": no store update, no
59
59
 
60
60
  ## API
61
61
 
62
- | Unit | Payload | Behaviour |
63
- | --------------- | -------------------------------------------------- | ---------------------------------------------------------- |
64
- | `$instances` | — | `Record<id, State>`, writable, has sid |
65
- | `$ids` | — | `string[]` |
66
- | `create` | `{ id, data? }` or array | creates with defaults; replaces existing id |
67
- | `upsert` | `{ id, data? }` or array | merges into existing or creates with defaults |
68
- | `update` | `{ id, data: Partial<State> \| (state) => State }` | existing only |
69
- | `delete` | `id` or `id[]` | |
70
- | `rename` | `{ from, to }` | moves instance in one step (e.g. draft → created document) |
71
- | `clear` | — | |
72
- | `events.<name>` | `{ id \| id[], payload }` | applies reducer synchronously |
73
- | `missed` | `{ action, ids }` | writes addressed to instances that do not exist |
62
+ | Unit | Payload | Behaviour |
63
+ | --------------- | -------------------------------------------------- | --------------------------------------------------------------------------------- |
64
+ | `$instances` | — | `Record<id, State>`, writable, has sid |
65
+ | `$ids` | — | `string[]` |
66
+ | `create` | `{ id, data? }` or array | creates with defaults; replaces existing id |
67
+ | `upsert` | `{ id, data? }` or array | merges into existing or creates with defaults |
68
+ | `update` | `{ id, data: Partial<State> \| (state) => State }` | existing only |
69
+ | `delete` | `id` or `id[]` | |
70
+ | `rename` | `{ from, to }` | moves instance in one step (e.g. draft → created document) |
71
+ | `clear` | — | |
72
+ | `events.<name>` | `{ id \| id[], payload }` | applies reducer synchronously |
73
+ | `missed` | `{ action, ids }` | writes addressed to instances that do not exist |
74
+ | `deleted` | `string[]` | fact: real ids of deleted instances, then their aliases |
75
+ | `renamed` | `{ from, to }` | fact: the instance moved, `from` is the real id |
76
+ | `$aliases` | — | `Record<alias, id>`, has a sid; see [aliases](#aliases--one-instance-several-ids) |
77
+ | `alias` | `{ alias, id }` or an array | adds aliases to existing instances |
78
+ | `unalias` | `alias` or `alias[]` | removes aliases, instances stay |
74
79
 
75
80
  ```ts
76
81
  sample({
@@ -175,29 +180,48 @@ const Bookings = model({
175
180
  ref({ from: Bookings, field: 'passengers', to: passengers });
176
181
  ```
177
182
 
178
- ### `aliases` — one instance, several ids
183
+ ### Aliases — one instance, several ids
179
184
 
180
- For the case when an instance must stay reachable by another id — a route id next to the server id. The instance is still stored once; aliases live in a separate store that follows the life of instances.
185
+ One instance reachable by several ids — a route id next to the server id.
186
+ The instance is still stored once; aliases live in the model, in `$aliases`,
187
+ and follow the life of instances.
181
188
 
182
189
  ```ts
183
- import { aliases } from '@olovyannikov/effector-models';
190
+ Chats.alias({ alias: 'route-id', id: 'server-id' });
191
+ Chats.$aliases; // Store<Record<alias, id>>, has a sid
184
192
 
185
- const chatAliases = aliases(Chats);
193
+ // Everything that takes an id takes an alias.
194
+ Chats.events.renamed({ id: 'route-id', payload: 'New title' });
195
+ Chats.update({ id: 'route-id', data: { title: 'New title' } });
196
+ Chats.delete('route-id');
186
197
 
187
- chatAliases.add({ alias: 'route-id', id: 'server-id' });
188
- chatAliases.$aliases; // Store<Record<alias, id>>, has a sid
189
-
190
- // An event that accepts aliases and writes to the real instance.
191
- const renamed = chatAliases.resolved(Chats.events.renamed);
198
+ Chats.unalias('route-id'); // the instance stays
199
+ ```
192
200
 
193
- renamed({ id: 'route-id', payload: 'New title' });
201
+ ```tsx
202
+ const chat = useInstance(Chats, routeId);
203
+ const { renamed } = useInstanceEvents(Chats, routeId);
204
+ const messageIds = useChildIds(messages, routeId);
194
205
  ```
195
206
 
207
+ - `update`, `upsert`, `delete`, `rename`, instance events and all hooks
208
+ resolve aliases; `create` does not — an instance created with the id of an
209
+ alias displaces the alias, a real id always wins
196
210
  - deleting or clearing instances removes their aliases, `rename` moves them
197
- - an instance created with the id of an alias displaces the alias: a real id always wins
198
- - an alias to a missing instance is not created
211
+ - an alias to a missing instance, or with the id of an existing one, is not
212
+ created
213
+ - relations see through aliases: a child or a reference may store an alias
214
+ of its target and is still cascaded and cleaned up
215
+ - `unalias` does not touch references that store the alias — keep real ids
216
+ in data when you can; `useResolvedId(model, id)` and
217
+ `resolveAlias(aliases, id)` give the real id
218
+
219
+ To react to changes, subscribe to the facts instead of the commands:
220
+ `model.deleted` carries the real ids of deleted instances followed by their
221
+ aliases, `model.renamed` carries `{ from, to }` with the real `from`.
199
222
 
200
- Use `rename` when an instance simply moves to a new id, and `aliases` when both ids must keep working.
223
+ Use `rename` when an instance simply moves to a new id, and aliases when
224
+ both ids must keep working.
201
225
 
202
226
  ## React
203
227
 
@@ -218,12 +242,12 @@ const Slides = () =>
218
242
  useInstanceIds(SlideModel).map(id => <Slide key={id} id={id} />);
219
243
  ```
220
244
 
221
- - `useInstance(model, id)` — instance or `undefined`; `useInstance(model, id, selector, isEqual?)` — selected value. Pass a stable selector to avoid re-subscribing.
245
+ - `useInstance(model, id)` — instance or `undefined`, `id` may be an alias; `useInstance(model, id, selector, isEqual?)` — selected value. Pass a stable selector to avoid re-subscribing.
222
246
  - `useInstanceIds(model)` — re-renders only when the set or order of ids changes.
223
247
  - `useInstanceEvents(model, id)` — instance events bound to the id and to the scope from `Provider`.
224
248
  - `useChildIds(relation, parentId)` — ids of the children of one parent; re-renders only when their set or order changes.
225
249
  - `useChildren(relation, parentId)` — the children themselves; `useChildren(relation, parentId, selector, isEqual?)` — an aggregate over them (a total, a counter) that re-renders only when the selected value changes.
226
- - `useResolvedId(aliases, id)` — the real id for an id that may be an alias: `useInstance(Chats, useResolvedId(chatAliases, routeId))`.
250
+ - `useResolvedId(model, id)` — the real id for an id that may be an alias. The other hooks resolve aliases themselves; use it when the real id is needed as data, for example as a `key`.
227
251
  - `useUnionInstance(union, { kind, id })` — `{ kind, id, state }` or `undefined`; `kind` narrows the type of `state`.
228
252
 
229
253
  ## Releasing
package/dist/index.cjs CHANGED
@@ -1,172 +1,27 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_aliases = require("./aliases-BuDSaLvV.cjs");
2
+ const require_model = require("./model-iPgSwajA.cjs");
3
3
  let effector = require("effector");
4
- // lib/model.ts
5
- const toList$1 = (ids) => typeof ids === "string" ? [ids] : ids;
6
- const toArray = (value) => Array.isArray(value) ? value : [value];
7
- function applyTo(instances, ids, fn) {
8
- let next = instances;
9
- const missing = [];
10
- for (const id of toList$1(ids)) {
11
- const current = instances[id];
12
- if (current === void 0) {
13
- missing.push(id);
14
- continue;
15
- }
16
- const updated = fn(current);
17
- if (updated !== current) {
18
- if (next === instances) next = { ...instances };
19
- next[id] = updated;
20
- }
21
- }
22
- return {
23
- instances: next,
24
- missing
25
- };
26
- }
27
- function model(config) {
28
- const { name, defaults } = config;
29
- const reducers = config.events ?? {};
30
- const $instances = (0, effector.createStore)({}, {
31
- sid: `effector-models:${name}`,
32
- name: `${name}/$instances`
33
- });
34
- const $ids = $instances.map((instances) => Object.keys(instances));
35
- const missed = (0, effector.createEvent)({ name: `${name}/missed` });
36
- const applied = (0, effector.createEvent)();
37
- (0, effector.sample)({
38
- clock: applied,
39
- source: $instances,
40
- filter: (instances, result) => result.instances !== instances,
41
- fn: (_, { instances }) => instances,
42
- target: $instances
43
- });
44
- (0, effector.sample)({
45
- clock: applied,
46
- filter: ({ missing }) => missing.length > 0,
47
- fn: ({ action, missing }) => ({
48
- action,
49
- ids: missing
50
- }),
51
- target: missed
52
- });
53
- const create = (0, effector.createEvent)({ name: `${name}/create` });
54
- (0, effector.sample)({
55
- clock: create,
56
- source: $instances,
57
- fn: (instances, params) => {
58
- const next = { ...instances };
59
- for (const { id, data } of toArray(params)) next[id] = {
60
- ...defaults,
61
- ...data
62
- };
63
- return next;
64
- },
65
- target: $instances
66
- });
67
- const upsert = (0, effector.createEvent)({ name: `${name}/upsert` });
68
- (0, effector.sample)({
69
- clock: upsert,
70
- source: $instances,
71
- fn: (instances, params) => {
72
- const next = { ...instances };
73
- for (const { id, data } of toArray(params)) next[id] = {
74
- ...next[id] ?? defaults,
75
- ...data
76
- };
77
- return next;
78
- },
79
- target: $instances
80
- });
81
- const update = (0, effector.createEvent)({ name: `${name}/update` });
82
- (0, effector.sample)({
83
- clock: update,
84
- source: $instances,
85
- fn: (instances, { id, data }) => ({
86
- action: "update",
87
- ...applyTo(instances, id, (state) => typeof data === "function" ? data(state) : {
88
- ...state,
89
- ...data
90
- })
91
- }),
92
- target: applied
93
- });
94
- const remove = (0, effector.createEvent)({ name: `${name}/delete` });
95
- (0, effector.sample)({
96
- clock: remove,
97
- source: $instances,
98
- filter: (instances, ids) => toList$1(ids).some((id) => id in instances),
99
- fn: (instances, ids) => {
100
- const next = { ...instances };
101
- for (const id of toList$1(ids)) delete next[id];
102
- return next;
103
- },
104
- target: $instances
105
- });
106
- const rename = (0, effector.createEvent)({ name: `${name}/rename` });
107
- (0, effector.sample)({
108
- clock: rename,
109
- source: $instances,
110
- fn: (instances, { from, to }) => {
111
- const current = instances[from];
112
- if (current === void 0) return {
113
- action: "rename",
114
- instances,
115
- missing: [from]
116
- };
117
- const next = {
118
- ...instances,
119
- [to]: current
120
- };
121
- delete next[from];
122
- return {
123
- action: "rename",
124
- instances: next,
125
- missing: []
126
- };
127
- },
128
- target: applied
129
- });
130
- const clear = (0, effector.createEvent)({ name: `${name}/clear` });
131
- (0, effector.sample)({
132
- clock: clear,
133
- fn: () => ({}),
134
- target: $instances
135
- });
136
- const events = {};
137
- for (const [action, reducer] of Object.entries(reducers)) {
138
- const event = (0, effector.createEvent)({ name: `${name}/${action}` });
139
- (0, effector.sample)({
140
- clock: event,
141
- source: $instances,
142
- fn: (instances, { id, payload }) => ({
143
- action,
144
- ...applyTo(instances, id, (state) => reducer(state, payload))
145
- }),
146
- target: applied
147
- });
148
- events[action] = event;
149
- }
4
+ // lib/aliases.ts
5
+ /**
6
+ * @deprecated Алиасы встроены в модель: `model.$aliases`, `model.alias`, `model.unalias`,
7
+ * а события и хуки принимают алиас вместо id. Обёртка оставлена для кода, написанного под alpha.2.
8
+ */ function aliases(model) {
150
9
  return {
151
- name,
152
- defaults,
153
- $instances,
154
- $ids,
155
- create,
156
- upsert,
157
- update,
158
- delete: remove,
159
- rename,
160
- clear,
161
- events,
162
- missed
10
+ $aliases: model.$aliases,
11
+ add: model.alias,
12
+ remove: model.unalias,
13
+ resolved: (target) => target
163
14
  };
164
15
  }
165
16
  // lib/relations.ts
166
- const toList = (ids) => typeof ids === "string" ? [ids] : ids;
167
17
  /** Несколько моделей как одна коллекция: экземпляр адресуется парой `{ kind, id }`. */ function union(models) {
168
18
  const stores = {};
169
- for (const [kind, member] of Object.entries(models)) stores[kind] = member.$instances;
19
+ const aliasStores = {};
20
+ for (const [kind, member] of Object.entries(models)) {
21
+ stores[kind] = member.$instances;
22
+ aliasStores[kind] = member.$aliases;
23
+ }
24
+ const $aliases = (0, effector.combine)(aliasStores);
170
25
  const $instances = (0, effector.combine)(stores);
171
26
  const remove = (0, effector.createEvent)();
172
27
  const create = (0, effector.createEvent)();
@@ -199,6 +54,7 @@ const toList = (ids) => typeof ids === "string" ? [ids] : ids;
199
54
  "~kind": "union",
200
55
  models,
201
56
  $instances,
57
+ $aliases,
202
58
  create,
203
59
  upsert,
204
60
  delete: remove
@@ -213,11 +69,11 @@ function isUnion(value) {
213
69
  */ function child(config) {
214
70
  const { parent, model, key } = config;
215
71
  const parentOf = (state) => state[key];
216
- const $idsByParent = model.$instances.map((instances) => {
72
+ const $idsByParent = (0, effector.combine)(model.$instances, parent.$aliases, (instances, aliases) => {
217
73
  const index = {};
218
74
  for (const [id, state] of Object.entries(instances)) {
219
75
  const parentId = parentOf(state);
220
- if (typeof parentId === "string") (index[parentId] ??= []).push(id);
76
+ if (typeof parentId === "string") (index[require_model.resolveAlias(aliases, parentId)] ??= []).push(id);
221
77
  }
222
78
  return index;
223
79
  });
@@ -240,10 +96,10 @@ function isUnion(value) {
240
96
  return [...found];
241
97
  };
242
98
  (0, effector.sample)({
243
- clock: parent.delete,
99
+ clock: parent.deleted,
244
100
  source: model.$instances,
245
- filter: (instances, ids) => descendantsOf(instances, toList(ids)).length > 0,
246
- fn: (instances, ids) => descendantsOf(instances, toList(ids)),
101
+ filter: (instances, ids) => descendantsOf(instances, ids).length > 0,
102
+ fn: (instances, ids) => descendantsOf(instances, ids),
247
103
  target: model.delete
248
104
  });
249
105
  if (!isTree) (0, effector.sample)({
@@ -254,7 +110,7 @@ function isUnion(value) {
254
110
  target: model.delete
255
111
  });
256
112
  (0, effector.sample)({
257
- clock: parent.rename,
113
+ clock: parent.renamed,
258
114
  source: model.$instances,
259
115
  filter: (instances, { from }) => childrenOf(instances, (parentId) => parentId === from).length > 0,
260
116
  fn: (instances, { from, to }) => ({
@@ -265,19 +121,17 @@ function isUnion(value) {
265
121
  });
266
122
  return {
267
123
  model,
124
+ parent: { $aliases: parent.$aliases },
268
125
  $idsByParent
269
126
  };
270
127
  }
271
128
  function modelSignals(target, wrap, read) {
272
129
  return {
273
- removed: (0, effector.merge)([target.delete.map((ids) => {
274
- const deleted = toList(ids);
275
- return (item) => {
276
- const id = read(item);
277
- return id !== void 0 && deleted.includes(id);
278
- };
130
+ removed: (0, effector.merge)([target.deleted.map((deleted) => (item) => {
131
+ const id = read(item);
132
+ return id !== void 0 && deleted.includes(id);
279
133
  }), target.clear.map(() => (item) => read(item) !== void 0)]),
280
- replaced: target.rename.map(({ from, to }) => (item) => read(item) === from ? wrap(to) : item)
134
+ replaced: target.renamed.map(({ from, to }) => (item) => read(item) === from ? wrap(to) : item)
281
135
  };
282
136
  }
283
137
  function targetSignals(target) {
@@ -335,9 +189,9 @@ function targetSignals(target) {
335
189
  target: from.$instances
336
190
  });
337
191
  }
338
- exports.aliases = require_aliases.aliases;
192
+ exports.aliases = aliases;
339
193
  exports.child = child;
340
- exports.model = model;
194
+ exports.model = require_model.model;
341
195
  exports.ref = ref;
342
- exports.resolveAlias = require_aliases.resolveAlias;
196
+ exports.resolveAlias = require_model.resolveAlias;
343
197
  exports.union = union;
package/dist/index.d.cts CHANGED
@@ -1,2 +1,21 @@
1
- import { C as Model, D as RenameParams, E as Reducers, O as UpdateParams, S as Missed, T as Reducer, _ as resolveAlias, a as Union, b as InstanceEventParams, c as UnionModels, d as ref, f as union, g as aliases, h as Aliases, i as RefConfig, k as model, l as UnionRef, m as AliasTarget, n as ChildConfig, o as UnionCreateParams, p as AliasParams, r as ModelLike, s as UnionInstances, t as Child, u as child, v as CreateParams, w as ModelConfig, x as Instances, y as Ids } from "./relations-iG_ubcG7.cjs";
2
- export { type AliasParams, type AliasTarget, type Aliases, type Child, type ChildConfig, type CreateParams, type Ids, type InstanceEventParams, type Instances, type Missed, type Model, type ModelConfig, type ModelLike, type Reducer, type Reducers, type RefConfig, type RenameParams, type Union, type UnionCreateParams, type UnionInstances, type UnionModels, type UnionRef, type UpdateParams, aliases, child, model, ref, resolveAlias, union };
1
+ import { EventCallable, Store } from "effector";
2
+ import { C as RenameParams, E as resolveAlias, S as Reducers, T as model, _ as Instances, a as Union, b as ModelConfig, c as UnionModels, d as ref, f as union, g as InstanceEventParams, h as Ids, i as RefConfig, l as UnionRef, m as CreateParams, n as ChildConfig, o as UnionCreateParams, p as AliasParams, r as ModelLike, s as UnionInstances, t as Child, u as child, v as Missed, w as UpdateParams, x as Reducer, y as Model } from "./relations-DXJ6slzh.cjs";
3
+ /** Часть модели, нужная алиасам. */
4
+ type AliasTarget = Pick<Model<object, Record<never, unknown>>, "$aliases" | "alias" | "unalias">;
5
+ interface Aliases {
6
+ /** Алиас → настоящий id экземпляра. */
7
+ readonly $aliases: Store<Record<string, string>>;
8
+ readonly add: EventCallable<AliasParams | AliasParams[]>;
9
+ readonly remove: EventCallable<Ids>;
10
+ /** Возвращает то же событие: события модели сами принимают алиасы. */
11
+ readonly resolved: <Params extends {
12
+ id: Ids;
13
+ }>(target: EventCallable<Params>) => EventCallable<Params>;
14
+ }
15
+ /**
16
+ * @deprecated Алиасы встроены в модель: `model.$aliases`, `model.alias`, `model.unalias`,
17
+ * а события и хуки принимают алиас вместо id. Обёртка оставлена для кода, написанного под alpha.2.
18
+ */
19
+ export declare function aliases(model: AliasTarget): Aliases;
20
+ export { type AliasParams, type AliasTarget, type Aliases, type Child, type ChildConfig, type CreateParams, type Ids, type InstanceEventParams, type Instances, type Missed, type Model, type ModelConfig, type ModelLike, type Reducer, type Reducers, type RefConfig, type RenameParams, type Union, type UnionCreateParams, type UnionInstances, type UnionModels, type UnionRef, type UpdateParams, child, model, ref, resolveAlias, union };
21
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../lib/aliases.ts"],"mappings":";;;KAKY,cAAc,KACxB,cAAc;UAIC;;WAEN,UAAU,MAAM;WAChB,KAAK,cAAc,cAAc;WACjC,QAAQ,cAAc;;WAEtB,WAAW;IAAiB,IAAI;KACvC,QAAQ,cAAc,YACnB,cAAc;;;;;;wBAOL,QAAQ,OAAO,cAAc"}
package/dist/index.d.mts CHANGED
@@ -1,2 +1,21 @@
1
- import { C as Model, D as RenameParams, E as Reducers, O as UpdateParams, S as Missed, T as Reducer, _ as resolveAlias, a as Union, b as InstanceEventParams, c as UnionModels, d as ref, f as union, g as aliases, h as Aliases, i as RefConfig, k as model, l as UnionRef, m as AliasTarget, n as ChildConfig, o as UnionCreateParams, p as AliasParams, r as ModelLike, s as UnionInstances, t as Child, u as child, v as CreateParams, w as ModelConfig, x as Instances, y as Ids } from "./relations-CwzpTh9E.mjs";
2
- export { type AliasParams, type AliasTarget, type Aliases, type Child, type ChildConfig, type CreateParams, type Ids, type InstanceEventParams, type Instances, type Missed, type Model, type ModelConfig, type ModelLike, type Reducer, type Reducers, type RefConfig, type RenameParams, type Union, type UnionCreateParams, type UnionInstances, type UnionModels, type UnionRef, type UpdateParams, aliases, child, model, ref, resolveAlias, union };
1
+ import { EventCallable, Store } from "effector";
2
+ import { C as RenameParams, E as resolveAlias, S as Reducers, T as model, _ as Instances, a as Union, b as ModelConfig, c as UnionModels, d as ref, f as union, g as InstanceEventParams, h as Ids, i as RefConfig, l as UnionRef, m as CreateParams, n as ChildConfig, o as UnionCreateParams, p as AliasParams, r as ModelLike, s as UnionInstances, t as Child, u as child, v as Missed, w as UpdateParams, x as Reducer, y as Model } from "./relations-Cc9Mv0m7.mjs";
3
+ /** Часть модели, нужная алиасам. */
4
+ type AliasTarget = Pick<Model<object, Record<never, unknown>>, "$aliases" | "alias" | "unalias">;
5
+ interface Aliases {
6
+ /** Алиас → настоящий id экземпляра. */
7
+ readonly $aliases: Store<Record<string, string>>;
8
+ readonly add: EventCallable<AliasParams | AliasParams[]>;
9
+ readonly remove: EventCallable<Ids>;
10
+ /** Возвращает то же событие: события модели сами принимают алиасы. */
11
+ readonly resolved: <Params extends {
12
+ id: Ids;
13
+ }>(target: EventCallable<Params>) => EventCallable<Params>;
14
+ }
15
+ /**
16
+ * @deprecated Алиасы встроены в модель: `model.$aliases`, `model.alias`, `model.unalias`,
17
+ * а события и хуки принимают алиас вместо id. Обёртка оставлена для кода, написанного под alpha.2.
18
+ */
19
+ export declare function aliases(model: AliasTarget): Aliases;
20
+ export { type AliasParams, type AliasTarget, type Aliases, type Child, type ChildConfig, type CreateParams, type Ids, type InstanceEventParams, type Instances, type Missed, type Model, type ModelConfig, type ModelLike, type Reducer, type Reducers, type RefConfig, type RenameParams, type Union, type UnionCreateParams, type UnionInstances, type UnionModels, type UnionRef, type UpdateParams, child, model, ref, resolveAlias, union };
21
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":["EventCallable","Store","AliasParams","Ids","Model","AliasTarget","Record","Pick","Aliases","Params","aliases"],"sources":["../lib/aliases.ts"],"mappings":";;;KAKYK,cAAcE,KACxBH,cAAcE;UAICE;;WAEN,UAAUP,MAAMK;WAChB,KAAKN,cAAcE,cAAcA;WACjC,QAAQF,cAAcG;;WAEtB,WAAW;IAAiB,IAAIA;KACvC,QAAQH,cAAcS,YACnBT,cAAcS;;;;;;wBAOLC,QAAQ,OAAOL,cAAcG"}