@microphi/list 2.4.0 → 2.6.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/LICENSE +21 -0
- package/README.md +3 -2
- package/lib/index.js +4 -2
- package/lib/lib/list/list.js +7 -4
- package/package.json +4 -3
- package/lib/index.js.map +0 -1
- package/lib/lib/list/list.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Davide Cavaliere
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> Simple and fast list-like class
|
|
4
4
|
|
|
5
|
-
It combines internally a map and an array of ids. The combination give this class the flexibility of an array and the ability to access directly to an element from its id.
|
|
5
|
+
It combines internally a javascrript map and an array of ids. The combination give this class the flexibility of an array and the ability to access directly to an element from its id.
|
|
6
|
+
|
|
6
7
|
|
|
7
8
|
## Install
|
|
8
9
|
With your preferred package manager install
|
|
@@ -15,7 +16,7 @@ With your preferred package manager install
|
|
|
15
16
|
|
|
16
17
|
interface Entity {
|
|
17
18
|
id: string;
|
|
18
|
-
user: {
|
|
19
|
+
user: {
|
|
19
20
|
email: string;
|
|
20
21
|
name: string;
|
|
21
22
|
};
|
package/lib/index.js
CHANGED
package/lib/lib/list/list.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.List = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
class List {
|
|
3
6
|
get size() {
|
|
4
7
|
if (this.ids.length !== this.entities.size) {
|
|
5
8
|
throw new Error(`Size Mismatch ${this.ids.length} !== ${this.entities.size}`);
|
|
@@ -17,7 +20,7 @@ export class List {
|
|
|
17
20
|
}
|
|
18
21
|
constructor(IDField, entities = []) {
|
|
19
22
|
this.IDField = IDField;
|
|
20
|
-
this.operations$ = new Subject();
|
|
23
|
+
this.operations$ = new rxjs_1.Subject();
|
|
21
24
|
this.entities = new Map();
|
|
22
25
|
/**
|
|
23
26
|
* maps entities position from the original array to their ids
|
|
@@ -94,4 +97,4 @@ export class List {
|
|
|
94
97
|
this.operations$.next({ op: 'append', payload: entities, timestamp: new Date() });
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
|
-
|
|
100
|
+
exports.List = List;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microphi/list",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Simple and fast list-like class",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"lint": "eslint ./src"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@microphi/debug": "^2.
|
|
32
|
+
"@microphi/debug": "^2.6.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
|
|
@@ -38,5 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"rxjs": "~7.8.0"
|
|
41
|
-
}
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "6239637f38d555081da1647b962184616010146e"
|
|
42
43
|
}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './lib/list/list';\n"]}
|
package/lib/lib/list/list.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/lib/list/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAW/B,MAAM,OAAO,IAAI;IAWf,IAAW,IAAI;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YAE3C,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,GAAG,CAAC,MAAM,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAChF,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAEM,GAAG,CAAC,EAAU;QACnB,OAAO,IAAI,CAAC,QAAQ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B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;IACpF,CAAC;CAGF","sourcesContent":["import { Subject } from 'rxjs';\nimport { $Keys, FunctionKeys } from 'utility-types';\n\n\nexport interface Operation {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n op: FunctionKeys<List<any>>;\n payload?: unknown;\n timestamp: Date;\n}\n\nexport class List<EntityType extends object> implements Iterable<EntityType> {\n\n public operations$ = new Subject<Operation>();\n\n public readonly entities = new Map<string, EntityType>();\n\n /**\n * maps entities position from the original array to their ids\n */\n private readonly ids: string[] = [];\n\n public get size() {\n if (this.ids.length !== this.entities.size) {\n\n throw new Error(`Size Mismatch ${this.ids.length} !== ${this.entities.size}`);\n }\n\n return this.entities.size;\n }\n\n public has(id: string) {\n return this.entities.has(id);\n }\n\n public get(id: string) {\n return this.entities.get(id);\n }\n\n private getId(entity: EntityType): string {\n return entity[this.IDField] as string;\n }\n\n constructor(private IDField: $Keys<EntityType>, entities: EntityType[] = []) {\n\n this.ids = entities.map((e) => this.getId(e));\n\n entities\n .forEach((item) => {\n const id = this.getId(item);\n this.entities.set(id, item);\n });\n }\n\n *[Symbol.iterator](): IterableIterator<EntityType> {\n for (const idx in this.ids) {\n const id = this.ids[idx];\n\n const entity = this.entities.get(id);\n if (entity) {\n yield entity;\n } else {\n throw new Error(`Cannot get entity with id ${id}`);\n }\n }\n }\n\n /**\n * Upsert one or more items. I.e.: append if new update otherwise\n * */\n public upsert(...entities: EntityType[]) {\n entities.forEach((e) => {\n const id = this.getId(e);\n\n if (!this.entities.has(id)) {\n this.ids.push(id);\n }\n\n this.entities.set(id, e);\n\n });\n\n this.operations$.next({ op: 'upsert', payload: entities, timestamp: new Date() });\n }\n\n public prepend(...entities: EntityType[]) {\n entities.reverse().forEach((e) => {\n const id = this.getId(e);\n\n if (this.entities.has(id)) {\n this.delete(e);\n }\n\n this.ids.unshift(id);\n\n this.entities.set(id, e);\n\n });\n this.operations$.next({ op: 'prepend', payload: entities, timestamp: new Date() });\n }\n\n public clear() {\n\n this.ids.length = 0;\n this.entities.clear();\n this.operations$.next({ op: 'clear', timestamp: new Date() });\n\n }\n\n public delete(...entities: EntityType[]) {\n\n entities.forEach((e) => {\n const id = this.getId(e);\n const indexOfId = this.ids.findIndex((_id) => _id === id);\n\n if (indexOfId >= 0) {\n this.ids.splice(indexOfId, 1);\n this.entities.delete(id);\n }\n });\n\n this.operations$.next({ op: 'delete', payload: entities, timestamp: new Date() });\n }\n\n public append(...entities: EntityType[]) {\n entities.forEach((e) => {\n const id = this.getId(e);\n\n if (this.entities.has(id)) {\n this.delete(e);\n }\n\n this.ids.push(id);\n this.entities.set(id, e);\n });\n\n this.operations$.next({ op: 'append', payload: entities, timestamp: new Date() });\n }\n\n\n}\n"]}
|