@wszerad/items 0.1.2 → 0.2.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/README.md +377 -547
- package/dist/index.d.mts +64 -54
- package/dist/index.mjs +110 -111
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/select.d.ts
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//#region src/diff.d.ts
|
|
8
|
-
interface ItemDiff<I> {
|
|
9
|
-
id: I;
|
|
10
|
-
changes: ReturnType<typeof diff>;
|
|
3
|
+
declare class BaseSelect<E> {
|
|
4
|
+
ids: ItemId[];
|
|
5
|
+
self: Items<E>;
|
|
6
|
+
constructor(ids: ItemId[], self: Items<E>);
|
|
11
7
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
declare class SingleSelect<E> extends BaseSelect<E> {}
|
|
9
|
+
declare class Select<E> extends BaseSelect<E> {
|
|
10
|
+
take(len: number): Select<E>;
|
|
11
|
+
skip(len: number): Select<E>;
|
|
12
|
+
filter(testFn: (entry: E, id: ItemId, index: number) => boolean): Select<E>;
|
|
13
|
+
revert(): Select<E>;
|
|
14
|
+
sort(sortFn: (x: E, y: E) => number): Select<E>;
|
|
15
|
+
at(index: number): SingleSelect<E>;
|
|
16
|
+
from(entities: Iterable<E>): Select<E>;
|
|
17
|
+
on(entry: E): SingleSelect<E>;
|
|
16
18
|
}
|
|
17
19
|
//#endregion
|
|
18
|
-
//#region src/
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
type
|
|
22
|
-
|
|
23
|
-
//#region src/updater.d.ts
|
|
24
|
-
type UpdateFn<E> = (entity: E) => E;
|
|
20
|
+
//#region src/types.d.ts
|
|
21
|
+
type ItemId = string | number;
|
|
22
|
+
type CheckFn<E> = (entity: E) => boolean;
|
|
23
|
+
type Selector<E> = ((selector: Select<E>) => SingleSelect<E>) | ((selector: Select<E>) => Select<E>) | ItemId | Iterable<ItemId>;
|
|
24
|
+
type UpdateFn<E> = (entity: E | undefined) => E;
|
|
25
25
|
type Updater<E> = UpdateFn<E> | Partial<E>;
|
|
26
|
-
|
|
27
|
-
//#region src/Items.d.ts
|
|
26
|
+
type SelectId<E> = (entity: E) => ItemId;
|
|
28
27
|
type ItemsOptions<E> = {
|
|
29
28
|
selectId?: SelectId<E>;
|
|
30
29
|
sortComparer?: false | ((a: E, b: E) => number);
|
|
@@ -33,45 +32,56 @@ interface ItemsState<E, I> {
|
|
|
33
32
|
ids: I[];
|
|
34
33
|
entities: Map<I, E>;
|
|
35
34
|
}
|
|
36
|
-
|
|
35
|
+
interface ItemDiff {
|
|
36
|
+
id: ItemId;
|
|
37
|
+
changes: any[];
|
|
38
|
+
}
|
|
39
|
+
interface ItemsDiff {
|
|
40
|
+
added: ItemId[];
|
|
41
|
+
removed: ItemId[];
|
|
42
|
+
updated: ItemDiff[];
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/Items.d.ts
|
|
46
|
+
declare class Items<E> {
|
|
37
47
|
private options;
|
|
38
48
|
private state;
|
|
39
49
|
constructor(items?: Iterable<E>, options?: ItemsOptions<E>);
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
add(items: Iterable<E>): Items<E>;
|
|
51
|
+
update(select: Selector<E>, updater: Updater<E>): Items<E>;
|
|
52
|
+
merge(items: Iterable<E>): Items<E>;
|
|
53
|
+
remove(select: Selector<E>): Items<E>;
|
|
54
|
+
pick(select: Selector<E>): Items<E>;
|
|
55
|
+
select(select: ItemId): E | undefined;
|
|
56
|
+
select(select: Iterable<ItemId>): E[];
|
|
57
|
+
select(select: (selector: Select<E>) => Select<E>): E[];
|
|
58
|
+
select(select: (selector: Select<E>) => SingleSelect<E>): E | undefined;
|
|
59
|
+
selectId(select: (selector: Select<E>) => Select<E>): ItemId[];
|
|
60
|
+
selectId(select: (selector: Select<E>) => SingleSelect<E>): ItemId | undefined;
|
|
61
|
+
clear(): Items<E>;
|
|
62
|
+
every(check: CheckFn<E>): boolean;
|
|
63
|
+
some(check: CheckFn<E>): boolean;
|
|
64
|
+
has(id: ItemId): boolean;
|
|
65
|
+
get(id: ItemId): E | undefined;
|
|
66
|
+
getIds(): ItemId[];
|
|
67
|
+
getEntities(): E[];
|
|
42
68
|
get length(): number;
|
|
43
|
-
|
|
44
|
-
insert(entity: E): Items<E, I>;
|
|
45
|
-
insertMany(entities: Iterable<E>): Items<E, I>;
|
|
46
|
-
upsert(entity: Partial<E>): Items<E, I>;
|
|
47
|
-
upsertMany(entities: Iterable<Partial<E>>): Items<E, I>;
|
|
48
|
-
set(entity: E): Items<E, I>;
|
|
49
|
-
setMany(entities: Iterable<E>): Items<E, I>;
|
|
50
|
-
every(check: SelectorFn<E>): boolean;
|
|
51
|
-
some(check: SelectorFn<E>): boolean;
|
|
52
|
-
has(id: I): boolean;
|
|
53
|
-
hasMany(select: Selector<E, I>): boolean;
|
|
54
|
-
update(id: I, updater: Updater<E>): Items<E, I>;
|
|
55
|
-
updateMany(select: Selector<E, I>, updater: Updater<E>): Items<E, I>;
|
|
56
|
-
remove(id: I): Items<E, I>;
|
|
57
|
-
removeMany(select: Selector<E, I>): Items<E, I>;
|
|
58
|
-
clear(): Items<E, I>;
|
|
59
|
-
filter(select: Selector<E, I>): Items<E, I>;
|
|
60
|
-
page(page: number, pageSize: number): {
|
|
61
|
-
items: NonNullable<E>[];
|
|
62
|
-
page: number;
|
|
63
|
-
pageSize: number;
|
|
64
|
-
hasNext: boolean;
|
|
65
|
-
hasPrevious: boolean;
|
|
66
|
-
total: number;
|
|
67
|
-
totalPages: number;
|
|
68
|
-
};
|
|
69
|
-
diff(base: Items<E, I>): ItemsDiff<I>;
|
|
69
|
+
private resolveSelector;
|
|
70
70
|
private sortIds;
|
|
71
|
-
|
|
71
|
+
extractId(entity: E): ItemId;
|
|
72
72
|
private get sortComparer();
|
|
73
73
|
[Symbol.iterator](): Iterator<E>;
|
|
74
|
+
static compare<E>(base: Items<E>, to: Items<E>): {
|
|
75
|
+
added: ItemId[];
|
|
76
|
+
removed: ItemId[];
|
|
77
|
+
updated: any[];
|
|
78
|
+
};
|
|
74
79
|
}
|
|
75
80
|
//#endregion
|
|
76
|
-
|
|
81
|
+
//#region src/utils.d.ts
|
|
82
|
+
declare function defaultSelectId<E extends {
|
|
83
|
+
id: ItemId;
|
|
84
|
+
}>(entity: E): ItemId;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { BaseSelect, type CheckFn, type ItemDiff, type ItemId, Items, type ItemsDiff, type ItemsOptions, type ItemsState, Select, type SelectId, type Selector, SingleSelect, type UpdateFn, type Updater, defaultSelectId };
|
|
77
87
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
1
|
import { diff } from "ohash/utils";
|
|
2
2
|
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/utils.ts
|
|
4
4
|
function defaultSelectId(entity) {
|
|
5
5
|
return entity.id;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
|
-
//#region src/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
9
|
+
//#region src/select.ts
|
|
10
|
+
var BaseSelect = class {
|
|
11
|
+
constructor(ids, self) {
|
|
12
|
+
this.ids = ids;
|
|
13
|
+
this.self = self;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var SingleSelect = class extends BaseSelect {};
|
|
17
|
+
var Select = class Select extends BaseSelect {
|
|
18
|
+
take(len) {
|
|
19
|
+
return new Select(this.ids.slice(0, len), this.self);
|
|
20
|
+
}
|
|
21
|
+
skip(len) {
|
|
22
|
+
return new Select(this.ids.slice(len), this.self);
|
|
23
|
+
}
|
|
24
|
+
filter(testFn) {
|
|
25
|
+
return new Select(this.ids.filter((id, index) => {
|
|
26
|
+
return testFn(this.self.get(id), id, index);
|
|
27
|
+
}), this.self);
|
|
28
|
+
}
|
|
29
|
+
revert() {
|
|
30
|
+
return new Select([...this.ids].reverse(), this.self);
|
|
31
|
+
}
|
|
32
|
+
sort(sortFn) {
|
|
33
|
+
return new Select([...this.ids].sort((aId, bId) => {
|
|
34
|
+
return sortFn(this.self.get(aId), this.self.get(bId));
|
|
35
|
+
}), this.self);
|
|
36
|
+
}
|
|
37
|
+
at(index) {
|
|
38
|
+
const id = this.ids[index];
|
|
39
|
+
return new SingleSelect([id], this.self);
|
|
40
|
+
}
|
|
41
|
+
from(entities) {
|
|
42
|
+
return new Select(Array.from(entities).map((entry) => this.self.extractId(entry)), this.self);
|
|
43
|
+
}
|
|
44
|
+
on(entry) {
|
|
45
|
+
return new SingleSelect([this.self.extractId(entry)], this.self);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
16
48
|
|
|
17
49
|
//#endregion
|
|
18
50
|
//#region src/diff.ts
|
|
@@ -39,15 +71,6 @@ function itemsDiff(fromItems, toItems) {
|
|
|
39
71
|
};
|
|
40
72
|
}
|
|
41
73
|
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region src/updater.ts
|
|
44
|
-
function update(entity, updater) {
|
|
45
|
-
return {
|
|
46
|
-
...entity,
|
|
47
|
-
...typeof updater === "function" ? updater(entity) : updater
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
74
|
//#endregion
|
|
52
75
|
//#region src/Items.ts
|
|
53
76
|
var Items = class Items {
|
|
@@ -55,121 +78,94 @@ var Items = class Items {
|
|
|
55
78
|
constructor(items = [], options = {}) {
|
|
56
79
|
this.options = options;
|
|
57
80
|
const entities = new Map(Array.from(items).map((item) => {
|
|
58
|
-
return [this.
|
|
81
|
+
return [this.extractId(item), item];
|
|
59
82
|
}));
|
|
60
83
|
this.state = {
|
|
61
84
|
ids: this.sortIds([...entities.keys()], entities),
|
|
62
85
|
entities
|
|
63
86
|
};
|
|
64
87
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
add(items) {
|
|
89
|
+
const newEntities = new Map(this.state.entities);
|
|
90
|
+
Array.from(items).forEach((item) => {
|
|
91
|
+
const id = this.extractId(item);
|
|
92
|
+
if (!newEntities.has(id)) newEntities.set(id, item);
|
|
93
|
+
});
|
|
94
|
+
return new Items(newEntities.values(), this.options);
|
|
95
|
+
}
|
|
96
|
+
update(select, updater) {
|
|
97
|
+
const [, selectedIds] = this.resolveSelector(select);
|
|
98
|
+
const newEntities = new Map(this.state.entities);
|
|
99
|
+
const isFn = typeof updater === "function";
|
|
100
|
+
selectedIds.forEach((id) => {
|
|
101
|
+
const entity = newEntities.get(id);
|
|
102
|
+
if (isFn) newEntities.set(id, updater(entity));
|
|
103
|
+
else if (entity) newEntities.set(id, {
|
|
104
|
+
...entity,
|
|
105
|
+
...updater
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return new Items(newEntities.values(), this.options);
|
|
109
|
+
}
|
|
110
|
+
merge(items) {
|
|
111
|
+
const newEntities = new Map(this.state.entities);
|
|
112
|
+
Array.from(items).forEach((item) => {
|
|
113
|
+
const id = this.extractId(item);
|
|
114
|
+
const entry = this.get(id);
|
|
115
|
+
newEntities.set(id, entry ? {
|
|
116
|
+
...entry,
|
|
117
|
+
...item
|
|
118
|
+
} : item);
|
|
119
|
+
});
|
|
120
|
+
return new Items(newEntities.values(), this.options);
|
|
76
121
|
}
|
|
77
|
-
|
|
78
|
-
|
|
122
|
+
remove(select) {
|
|
123
|
+
const [, selectedIds] = this.resolveSelector(select);
|
|
124
|
+
return new Items(this.state.ids.filter((id) => !selectedIds.includes(id)).map((id) => this.get(id)), this.options);
|
|
79
125
|
}
|
|
80
|
-
|
|
81
|
-
|
|
126
|
+
pick(select) {
|
|
127
|
+
const [, selectedIds] = this.resolveSelector(select);
|
|
128
|
+
return new Items(selectedIds.map((id) => this.get(id)), this.options);
|
|
82
129
|
}
|
|
83
|
-
|
|
84
|
-
|
|
130
|
+
select(select) {
|
|
131
|
+
const [single, selectedIds] = this.resolveSelector(select);
|
|
132
|
+
const items = selectedIds.map((id) => this.get(id)).filter(Boolean);
|
|
133
|
+
return single ? items[0] : items;
|
|
85
134
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const id = this.selectId(entity);
|
|
90
|
-
const existing = clone.get(id);
|
|
91
|
-
if (existing) clone.set(id, {
|
|
92
|
-
...existing,
|
|
93
|
-
...entity
|
|
94
|
-
});
|
|
95
|
-
else clone.set(id, entity);
|
|
96
|
-
});
|
|
97
|
-
return new Items(clone.values(), this.options);
|
|
135
|
+
selectId(select) {
|
|
136
|
+
const [single, selectedIds] = this.resolveSelector(select);
|
|
137
|
+
return single ? selectedIds[0] : selectedIds;
|
|
98
138
|
}
|
|
99
|
-
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
setMany(entities) {
|
|
103
|
-
return new Items([...this, ...entities], this.options);
|
|
139
|
+
clear() {
|
|
140
|
+
return new Items([], this.options);
|
|
104
141
|
}
|
|
105
142
|
every(check) {
|
|
106
|
-
return this.getIds().every((id) => check(this.
|
|
143
|
+
return this.getIds().every((id) => check(this.get(id)));
|
|
107
144
|
}
|
|
108
145
|
some(check) {
|
|
109
|
-
return this.getIds().some((id) => check(this.
|
|
146
|
+
return this.getIds().some((id) => check(this.get(id)));
|
|
110
147
|
}
|
|
111
148
|
has(id) {
|
|
112
149
|
return this.state.ids.includes(id);
|
|
113
150
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let result = false;
|
|
117
|
-
selector(this, select, (entity) => {
|
|
118
|
-
if (entity) result = true;
|
|
119
|
-
else failToFind = true;
|
|
120
|
-
});
|
|
121
|
-
return !failToFind && result;
|
|
122
|
-
}
|
|
123
|
-
update(id, updater) {
|
|
124
|
-
const entity = this.select(id);
|
|
125
|
-
if (!entity) return this;
|
|
126
|
-
const clone = this.getEntities();
|
|
127
|
-
clone.set(id, update(entity, updater));
|
|
128
|
-
return new Items(clone.values(), this.options);
|
|
129
|
-
}
|
|
130
|
-
updateMany(select, updater) {
|
|
131
|
-
const clone = this.getEntities();
|
|
132
|
-
selector(this, select, (entity, id) => {
|
|
133
|
-
if (entity) clone.set(id, update(entity, updater));
|
|
134
|
-
});
|
|
135
|
-
return new Items(clone.values(), this.options);
|
|
136
|
-
}
|
|
137
|
-
remove(id) {
|
|
138
|
-
const clone = this.getEntities();
|
|
139
|
-
clone.delete(id);
|
|
140
|
-
return new Items(clone.values(), this.options);
|
|
151
|
+
get(id) {
|
|
152
|
+
return this.state.entities.get(id);
|
|
141
153
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
selector(this, select, (_, id) => {
|
|
145
|
-
clone.delete(id);
|
|
146
|
-
});
|
|
147
|
-
return new Items(clone.values(), this.options);
|
|
154
|
+
getIds() {
|
|
155
|
+
return [...this.state.ids];
|
|
148
156
|
}
|
|
149
|
-
|
|
150
|
-
return
|
|
157
|
+
getEntities() {
|
|
158
|
+
return this.state.ids.map((id) => this.get(id));
|
|
151
159
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
selector(this, select, (entity, id) => {
|
|
155
|
-
if (entity) clone.set(id, entity);
|
|
156
|
-
});
|
|
157
|
-
return new Items(clone.values(), this.options);
|
|
158
|
-
}
|
|
159
|
-
page(page, pageSize) {
|
|
160
|
-
const totalPages = Math.ceil(this.length / pageSize);
|
|
161
|
-
return {
|
|
162
|
-
items: this.getIds().slice(page * pageSize, (page + 1) * pageSize).map((id) => this.select(id)),
|
|
163
|
-
page,
|
|
164
|
-
pageSize,
|
|
165
|
-
hasNext: page < totalPages - 1,
|
|
166
|
-
hasPrevious: page > 0,
|
|
167
|
-
total: this.length,
|
|
168
|
-
totalPages
|
|
169
|
-
};
|
|
160
|
+
get length() {
|
|
161
|
+
return this.state.ids.length;
|
|
170
162
|
}
|
|
171
|
-
|
|
172
|
-
|
|
163
|
+
resolveSelector(select) {
|
|
164
|
+
if (typeof select === "function") {
|
|
165
|
+
const result = select(new Select(this.state.ids, this));
|
|
166
|
+
return [result instanceof SingleSelect, result.ids];
|
|
167
|
+
} else if (typeof select === "string" || typeof select === "number") return [true, [select]];
|
|
168
|
+
else return [false, Array.from(select)];
|
|
173
169
|
}
|
|
174
170
|
sortIds(ids, entities) {
|
|
175
171
|
if (this.sortComparer === false) return ids;
|
|
@@ -178,7 +174,7 @@ var Items = class Items {
|
|
|
178
174
|
return sorter(entities.get(aId), entities.get(bId));
|
|
179
175
|
});
|
|
180
176
|
}
|
|
181
|
-
|
|
177
|
+
extractId(entity) {
|
|
182
178
|
return this.options?.selectId?.(entity) || defaultSelectId(entity);
|
|
183
179
|
}
|
|
184
180
|
get sortComparer() {
|
|
@@ -187,8 +183,11 @@ var Items = class Items {
|
|
|
187
183
|
[Symbol.iterator]() {
|
|
188
184
|
return this.state.entities.values();
|
|
189
185
|
}
|
|
186
|
+
static compare(base, to) {
|
|
187
|
+
return itemsDiff(base, to);
|
|
188
|
+
}
|
|
190
189
|
};
|
|
191
190
|
|
|
192
191
|
//#endregion
|
|
193
|
-
export { Items };
|
|
192
|
+
export { BaseSelect, Items, Select, SingleSelect, defaultSelectId };
|
|
194
193
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["selector","added: I[]","updated: ItemDiff<I>[]","options: ItemsOptions<E>"],"sources":["../src/selectId.ts","../src/selector.ts","../src/diff.ts","../src/updater.ts","../src/Items.ts"],"sourcesContent":["export type StrOrNum = string | number\n\nexport type SelectId<E> = (entity: E) => StrOrNum\n\nexport function defaultSelectId<E extends { id: I }, I = E['id']>(entity: E) {\n return entity.id\n}\n","import { Items } from './Items'\nimport { StrOrNum } from './selectId'\n\nexport type SelectorFn<E> = (entity: E) => boolean\nexport type Selector<E, I> = Iterable<I> | SelectorFn<E>\nexport type Operation<E, I> = (entity: E | undefined, id: I) => void\n\nexport function selector<E, I extends StrOrNum>(items: Items<E, I>, selector: Selector<E, I>, operation: Operation<E, I>) {\n if (typeof selector === 'function') {\n items.getEntities().forEach((entity, id) => {\n if ((selector as SelectorFn<E>)(entity)) {\n operation(entity, id)\n }\n })\n } else {\n Array\n .from(selector as Iterable<I>)\n .forEach(id => operation(items.select(id), id))\n }\n}\n","import { diff } from 'ohash/utils'\nimport { Items } from './Items'\nimport { StrOrNum } from './selectId'\n\nexport interface ItemDiff<I> {\n id: I\n changes: ReturnType<typeof diff>\n}\n\nexport interface ItemsDiff<I> {\n added: I[]\n removed: I[]\n updated: ItemDiff<I>[]\n}\n\nexport function itemsDiff<E, I extends StrOrNum>(fromItems: Items<E, I>, toItems: Items<E, I>): ItemsDiff<I> {\n const ids = new Set(toItems.getIds())\n const baseIds = new Set(fromItems.getIds())\n\n const added: I[] = []\n const updated: ItemDiff<I>[] = []\n\n ids.forEach(id => {\n if (!baseIds.has(id)) {\n added.push(id)\n } else {\n const changes = diff(fromItems.select(id), toItems.select(id))\n\n if (changes.length > 0) {\n updated.push({ id, changes })\n }\n\n baseIds.delete(id)\n }\n })\n\n const removed = [...baseIds]\n\n return {\n added,\n removed,\n updated\n }\n}\n","export type UpdateFn<E> = (entity: E) => E\nexport type Updater<E> = UpdateFn<E> | Partial<E>\n\nexport function update<E>(entity: E, updater: Updater<E>) {\n return { ...entity, ...(typeof updater === 'function' ? updater(entity) : updater) }\n}\n","import { defaultSelectId, SelectId, StrOrNum } from './selectId'\nimport { selector, Selector, SelectorFn } from './selector'\nimport { Updater } from './updater'\nimport { itemsDiff } from './diff'\nimport { update } from './updater'\n\nexport type ItemsOptions<E> = {\n selectId?: SelectId<E>\n sortComparer?: false | ((a: E, b: E) => number)\n}\n\nexport interface ItemsState<E, I> {\n ids: I[]\n entities: Map<I, E>\n}\n\nexport class Items<E, I extends StrOrNum = StrOrNum> {\n private state: ItemsState<E, I>\n\n constructor(\n items: Iterable<E> = [],\n private options: ItemsOptions<E> = {}\n ) {\n const entities = new Map(\n Array\n .from(items)\n .map((item) => {\n const id = this.selectId(item)\n return [id, item]\n })\n )\n\n this.state = {\n ids: this.sortIds([...entities.keys()], entities),\n entities\n }\n }\n\n getIds(): I[] {\n return [...this.state.ids]\n }\n\n getEntities(): Map<I, E> {\n return new Map(this.state.entities)\n }\n\n get length(): number {\n return this.state.ids.length\n }\n\n select(id: I): E | undefined {\n return this.state.entities.get(id)\n }\n\n insert(entity: E) {\n return this.insertMany([entity])\n }\n\n insertMany(entities: Iterable<E>) {\n return new Items<E, I>([\n ...this,\n ...Array.from(entities).filter(entity => !this.has(this.selectId(entity)))\n ], this.options)\n }\n\n upsert(entity: Partial<E>) {\n return this.upsertMany([entity])\n }\n\n upsertMany(entities: Iterable<Partial<E>>) {\n const clone = this.getEntities()\n Array.from(entities).forEach(entity => {\n const id = this.selectId(entity as E)\n const existing = clone.get(id)\n if (existing) {\n clone.set(id, { ...existing, ...entity } as E)\n } else {\n clone.set(id, entity as E)\n }\n })\n return new Items<E, I>(clone.values(), this.options)\n }\n\n set(entity: E) {\n return this.setMany([entity])\n }\n\n setMany(entities: Iterable<E>) {\n return new Items<E, I>([\n ...this,\n ...entities\n ], this.options)\n }\n\n every(check: SelectorFn<E>) {\n return this.getIds().every(id => check(this.select(id)!))\n }\n\n some(check: SelectorFn<E>) {\n return this.getIds().some(id => check(this.select(id)!))\n }\n\n has(id: I) {\n return this.state.ids.includes(id)\n }\n\n hasMany(select: Selector<E, I>) {\n let failToFind = false\n let result = false\n selector(this, select, (entity) => {\n if (entity) {\n result = true\n } else {\n failToFind = true\n }\n })\n return !failToFind && result\n }\n\n update(id: I, updater: Updater<E>) {\n const entity = this.select(id)\n if (!entity) {\n return this\n }\n const clone = this.getEntities()\n clone.set(id, update(entity, updater))\n return new Items<E, I>(clone.values(), this.options)\n }\n\n updateMany(select: Selector<E, I>, updater: Updater<E>) {\n const clone = this.getEntities()\n selector(this, select, (entity, id) => {\n if (entity) {\n clone.set(id, update(entity, updater))\n }\n })\n return new Items<E, I>(clone.values(), this.options)\n }\n\n remove(id: I) {\n const clone = this.getEntities()\n clone.delete(id)\n return new Items<E, I>(clone.values(), this.options)\n }\n\n removeMany(select: Selector<E, I>) {\n const clone = this.getEntities()\n selector(this, select, (_, id) => {\n clone.delete(id)\n })\n return new Items<E, I>(clone.values(), this.options)\n }\n\n clear() {\n return new Items<E, I>([], this.options)\n }\n\n filter(select: Selector<E, I>) {\n const clone = new Map<I, E>()\n\n selector(this, select, (entity, id) => {\n if (entity) {\n clone.set(id, entity)\n }\n })\n\n return new Items<E, I>(clone.values(), this.options)\n }\n\n page(page: number, pageSize: number) {\n const totalPages = Math.ceil(this.length / pageSize)\n return {\n items: this.getIds()\n .slice(page * pageSize, (page + 1) * pageSize)\n .map(id => this.select(id)!),\n page,\n pageSize,\n hasNext: page < totalPages - 1,\n hasPrevious: page > 0,\n total: this.length,\n totalPages\n }\n }\n\n diff(base: Items<E, I>) {\n return itemsDiff(base, this)\n }\n\n private sortIds(\n ids: I[],\n entities: Map<I, E>\n ): Array<I> {\n if (this.sortComparer === false) {\n return ids\n }\n const sorter = this.sortComparer\n return [...ids].sort((aId, bId) => {\n const a = entities.get(aId)!\n const b = entities.get(bId)!\n return sorter(a, b)\n })\n }\n\n private selectId(entity: E): I {\n return this.options?.selectId?.(entity) as undefined || defaultSelectId(entity as E & { id: I })\n }\n\n private get sortComparer() {\n return this.options.sortComparer || false\n }\n\n [Symbol.iterator](): Iterator<E> {\n return this.state.entities.values()\n }\n}\n"],"mappings":";;;AAIA,SAAgB,gBAAkD,QAAW;AAC3E,QAAO,OAAO;;;;;ACEhB,SAAgB,SAAgC,OAAoB,YAA0B,WAA4B;AACxH,KAAI,OAAOA,eAAa,WACtB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S;AACpD,SAAO;GACL,OAAO,KAAK,QAAQ,CACjB,MAAM,OAAO,WAAW,OAAO,KAAK,SAAS,CAC7C,KAAI,OAAM,KAAK,OAAO,GAAG,CAAE;GAC9B;GACA;GACA,SAAS,OAAO,aAAa;GAC7B,aAAa,OAAO;GACpB,OAAO,KAAK;GACZ;GACD;;CAGH,KAAK,MAAmB;AACtB,SAAO,UAAU,MAAM,KAAK;;CAG9B,AAAQ,QACN,KACA,UACU;AACV,MAAI,KAAK,iBAAiB,MACxB,QAAO;EAET,MAAM,SAAS,KAAK;AACpB,SAAO,CAAC,GAAG,IAAI,CAAC,MAAM,KAAK,QAAQ;AAGjC,UAAO,OAFG,SAAS,IAAI,IAAI,EACjB,SAAS,IAAI,IAAI,CACR;IACnB;;CAGJ,AAAQ,SAAS,QAAc;AAC7B,SAAO,KAAK,SAAS,WAAW,OAAO,IAAiB,gBAAgB,OAAwB;;CAGlG,IAAY,eAAe;AACzB,SAAO,KAAK,QAAQ,gBAAgB;;CAGtC,CAAC,OAAO,YAAyB;AAC/B,SAAO,KAAK,MAAM,SAAS,QAAQ"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["ids: ItemId[]","self: Items<E>","added: ItemId[]","updated: any[]","options: ItemsOptions<E>"],"sources":["../src/utils.ts","../src/select.ts","../src/diff.ts","../src/Items.ts"],"sourcesContent":["import type { ItemId } from './types'\nexport function defaultSelectId<E extends { id: ItemId }>(entity: E): ItemId {\n return entity.id\n}\n","import type { ItemId } from './types'\nimport type { Items } from './Items'\n\nexport class BaseSelect<E> {\n constructor(\n public ids: ItemId[],\n public self: Items<E>\n ) {}\n}\n\nexport class SingleSelect<E> extends BaseSelect<E> {}\n\nexport class Select<E> extends BaseSelect<E> {\n take(len: number): Select<E> {\n return new Select(this.ids.slice(0, len), this.self)\n }\n\n skip(len: number): Select<E> {\n return new Select(this.ids.slice(len), this.self)\n }\n\n filter(testFn: (entry: E, id: ItemId, index: number) => boolean): Select<E> {\n const filteredIds = this.ids.filter((id, index) => {\n const entry = this.self.get(id)!\n return testFn(entry, id, index)\n })\n return new Select(filteredIds, this.self)\n }\n\n revert(): Select<E> {\n return new Select([...this.ids].reverse(), this.self)\n }\n\n sort(sortFn: (x: E, y: E) => number): Select<E> {\n const sortedIds = [...this.ids].sort((aId, bId) => {\n const a = this.self.get(aId)!\n const b = this.self.get(bId)!\n return sortFn(a, b)\n })\n return new Select(sortedIds, this.self)\n }\n\n at(index: number): SingleSelect<E> {\n const id = this.ids[index]\n return new SingleSelect([id], this.self)\n }\n\n from(entities: Iterable<E>): Select<E> {\n const newIds = Array.from(entities).map(entry => this.self.extractId(entry))\n return new Select(newIds, this.self)\n }\n\n on(entry: E): SingleSelect<E> {\n const id = this.self.extractId(entry)\n return new SingleSelect([id], this.self)\n }\n}\n","import type { ItemId } from './types'\nimport { Items } from './Items'\nimport { diff} from 'ohash/utils'\n\nexport function itemsDiff<E>(fromItems: Items<E>, toItems: Items<E>) {\n const ids = new Set(toItems.getIds())\n const baseIds = new Set(fromItems.getIds())\n\n const added: ItemId[] = []\n const updated: any[] = []\n\n ids.forEach(id => {\n if (!baseIds.has(id)) {\n added.push(id)\n } else {\n const changes = diff(fromItems.select(id), toItems.select(id))\n\n if (changes.length > 0) {\n updated.push({ id, changes })\n }\n\n baseIds.delete(id)\n }\n })\n\n const removed = [...baseIds]\n\n return {\n added,\n removed,\n updated\n }\n}\n","import type { CheckFn, ItemId, ItemsOptions, ItemsState, Selector, Updater } from './types'\nimport { defaultSelectId } from './utils'\nimport { Select, SingleSelect } from './select'\nimport { itemsDiff } from './diff'\n\nexport class Items<E> {\n private state: ItemsState<E, ItemId>\n\n constructor(\n items: Iterable<E> = [],\n private options: ItemsOptions<E> = {}\n ) {\n const entities = new Map(\n Array\n .from(items)\n .map((item) => {\n const id = this.extractId(item)\n return [id, item]\n })\n )\n\n this.state = {\n ids: this.sortIds([...entities.keys()], entities),\n entities\n }\n }\n\n // NOTE: Add item if id not exists\n add(items: Iterable<E>): Items<E> {\n const newEntities = new Map(this.state.entities)\n\n Array.from(items).forEach((item) => {\n const id = this.extractId(item)\n if (!newEntities.has(id)) {\n newEntities.set(id, item)\n }\n })\n\n return new Items<E>(newEntities.values(), this.options)\n }\n\n // NOTE: update selected ids with partial data or call function (even if selected id not exists)\n update(select: Selector<E>, updater: Updater<E>): Items<E> {\n const [, selectedIds] = this.resolveSelector(select)\n const newEntities = new Map(this.state.entities)\n const isFn = typeof updater === 'function'\n\n selectedIds\n .forEach((id) => {\n const entity = newEntities.get(id)\n\n if (isFn) {\n newEntities.set(id, updater(entity))\n } else if (entity) {\n newEntities.set(id, { ...entity, ...updater })\n }\n })\n\n return new Items<E>(newEntities.values(), this.options)\n }\n\n // NOTE: add if not exists, overwrite if exists\n merge(items: Iterable<E>): Items<E> {\n const newEntities = new Map(this.state.entities)\n\n Array.from(items).forEach((item) => {\n const id = this.extractId(item)\n const entry = this.get(id)\n newEntities.set(id, entry ? { ...entry, ...item } : item)\n })\n\n return new Items<E>(newEntities.values(), this.options)\n }\n\n remove(select: Selector<E>): Items<E> {\n const [, selectedIds] = this.resolveSelector(select)\n const idsToKeep = this.state.ids.filter(id => !selectedIds.includes(id))\n const items = idsToKeep.map(id => this.get(id)!)\n return new Items<E>(items, this.options)\n }\n\n pick(select: Selector<E>): Items<E> {\n const [, selectedIds] = this.resolveSelector(select)\n const items = selectedIds.map(id => this.get(id)!)\n return new Items<E>(items, this.options)\n }\n\n select(select: ItemId): E | undefined\n select(select: Iterable<ItemId>): E[]\n select(select: (selector: Select<E>) => Select<E>): E[]\n select(select: (selector: Select<E>) => SingleSelect<E>): E | undefined\n select(select: Selector<E>): undefined | E | E[] {\n const [single, selectedIds] = this.resolveSelector(select)\n const items = selectedIds.map(id => this.get(id)).filter(Boolean) as E[]\n return single ? items[0] : items\n }\n\n selectId(select: (selector: Select<E>) => Select<E>): ItemId[]\n selectId(select: (selector: Select<E>) => SingleSelect<E>): ItemId | undefined\n selectId(select: Selector<E>): undefined | ItemId | ItemId[] {\n const [single, selectedIds] = this.resolveSelector(select)\n return single ? selectedIds[0] : selectedIds\n }\n\n clear(): Items<E> {\n return new Items<E>([], this.options)\n }\n\n every(check: CheckFn<E>) {\n return this.getIds().every(id => check(this.get(id)!))\n }\n\n some(check: CheckFn<E>) {\n return this.getIds().some(id => check(this.get(id)!))\n }\n\n has(id: ItemId) {\n return this.state.ids.includes(id)\n }\n\n get(id: ItemId): E | undefined {\n return this.state.entities.get(id)\n }\n\n getIds(): ItemId[] {\n return [...this.state.ids]\n }\n\n getEntities(): E[] {\n return this.state.ids.map(id => this.get(id)!)\n }\n\n get length(): number {\n return this.state.ids.length\n }\n\n private resolveSelector(select: Selector<E>): [boolean, ItemId[]]{\n if (typeof select === 'function') {\n const newSelect = new Select(this.state.ids, this)\n const result = select(newSelect)\n return [result instanceof SingleSelect, result.ids]\n } else if (typeof select === 'string' || typeof select === 'number') {\n return [true, [select]]\n } else {\n return [false, Array.from(select)]\n }\n }\n\n private sortIds(\n ids: ItemId[],\n entities: Map<ItemId, E>\n ): Array<ItemId> {\n if (this.sortComparer === false) {\n return ids\n }\n const sorter = this.sortComparer\n return [...ids].sort((aId, bId) => {\n const a = entities.get(aId)!\n const b = entities.get(bId)!\n return sorter(a, b)\n })\n }\n\n extractId(entity: E): ItemId {\n return this.options?.selectId?.(entity) as undefined || defaultSelectId(entity as E & { id: ItemId })\n }\n\n private get sortComparer() {\n return this.options.sortComparer || false\n }\n\n [Symbol.iterator](): Iterator<E> {\n return this.state.entities.values()\n }\n\n static compare<E>(base: Items<E>, to: Items<E>) {\n return itemsDiff(base, to)\n }\n}\n\n"],"mappings":";;;AACA,SAAgB,gBAA0C,QAAmB;AAC3E,QAAO,OAAO;;;;;ACChB,IAAa,aAAb,MAA2B;CACzB,YACE,AAAOA,KACP,AAAOC,MACP;EAFO;EACA;;;AAIX,IAAa,eAAb,cAAqC,WAAc;AAEnD,IAAa,SAAb,MAAa,eAAkB,WAAc;CAC3C,KAAK,KAAwB;AA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