@data-weave/datamanager 0.4.2 → 0.4.4
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/lib/Cache.d.ts +15 -0
- package/lib/Cache.js +32 -0
- package/lib/DataManager.d.ts +42 -0
- package/lib/DataManager.js +13 -0
- package/lib/List.d.ts +11 -0
- package/lib/List.js +24 -0
- package/lib/LiveList.d.ts +24 -0
- package/lib/LiveList.js +55 -0
- package/lib/LiveReference.d.ts +21 -0
- package/lib/LiveReference.js +46 -0
- package/lib/Reference.d.ts +15 -0
- package/lib/Reference.js +25 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +22 -0
- package/lib/version.js +1 -1
- package/package.json +7 -3
- package/CHANGELOG.md +0 -62
- package/lib/Cache.ts +0 -41
- package/lib/DataManager.ts +0 -50
- package/lib/List.ts +0 -24
- package/lib/LiveList.ts +0 -70
- package/lib/LiveReference.ts +0 -57
- package/lib/Reference.ts +0 -34
- package/lib/index.ts +0 -6
package/lib/Cache.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface Cache<K = any, V = any> {
|
|
2
|
+
get(key: K): V | undefined;
|
|
3
|
+
set(key: K, value: V): void;
|
|
4
|
+
has(key: K): boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class MapCache<K, V> implements Cache<K, V> {
|
|
7
|
+
private cache;
|
|
8
|
+
private maxSize?;
|
|
9
|
+
constructor(maxSize?: number);
|
|
10
|
+
get(key: K): V | undefined;
|
|
11
|
+
set(key: K, value: V): void;
|
|
12
|
+
has(key: K): boolean;
|
|
13
|
+
delete(key: K): boolean;
|
|
14
|
+
clear(): void;
|
|
15
|
+
}
|
package/lib/Cache.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapCache = void 0;
|
|
4
|
+
class MapCache {
|
|
5
|
+
constructor(maxSize) {
|
|
6
|
+
this.cache = new Map();
|
|
7
|
+
this.maxSize = maxSize;
|
|
8
|
+
}
|
|
9
|
+
get(key) {
|
|
10
|
+
return this.cache.get(key);
|
|
11
|
+
}
|
|
12
|
+
set(key, value) {
|
|
13
|
+
if (this.maxSize && this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
14
|
+
// Remove the first entry (oldest) when cache is full
|
|
15
|
+
const firstKey = this.cache.keys().next().value;
|
|
16
|
+
if (firstKey) {
|
|
17
|
+
this.cache.delete(firstKey);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
this.cache.set(key, value);
|
|
21
|
+
}
|
|
22
|
+
has(key) {
|
|
23
|
+
return this.cache.has(key);
|
|
24
|
+
}
|
|
25
|
+
delete(key) {
|
|
26
|
+
return this.cache.delete(key);
|
|
27
|
+
}
|
|
28
|
+
clear() {
|
|
29
|
+
this.cache.clear();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.MapCache = MapCache;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { List } from './List';
|
|
2
|
+
import { IdentifiableReference, WithoutId } from './Reference';
|
|
3
|
+
export interface ReadOptions {
|
|
4
|
+
readonly transaction?: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface WriteOptions {
|
|
7
|
+
readonly transaction?: unknown;
|
|
8
|
+
readonly batcher?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface CreateOptions extends WriteOptions {
|
|
11
|
+
id?: string;
|
|
12
|
+
merge?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export type OrderByOption = 'asc' | 'desc';
|
|
15
|
+
export interface GetListOptions {
|
|
16
|
+
readonly filterBy?: unknown;
|
|
17
|
+
readonly orderBy?: unknown;
|
|
18
|
+
readonly limit?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Metadata {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly createdAt: Date;
|
|
23
|
+
readonly updatedAt: Date;
|
|
24
|
+
readonly deleted: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type WithMetadata<T> = T & Metadata;
|
|
27
|
+
/**
|
|
28
|
+
* DataManager is the base class for all data managers.
|
|
29
|
+
* It is responsible for reading, creating, deleting, and updating data.
|
|
30
|
+
* It is also responsible for returning references and lists.
|
|
31
|
+
* It is generic and can be used for any type of data.
|
|
32
|
+
* @template T - The type of the data to be managed.
|
|
33
|
+
*/
|
|
34
|
+
export declare abstract class DataManager<T> {
|
|
35
|
+
abstract read(id: string): Promise<T | undefined>;
|
|
36
|
+
abstract create(data: WithoutId<T>, options?: CreateOptions): Promise<IdentifiableReference<WithMetadata<T>>>;
|
|
37
|
+
abstract delete(id: string): Promise<void>;
|
|
38
|
+
abstract update(id: string, data: Partial<WithoutId<T>>): Promise<void>;
|
|
39
|
+
abstract upsert(id: string, data: WithoutId<T>): Promise<void>;
|
|
40
|
+
abstract getRef(id: string): IdentifiableReference<WithMetadata<T>>;
|
|
41
|
+
abstract getList(params?: GetListOptions): List<WithMetadata<T>>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* DataManager is the base class for all data managers.
|
|
6
|
+
* It is responsible for reading, creating, deleting, and updating data.
|
|
7
|
+
* It is also responsible for returning references and lists.
|
|
8
|
+
* It is generic and can be used for any type of data.
|
|
9
|
+
* @template T - The type of the data to be managed.
|
|
10
|
+
*/
|
|
11
|
+
class DataManager {
|
|
12
|
+
}
|
|
13
|
+
exports.DataManager = DataManager;
|
package/lib/List.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Resolvable } from './Reference';
|
|
2
|
+
export interface ListPaginationParams {
|
|
3
|
+
readonly pageSize?: number;
|
|
4
|
+
readonly append?: boolean;
|
|
5
|
+
readonly loadFirstPageManually?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface List<T> extends Resolvable<readonly T[]> {
|
|
8
|
+
readonly values: readonly T[];
|
|
9
|
+
}
|
|
10
|
+
export declare function createInitializedList<T>(values: ReadonlyArray<T>): List<T>;
|
|
11
|
+
export declare function createEmptyList<T>(): List<T>;
|
package/lib/List.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createInitializedList = createInitializedList;
|
|
13
|
+
exports.createEmptyList = createEmptyList;
|
|
14
|
+
function createInitializedList(values) {
|
|
15
|
+
return {
|
|
16
|
+
values,
|
|
17
|
+
resolved: true,
|
|
18
|
+
hasError: false,
|
|
19
|
+
resolve: () => __awaiter(this, void 0, void 0, function* () { return values; }),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function createEmptyList() {
|
|
23
|
+
return createInitializedList([]);
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { List } from './List';
|
|
2
|
+
export interface LiveListOptions<T> {
|
|
3
|
+
onUpdate?: (newValues: T[]) => void;
|
|
4
|
+
onError?: (error: unknown) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare class LiveList<T> implements List<T> {
|
|
7
|
+
private _values;
|
|
8
|
+
private _resolved;
|
|
9
|
+
private _hasError;
|
|
10
|
+
private _options;
|
|
11
|
+
constructor(options: LiveListOptions<T>);
|
|
12
|
+
resolve(): Promise<readonly T[]>;
|
|
13
|
+
get values(): T[];
|
|
14
|
+
get hasError(): boolean;
|
|
15
|
+
get resolved(): boolean;
|
|
16
|
+
protected setStale(): void;
|
|
17
|
+
protected onValuesChange(): void;
|
|
18
|
+
protected onUpdate(): void;
|
|
19
|
+
protected onUpdateAll(values: T[]): void;
|
|
20
|
+
protected onUpdateAtIndex(index: number, value: T): void;
|
|
21
|
+
protected onAddAtIndex(index: number, value: T): void;
|
|
22
|
+
protected onRemoveAtIndex(index: number): void;
|
|
23
|
+
protected onError(error: unknown): void;
|
|
24
|
+
}
|
package/lib/LiveList.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiveList = void 0;
|
|
4
|
+
class LiveList {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this._values = [];
|
|
7
|
+
this._resolved = false;
|
|
8
|
+
this._hasError = false;
|
|
9
|
+
this._options = options;
|
|
10
|
+
}
|
|
11
|
+
resolve() {
|
|
12
|
+
throw new Error('Method not implemented.');
|
|
13
|
+
}
|
|
14
|
+
get values() {
|
|
15
|
+
return this._values;
|
|
16
|
+
}
|
|
17
|
+
get hasError() {
|
|
18
|
+
return this._hasError;
|
|
19
|
+
}
|
|
20
|
+
get resolved() {
|
|
21
|
+
return this._resolved;
|
|
22
|
+
}
|
|
23
|
+
setStale() {
|
|
24
|
+
this._resolved = false;
|
|
25
|
+
}
|
|
26
|
+
onValuesChange() { }
|
|
27
|
+
onUpdate() {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
this._resolved = true;
|
|
30
|
+
this.onValuesChange();
|
|
31
|
+
(_b = (_a = this._options).onUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, this._values);
|
|
32
|
+
}
|
|
33
|
+
onUpdateAll(values) {
|
|
34
|
+
this._values = values;
|
|
35
|
+
this.onUpdate();
|
|
36
|
+
}
|
|
37
|
+
onUpdateAtIndex(index, value) {
|
|
38
|
+
this._values[index] = value;
|
|
39
|
+
}
|
|
40
|
+
onAddAtIndex(index, value) {
|
|
41
|
+
this._values.splice(index, 0, value);
|
|
42
|
+
}
|
|
43
|
+
onRemoveAtIndex(index) {
|
|
44
|
+
this._values.splice(index, 1);
|
|
45
|
+
}
|
|
46
|
+
onError(error) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
this._hasError = true;
|
|
49
|
+
this._values = [];
|
|
50
|
+
this._resolved = true;
|
|
51
|
+
(_b = (_a = this._options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
52
|
+
this.onValuesChange();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.LiveList = LiveList;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Reference } from './Reference';
|
|
2
|
+
export interface LiveReferenceOptions<T> {
|
|
3
|
+
onUpdate?: (newValue: T | undefined) => void;
|
|
4
|
+
onError?: (error: unknown) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare class LiveReference<T> implements Reference<T> {
|
|
7
|
+
readonly options: LiveReferenceOptions<T>;
|
|
8
|
+
private _value;
|
|
9
|
+
private _resolved;
|
|
10
|
+
private _hasError;
|
|
11
|
+
private _options;
|
|
12
|
+
resolve(): Promise<T | undefined>;
|
|
13
|
+
constructor(options: LiveReferenceOptions<T>);
|
|
14
|
+
get value(): T | undefined;
|
|
15
|
+
get resolved(): boolean;
|
|
16
|
+
get hasError(): boolean;
|
|
17
|
+
protected setStale(): void;
|
|
18
|
+
protected onUpdate(data: T | undefined): void;
|
|
19
|
+
protected onError(error: unknown): void;
|
|
20
|
+
protected onValueChange(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiveReference = void 0;
|
|
4
|
+
class LiveReference {
|
|
5
|
+
resolve() {
|
|
6
|
+
throw new Error('Method not implemented.');
|
|
7
|
+
}
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = options;
|
|
10
|
+
this._resolved = false;
|
|
11
|
+
this._hasError = false;
|
|
12
|
+
this._value = undefined;
|
|
13
|
+
this._resolved = false;
|
|
14
|
+
this._hasError = false;
|
|
15
|
+
this._options = options;
|
|
16
|
+
}
|
|
17
|
+
get value() {
|
|
18
|
+
return this._value;
|
|
19
|
+
}
|
|
20
|
+
get resolved() {
|
|
21
|
+
return this._resolved;
|
|
22
|
+
}
|
|
23
|
+
get hasError() {
|
|
24
|
+
return this._hasError;
|
|
25
|
+
}
|
|
26
|
+
setStale() {
|
|
27
|
+
this._resolved = false;
|
|
28
|
+
}
|
|
29
|
+
onUpdate(data) {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
this._value = data;
|
|
32
|
+
this._resolved = true;
|
|
33
|
+
this.onValueChange();
|
|
34
|
+
(_b = (_a = this._options).onUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, this._value);
|
|
35
|
+
}
|
|
36
|
+
onError(error) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
this._hasError = true;
|
|
39
|
+
this._value = undefined;
|
|
40
|
+
this._resolved = true;
|
|
41
|
+
this.onValueChange();
|
|
42
|
+
(_b = (_a = this._options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
43
|
+
}
|
|
44
|
+
onValueChange() { }
|
|
45
|
+
}
|
|
46
|
+
exports.LiveReference = LiveReference;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface Identifiable {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
}
|
|
4
|
+
export type WithoutId<T> = Omit<T, 'id'>;
|
|
5
|
+
export interface Resolvable<T> {
|
|
6
|
+
readonly resolved: boolean;
|
|
7
|
+
readonly hasError: boolean;
|
|
8
|
+
resolve(): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
export interface Reference<T> extends Resolvable<T | undefined> {
|
|
11
|
+
readonly value: T | undefined;
|
|
12
|
+
}
|
|
13
|
+
export type IdentifiableReference<T> = Reference<T> & Identifiable;
|
|
14
|
+
export declare function createInitializedIdentifiableReference<T>(value: T | undefined, id: string): Reference<T> & Identifiable;
|
|
15
|
+
export declare function createEmptyIdentifiableReference<T>(id: string): Reference<T>;
|
package/lib/Reference.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createInitializedIdentifiableReference = createInitializedIdentifiableReference;
|
|
13
|
+
exports.createEmptyIdentifiableReference = createEmptyIdentifiableReference;
|
|
14
|
+
function createInitializedIdentifiableReference(value, id) {
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
value,
|
|
18
|
+
resolved: true,
|
|
19
|
+
hasError: false,
|
|
20
|
+
resolve: () => __awaiter(this, void 0, void 0, function* () { return value; }),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function createEmptyIdentifiableReference(id) {
|
|
24
|
+
return createInitializedIdentifiableReference(undefined, id);
|
|
25
|
+
}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Cache"), exports);
|
|
18
|
+
__exportStar(require("./DataManager"), exports);
|
|
19
|
+
__exportStar(require("./List"), exports);
|
|
20
|
+
__exportStar(require("./LiveList"), exports);
|
|
21
|
+
__exportStar(require("./LiveReference"), exports);
|
|
22
|
+
__exportStar(require("./Reference"), exports);
|
package/lib/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
module.exports = '0.4.
|
|
2
|
+
module.exports = '0.4.4';
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-weave/datamanager",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"author": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*.js",
|
|
9
|
+
"lib/**/*.d.ts"
|
|
10
|
+
],
|
|
7
11
|
"scripts": {
|
|
8
|
-
"build": "genversion --semi lib/version.js",
|
|
12
|
+
"build": "genversion --semi lib/version.js && cp ../../build/datamanager/lib/*.js lib/ && cp ../../build/types/datamanager/lib/*.d.ts lib/",
|
|
9
13
|
"build:clean": "rimraf android/build && rimraf ios/build",
|
|
10
14
|
"prepare": "npm run build"
|
|
11
15
|
},
|
|
@@ -17,5 +21,5 @@
|
|
|
17
21
|
"access": "public",
|
|
18
22
|
"registry": "https://registry.npmjs.org/"
|
|
19
23
|
},
|
|
20
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "df44d823b93b392d9e3b685fafb0d17399001291"
|
|
21
25
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [0.4.2](https://github.com/data-weave/datamanager/compare/v0.4.1...v0.4.2) (2025-10-15)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
9
|
-
|
|
10
|
-
## [0.4.1](https://github.com/data-weave/datamanager/compare/v0.4.0...v0.4.1) (2025-10-15)
|
|
11
|
-
|
|
12
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
13
|
-
|
|
14
|
-
## [0.4.0](https://github.com/data-weave/datamanager/compare/v0.3.8...v0.4.0) (2025-10-15)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
17
|
-
|
|
18
|
-
## [0.3.8](https://github.com/data-weave/datamanager/compare/v0.3.7...v0.3.8) (2025-09-28)
|
|
19
|
-
|
|
20
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
21
|
-
|
|
22
|
-
## [0.3.7](https://github.com/data-weave/datamanager/compare/v0.3.6...v0.3.7) (2025-09-28)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
25
|
-
|
|
26
|
-
## [0.3.6](https://github.com/data-weave/datamanager/compare/v0.3.5...v0.3.6) (2025-09-28)
|
|
27
|
-
|
|
28
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
29
|
-
|
|
30
|
-
## [0.3.5](https://github.com/data-weave/datamanager/compare/v0.3.4...v0.3.5) (2025-09-28)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
33
|
-
|
|
34
|
-
## [0.3.4](https://github.com/data-weave/datamanager/compare/v0.3.3...v0.3.4) (2025-09-28)
|
|
35
|
-
|
|
36
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
37
|
-
|
|
38
|
-
## [0.3.2](https://github.com/data-weave/datamanager/compare/v0.3.1...v0.3.2) (2025-09-28)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
41
|
-
|
|
42
|
-
## [0.3.1](https://github.com/data-weave/datamanager/compare/v0.3.0...v0.3.1) (2025-09-28)
|
|
43
|
-
|
|
44
|
-
**Note:** Version bump only for package @data-weave/datamanager
|
|
45
|
-
|
|
46
|
-
## 0.3.0 (2025-09-28)
|
|
47
|
-
|
|
48
|
-
### Features
|
|
49
|
-
|
|
50
|
-
- add code quality workflow and circular dep check ([9c7b7e3](https://github.com/data-weave/datamanager/commit/9c7b7e34501dfc95ddc2bcff686f55db06d9b1b8))
|
|
51
|
-
- project re-organization ([4a00af3](https://github.com/data-weave/datamanager/commit/4a00af36c4c2f6e49287542e0d5ad85acaa50cda))
|
|
52
|
-
|
|
53
|
-
### Bug Fixes
|
|
54
|
-
|
|
55
|
-
- adjust config and lib versions ([9c7e2c9](https://github.com/data-weave/datamanager/commit/9c7e2c9072ea34b1e54326c2612b43c92ec2da4e))
|
|
56
|
-
- implement Cache prop & clean up some of anys ([955b11a](https://github.com/data-weave/datamanager/commit/955b11a6ab05224f843db834ad28796602679fac))
|
|
57
|
-
|
|
58
|
-
### Code Refactoring
|
|
59
|
-
|
|
60
|
-
- abstract out firestoreReference into LiveReference ([7848a87](https://github.com/data-weave/datamanager/commit/7848a872155593e5acab56696d4d9f27f0e6abb2))
|
|
61
|
-
- abstract out LiveList function from FirestorList ([bb4278e](https://github.com/data-weave/datamanager/commit/bb4278e960d0080d1fb18d847036acb189782ec9))
|
|
62
|
-
- adjustments for LiveList & ListReference ([49cd540](https://github.com/data-weave/datamanager/commit/49cd540295693e40bbb9eb75b5101b45c6932921))
|
package/lib/Cache.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export interface Cache<K = any, V = any> {
|
|
2
|
-
get(key: K): V | undefined
|
|
3
|
-
set(key: K, value: V): void
|
|
4
|
-
has(key: K): boolean
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export class MapCache<K, V> implements Cache<K, V> {
|
|
8
|
-
private cache = new Map<K, V>()
|
|
9
|
-
private maxSize?: number
|
|
10
|
-
|
|
11
|
-
constructor(maxSize?: number) {
|
|
12
|
-
this.maxSize = maxSize
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get(key: K): V | undefined {
|
|
16
|
-
return this.cache.get(key)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
set(key: K, value: V): void {
|
|
20
|
-
if (this.maxSize && this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
21
|
-
// Remove the first entry (oldest) when cache is full
|
|
22
|
-
const firstKey = this.cache.keys().next().value
|
|
23
|
-
if (firstKey) {
|
|
24
|
-
this.cache.delete(firstKey)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
this.cache.set(key, value)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
has(key: K): boolean {
|
|
31
|
-
return this.cache.has(key)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
delete(key: K): boolean {
|
|
35
|
-
return this.cache.delete(key)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
clear(): void {
|
|
39
|
-
this.cache.clear()
|
|
40
|
-
}
|
|
41
|
-
}
|
package/lib/DataManager.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { List } from './List'
|
|
2
|
-
import { IdentifiableReference, WithoutId } from './Reference'
|
|
3
|
-
|
|
4
|
-
export interface ReadOptions {
|
|
5
|
-
readonly transaction?: unknown
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface WriteOptions {
|
|
9
|
-
readonly transaction?: unknown
|
|
10
|
-
readonly batcher?: unknown
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface CreateOptions extends WriteOptions {
|
|
14
|
-
id?: string
|
|
15
|
-
merge?: boolean
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type OrderByOption = 'asc' | 'desc'
|
|
19
|
-
|
|
20
|
-
export interface GetListOptions {
|
|
21
|
-
readonly filterBy?: unknown
|
|
22
|
-
readonly orderBy?: unknown
|
|
23
|
-
readonly limit?: number
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface Metadata {
|
|
27
|
-
readonly id: string
|
|
28
|
-
readonly createdAt: Date
|
|
29
|
-
readonly updatedAt: Date
|
|
30
|
-
readonly deleted: boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type WithMetadata<T> = T & Metadata
|
|
34
|
-
/**
|
|
35
|
-
* DataManager is the base class for all data managers.
|
|
36
|
-
* It is responsible for reading, creating, deleting, and updating data.
|
|
37
|
-
* It is also responsible for returning references and lists.
|
|
38
|
-
* It is generic and can be used for any type of data.
|
|
39
|
-
* @template T - The type of the data to be managed.
|
|
40
|
-
*/
|
|
41
|
-
export abstract class DataManager<T> {
|
|
42
|
-
public abstract read(id: string): Promise<T | undefined>
|
|
43
|
-
public abstract create(data: WithoutId<T>, options?: CreateOptions): Promise<IdentifiableReference<WithMetadata<T>>>
|
|
44
|
-
public abstract delete(id: string): Promise<void>
|
|
45
|
-
public abstract update(id: string, data: Partial<WithoutId<T>>): Promise<void>
|
|
46
|
-
public abstract upsert(id: string, data: WithoutId<T>): Promise<void>
|
|
47
|
-
|
|
48
|
-
public abstract getRef(id: string): IdentifiableReference<WithMetadata<T>>
|
|
49
|
-
public abstract getList(params?: GetListOptions): List<WithMetadata<T>>
|
|
50
|
-
}
|
package/lib/List.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Resolvable } from './Reference'
|
|
2
|
-
|
|
3
|
-
export interface ListPaginationParams {
|
|
4
|
-
readonly pageSize?: number
|
|
5
|
-
readonly append?: boolean
|
|
6
|
-
readonly loadFirstPageManually?: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface List<T> extends Resolvable<readonly T[]> {
|
|
10
|
-
readonly values: readonly T[]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function createInitializedList<T>(values: ReadonlyArray<T>): List<T> {
|
|
14
|
-
return {
|
|
15
|
-
values,
|
|
16
|
-
resolved: true,
|
|
17
|
-
hasError: false,
|
|
18
|
-
resolve: async () => values,
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function createEmptyList<T>(): List<T> {
|
|
23
|
-
return createInitializedList([])
|
|
24
|
-
}
|
package/lib/LiveList.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { List } from './List'
|
|
2
|
-
|
|
3
|
-
export interface LiveListOptions<T> {
|
|
4
|
-
onUpdate?: (newValues: T[]) => void
|
|
5
|
-
onError?: (error: unknown) => void
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class LiveList<T> implements List<T> {
|
|
9
|
-
private _values: T[] = []
|
|
10
|
-
private _resolved: boolean = false
|
|
11
|
-
private _hasError: boolean = false
|
|
12
|
-
private _options: LiveListOptions<T>
|
|
13
|
-
|
|
14
|
-
constructor(options: LiveListOptions<T>) {
|
|
15
|
-
this._options = options
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
resolve(): Promise<readonly T[]> {
|
|
19
|
-
throw new Error('Method not implemented.')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public get values() {
|
|
23
|
-
return this._values
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public get hasError() {
|
|
27
|
-
return this._hasError
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public get resolved() {
|
|
31
|
-
return this._resolved
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
protected setStale() {
|
|
35
|
-
this._resolved = false
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected onValuesChange(): void {}
|
|
39
|
-
|
|
40
|
-
protected onUpdate(): void {
|
|
41
|
-
this._resolved = true
|
|
42
|
-
this.onValuesChange()
|
|
43
|
-
this._options.onUpdate?.(this._values)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
protected onUpdateAll(values: T[]): void {
|
|
47
|
-
this._values = values
|
|
48
|
-
this.onUpdate()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected onUpdateAtIndex(index: number, value: T): void {
|
|
52
|
-
this._values[index] = value
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
protected onAddAtIndex(index: number, value: T): void {
|
|
56
|
-
this._values.splice(index, 0, value)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
protected onRemoveAtIndex(index: number): void {
|
|
60
|
-
this._values.splice(index, 1)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
protected onError(error: unknown): void {
|
|
64
|
-
this._hasError = true
|
|
65
|
-
this._values = []
|
|
66
|
-
this._resolved = true
|
|
67
|
-
this._options.onError?.(error)
|
|
68
|
-
this.onValuesChange()
|
|
69
|
-
}
|
|
70
|
-
}
|
package/lib/LiveReference.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Reference } from './Reference'
|
|
2
|
-
|
|
3
|
-
export interface LiveReferenceOptions<T> {
|
|
4
|
-
onUpdate?: (newValue: T | undefined) => void
|
|
5
|
-
onError?: (error: unknown) => void
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class LiveReference<T> implements Reference<T> {
|
|
9
|
-
private _value: T | undefined
|
|
10
|
-
private _resolved: boolean = false
|
|
11
|
-
private _hasError: boolean = false
|
|
12
|
-
private _options: LiveReferenceOptions<T>
|
|
13
|
-
|
|
14
|
-
resolve(): Promise<T | undefined> {
|
|
15
|
-
throw new Error('Method not implemented.')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor(readonly options: LiveReferenceOptions<T>) {
|
|
19
|
-
this._value = undefined
|
|
20
|
-
this._resolved = false
|
|
21
|
-
this._hasError = false
|
|
22
|
-
this._options = options
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public get value(): T | undefined {
|
|
26
|
-
return this._value
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public get resolved() {
|
|
30
|
-
return this._resolved
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public get hasError() {
|
|
34
|
-
return this._hasError
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected setStale() {
|
|
38
|
-
this._resolved = false
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected onUpdate(data: T | undefined): void {
|
|
42
|
-
this._value = data
|
|
43
|
-
this._resolved = true
|
|
44
|
-
this.onValueChange()
|
|
45
|
-
this._options.onUpdate?.(this._value)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
protected onError(error: unknown) {
|
|
49
|
-
this._hasError = true
|
|
50
|
-
this._value = undefined
|
|
51
|
-
this._resolved = true
|
|
52
|
-
this.onValueChange()
|
|
53
|
-
this._options.onError?.(error)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected onValueChange(): void {}
|
|
57
|
-
}
|
package/lib/Reference.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export interface Identifiable {
|
|
2
|
-
readonly id: string
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export type WithoutId<T> = Omit<T, 'id'>
|
|
6
|
-
|
|
7
|
-
export interface Resolvable<T> {
|
|
8
|
-
readonly resolved: boolean
|
|
9
|
-
readonly hasError: boolean
|
|
10
|
-
resolve(): Promise<T>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface Reference<T> extends Resolvable<T | undefined> {
|
|
14
|
-
readonly value: T | undefined
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type IdentifiableReference<T> = Reference<T> & Identifiable
|
|
18
|
-
|
|
19
|
-
export function createInitializedIdentifiableReference<T>(
|
|
20
|
-
value: T | undefined,
|
|
21
|
-
id: string
|
|
22
|
-
): Reference<T> & Identifiable {
|
|
23
|
-
return {
|
|
24
|
-
id,
|
|
25
|
-
value,
|
|
26
|
-
resolved: true,
|
|
27
|
-
hasError: false,
|
|
28
|
-
resolve: async () => value,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function createEmptyIdentifiableReference<T>(id: string): Reference<T> {
|
|
33
|
-
return createInitializedIdentifiableReference<T>(undefined, id)
|
|
34
|
-
}
|