@brightchain/brightchain-api-lib 0.25.0 → 0.26.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/package.json +4 -3
- package/src/lib/application.d.ts +3 -14
- package/src/lib/application.d.ts.map +1 -1
- package/src/lib/application.js +89 -34
- package/src/lib/application.js.map +1 -1
- package/src/lib/databaseInit.d.ts +7 -11
- package/src/lib/databaseInit.d.ts.map +1 -1
- package/src/lib/databaseInit.js +41 -107
- package/src/lib/databaseInit.js.map +1 -1
- package/src/lib/datastore/block-document-store-factory.d.ts +3 -0
- package/src/lib/datastore/block-document-store-factory.d.ts.map +1 -1
- package/src/lib/datastore/block-document-store-factory.js +15 -18
- package/src/lib/datastore/block-document-store-factory.js.map +1 -1
- package/src/lib/datastore/block-document-store.d.ts +2 -191
- package/src/lib/datastore/block-document-store.d.ts.map +1 -1
- package/src/lib/datastore/block-document-store.js +4 -628
- package/src/lib/datastore/block-document-store.js.map +1 -1
- package/src/lib/datastore/document-store.d.ts +1 -62
- package/src/lib/datastore/document-store.d.ts.map +1 -1
- package/src/lib/datastore/memory-document-store.d.ts +1 -8
- package/src/lib/datastore/memory-document-store.d.ts.map +1 -1
- package/src/lib/datastore/memory-document-store.js +3 -214
- package/src/lib/datastore/memory-document-store.js.map +1 -1
- package/src/lib/environment.d.ts +4 -47
- package/src/lib/environment.d.ts.map +1 -1
- package/src/lib/environment.js +2 -136
- package/src/lib/environment.js.map +1 -1
- package/src/lib/interfaces/environment.d.ts +3 -25
- package/src/lib/interfaces/environment.d.ts.map +1 -1
- package/src/lib/middleware/index.d.ts +1 -1
- package/src/lib/middleware/index.d.ts.map +1 -1
- package/src/lib/middleware/index.js +3 -2
- package/src/lib/middleware/index.js.map +1 -1
- package/src/lib/middleware/validateBody.d.ts +1 -12
- package/src/lib/middleware/validateBody.d.ts.map +1 -1
- package/src/lib/middleware/validateBody.js +4 -32
- package/src/lib/middleware/validateBody.js.map +1 -1
- package/src/lib/middlewares.d.ts.map +1 -1
- package/src/lib/middlewares.js +7 -1
- package/src/lib/middlewares.js.map +1 -1
- package/src/lib/plugins/brightchain-database-plugin.d.ts +27 -79
- package/src/lib/plugins/brightchain-database-plugin.d.ts.map +1 -1
- package/src/lib/plugins/brightchain-database-plugin.js +27 -97
- package/src/lib/plugins/brightchain-database-plugin.js.map +1 -1
- package/src/lib/services/emailGateway/antiSpamFilter.d.ts +229 -0
- package/src/lib/services/emailGateway/antiSpamFilter.d.ts.map +1 -0
- package/src/lib/services/emailGateway/antiSpamFilter.js +325 -0
- package/src/lib/services/emailGateway/antiSpamFilter.js.map +1 -0
- package/src/lib/services/emailGateway/bounceProcessor.d.ts +171 -0
- package/src/lib/services/emailGateway/bounceProcessor.d.ts.map +1 -0
- package/src/lib/services/emailGateway/bounceProcessor.js +378 -0
- package/src/lib/services/emailGateway/bounceProcessor.js.map +1 -0
- package/src/lib/services/emailGateway/emailAuthVerifier.d.ts +99 -0
- package/src/lib/services/emailGateway/emailAuthVerifier.d.ts.map +1 -0
- package/src/lib/services/emailGateway/emailAuthVerifier.js +202 -0
- package/src/lib/services/emailGateway/emailAuthVerifier.js.map +1 -0
- package/src/lib/services/emailGateway/emailGatewayConfig.d.ts +73 -0
- package/src/lib/services/emailGateway/emailGatewayConfig.d.ts.map +1 -0
- package/src/lib/services/emailGateway/emailGatewayConfig.js +107 -0
- package/src/lib/services/emailGateway/emailGatewayConfig.js.map +1 -0
- package/src/lib/services/emailGateway/emailGatewayService.d.ts +152 -0
- package/src/lib/services/emailGateway/emailGatewayService.d.ts.map +1 -0
- package/src/lib/services/emailGateway/emailGatewayService.js +201 -0
- package/src/lib/services/emailGateway/emailGatewayService.js.map +1 -0
- package/src/lib/services/emailGateway/gatewayObservability.d.ts +123 -0
- package/src/lib/services/emailGateway/gatewayObservability.d.ts.map +1 -0
- package/src/lib/services/emailGateway/gatewayObservability.js +186 -0
- package/src/lib/services/emailGateway/gatewayObservability.js.map +1 -0
- package/src/lib/services/emailGateway/inboundProcessor.d.ts +113 -0
- package/src/lib/services/emailGateway/inboundProcessor.d.ts.map +1 -0
- package/src/lib/services/emailGateway/inboundProcessor.js +298 -0
- package/src/lib/services/emailGateway/inboundProcessor.js.map +1 -0
- package/src/lib/services/emailGateway/index.d.ts +23 -0
- package/src/lib/services/emailGateway/index.d.ts.map +1 -0
- package/src/lib/services/emailGateway/index.js +26 -0
- package/src/lib/services/emailGateway/index.js.map +1 -0
- package/src/lib/services/emailGateway/outboundDeliveryWorker.d.ts +111 -0
- package/src/lib/services/emailGateway/outboundDeliveryWorker.d.ts.map +1 -0
- package/src/lib/services/emailGateway/outboundDeliveryWorker.js +97 -0
- package/src/lib/services/emailGateway/outboundDeliveryWorker.js.map +1 -0
- package/src/lib/services/emailGateway/outboundQueue.d.ts +135 -0
- package/src/lib/services/emailGateway/outboundQueue.d.ts.map +1 -0
- package/src/lib/services/emailGateway/outboundQueue.js +227 -0
- package/src/lib/services/emailGateway/outboundQueue.js.map +1 -0
- package/src/lib/services/emailGateway/outboundQueueStore.d.ts +110 -0
- package/src/lib/services/emailGateway/outboundQueueStore.d.ts.map +1 -0
- package/src/lib/services/emailGateway/outboundQueueStore.js +131 -0
- package/src/lib/services/emailGateway/outboundQueueStore.js.map +1 -0
- package/src/lib/services/emailGateway/recipientLookupService.d.ts +135 -0
- package/src/lib/services/emailGateway/recipientLookupService.d.ts.map +1 -0
- package/src/lib/services/emailGateway/recipientLookupService.js +294 -0
- package/src/lib/services/emailGateway/recipientLookupService.js.map +1 -0
- package/src/lib/services/emailGateway/retryBackoff.d.ts +79 -0
- package/src/lib/services/emailGateway/retryBackoff.d.ts.map +1 -0
- package/src/lib/services/emailGateway/retryBackoff.js +77 -0
- package/src/lib/services/emailGateway/retryBackoff.js.map +1 -0
- package/src/lib/services/index.d.ts +1 -0
- package/src/lib/services/index.d.ts.map +1 -1
- package/src/lib/services/index.js +1 -0
- package/src/lib/services/index.js.map +1 -1
- package/src/lib/services/quorumDatabaseAdapter.d.ts +7 -1
- package/src/lib/services/quorumDatabaseAdapter.d.ts.map +1 -1
- package/src/lib/services/quorumDatabaseAdapter.js +83 -0
- package/src/lib/services/quorumDatabaseAdapter.js.map +1 -1
- package/src/lib/services/sessionAdapter.d.ts +2 -61
- package/src/lib/services/sessionAdapter.d.ts.map +1 -1
- package/src/lib/services/sessionAdapter.js +2 -102
- package/src/lib/services/sessionAdapter.js.map +1 -1
- package/src/lib/shared-types.d.ts +7 -15
- package/src/lib/shared-types.d.ts.map +1 -1
- package/src/lib/types/backend-id.d.ts +1 -2
- package/src/lib/types/backend-id.d.ts.map +1 -1
- package/src/lib/validation/userValidation.d.ts +2 -43
- package/src/lib/validation/userValidation.d.ts.map +1 -1
- package/src/lib/validation/userValidation.js +6 -144
- package/src/lib/validation/userValidation.js.map +1 -1
package/src/lib/databaseInit.js
CHANGED
|
@@ -2,131 +2,65 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @fileoverview BrightChain database initialization function.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Wraps the generic brightchainDatabaseInit from @brightchain/node-express-suite,
|
|
6
|
+
* passing domain-specific model registrations (energy account hydration schema)
|
|
7
|
+
* as a callback. Returns the full IBrightChainInitData including MemberStore
|
|
8
|
+
* and EnergyAccountStore.
|
|
7
9
|
*
|
|
8
10
|
* @module databaseInit
|
|
9
11
|
*/
|
|
10
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
13
|
exports.brightchainDatabaseInit = brightchainDatabaseInit;
|
|
12
14
|
const brightchain_lib_1 = require("@brightchain/brightchain-lib");
|
|
13
|
-
const
|
|
14
|
-
const fs_1 = require("fs");
|
|
15
|
-
const promises_1 = require("fs/promises");
|
|
16
|
-
const blockStoreFactory_1 = require("./factories/blockStoreFactory");
|
|
15
|
+
const node_express_suite_1 = require("@brightchain/node-express-suite");
|
|
17
16
|
const energyAccountHydration_1 = require("./hydration/energyAccountHydration");
|
|
18
|
-
/**
|
|
19
|
-
* Validate that the given directory path exists and is accessible.
|
|
20
|
-
* If the directory does not exist, attempt to create it recursively.
|
|
21
|
-
* Throws if the path is inaccessible after creation attempt.
|
|
22
|
-
*/
|
|
23
|
-
async function validateDataDir(dirPath) {
|
|
24
|
-
try {
|
|
25
|
-
await (0, promises_1.access)(dirPath, fs_1.constants.R_OK | fs_1.constants.W_OK);
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
// Directory doesn't exist or isn't accessible — try to create it
|
|
29
|
-
try {
|
|
30
|
-
await (0, promises_1.mkdir)(dirPath, { recursive: true });
|
|
31
|
-
}
|
|
32
|
-
catch (mkdirError) {
|
|
33
|
-
const message = mkdirError instanceof Error ? mkdirError.message : String(mkdirError);
|
|
34
|
-
throw new Error(`Cannot create or access data directory "${dirPath}": ${message}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
17
|
/**
|
|
39
18
|
* Initialize the BrightChain database stack.
|
|
40
19
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* - If `blockStorePath` is not set: creates a MemoryBlockStore, logs a warning,
|
|
45
|
-
* and creates a BrightDb with an InMemoryHeadRegistry.
|
|
46
|
-
*
|
|
47
|
-
* Registers an `energy_accounts` Model on BrightDB with the energy account
|
|
48
|
-
* hydration schema, then passes the Model (as ITypedCollection) directly to
|
|
49
|
-
* EnergyAccountStore — no adapter needed.
|
|
20
|
+
* Delegates to the Suite's generic brightchainDatabaseInit for block store
|
|
21
|
+
* and BrightDb creation, then adds domain-specific stores (MemberStore,
|
|
22
|
+
* EnergyAccountStore) on top via the modelRegistrations callback.
|
|
50
23
|
*
|
|
51
24
|
* @returns An IInitResult containing the initialized stores on success,
|
|
52
25
|
* or a failure result with a descriptive error message.
|
|
53
26
|
*/
|
|
54
27
|
async function brightchainDatabaseInit(environment) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await validateDataDir(blockStorePath);
|
|
79
|
-
blockStore = blockStoreFactory_1.BlockStoreFactory.createDiskStore({
|
|
80
|
-
storePath: blockStorePath,
|
|
81
|
-
supportedBlockSizes,
|
|
82
|
-
});
|
|
83
|
-
dataDir = blockStorePath;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
throw new Error('Neither DEV_DATABASE nor BRIGHTCHAIN_BLOCKSTORE_PATH is set. ' +
|
|
87
|
-
'Set DEV_DATABASE to a pool name for in-memory development mode, ' +
|
|
88
|
-
'or set BRIGHTCHAIN_BLOCKSTORE_PATH for persistent disk storage.');
|
|
89
|
-
}
|
|
90
|
-
// Create BrightDb — uses PersistentHeadRegistry when dataDir is set,
|
|
91
|
-
// InMemoryHeadRegistry otherwise.
|
|
92
|
-
// IMPORTANT: name must match what BrightChainMemberInitService uses
|
|
93
|
-
// (config.memberPoolName) so the head registry keys are consistent across
|
|
94
|
-
// the plugin's db and the seeding service's db.
|
|
95
|
-
const db = new db_1.BrightDb(blockStore, dataDir ? { name: environment.memberPoolName, dataDir } : undefined);
|
|
96
|
-
// Mark the db as connected (no-op for block-store-backed DB, but sets
|
|
97
|
-
// the isConnected() flag that consumers check).
|
|
98
|
-
await db.connect();
|
|
99
|
-
// Register the energy_accounts Model with hydration schema.
|
|
100
|
-
// The Model satisfies ITypedCollection<IEnergyAccountDto, EnergyAccount>
|
|
101
|
-
// so EnergyAccountStore can use it directly — no adapter needed.
|
|
102
|
-
const energyAccountModel = db.model('energy_accounts', { hydration: (0, energyAccountHydration_1.createEnergyAccountHydrationSchema)() });
|
|
103
|
-
// Initialize stores
|
|
104
|
-
const memberStore = new brightchain_lib_1.MemberStore(blockStore);
|
|
105
|
-
const energyStore = new brightchain_lib_1.EnergyAccountStore(energyAccountModel);
|
|
106
|
-
// Load persisted energy accounts (no-op if no typed collection)
|
|
107
|
-
try {
|
|
108
|
-
await energyStore.loadFromStore();
|
|
109
|
-
}
|
|
110
|
-
catch (loadError) {
|
|
111
|
-
const message = loadError instanceof Error ? loadError.message : String(loadError);
|
|
112
|
-
console.warn(`[BrightChain] Failed to load energy accounts from store, continuing with empty store: ${message}`);
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
success: true,
|
|
116
|
-
backend: {
|
|
117
|
-
blockStore,
|
|
118
|
-
db,
|
|
119
|
-
memberStore,
|
|
120
|
-
energyStore,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
28
|
+
// Domain-specific references captured in the callback
|
|
29
|
+
let memberStore;
|
|
30
|
+
let energyStore;
|
|
31
|
+
const genericResult = await (0, node_express_suite_1.brightchainDatabaseInit)(environment, {
|
|
32
|
+
modelRegistrations: async (db, blockStore) => {
|
|
33
|
+
// Register the energy_accounts Model with hydration schema.
|
|
34
|
+
// The Model satisfies ITypedCollection<IEnergyAccountDto, EnergyAccount>
|
|
35
|
+
// so EnergyAccountStore can use it directly — no adapter needed.
|
|
36
|
+
const energyAccountModel = db.model('energy_accounts', { hydration: (0, energyAccountHydration_1.createEnergyAccountHydrationSchema)() });
|
|
37
|
+
// Initialize stores
|
|
38
|
+
memberStore = new brightchain_lib_1.MemberStore(blockStore);
|
|
39
|
+
energyStore = new brightchain_lib_1.EnergyAccountStore(energyAccountModel);
|
|
40
|
+
// Load persisted energy accounts (no-op if no typed collection)
|
|
41
|
+
try {
|
|
42
|
+
await energyStore.loadFromStore();
|
|
43
|
+
}
|
|
44
|
+
catch (loadError) {
|
|
45
|
+
const message = loadError instanceof Error ? loadError.message : String(loadError);
|
|
46
|
+
console.warn(`[BrightChain] Failed to load energy accounts from store, continuing with empty store: ${message}`);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (!genericResult.success || !genericResult.backend) {
|
|
126
51
|
return {
|
|
127
52
|
success: false,
|
|
128
|
-
error:
|
|
53
|
+
error: genericResult.error,
|
|
129
54
|
};
|
|
130
55
|
}
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
backend: {
|
|
59
|
+
blockStore: genericResult.backend.blockStore,
|
|
60
|
+
db: genericResult.backend.db,
|
|
61
|
+
memberStore: memberStore,
|
|
62
|
+
energyStore: energyStore,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
131
65
|
}
|
|
132
66
|
//# sourceMappingURL=databaseInit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"databaseInit.js","sourceRoot":"","sources":["../../../../brightchain-api-lib/src/lib/databaseInit.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"databaseInit.js","sourceRoot":"","sources":["../../../../brightchain-api-lib/src/lib/databaseInit.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AA6BH,0DAkDC;AAvED,kEAIsC;AAEtC,wEAAiG;AAGjG,+EAAwF;AAExF;;;;;;;;;GASG;AACI,KAAK,UAAU,uBAAuB,CAC3C,WAA6B;IAE7B,sDAAsD;IACtD,IAAI,WAAoC,CAAC;IACzC,IAAI,WAA2C,CAAC;IAEhD,MAAM,aAAa,GAAG,MAAM,IAAA,4CAAmB,EAAC,WAAW,EAAE;QAC3D,kBAAkB,EAAE,KAAK,EAAE,EAAY,EAAE,UAAuB,EAAE,EAAE;YAClE,4DAA4D;YAC5D,yEAAyE;YACzE,iEAAiE;YACjE,MAAM,kBAAkB,GAAG,EAAE,CAAC,KAAK,CACjC,iBAAiB,EACjB,EAAE,SAAS,EAAE,IAAA,2DAAkC,GAAE,EAAE,CACpD,CAAC;YAEF,oBAAoB;YACpB,WAAW,GAAG,IAAI,6BAAW,CAAC,UAAU,CAAC,CAAC;YAC1C,WAAW,GAAG,IAAI,oCAAkB,CAAC,kBAAkB,CAAC,CAAC;YAEzD,gEAAgE;YAChE,IAAI,CAAC;gBACH,MAAM,WAAW,CAAC,aAAa,EAAE,CAAC;YACpC,CAAC;YAAC,OAAO,SAAkB,EAAE,CAAC;gBAC5B,MAAM,OAAO,GACX,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBACrE,OAAO,CAAC,IAAI,CACV,yFAAyF,OAAO,EAAE,CACnG,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,IAAI,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QACrD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE;YACP,UAAU,EAAE,aAAa,CAAC,OAAO,CAAC,UAAU;YAC5C,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE;YAC5B,WAAW,EAAE,WAAY;YACzB,WAAW,EAAE,WAAY;SAC1B;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -14,6 +14,9 @@ export type BlockDocumentStoreOptions = {
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a BlockDocumentStore backed by either a provided BlockStore, a disk store, or an in-memory store.
|
|
16
16
|
* Optionally supports encryption via QuorumService.
|
|
17
|
+
*
|
|
18
|
+
* This api-lib version automatically injects DiskBlockAsyncStore for disk-backed stores,
|
|
19
|
+
* maintaining backward compatibility with existing consumers.
|
|
17
20
|
*/
|
|
18
21
|
export declare function createBlockDocumentStore(options: BlockDocumentStoreOptions): DocumentStore;
|
|
19
22
|
//# sourceMappingURL=block-document-store-factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-document-store-factory.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/datastore/block-document-store-factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"block-document-store-factory.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/datastore/block-document-store-factory.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,SAAS,EACT,WAAW,EACX,cAAc,EACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,yBAAyB,GACjC,aAAa,CAWf"}
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createBlockDocumentStore = createBlockDocumentStore;
|
|
4
|
-
|
|
4
|
+
// Re-export the generic factory and options type from @brightchain/node-express-suite
|
|
5
|
+
// with backward-compatible DiskBlockAsyncStore integration
|
|
6
|
+
const node_express_suite_1 = require("@brightchain/node-express-suite");
|
|
5
7
|
const diskBlockAsyncStore_1 = require("../stores/diskBlockAsyncStore");
|
|
6
|
-
const block_document_store_1 = require("./block-document-store");
|
|
7
8
|
/**
|
|
8
9
|
* Create a BlockDocumentStore backed by either a provided BlockStore, a disk store, or an in-memory store.
|
|
9
10
|
* Optionally supports encryption via QuorumService.
|
|
11
|
+
*
|
|
12
|
+
* This api-lib version automatically injects DiskBlockAsyncStore for disk-backed stores,
|
|
13
|
+
* maintaining backward compatibility with existing consumers.
|
|
10
14
|
*/
|
|
11
15
|
function createBlockDocumentStore(options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const diskStore = new diskBlockAsyncStore_1.DiskBlockAsyncStore({
|
|
22
|
-
storePath: options.storePath,
|
|
23
|
-
blockSize,
|
|
24
|
-
});
|
|
25
|
-
return new block_document_store_1.BlockDocumentStore(diskStore, options.quorumService);
|
|
26
|
-
}
|
|
27
|
-
throw new Error('createBlockDocumentStore requires a blockStore, storePath, or useMemory=true');
|
|
16
|
+
// Convert to suite options, injecting DiskBlockAsyncStore as the disk factory
|
|
17
|
+
const suiteOptions = {
|
|
18
|
+
...options,
|
|
19
|
+
diskBlockStoreFactory: (opts) => new diskBlockAsyncStore_1.DiskBlockAsyncStore({
|
|
20
|
+
storePath: opts.storePath,
|
|
21
|
+
blockSize: opts.blockSize,
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
return (0, node_express_suite_1.createBlockDocumentStore)(suiteOptions);
|
|
28
25
|
}
|
|
29
26
|
//# sourceMappingURL=block-document-store-factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-document-store-factory.js","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/datastore/block-document-store-factory.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"block-document-store-factory.js","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/datastore/block-document-store-factory.ts"],"names":[],"mappings":";;AAiCA,4DAaC;AA9CD,sFAAsF;AACtF,2DAA2D;AAC3D,wEAGyC;AAOzC,uEAAoE;AAcpE;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,OAAkC;IAElC,8EAA8E;IAC9E,MAAM,YAAY,GAAmC;QACnD,GAAG,OAAO;QACV,qBAAqB,EAAE,CAAC,IAAI,EAAE,EAAE,CAC9B,IAAI,yCAAmB,CAAC;YACtB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;KACL,CAAC;IACF,OAAO,IAAA,6CAA6B,EAAC,YAAY,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -1,192 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { DocumentCollection, DocumentId, DocumentRecord, DocumentStore, QueryBuilder } from './document-store';
|
|
4
|
-
/**
|
|
5
|
-
* Options for creating a document with optional encryption
|
|
6
|
-
*/
|
|
7
|
-
export interface CreateDocumentOptions<TID extends PlatformID = Uint8Array> {
|
|
8
|
-
/**
|
|
9
|
-
* Whether to encrypt the document using quorum sealing
|
|
10
|
-
*/
|
|
11
|
-
encrypt?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* The member performing the sealing operation (required if encrypt is true)
|
|
14
|
-
*/
|
|
15
|
-
agent?: Member<TID>;
|
|
16
|
-
/**
|
|
17
|
-
* IDs of members who will receive shares (required if encrypt is true)
|
|
18
|
-
*/
|
|
19
|
-
memberIds?: TID[];
|
|
20
|
-
/**
|
|
21
|
-
* Number of shares required to unseal (defaults to all members)
|
|
22
|
-
*/
|
|
23
|
-
sharesRequired?: number;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Options for retrieving an encrypted document
|
|
27
|
-
*/
|
|
28
|
-
export interface RetrieveDocumentOptions<TID extends PlatformID = Uint8Array> {
|
|
29
|
-
/**
|
|
30
|
-
* Members with loaded private keys for decryption (required for encrypted documents)
|
|
31
|
-
*/
|
|
32
|
-
membersWithPrivateKey?: Member<TID>[];
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Metadata stored alongside encrypted documents
|
|
36
|
-
*/
|
|
37
|
-
interface EncryptedDocumentMetadata {
|
|
38
|
-
isEncrypted: boolean;
|
|
39
|
-
sealedDocumentId?: HexString;
|
|
40
|
-
memberIds?: HexString[];
|
|
41
|
-
sharesRequired?: number;
|
|
42
|
-
createdAt?: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Simple in-memory registry for collection head pointers.
|
|
46
|
-
* This maps collection names to their latest index block IDs.
|
|
47
|
-
*
|
|
48
|
-
* In a production system, this would be persisted to a separate
|
|
49
|
-
* key-value store or database. For now, we use a static map
|
|
50
|
-
* that's shared across all BlockDocumentStore instances.
|
|
51
|
-
*/
|
|
52
|
-
export declare class CollectionHeadRegistry {
|
|
53
|
-
private static instance;
|
|
54
|
-
private readonly heads;
|
|
55
|
-
private constructor();
|
|
56
|
-
static getInstance(): CollectionHeadRegistry;
|
|
57
|
-
getHead(collectionKey: string): string | undefined;
|
|
58
|
-
setHead(collectionKey: string, indexBlockId: string): void;
|
|
59
|
-
/**
|
|
60
|
-
* Generate a unique key for a collection based on store identity and collection name
|
|
61
|
-
*/
|
|
62
|
-
static makeKey(storeId: string, collectionName: string): string;
|
|
63
|
-
/**
|
|
64
|
-
* Clear all heads (useful for testing)
|
|
65
|
-
*/
|
|
66
|
-
clear(): void;
|
|
67
|
-
}
|
|
68
|
-
declare class BlockCollection<T extends DocumentRecord, TID extends PlatformID = PlatformID> implements DocumentCollection<T> {
|
|
69
|
-
private readonly store;
|
|
70
|
-
private readonly collectionName;
|
|
71
|
-
private readonly quorumService?;
|
|
72
|
-
private readonly storeId;
|
|
73
|
-
private readonly generateId;
|
|
74
|
-
private readonly index;
|
|
75
|
-
private readonly registryKey;
|
|
76
|
-
private indexLoaded;
|
|
77
|
-
private indexLoading;
|
|
78
|
-
constructor(store: IBlockStore, collectionName: string, quorumService?: IQuorumService<TID> | undefined, storeId?: string, generateId?: () => string);
|
|
79
|
-
private ensureIndexLoaded;
|
|
80
|
-
private persistIndex;
|
|
81
|
-
private resolveBlockId;
|
|
82
|
-
private writeDoc;
|
|
83
|
-
private readDoc;
|
|
84
|
-
private toSingleQuery;
|
|
85
|
-
private toManyQuery;
|
|
86
|
-
find(filter?: Partial<T>): QueryBuilder<T[]>;
|
|
87
|
-
findOne(filter?: Partial<T>): QueryBuilder<T>;
|
|
88
|
-
findById(id: DocumentId): QueryBuilder<T>;
|
|
89
|
-
/**
|
|
90
|
-
* Retrieve a document by ID, decrypting if necessary
|
|
91
|
-
* @param id - The document ID
|
|
92
|
-
* @param options - Options for retrieving encrypted documents
|
|
93
|
-
* @returns The document (decrypted if it was encrypted)
|
|
94
|
-
*/
|
|
95
|
-
findByIdDecrypted(id: DocumentId, options?: RetrieveDocumentOptions<TID>): Promise<T | null>;
|
|
96
|
-
/**
|
|
97
|
-
* Check if a document is encrypted
|
|
98
|
-
* @param id - The document ID
|
|
99
|
-
* @returns True if the document is encrypted
|
|
100
|
-
*/
|
|
101
|
-
isEncrypted(id: DocumentId): Promise<boolean>;
|
|
102
|
-
/**
|
|
103
|
-
* Get encryption metadata for a document
|
|
104
|
-
* @param id - The document ID
|
|
105
|
-
* @returns The encryption metadata, or null if not encrypted
|
|
106
|
-
*/
|
|
107
|
-
getEncryptionMetadata(id: DocumentId): Promise<EncryptedDocumentMetadata | null>;
|
|
108
|
-
/**
|
|
109
|
-
* Check if a member has access to a document
|
|
110
|
-
* @param id - The document ID
|
|
111
|
-
* @param memberId - The member ID to check access for
|
|
112
|
-
* @returns True if the member has access (either unencrypted or member is in the encryption list)
|
|
113
|
-
*/
|
|
114
|
-
hasAccess(id: DocumentId, memberId: HexString): Promise<boolean>;
|
|
115
|
-
/**
|
|
116
|
-
* Find all documents accessible by a specific member
|
|
117
|
-
* @param memberId - The member ID to filter by
|
|
118
|
-
* @param filter - Optional additional filter criteria
|
|
119
|
-
* @returns Array of documents the member has access to
|
|
120
|
-
*/
|
|
121
|
-
findAccessibleBy(memberId: HexString, filter?: Partial<T>): Promise<T[]>;
|
|
122
|
-
/**
|
|
123
|
-
* Find one document accessible by a specific member
|
|
124
|
-
* @param memberId - The member ID to filter by
|
|
125
|
-
* @param filter - Optional additional filter criteria
|
|
126
|
-
* @returns The first document the member has access to, or null
|
|
127
|
-
*/
|
|
128
|
-
findOneAccessibleBy(memberId: HexString, filter?: Partial<T>): Promise<T | null>;
|
|
129
|
-
/**
|
|
130
|
-
* Count documents accessible by a specific member
|
|
131
|
-
* @param memberId - The member ID to filter by
|
|
132
|
-
* @param filter - Optional additional filter criteria
|
|
133
|
-
* @returns The count of documents the member has access to
|
|
134
|
-
*/
|
|
135
|
-
countAccessibleBy(memberId: HexString, filter?: Partial<T>): Promise<number>;
|
|
136
|
-
findOneAndUpdate(filter: Partial<T>, update: Partial<T>): QueryBuilder<T>;
|
|
137
|
-
findOneAndDelete(filter: Partial<T>): QueryBuilder<T>;
|
|
138
|
-
findByIdAndUpdate(id: DocumentId, update: Partial<T>): QueryBuilder<T>;
|
|
139
|
-
findByIdAndDelete(id: DocumentId): QueryBuilder<T>;
|
|
140
|
-
create(doc: T): Promise<T>;
|
|
141
|
-
create(doc: T, options?: CreateDocumentOptions<TID>): Promise<T>;
|
|
142
|
-
insertMany(docs: T[]): Promise<T[]>;
|
|
143
|
-
updateOne(filter: Partial<T>, update: Partial<T>): Promise<{
|
|
144
|
-
modifiedCount: number;
|
|
145
|
-
matchedCount: number;
|
|
146
|
-
}>;
|
|
147
|
-
updateMany(filter: Partial<T>, update: Partial<T>): Promise<{
|
|
148
|
-
modifiedCount: number;
|
|
149
|
-
matchedCount: number;
|
|
150
|
-
}>;
|
|
151
|
-
replaceOne(filter: Partial<T>, doc: T): Promise<{
|
|
152
|
-
modifiedCount: number;
|
|
153
|
-
matchedCount: number;
|
|
154
|
-
}>;
|
|
155
|
-
deleteOne(filter: Partial<T>): Promise<{
|
|
156
|
-
deletedCount: number;
|
|
157
|
-
}>;
|
|
158
|
-
deleteMany(filter: Partial<T>): Promise<{
|
|
159
|
-
deletedCount: number;
|
|
160
|
-
}>;
|
|
161
|
-
countDocuments(filter?: Partial<T>): Promise<number>;
|
|
162
|
-
estimatedDocumentCount(): Promise<number>;
|
|
163
|
-
aggregate<U = unknown>(_pipeline: unknown[]): QueryBuilder<U[]>;
|
|
164
|
-
distinct(field: keyof T): QueryBuilder<T[keyof T][]>;
|
|
165
|
-
exists(filter: Partial<T>): Promise<{
|
|
166
|
-
_id: DocumentId;
|
|
167
|
-
} | null>;
|
|
168
|
-
watch(): void;
|
|
169
|
-
startSession(): unknown;
|
|
170
|
-
}
|
|
171
|
-
export declare class BlockDocumentStore<TID extends PlatformID = PlatformID> implements DocumentStore {
|
|
172
|
-
private readonly blockStore;
|
|
173
|
-
private readonly quorumService?;
|
|
174
|
-
private readonly collections;
|
|
175
|
-
private readonly storeId;
|
|
176
|
-
private readonly generateId;
|
|
177
|
-
constructor(blockStore: IBlockStore, quorumService?: IQuorumService<TID> | undefined, idProvider?: IIdProvider<TID>);
|
|
178
|
-
/**
|
|
179
|
-
* Attempt to resolve the ID provider from the global ServiceProvider.
|
|
180
|
-
* Returns undefined if the ServiceProvider is not yet initialized.
|
|
181
|
-
*/
|
|
182
|
-
private resolveIdProvider;
|
|
183
|
-
collection<T extends DocumentRecord>(name: string): DocumentCollection<T>;
|
|
184
|
-
/**
|
|
185
|
-
* Get a collection with encryption support
|
|
186
|
-
* @param name - The collection name
|
|
187
|
-
* @returns The collection with encryption methods available
|
|
188
|
-
*/
|
|
189
|
-
encryptedCollection<T extends DocumentRecord>(name: string): BlockCollection<T, TID>;
|
|
190
|
-
}
|
|
191
|
-
export {};
|
|
1
|
+
export type { CreateDocumentOptions, RetrieveDocumentOptions, } from '@brightchain/node-express-suite';
|
|
2
|
+
export { BlockDocumentStore, CollectionHeadRegistry, } from '@brightchain/node-express-suite';
|
|
192
3
|
//# sourceMappingURL=block-document-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-document-store.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/datastore/block-document-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"block-document-store.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/datastore/block-document-store.ts"],"names":[],"mappings":"AACA,YAAY,EACV,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,iCAAiC,CAAC"}
|