@matter/general 0.16.6-alpha.0-20260121-06f1d9611 → 0.16.6-alpha.0-20260122-b5154bcb4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/storage/Storage.d.ts +1 -0
- package/dist/cjs/storage/Storage.d.ts.map +1 -1
- package/dist/cjs/storage/Storage.js.map +1 -1
- package/dist/cjs/storage/StorageMigration.d.ts +33 -0
- package/dist/cjs/storage/StorageMigration.d.ts.map +1 -0
- package/dist/cjs/storage/StorageMigration.js +116 -0
- package/dist/cjs/storage/StorageMigration.js.map +6 -0
- package/dist/cjs/storage/StorageService.d.ts +3 -2
- package/dist/cjs/storage/StorageService.d.ts.map +1 -1
- package/dist/cjs/storage/StorageService.js +1 -1
- package/dist/cjs/storage/StorageService.js.map +1 -1
- package/dist/cjs/storage/index.d.ts +1 -0
- package/dist/cjs/storage/index.d.ts.map +1 -1
- package/dist/cjs/storage/index.js +1 -0
- package/dist/cjs/storage/index.js.map +1 -1
- package/dist/esm/storage/Storage.d.ts +1 -0
- package/dist/esm/storage/Storage.d.ts.map +1 -1
- package/dist/esm/storage/Storage.js.map +1 -1
- package/dist/esm/storage/StorageMigration.d.ts +33 -0
- package/dist/esm/storage/StorageMigration.d.ts.map +1 -0
- package/dist/esm/storage/StorageMigration.js +96 -0
- package/dist/esm/storage/StorageMigration.js.map +6 -0
- package/dist/esm/storage/StorageService.d.ts +3 -2
- package/dist/esm/storage/StorageService.d.ts.map +1 -1
- package/dist/esm/storage/StorageService.js +1 -1
- package/dist/esm/storage/StorageService.js.map +1 -1
- package/dist/esm/storage/index.d.ts +1 -0
- package/dist/esm/storage/index.d.ts.map +1 -1
- package/dist/esm/storage/index.js +1 -0
- package/dist/esm/storage/index.js.map +1 -1
- package/package.json +2 -2
- package/src/storage/Storage.ts +2 -0
- package/src/storage/StorageMigration.ts +141 -0
- package/src/storage/StorageService.ts +6 -4
- package/src/storage/index.ts +1 -0
|
@@ -24,6 +24,7 @@ export declare abstract class Storage {
|
|
|
24
24
|
abstract values(contexts: string[]): MaybePromise<Record<string, SupportedStorageTypes>>;
|
|
25
25
|
abstract contexts(contexts: string[]): MaybePromise<string[]>;
|
|
26
26
|
abstract clearAll(contexts: string[]): MaybePromise<void>;
|
|
27
|
+
abstract clear(completely?: boolean): MaybePromise<void>;
|
|
27
28
|
/**
|
|
28
29
|
* Checks if a key exists in the storage for the given contexts.
|
|
29
30
|
* Important Note: This default implementation just reads the value for the key and checks if it is undefined.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../../../src/storage/Storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAuB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,qBAAa,YAAa,SAAQ,WAAW;CAAG;AAEhD;;GAEG;AACH,8BAAsB,OAAO;IACzB,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,UAAU,IAAI,YAAY,CAAC,IAAI,CAAC;IACzC,QAAQ,CAAC,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC;IACpC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAC9F,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC;IACnG,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,EAA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|
"sources": ["../../../src/storage/Storage.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,yBAAiD;AACjD,sBAA6B;AAP7B;AAAA;AAAA;AAAA;AAAA;AAUO,MAAM,qBAAqB,+BAAY;AAAC;AAKxC,MAAe,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,yBAAiD;AACjD,sBAA6B;AAP7B;AAAA;AAAA;AAAA;AAAA;AAUO,MAAM,qBAAqB,+BAAY;AAAC;AAKxC,MAAe,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB1B,IAAI,UAAoB,KAAoC;AACxD,UAAM,QAAQ,KAAK,IAAI,UAAU,GAAG;AACpC,QAAI,6BAAa,GAAG,KAAK,GAAG;AACxB,aAAO,6BAAa,KAAK,OAAO,OAAK,MAAM,MAAS;AAAA,IACxD;AACA,WAAO,UAAU;AAAA,EACrB;AAIJ;AASO,IAAU;AAAA,CAAV,CAAUA,sBAAV;AACI,WAAS,GAAiB,SAA6C;AAC1E,WAAO,WAAW,WAAW,OAAO,QAAQ,UAAU;AAAA,EAC1D;AAFO,EAAAA,kBAAS;AAIT,WAAS,OAAqB,SAAqD;AACtF,QAAI,CAAC,GAAG,OAAO,GAAG;AACd,YAAM,IAAI,uCAAoB,yDAAyD;AAAA,IAC3F;AAAA,EACJ;AAJO,EAAAA,kBAAS;AAAA,GALH;",
|
|
5
5
|
"names": ["CloneableStorage"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2026 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { Storage } from "./Storage.js";
|
|
7
|
+
/**
|
|
8
|
+
* A simple storage migrator of storage.
|
|
9
|
+
*
|
|
10
|
+
* It does not modify or remove source data.
|
|
11
|
+
*/
|
|
12
|
+
export declare namespace StorageMigration {
|
|
13
|
+
interface MigrationSkipped {
|
|
14
|
+
contexts: string[];
|
|
15
|
+
key: string;
|
|
16
|
+
error: string;
|
|
17
|
+
}
|
|
18
|
+
interface MigrationResult {
|
|
19
|
+
success: boolean;
|
|
20
|
+
migratedCount: number;
|
|
21
|
+
skippedCount: number;
|
|
22
|
+
skippedItems: MigrationSkipped[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Migrate storage from `source` to `target`.
|
|
26
|
+
*/
|
|
27
|
+
function migrate(source: Storage, target: Storage): Promise<MigrationResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Export migration result to log
|
|
30
|
+
*/
|
|
31
|
+
function resultToLog(result: MigrationResult): string;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=StorageMigration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageMigration.d.ts","sourceRoot":"","sources":["../../../src/storage/StorageMigration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C;;;;GAIG;AACH,yBAAiB,gBAAgB,CAAC;IAC9B,UAAiB,gBAAgB;QAC7B,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;KACjB;IAED,UAAiB,eAAe;QAC5B,OAAO,EAAE,OAAO,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,gBAAgB,EAAE,CAAC;KACpC;IAED;;OAEG;IACH,SAAsB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAmBxF;IAED;;OAEG;IACH,SAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,UAkBlD;CACJ"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var StorageMigration_exports = {};
|
|
20
|
+
__export(StorageMigration_exports, {
|
|
21
|
+
StorageMigration: () => StorageMigration
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(StorageMigration_exports);
|
|
24
|
+
var import_Logger = require("#log/Logger.js");
|
|
25
|
+
var import_MatterError = require("#MatterError.js");
|
|
26
|
+
/**
|
|
27
|
+
* @license
|
|
28
|
+
* Copyright 2022-2026 Matter.js Authors
|
|
29
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
30
|
+
*/
|
|
31
|
+
const logger = new import_Logger.Logger("StorageMigrator");
|
|
32
|
+
var StorageMigration;
|
|
33
|
+
((StorageMigration2) => {
|
|
34
|
+
async function migrate(source, target) {
|
|
35
|
+
const result = {
|
|
36
|
+
success: true,
|
|
37
|
+
migratedCount: 0,
|
|
38
|
+
skippedCount: 0,
|
|
39
|
+
skippedItems: []
|
|
40
|
+
};
|
|
41
|
+
await migrateContext({
|
|
42
|
+
source,
|
|
43
|
+
target,
|
|
44
|
+
contexts: [],
|
|
45
|
+
result
|
|
46
|
+
});
|
|
47
|
+
result.success = result.skippedCount === 0;
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
StorageMigration2.migrate = migrate;
|
|
51
|
+
function resultToLog(result) {
|
|
52
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
53
|
+
let logContent = `
|
|
54
|
+
# Migration Log
|
|
55
|
+
- Timestamp: ${timestamp}
|
|
56
|
+
- Success: ${result.success}
|
|
57
|
+
- Migrated: ${result.migratedCount}
|
|
58
|
+
- Skipped: ${result.skippedCount}
|
|
59
|
+
`.replace(/^\s+/gm, "");
|
|
60
|
+
if (result.skippedCount > 0 && result.skippedItems.length > 0) {
|
|
61
|
+
logContent += `
|
|
62
|
+
## Skipped Items
|
|
63
|
+
`;
|
|
64
|
+
for (const item of result.skippedItems) {
|
|
65
|
+
logContent += `- ${buildContextKeyLog(item.contexts, item.key)}: ${item.error}
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return logContent;
|
|
70
|
+
}
|
|
71
|
+
StorageMigration2.resultToLog = resultToLog;
|
|
72
|
+
})(StorageMigration || (StorageMigration = {}));
|
|
73
|
+
async function migrateContext(args) {
|
|
74
|
+
const { source, target, contexts, result } = args;
|
|
75
|
+
const keys = await source.keys(contexts);
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
try {
|
|
78
|
+
const value = await source.get(contexts, key);
|
|
79
|
+
if (value === void 0) {
|
|
80
|
+
const blob = await source.openBlob(contexts, key);
|
|
81
|
+
if (blob.size === 0) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const stream = blob.stream();
|
|
85
|
+
await target.writeBlobFromStream(contexts, key, stream);
|
|
86
|
+
result.migratedCount += 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
await target.set(contexts, key, value);
|
|
90
|
+
result.migratedCount += 1;
|
|
91
|
+
} catch (err) {
|
|
92
|
+
result.skippedCount += 1;
|
|
93
|
+
result.skippedItems.push({
|
|
94
|
+
contexts,
|
|
95
|
+
key,
|
|
96
|
+
error: err instanceof Error ? err.message : String(err)
|
|
97
|
+
});
|
|
98
|
+
logger.warn(`[migrate] Skipped '${buildContextKeyLog(contexts, key)}' entity: ${err}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const subContexts = await source.contexts(contexts);
|
|
102
|
+
const promises = [];
|
|
103
|
+
subContexts.forEach((subCon) => {
|
|
104
|
+
promises.push(
|
|
105
|
+
migrateContext({
|
|
106
|
+
...args,
|
|
107
|
+
contexts: [...contexts, subCon]
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
await import_MatterError.MatterAggregateError.allSettled(promises, "[migrate] Error migrating sub-contexts!");
|
|
112
|
+
}
|
|
113
|
+
function buildContextKeyLog(contexts, key) {
|
|
114
|
+
return `${contexts.join(".")}$${key}`;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=StorageMigration.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/storage/StorageMigration.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,oBAAuB;AACvB,yBAAqC;AAPrC;AAAA;AAAA;AAAA;AAAA;AAUA,MAAM,SAAS,IAAI,qBAAO,iBAAiB;AAOpC,IAAU;AAAA,CAAV,CAAUA,sBAAV;AAiBH,iBAAsB,QAAQ,QAAiB,QAA2C;AACtF,UAAM,SAAS;AAAA,MACX,SAAS;AAAA,MACT,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc,CAAC;AAAA,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AO,aAAa,KAAK;AAAA,QACrB;AAAA,QACA;AAAA,QACA,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA,MAC1D,CAAC;AACD,aAAO,KAAK,sBAAsB,mBAAmB,UAAU,GAAG,CAAC,aAAa,GAAG,EAAE;AAAA,IACzF;AAAA,EACJ;AAGA,QAAM,cAAc,MAAM,OAAO,SAAS,QAAQ;AAClD,QAAM,WAA4B,CAAC;AAEnC,cAAY,QAAQ,YAAU;AAC1B,aAAS;AAAA,MACL,eAAe;AAAA,QACX,GAAG;AAAA,QACH,UAAU,CAAC,GAAG,UAAU,MAAM;AAAA,MAClC,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAGD,QAAM,wCAAqB,WAAW,UAAU,yCAAyC;AAC7F;AAEA,SAAS,mBAAmB,UAAoB,KAAa;AACzD,SAAO,GAAG,SAAS,KAAK,GAAG,CAAC,IAAI,GAAG;AACvC;",
|
|
5
|
+
"names": ["StorageMigration"]
|
|
6
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2022-2026 Matter.js Authors
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { MaybePromise } from "#util/Promises.js";
|
|
6
7
|
import { Environment } from "../environment/Environment.js";
|
|
7
8
|
import { Environmental } from "../environment/Environmental.js";
|
|
8
9
|
import { Diagnostic } from "../log/Diagnostic.js";
|
|
@@ -14,7 +15,7 @@ import { StorageManager } from "./StorageManager.js";
|
|
|
14
15
|
export declare class StorageService {
|
|
15
16
|
#private;
|
|
16
17
|
[Diagnostic.value]: () => (string | (Record<string, unknown> & Diagnostic))[];
|
|
17
|
-
constructor(environment: Environment, factory?: (namespace: string) => Storage
|
|
18
|
+
constructor(environment: Environment, factory?: (namespace: string) => MaybePromise<Storage>, resolver?: (...paths: string[]) => string);
|
|
18
19
|
static [Environmental.create](environment: Environment): StorageService;
|
|
19
20
|
/**
|
|
20
21
|
* Open storage. The storage is initialized but the caller must take ownership.
|
|
@@ -25,7 +26,7 @@ export declare class StorageService {
|
|
|
25
26
|
/**
|
|
26
27
|
* Install a factory for opening storage. Without such a factory storage is unavailable.
|
|
27
28
|
*/
|
|
28
|
-
set factory(factory: (namespace: string) => Storage);
|
|
29
|
+
set factory(factory: (namespace: string) => MaybePromise<Storage>);
|
|
29
30
|
/**
|
|
30
31
|
* The storage location. Only used for diagnostic purposes.
|
|
31
32
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageService.d.ts","sourceRoot":"","sources":["../../../src/storage/StorageService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"StorageService.d.ts","sourceRoot":"","sources":["../../../src/storage/StorageService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AACH,qBAAa,cAAc;;IA6DvB,CAAC,UAAU,CAAC,KAAK,CAAC;gBAxDd,WAAW,EAAE,WAAW,EAExB,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC,OAAO,CAAC,EACtD,QAAQ,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM;IAU7C,MAAM,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,WAAW;IAItD;;;;OAIG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM;IAW5B;;OAEG;IACH,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC,OAAO,CAAC,EAEhE;IAED;;OAEG;IACH,IAAI,QAAQ,IAIW,MAAM,GAAG,SAAS,CAFxC;IAED,IAAI,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAExC;IAED;;OAEG;IACH,OAAO,EAAE,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CAW3C"}
|
|
@@ -50,7 +50,7 @@ class StorageService {
|
|
|
50
50
|
if (this.#factory === void 0) {
|
|
51
51
|
throw new import_MatterError.NoProviderError("Storage is unavailable because no platform implementation is installed");
|
|
52
52
|
}
|
|
53
|
-
const storage = this.#factory(namespace);
|
|
53
|
+
const storage = await this.#factory(namespace);
|
|
54
54
|
const manager = new import_StorageManager.StorageManager(storage);
|
|
55
55
|
await manager.initialize();
|
|
56
56
|
return manager;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storage/StorageService.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,yBAAgC;AAEhC,2BAA8B;AAC9B,wBAA2B;AAE3B,4BAA+B;AAZ/B;AAAA;AAAA;AAAA;AAAA;AAiBO,MAAM,eAAe;AAAA,EACxB;AAAA,EACA;AAAA,EAEA,YACI,aAEA,SACA,UACF;AACE,gBAAY,IAAI,gBAAgB,IAAI;AACpC,SAAK,WAAW;AAIhB,SAAK,UAAU,aAAa,IAAI,UAAc,MAAM,KAAK,GAAG;AAAA,EAChE;AAAA,EAEA,QAAQ,mCAAc,MAAM,EAAE,aAA0B;AACpD,WAAO,IAAI,KAAK,WAAW;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,KAAK,WAAmB;AAC1B,QAAI,KAAK,aAAa,QAAW;AAC7B,YAAM,IAAI,mCAAgB,wEAAwE;AAAA,IACtG;AAEA,UAAM,UAAU,MAAM,KAAK,SAAS,SAAS;AAC7C,UAAM,UAAU,IAAI,qCAAe,OAAO;AAC1C,UAAM,QAAQ,WAAW;AACzB,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,QAAQ,SAAuD;AAC/D,SAAK,WAAW;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,WAAW;AACX,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,SAASA,WAA8B;AACvC,SAAK,YAAYA;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEA,CAAC,6BAAW,KAAK,IAAI;AACjB,WAAO;AAAA,MACH;AAAA,MACA,6BAAW,KAAK;AAAA,QACZ,UAAU,YAAY;AAAA,QACtB,WAAW,CAAC,CAAC,KAAK;AAAA,MACtB,CAAC;AAAA,IACL;AAAA,EACJ;AACJ;",
|
|
5
5
|
"names": ["location"]
|
|
6
6
|
}
|
|
@@ -8,6 +8,7 @@ export * from "./Storage.js";
|
|
|
8
8
|
export * from "./StorageBackendMemory.js";
|
|
9
9
|
export * from "./StorageContext.js";
|
|
10
10
|
export * from "./StorageManager.js";
|
|
11
|
+
export * from "./StorageMigration.js";
|
|
11
12
|
export * from "./StorageService.js";
|
|
12
13
|
export * from "./StringifyTools.js";
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
|
@@ -20,6 +20,7 @@ __reExport(storage_exports, require("./Storage.js"), module.exports);
|
|
|
20
20
|
__reExport(storage_exports, require("./StorageBackendMemory.js"), module.exports);
|
|
21
21
|
__reExport(storage_exports, require("./StorageContext.js"), module.exports);
|
|
22
22
|
__reExport(storage_exports, require("./StorageManager.js"), module.exports);
|
|
23
|
+
__reExport(storage_exports, require("./StorageMigration.js"), module.exports);
|
|
23
24
|
__reExport(storage_exports, require("./StorageService.js"), module.exports);
|
|
24
25
|
__reExport(storage_exports, require("./StringifyTools.js"), module.exports);
|
|
25
26
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storage/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAMA,4BAAc,mCANd;AAOA,4BAAc,yBAPd;AAQA,4BAAc,sCARd;AASA,4BAAc,gCATd;AAUA,4BAAc,gCAVd;AAWA,4BAAc,
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAMA,4BAAc,mCANd;AAOA,4BAAc,yBAPd;AAQA,4BAAc,sCARd;AASA,4BAAc,gCATd;AAUA,4BAAc,gCAVd;AAWA,4BAAc,kCAXd;AAYA,4BAAc,gCAZd;AAaA,4BAAc,gCAbd;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -24,6 +24,7 @@ export declare abstract class Storage {
|
|
|
24
24
|
abstract values(contexts: string[]): MaybePromise<Record<string, SupportedStorageTypes>>;
|
|
25
25
|
abstract contexts(contexts: string[]): MaybePromise<string[]>;
|
|
26
26
|
abstract clearAll(contexts: string[]): MaybePromise<void>;
|
|
27
|
+
abstract clear(completely?: boolean): MaybePromise<void>;
|
|
27
28
|
/**
|
|
28
29
|
* Checks if a key exists in the storage for the given contexts.
|
|
29
30
|
* Important Note: This default implementation just reads the value for the key and checks if it is undefined.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../../../src/storage/Storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAuB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,qBAAa,YAAa,SAAQ,WAAW;CAAG;AAEhD;;GAEG;AACH,8BAAsB,OAAO;IACzB,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,UAAU,IAAI,YAAY,CAAC,IAAI,CAAC;IACzC,QAAQ,CAAC,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC;IACpC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAC9F,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC;IACnG,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE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
"sources": ["../../../src/storage/Storage.ts"],
|
|
4
|
-
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,qBAAqB,mBAAmB;AACjD,SAAS,oBAAoB;AAGtB,MAAM,qBAAqB,YAAY;AAAC;AAKxC,MAAe,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,qBAAqB,mBAAmB;AACjD,SAAS,oBAAoB;AAGtB,MAAM,qBAAqB,YAAY;AAAC;AAKxC,MAAe,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB1B,IAAI,UAAoB,KAAoC;AACxD,UAAM,QAAQ,KAAK,IAAI,UAAU,GAAG;AACpC,QAAI,aAAa,GAAG,KAAK,GAAG;AACxB,aAAO,aAAa,KAAK,OAAO,OAAK,MAAM,MAAS;AAAA,IACxD;AACA,WAAO,UAAU;AAAA,EACrB;AAIJ;AASO,IAAU;AAAA,CAAV,CAAUA,sBAAV;AACI,WAAS,GAAiB,SAA6C;AAC1E,WAAO,WAAW,WAAW,OAAO,QAAQ,UAAU;AAAA,EAC1D;AAFO,EAAAA,kBAAS;AAIT,WAAS,OAAqB,SAAqD;AACtF,QAAI,CAAC,GAAG,OAAO,GAAG;AACd,YAAM,IAAI,oBAAoB,yDAAyD;AAAA,IAC3F;AAAA,EACJ;AAJO,EAAAA,kBAAS;AAAA,GALH;",
|
|
5
5
|
"names": ["CloneableStorage"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2026 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { Storage } from "./Storage.js";
|
|
7
|
+
/**
|
|
8
|
+
* A simple storage migrator of storage.
|
|
9
|
+
*
|
|
10
|
+
* It does not modify or remove source data.
|
|
11
|
+
*/
|
|
12
|
+
export declare namespace StorageMigration {
|
|
13
|
+
interface MigrationSkipped {
|
|
14
|
+
contexts: string[];
|
|
15
|
+
key: string;
|
|
16
|
+
error: string;
|
|
17
|
+
}
|
|
18
|
+
interface MigrationResult {
|
|
19
|
+
success: boolean;
|
|
20
|
+
migratedCount: number;
|
|
21
|
+
skippedCount: number;
|
|
22
|
+
skippedItems: MigrationSkipped[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Migrate storage from `source` to `target`.
|
|
26
|
+
*/
|
|
27
|
+
function migrate(source: Storage, target: Storage): Promise<MigrationResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Export migration result to log
|
|
30
|
+
*/
|
|
31
|
+
function resultToLog(result: MigrationResult): string;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=StorageMigration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageMigration.d.ts","sourceRoot":"","sources":["../../../src/storage/StorageMigration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C;;;;GAIG;AACH,yBAAiB,gBAAgB,CAAC;IAC9B,UAAiB,gBAAgB;QAC7B,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;KACjB;IAED,UAAiB,eAAe;QAC5B,OAAO,EAAE,OAAO,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,gBAAgB,EAAE,CAAC;KACpC;IAED;;OAEG;IACH,SAAsB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAmBxF;IAED;;OAEG;IACH,SAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,UAkBlD;CACJ"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2026 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Logger } from "#log/Logger.js";
|
|
7
|
+
import { MatterAggregateError } from "#MatterError.js";
|
|
8
|
+
const logger = new Logger("StorageMigrator");
|
|
9
|
+
var StorageMigration;
|
|
10
|
+
((StorageMigration2) => {
|
|
11
|
+
async function migrate(source, target) {
|
|
12
|
+
const result = {
|
|
13
|
+
success: true,
|
|
14
|
+
migratedCount: 0,
|
|
15
|
+
skippedCount: 0,
|
|
16
|
+
skippedItems: []
|
|
17
|
+
};
|
|
18
|
+
await migrateContext({
|
|
19
|
+
source,
|
|
20
|
+
target,
|
|
21
|
+
contexts: [],
|
|
22
|
+
result
|
|
23
|
+
});
|
|
24
|
+
result.success = result.skippedCount === 0;
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
StorageMigration2.migrate = migrate;
|
|
28
|
+
function resultToLog(result) {
|
|
29
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
30
|
+
let logContent = `
|
|
31
|
+
# Migration Log
|
|
32
|
+
- Timestamp: ${timestamp}
|
|
33
|
+
- Success: ${result.success}
|
|
34
|
+
- Migrated: ${result.migratedCount}
|
|
35
|
+
- Skipped: ${result.skippedCount}
|
|
36
|
+
`.replace(/^\s+/gm, "");
|
|
37
|
+
if (result.skippedCount > 0 && result.skippedItems.length > 0) {
|
|
38
|
+
logContent += `
|
|
39
|
+
## Skipped Items
|
|
40
|
+
`;
|
|
41
|
+
for (const item of result.skippedItems) {
|
|
42
|
+
logContent += `- ${buildContextKeyLog(item.contexts, item.key)}: ${item.error}
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return logContent;
|
|
47
|
+
}
|
|
48
|
+
StorageMigration2.resultToLog = resultToLog;
|
|
49
|
+
})(StorageMigration || (StorageMigration = {}));
|
|
50
|
+
async function migrateContext(args) {
|
|
51
|
+
const { source, target, contexts, result } = args;
|
|
52
|
+
const keys = await source.keys(contexts);
|
|
53
|
+
for (const key of keys) {
|
|
54
|
+
try {
|
|
55
|
+
const value = await source.get(contexts, key);
|
|
56
|
+
if (value === void 0) {
|
|
57
|
+
const blob = await source.openBlob(contexts, key);
|
|
58
|
+
if (blob.size === 0) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const stream = blob.stream();
|
|
62
|
+
await target.writeBlobFromStream(contexts, key, stream);
|
|
63
|
+
result.migratedCount += 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
await target.set(contexts, key, value);
|
|
67
|
+
result.migratedCount += 1;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
result.skippedCount += 1;
|
|
70
|
+
result.skippedItems.push({
|
|
71
|
+
contexts,
|
|
72
|
+
key,
|
|
73
|
+
error: err instanceof Error ? err.message : String(err)
|
|
74
|
+
});
|
|
75
|
+
logger.warn(`[migrate] Skipped '${buildContextKeyLog(contexts, key)}' entity: ${err}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const subContexts = await source.contexts(contexts);
|
|
79
|
+
const promises = [];
|
|
80
|
+
subContexts.forEach((subCon) => {
|
|
81
|
+
promises.push(
|
|
82
|
+
migrateContext({
|
|
83
|
+
...args,
|
|
84
|
+
contexts: [...contexts, subCon]
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
await MatterAggregateError.allSettled(promises, "[migrate] Error migrating sub-contexts!");
|
|
89
|
+
}
|
|
90
|
+
function buildContextKeyLog(contexts, key) {
|
|
91
|
+
return `${contexts.join(".")}$${key}`;
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
StorageMigration
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=StorageMigration.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2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,GAAG;AAC5C,UAAI,UAAU,QAAW;AAErB,cAAM,OAAO,MAAM,OAAO,SAAS,UAAU,GAAG;AAChD,YAAI,KAAK,SAAS,GAAG;AACjB;AAAA,QACJ;AAEA,cAAM,SAAS,KAAK,OAAO;AAC3B,cAAM,OAAO,oBAAoB,UAAU,KAAK,MAAM;AAEtD,eAAO,iBAAiB;AACxB;AAAA,MACJ;AAEA,YAAM,OAAO,IAAI,UAAU,KAAK,KAAK;AACrC,aAAO,iBAAiB;AAAA,IAC5B,SAAS,KAAK;AACV,aAAO,gBAAgB;AACvB,aAAO,aAAa,KAAK;AAAA,QACrB;AAAA,QACA;AAAA,QACA,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA,MAC1D,CAAC;AACD,aAAO,KAAK,sBAAsB,mBAAmB,UAAU,GAAG,CAAC,aAAa,GAAG,EAAE;AAAA,IACzF;AAAA,EACJ;AAGA,QAAM,cAAc,MAAM,OAAO,SAAS,QAAQ;AAClD,QAAM,WAA4B,CAAC;AAEnC,cAAY,QAAQ,YAAU;AAC1B,aAAS;AAAA,MACL,eAAe;AAAA,QACX,GAAG;AAAA,QACH,UAAU,CAAC,GAAG,UAAU,MAAM;AAAA,MAClC,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAGD,QAAM,qBAAqB,WAAW,UAAU,yCAAyC;AAC7F;AAEA,SAAS,mBAAmB,UAAoB,KAAa;AACzD,SAAO,GAAG,SAAS,KAAK,GAAG,CAAC,IAAI,GAAG;AACvC;",
|
|
5
|
+
"names": ["StorageMigration"]
|
|
6
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2022-2026 Matter.js Authors
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { MaybePromise } from "#util/Promises.js";
|
|
6
7
|
import { Environment } from "../environment/Environment.js";
|
|
7
8
|
import { Environmental } from "../environment/Environmental.js";
|
|
8
9
|
import { Diagnostic } from "../log/Diagnostic.js";
|
|
@@ -14,7 +15,7 @@ import { StorageManager } from "./StorageManager.js";
|
|
|
14
15
|
export declare class StorageService {
|
|
15
16
|
#private;
|
|
16
17
|
[Diagnostic.value]: () => (string | (Record<string, unknown> & Diagnostic))[];
|
|
17
|
-
constructor(environment: Environment, factory?: (namespace: string) => Storage
|
|
18
|
+
constructor(environment: Environment, factory?: (namespace: string) => MaybePromise<Storage>, resolver?: (...paths: string[]) => string);
|
|
18
19
|
static [Environmental.create](environment: Environment): StorageService;
|
|
19
20
|
/**
|
|
20
21
|
* Open storage. The storage is initialized but the caller must take ownership.
|
|
@@ -25,7 +26,7 @@ export declare class StorageService {
|
|
|
25
26
|
/**
|
|
26
27
|
* Install a factory for opening storage. Without such a factory storage is unavailable.
|
|
27
28
|
*/
|
|
28
|
-
set factory(factory: (namespace: string) => Storage);
|
|
29
|
+
set factory(factory: (namespace: string) => MaybePromise<Storage>);
|
|
29
30
|
/**
|
|
30
31
|
* The storage location. Only used for diagnostic purposes.
|
|
31
32
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageService.d.ts","sourceRoot":"","sources":["../../../src/storage/StorageService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"StorageService.d.ts","sourceRoot":"","sources":["../../../src/storage/StorageService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AACH,qBAAa,cAAc;;IA6DvB,CAAC,UAAU,CAAC,KAAK,CAAC;gBAxDd,WAAW,EAAE,WAAW,EAExB,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC,OAAO,CAAC,EACtD,QAAQ,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM;IAU7C,MAAM,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,WAAW;IAItD;;;;OAIG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM;IAW5B;;OAEG;IACH,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC,OAAO,CAAC,EAEhE;IAED;;OAEG;IACH,IAAI,QAAQ,IAIW,MAAM,GAAG,SAAS,CAFxC;IAED,IAAI,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAExC;IAED;;OAEG;IACH,OAAO,EAAE,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CAW3C"}
|
|
@@ -27,7 +27,7 @@ class StorageService {
|
|
|
27
27
|
if (this.#factory === void 0) {
|
|
28
28
|
throw new NoProviderError("Storage is unavailable because no platform implementation is installed");
|
|
29
29
|
}
|
|
30
|
-
const storage = this.#factory(namespace);
|
|
30
|
+
const storage = await this.#factory(namespace);
|
|
31
31
|
const manager = new StorageManager(storage);
|
|
32
32
|
await manager.initialize();
|
|
33
33
|
return manager;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storage/StorageService.ts"],
|
|
4
|
-
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,SAAS,uBAAuB;AAEhC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAE3B,SAAS,sBAAsB;AAKxB,MAAM,eAAe;AAAA,EACxB;AAAA,EACA;AAAA,EAEA,YACI,aAEA,SACA,UACF;AACE,gBAAY,IAAI,gBAAgB,IAAI;AACpC,SAAK,WAAW;AAIhB,SAAK,UAAU,aAAa,IAAI,UAAc,MAAM,KAAK,GAAG;AAAA,EAChE;AAAA,EAEA,QAAQ,cAAc,MAAM,EAAE,aAA0B;AACpD,WAAO,IAAI,KAAK,WAAW;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,KAAK,WAAmB;AAC1B,QAAI,KAAK,aAAa,QAAW;AAC7B,YAAM,IAAI,gBAAgB,wEAAwE;AAAA,IACtG;AAEA,UAAM,UAAU,MAAM,KAAK,SAAS,SAAS;AAC7C,UAAM,UAAU,IAAI,eAAe,OAAO;AAC1C,UAAM,QAAQ,WAAW;AACzB,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,QAAQ,SAAuD;AAC/D,SAAK,WAAW;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,WAAW;AACX,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,SAASA,WAA8B;AACvC,SAAK,YAAYA;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEA,CAAC,WAAW,KAAK,IAAI;AACjB,WAAO;AAAA,MACH;AAAA,MACA,WAAW,KAAK;AAAA,QACZ,UAAU,YAAY;AAAA,QACtB,WAAW,CAAC,CAAC,KAAK;AAAA,MACtB,CAAC;AAAA,IACL;AAAA,EACJ;AACJ;",
|
|
5
5
|
"names": ["location"]
|
|
6
6
|
}
|
|
@@ -8,6 +8,7 @@ export * from "./Storage.js";
|
|
|
8
8
|
export * from "./StorageBackendMemory.js";
|
|
9
9
|
export * from "./StorageContext.js";
|
|
10
10
|
export * from "./StorageManager.js";
|
|
11
|
+
export * from "./StorageMigration.js";
|
|
11
12
|
export * from "./StorageService.js";
|
|
12
13
|
export * from "./StringifyTools.js";
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
|
@@ -8,6 +8,7 @@ export * from "./Storage.js";
|
|
|
8
8
|
export * from "./StorageBackendMemory.js";
|
|
9
9
|
export * from "./StorageContext.js";
|
|
10
10
|
export * from "./StorageManager.js";
|
|
11
|
+
export * from "./StorageMigration.js";
|
|
11
12
|
export * from "./StorageService.js";
|
|
12
13
|
export * from "./StringifyTools.js";
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storage/index.ts"],
|
|
4
|
-
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matter/general",
|
|
3
|
-
"version": "0.16.6-alpha.0-
|
|
3
|
+
"version": "0.16.6-alpha.0-20260122-b5154bcb4",
|
|
4
4
|
"description": "Non-Matter support for Matter.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"iot",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@noble/curves": "^2.0.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@matter/testing": "0.16.6-alpha.0-
|
|
39
|
+
"@matter/testing": "0.16.6-alpha.0-20260122-b5154bcb4"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"dist/**/*",
|
package/src/storage/Storage.ts
CHANGED
|
@@ -25,6 +25,8 @@ export abstract class Storage {
|
|
|
25
25
|
abstract values(contexts: string[]): MaybePromise<Record<string, SupportedStorageTypes>>;
|
|
26
26
|
abstract contexts(contexts: string[]): MaybePromise<string[]>;
|
|
27
27
|
abstract clearAll(contexts: string[]): MaybePromise<void>;
|
|
28
|
+
// TODO: use `completely` variable for removing storage completely
|
|
29
|
+
abstract clear(completely?: boolean): MaybePromise<void>;
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Checks if a key exists in the storage for the given contexts.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2026 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Logger } from "#log/Logger.js";
|
|
8
|
+
import { MatterAggregateError } from "#MatterError.js";
|
|
9
|
+
import type { Storage } from "./Storage.js";
|
|
10
|
+
|
|
11
|
+
const logger = new Logger("StorageMigrator");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A simple storage migrator of storage.
|
|
15
|
+
*
|
|
16
|
+
* It does not modify or remove source data.
|
|
17
|
+
*/
|
|
18
|
+
export namespace StorageMigration {
|
|
19
|
+
export interface MigrationSkipped {
|
|
20
|
+
contexts: string[];
|
|
21
|
+
key: string;
|
|
22
|
+
error: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface MigrationResult {
|
|
26
|
+
success: boolean;
|
|
27
|
+
migratedCount: number;
|
|
28
|
+
skippedCount: number;
|
|
29
|
+
skippedItems: MigrationSkipped[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Migrate storage from `source` to `target`.
|
|
34
|
+
*/
|
|
35
|
+
export async function migrate(source: Storage, target: Storage): Promise<MigrationResult> {
|
|
36
|
+
const result = {
|
|
37
|
+
success: true,
|
|
38
|
+
migratedCount: 0,
|
|
39
|
+
skippedCount: 0,
|
|
40
|
+
skippedItems: [],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Migrate all contexts recursively
|
|
44
|
+
await migrateContext({
|
|
45
|
+
source,
|
|
46
|
+
target,
|
|
47
|
+
contexts: [],
|
|
48
|
+
result,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Result
|
|
52
|
+
result.success = result.skippedCount === 0;
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Export migration result to log
|
|
58
|
+
*/
|
|
59
|
+
export function resultToLog(result: MigrationResult) {
|
|
60
|
+
const timestamp = new Date().toISOString();
|
|
61
|
+
|
|
62
|
+
let logContent = `
|
|
63
|
+
# Migration Log
|
|
64
|
+
- Timestamp: ${timestamp}
|
|
65
|
+
- Success: ${result.success}
|
|
66
|
+
- Migrated: ${result.migratedCount}
|
|
67
|
+
- Skipped: ${result.skippedCount}
|
|
68
|
+
`.replace(/^\s+/gm, "");
|
|
69
|
+
if (result.skippedCount > 0 && result.skippedItems.length > 0) {
|
|
70
|
+
logContent += `\n## Skipped Items\n`;
|
|
71
|
+
for (const item of result.skippedItems) {
|
|
72
|
+
logContent += `- ${buildContextKeyLog(item.contexts, item.key)}: ${item.error}\n`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return logContent;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Migrate a specific context and its sub-contexts recursively
|
|
82
|
+
*/
|
|
83
|
+
async function migrateContext(args: {
|
|
84
|
+
source: Storage;
|
|
85
|
+
target: Storage;
|
|
86
|
+
contexts: string[];
|
|
87
|
+
result: StorageMigration.MigrationResult;
|
|
88
|
+
}) {
|
|
89
|
+
const { source, target, contexts, result } = args;
|
|
90
|
+
const keys = await source.keys(contexts);
|
|
91
|
+
|
|
92
|
+
for (const key of keys) {
|
|
93
|
+
try {
|
|
94
|
+
const value = await source.get(contexts, key);
|
|
95
|
+
if (value === undefined) {
|
|
96
|
+
// Blob
|
|
97
|
+
const blob = await source.openBlob(contexts, key);
|
|
98
|
+
if (blob.size === 0) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const stream = blob.stream();
|
|
103
|
+
await target.writeBlobFromStream(contexts, key, stream);
|
|
104
|
+
|
|
105
|
+
result.migratedCount += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
// Json
|
|
109
|
+
await target.set(contexts, key, value);
|
|
110
|
+
result.migratedCount += 1;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
result.skippedCount += 1;
|
|
113
|
+
result.skippedItems.push({
|
|
114
|
+
contexts,
|
|
115
|
+
key,
|
|
116
|
+
error: err instanceof Error ? err.message : String(err),
|
|
117
|
+
});
|
|
118
|
+
logger.warn(`[migrate] Skipped '${buildContextKeyLog(contexts, key)}' entity: ${err}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Migrate subcontext recursively
|
|
123
|
+
const subContexts = await source.contexts(contexts);
|
|
124
|
+
const promises: Promise<void>[] = [];
|
|
125
|
+
|
|
126
|
+
subContexts.forEach(subCon => {
|
|
127
|
+
promises.push(
|
|
128
|
+
migrateContext({
|
|
129
|
+
...args,
|
|
130
|
+
contexts: [...contexts, subCon],
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Promise.all with try catch
|
|
136
|
+
await MatterAggregateError.allSettled(promises, "[migrate] Error migrating sub-contexts!");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function buildContextKeyLog(contexts: string[], key: string) {
|
|
140
|
+
return `${contexts.join(".")}$${key}`;
|
|
141
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2022-2026 Matter.js Authors
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { MaybePromise } from "#util/Promises.js";
|
|
6
7
|
|
|
7
8
|
import { NoProviderError } from "../MatterError.js";
|
|
8
9
|
import { Environment } from "../environment/Environment.js";
|
|
@@ -15,12 +16,13 @@ import { StorageManager } from "./StorageManager.js";
|
|
|
15
16
|
* Service adapter for the Matter.js storage API.
|
|
16
17
|
*/
|
|
17
18
|
export class StorageService {
|
|
18
|
-
#factory?: (namespace: string) => Storage
|
|
19
|
+
#factory?: (namespace: string) => MaybePromise<Storage>;
|
|
19
20
|
#location?: string;
|
|
20
21
|
|
|
21
22
|
constructor(
|
|
22
23
|
environment: Environment,
|
|
23
|
-
|
|
24
|
+
|
|
25
|
+
factory?: (namespace: string) => MaybePromise<Storage>,
|
|
24
26
|
resolver?: (...paths: string[]) => string,
|
|
25
27
|
) {
|
|
26
28
|
environment.set(StorageService, this);
|
|
@@ -45,7 +47,7 @@ export class StorageService {
|
|
|
45
47
|
throw new NoProviderError("Storage is unavailable because no platform implementation is installed");
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
const storage = this.#factory(namespace);
|
|
50
|
+
const storage = await this.#factory(namespace);
|
|
49
51
|
const manager = new StorageManager(storage);
|
|
50
52
|
await manager.initialize();
|
|
51
53
|
return manager;
|
|
@@ -54,7 +56,7 @@ export class StorageService {
|
|
|
54
56
|
/**
|
|
55
57
|
* Install a factory for opening storage. Without such a factory storage is unavailable.
|
|
56
58
|
*/
|
|
57
|
-
set factory(factory: (namespace: string) => Storage) {
|
|
59
|
+
set factory(factory: (namespace: string) => MaybePromise<Storage>) {
|
|
58
60
|
this.#factory = factory;
|
|
59
61
|
}
|
|
60
62
|
|
package/src/storage/index.ts
CHANGED
|
@@ -9,5 +9,6 @@ export * from "./Storage.js";
|
|
|
9
9
|
export * from "./StorageBackendMemory.js";
|
|
10
10
|
export * from "./StorageContext.js";
|
|
11
11
|
export * from "./StorageManager.js";
|
|
12
|
+
export * from "./StorageMigration.js";
|
|
12
13
|
export * from "./StorageService.js";
|
|
13
14
|
export * from "./StringifyTools.js";
|