@brightchain/node-express-suite 0.25.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/MIGRATION.md +131 -0
- package/README.md +11 -0
- package/package.json +18 -0
- package/src/index.d.ts +46 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +73 -0
- package/src/index.js.map +1 -0
- package/src/lib/application.d.ts +35 -0
- package/src/lib/application.d.ts.map +1 -0
- package/src/lib/application.js +38 -0
- package/src/lib/application.js.map +1 -0
- package/src/lib/bright-db-model-registry.d.ts +56 -0
- package/src/lib/bright-db-model-registry.d.ts.map +1 -0
- package/src/lib/bright-db-model-registry.js +71 -0
- package/src/lib/bright-db-model-registry.js.map +1 -0
- package/src/lib/brightchain-lib.d.ts +7 -0
- package/src/lib/brightchain-lib.d.ts.map +1 -0
- package/src/lib/brightchain-lib.js +12 -0
- package/src/lib/brightchain-lib.js.map +1 -0
- package/src/lib/brightdb.d.ts +7 -0
- package/src/lib/brightdb.d.ts.map +1 -0
- package/src/lib/brightdb.js +11 -0
- package/src/lib/brightdb.js.map +1 -0
- package/src/lib/constants.d.ts +6 -0
- package/src/lib/constants.d.ts.map +1 -0
- package/src/lib/constants.js +12 -0
- package/src/lib/constants.js.map +1 -0
- package/src/lib/create-test-app.d.ts +22 -0
- package/src/lib/create-test-app.d.ts.map +1 -0
- package/src/lib/create-test-app.js +49 -0
- package/src/lib/create-test-app.js.map +1 -0
- package/src/lib/databaseInit.d.ts +53 -0
- package/src/lib/databaseInit.d.ts.map +1 -0
- package/src/lib/databaseInit.js +114 -0
- package/src/lib/databaseInit.js.map +1 -0
- package/src/lib/datastore/block-document-store-factory.d.ts +31 -0
- package/src/lib/datastore/block-document-store-factory.d.ts.map +1 -0
- package/src/lib/datastore/block-document-store-factory.js +35 -0
- package/src/lib/datastore/block-document-store-factory.js.map +1 -0
- package/src/lib/datastore/block-document-store.d.ts +201 -0
- package/src/lib/datastore/block-document-store.d.ts.map +1 -0
- package/src/lib/datastore/block-document-store.js +649 -0
- package/src/lib/datastore/block-document-store.js.map +1 -0
- package/src/lib/datastore/document-store.d.ts +83 -0
- package/src/lib/datastore/document-store.d.ts.map +1 -0
- package/src/lib/datastore/document-store.js +3 -0
- package/src/lib/datastore/document-store.js.map +1 -0
- package/src/lib/datastore/index.d.ts +6 -0
- package/src/lib/datastore/index.d.ts.map +1 -0
- package/src/lib/datastore/index.js +11 -0
- package/src/lib/datastore/index.js.map +1 -0
- package/src/lib/datastore/memory-document-store.d.ts +9 -0
- package/src/lib/datastore/memory-document-store.d.ts.map +1 -0
- package/src/lib/datastore/memory-document-store.js +218 -0
- package/src/lib/datastore/memory-document-store.js.map +1 -0
- package/src/lib/environment.d.ts +64 -0
- package/src/lib/environment.d.ts.map +1 -0
- package/src/lib/environment.js +165 -0
- package/src/lib/environment.js.map +1 -0
- package/src/lib/factories/blockStoreFactory.d.ts +10 -0
- package/src/lib/factories/blockStoreFactory.d.ts.map +1 -0
- package/src/lib/factories/blockStoreFactory.js +14 -0
- package/src/lib/factories/blockStoreFactory.js.map +1 -0
- package/src/lib/interfaces/bright-db-application.d.ts +34 -0
- package/src/lib/interfaces/bright-db-application.d.ts.map +1 -0
- package/src/lib/interfaces/bright-db-application.js +13 -0
- package/src/lib/interfaces/bright-db-application.js.map +1 -0
- package/src/lib/interfaces/environment.d.ts +34 -0
- package/src/lib/interfaces/environment.d.ts.map +1 -0
- package/src/lib/interfaces/environment.js +11 -0
- package/src/lib/interfaces/environment.js.map +1 -0
- package/src/lib/middleware/index.d.ts +2 -0
- package/src/lib/middleware/index.d.ts.map +1 -0
- package/src/lib/middleware/index.js +6 -0
- package/src/lib/middleware/index.js.map +1 -0
- package/src/lib/middleware/validateBody.d.ts +13 -0
- package/src/lib/middleware/validateBody.d.ts.map +1 -0
- package/src/lib/middleware/validateBody.js +35 -0
- package/src/lib/middleware/validateBody.js.map +1 -0
- package/src/lib/middlewares.d.ts +9 -0
- package/src/lib/middlewares.d.ts.map +1 -0
- package/src/lib/middlewares.js +21 -0
- package/src/lib/middlewares.js.map +1 -0
- package/src/lib/plugins/bright-db-database-plugin.d.ts +95 -0
- package/src/lib/plugins/bright-db-database-plugin.d.ts.map +1 -0
- package/src/lib/plugins/bright-db-database-plugin.js +143 -0
- package/src/lib/plugins/bright-db-database-plugin.js.map +1 -0
- package/src/lib/plugins/configure-bright-db-app.d.ts +25 -0
- package/src/lib/plugins/configure-bright-db-app.d.ts.map +1 -0
- package/src/lib/plugins/configure-bright-db-app.js +31 -0
- package/src/lib/plugins/configure-bright-db-app.js.map +1 -0
- package/src/lib/services/bright-db-authentication-provider.d.ts +31 -0
- package/src/lib/services/bright-db-authentication-provider.d.ts.map +1 -0
- package/src/lib/services/bright-db-authentication-provider.js +91 -0
- package/src/lib/services/bright-db-authentication-provider.js.map +1 -0
- package/src/lib/services/bright-db-base-service.d.ts +26 -0
- package/src/lib/services/bright-db-base-service.d.ts.map +1 -0
- package/src/lib/services/bright-db-base-service.js +30 -0
- package/src/lib/services/bright-db-base-service.js.map +1 -0
- package/src/lib/services/bright-db-collection.d.ts +50 -0
- package/src/lib/services/bright-db-collection.d.ts.map +1 -0
- package/src/lib/services/bright-db-collection.js +116 -0
- package/src/lib/services/bright-db-collection.js.map +1 -0
- package/src/lib/services/sessionAdapter.d.ts +62 -0
- package/src/lib/services/sessionAdapter.d.ts.map +1 -0
- package/src/lib/services/sessionAdapter.js +106 -0
- package/src/lib/services/sessionAdapter.js.map +1 -0
- package/src/lib/shared-types.d.ts +41 -0
- package/src/lib/shared-types.d.ts.map +1 -0
- package/src/lib/shared-types.js +3 -0
- package/src/lib/shared-types.js.map +1 -0
- package/src/lib/transactions/bright-db-transaction-manager.d.ts +46 -0
- package/src/lib/transactions/bright-db-transaction-manager.d.ts.map +1 -0
- package/src/lib/transactions/bright-db-transaction-manager.js +81 -0
- package/src/lib/transactions/bright-db-transaction-manager.js.map +1 -0
- package/src/lib/types/backend-id.d.ts +3 -0
- package/src/lib/types/backend-id.d.ts.map +1 -0
- package/src/lib/types/backend-id.js +3 -0
- package/src/lib/types/backend-id.js.map +1 -0
- package/src/lib/upstream.d.ts +8 -0
- package/src/lib/upstream.d.ts.map +1 -0
- package/src/lib/upstream.js +13 -0
- package/src/lib/upstream.js.map +1 -0
- package/src/lib/validation/userValidation.d.ts +44 -0
- package/src/lib/validation/userValidation.d.ts.map +1 -0
- package/src/lib/validation/userValidation.js +147 -0
- package/src/lib/validation/userValidation.js.map +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Test utility for creating an in-memory BrightDB plugin instance.
|
|
4
|
+
*
|
|
5
|
+
* Useful for integration tests that need a connected BrightDB instance
|
|
6
|
+
* without requiring a real block store on disk.
|
|
7
|
+
*
|
|
8
|
+
* @module create-test-app
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createTestApp = createTestApp;
|
|
12
|
+
const bright_db_database_plugin_1 = require("./plugins/bright-db-database-plugin");
|
|
13
|
+
const environment_1 = require("./environment");
|
|
14
|
+
/**
|
|
15
|
+
* Create a test-friendly BrightDB plugin with in-memory configuration.
|
|
16
|
+
* Useful for integration tests that need a connected BrightDB instance.
|
|
17
|
+
*/
|
|
18
|
+
async function createTestApp(envOverrides) {
|
|
19
|
+
// Set up in-memory environment
|
|
20
|
+
const envVars = {
|
|
21
|
+
USE_MEMORY_DOCSTORE: 'true',
|
|
22
|
+
DEV_DATABASE: 'test-pool',
|
|
23
|
+
NODE_ENV: 'test',
|
|
24
|
+
...envOverrides,
|
|
25
|
+
};
|
|
26
|
+
// Set env vars temporarily
|
|
27
|
+
const originalEnv = {};
|
|
28
|
+
for (const [key, value] of Object.entries(envVars)) {
|
|
29
|
+
originalEnv[key] = process.env[key];
|
|
30
|
+
process.env[key] = value;
|
|
31
|
+
}
|
|
32
|
+
const environment = new environment_1.BrightDbEnvironment();
|
|
33
|
+
// Restore env vars
|
|
34
|
+
for (const [key, value] of Object.entries(originalEnv)) {
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
delete process.env[key];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
process.env[key] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const plugin = new bright_db_database_plugin_1.BrightDbDatabasePlugin(environment);
|
|
43
|
+
await plugin.connect();
|
|
44
|
+
const teardown = async () => {
|
|
45
|
+
await plugin.disconnect();
|
|
46
|
+
};
|
|
47
|
+
return { plugin, environment, teardown };
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=create-test-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-test-app.js","sourceRoot":"","sources":["../../../../brightchain-node-express-suite/src/lib/create-test-app.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAgBH,sCAqCC;AAnDD,mFAA6E;AAC7E,+CAAoD;AASpD;;;GAGG;AACI,KAAK,UAAU,aAAa,CACjC,YAAqC;IAErC,+BAA+B;IAC/B,MAAM,OAAO,GAA2B;QACtC,mBAAmB,EAAE,MAAM;QAC3B,YAAY,EAAE,WAAW;QACzB,QAAQ,EAAE,MAAM;QAChB,GAAG,YAAY;KAChB,CAAC;IAEF,2BAA2B;IAC3B,MAAM,WAAW,GAAuC,EAAE,CAAC;IAC3D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,WAAW,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,iCAAmB,EAAO,CAAC;IAEnD,mBAAmB;IACnB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QACvD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,kDAAsB,CAAM,WAAW,CAAC,CAAC;IAC5D,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAEvB,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IAC5B,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Generic BrightChain database initialization function.
|
|
3
|
+
*
|
|
4
|
+
* This is the Suite's generic version of the database init — it creates
|
|
5
|
+
* the block store and BrightDb instance based on environment configuration,
|
|
6
|
+
* but does NOT create domain-specific stores (MemberStore, EnergyAccountStore).
|
|
7
|
+
*
|
|
8
|
+
* Domain-specific model registrations are passed in via an optional callback.
|
|
9
|
+
*
|
|
10
|
+
* @module databaseInit
|
|
11
|
+
*/
|
|
12
|
+
import type { IBlockStore, ICloudBlockStoreConfig, IInitResult } from '@brightchain/brightchain-lib';
|
|
13
|
+
import { BlockSize, BlockStoreType } from '@brightchain/brightchain-lib';
|
|
14
|
+
import { BrightDb } from '@brightchain/db';
|
|
15
|
+
/**
|
|
16
|
+
* Minimal environment interface required by the generic database init.
|
|
17
|
+
* Consumers pass an object satisfying this shape — it does NOT depend on
|
|
18
|
+
* api-lib's full Environment class.
|
|
19
|
+
*/
|
|
20
|
+
export interface IDatabaseInitEnvironment {
|
|
21
|
+
blockStorePath?: string;
|
|
22
|
+
blockStoreBlockSizes: readonly BlockSize[];
|
|
23
|
+
blockStoreType: BlockStoreType;
|
|
24
|
+
devDatabasePoolName?: string;
|
|
25
|
+
azureConfig?: ICloudBlockStoreConfig & Record<string, any>;
|
|
26
|
+
s3Config?: ICloudBlockStoreConfig & Record<string, any>;
|
|
27
|
+
memberPoolName: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The backend data returned on successful generic database init.
|
|
31
|
+
* Does NOT include domain-specific stores — those are added by the caller.
|
|
32
|
+
*/
|
|
33
|
+
export interface IGenericInitData {
|
|
34
|
+
blockStore: IBlockStore;
|
|
35
|
+
db: BrightDb;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Initialize the BrightChain database stack (generic version).
|
|
39
|
+
*
|
|
40
|
+
* Creates a block store and BrightDb instance based on environment config.
|
|
41
|
+
* Optionally calls a `modelRegistrations` callback after db.connect() so
|
|
42
|
+
* that the caller can register domain-specific models (e.g. energy_accounts).
|
|
43
|
+
*
|
|
44
|
+
* @param environment - Object satisfying IDatabaseInitEnvironment
|
|
45
|
+
* @param options.modelRegistrations - Optional callback to register models on the BrightDb instance.
|
|
46
|
+
* Receives both the db and blockStore so callers can create domain-specific stores.
|
|
47
|
+
* @returns An IInitResult containing { blockStore, db } on success,
|
|
48
|
+
* or a failure result with a descriptive error message.
|
|
49
|
+
*/
|
|
50
|
+
export declare function brightchainDatabaseInit(environment: IDatabaseInitEnvironment, options?: {
|
|
51
|
+
modelRegistrations?: (db: BrightDb, blockStore: IBlockStore) => void | Promise<void>;
|
|
52
|
+
}): Promise<IInitResult<IGenericInitData>>;
|
|
53
|
+
//# sourceMappingURL=databaseInit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"databaseInit.d.ts","sourceRoot":"","sources":["../../../../brightchain-node-express-suite/src/lib/databaseInit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,sBAAsB,EACtB,WAAW,EACZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,SAAS,EAET,cAAc,EACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,EAAE,SAAS,SAAS,EAAE,CAAC;IAC3C,cAAc,EAAE,cAAc,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,WAAW,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE3D,QAAQ,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxD,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,WAAW,CAAC;IACxB,EAAE,EAAE,QAAQ,CAAC;CACd;AAwBD;;;;;;;;;;;;GAYG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,wBAAwB,EACrC,OAAO,CAAC,EAAE;IACR,kBAAkB,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtF,GACA,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAuExC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Generic BrightChain database initialization function.
|
|
4
|
+
*
|
|
5
|
+
* This is the Suite's generic version of the database init — it creates
|
|
6
|
+
* the block store and BrightDb instance based on environment configuration,
|
|
7
|
+
* but does NOT create domain-specific stores (MemberStore, EnergyAccountStore).
|
|
8
|
+
*
|
|
9
|
+
* Domain-specific model registrations are passed in via an optional callback.
|
|
10
|
+
*
|
|
11
|
+
* @module databaseInit
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.brightchainDatabaseInit = brightchainDatabaseInit;
|
|
15
|
+
const brightchain_lib_1 = require("@brightchain/brightchain-lib");
|
|
16
|
+
const db_1 = require("@brightchain/db");
|
|
17
|
+
const fs_1 = require("fs");
|
|
18
|
+
const promises_1 = require("fs/promises");
|
|
19
|
+
/**
|
|
20
|
+
* Validate that the given directory path exists and is accessible.
|
|
21
|
+
* If the directory does not exist, attempt to create it recursively.
|
|
22
|
+
* Throws if the path is inaccessible after creation attempt.
|
|
23
|
+
*/
|
|
24
|
+
async function validateDataDir(dirPath) {
|
|
25
|
+
try {
|
|
26
|
+
await (0, promises_1.access)(dirPath, fs_1.constants.R_OK | fs_1.constants.W_OK);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Directory doesn't exist or isn't accessible — try to create it
|
|
30
|
+
try {
|
|
31
|
+
await (0, promises_1.mkdir)(dirPath, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
catch (mkdirError) {
|
|
34
|
+
const message = mkdirError instanceof Error ? mkdirError.message : String(mkdirError);
|
|
35
|
+
throw new Error(`Cannot create or access data directory "${dirPath}": ${message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Initialize the BrightChain database stack (generic version).
|
|
41
|
+
*
|
|
42
|
+
* Creates a block store and BrightDb instance based on environment config.
|
|
43
|
+
* Optionally calls a `modelRegistrations` callback after db.connect() so
|
|
44
|
+
* that the caller can register domain-specific models (e.g. energy_accounts).
|
|
45
|
+
*
|
|
46
|
+
* @param environment - Object satisfying IDatabaseInitEnvironment
|
|
47
|
+
* @param options.modelRegistrations - Optional callback to register models on the BrightDb instance.
|
|
48
|
+
* Receives both the db and blockStore so callers can create domain-specific stores.
|
|
49
|
+
* @returns An IInitResult containing { blockStore, db } on success,
|
|
50
|
+
* or a failure result with a descriptive error message.
|
|
51
|
+
*/
|
|
52
|
+
async function brightchainDatabaseInit(environment, options) {
|
|
53
|
+
try {
|
|
54
|
+
const blockStorePath = environment.blockStorePath;
|
|
55
|
+
const supportedBlockSizes = environment.blockStoreBlockSizes;
|
|
56
|
+
const devPoolName = environment.devDatabasePoolName;
|
|
57
|
+
let blockStore;
|
|
58
|
+
let dataDir;
|
|
59
|
+
if (devPoolName) {
|
|
60
|
+
// DEV_DATABASE is set — use ephemeral in-memory store for development
|
|
61
|
+
console.info(`[BrightChain] DEV_DATABASE="${devPoolName}" — using ephemeral MemoryBlockStore. Data will not persist across restarts.`);
|
|
62
|
+
blockStore = brightchain_lib_1.BlockStoreFactory.createMemoryStore({ supportedBlockSizes });
|
|
63
|
+
}
|
|
64
|
+
else if (environment.blockStoreType === brightchain_lib_1.BlockStoreType.AzureBlob) {
|
|
65
|
+
// Factory must have been registered by the consuming app importing
|
|
66
|
+
// '@brightchain/azure-store' at its entry point.
|
|
67
|
+
blockStore = brightchain_lib_1.BlockStoreFactory.createAzureStore(environment.azureConfig);
|
|
68
|
+
}
|
|
69
|
+
else if (environment.blockStoreType === brightchain_lib_1.BlockStoreType.S3) {
|
|
70
|
+
// Factory must have been registered by the consuming app importing
|
|
71
|
+
// '@brightchain/s3-store' at its entry point.
|
|
72
|
+
blockStore = brightchain_lib_1.BlockStoreFactory.createS3Store(environment.s3Config);
|
|
73
|
+
}
|
|
74
|
+
else if (blockStorePath) {
|
|
75
|
+
// Validate path accessibility, create if needed
|
|
76
|
+
await validateDataDir(blockStorePath);
|
|
77
|
+
blockStore = brightchain_lib_1.BlockStoreFactory.createDiskStore({
|
|
78
|
+
storePath: blockStorePath,
|
|
79
|
+
supportedBlockSizes,
|
|
80
|
+
});
|
|
81
|
+
dataDir = blockStorePath;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error('Neither DEV_DATABASE nor BRIGHTCHAIN_BLOCKSTORE_PATH is set. ' +
|
|
85
|
+
'Set DEV_DATABASE to a pool name for in-memory development mode, ' +
|
|
86
|
+
'or set BRIGHTCHAIN_BLOCKSTORE_PATH for persistent disk storage.');
|
|
87
|
+
}
|
|
88
|
+
// Create BrightDb — uses PersistentHeadRegistry when dataDir is set,
|
|
89
|
+
// InMemoryHeadRegistry otherwise.
|
|
90
|
+
const db = new db_1.BrightDb(blockStore, dataDir ? { name: environment.memberPoolName, dataDir } : undefined);
|
|
91
|
+
// Mark the db as connected (no-op for block-store-backed DB, but sets
|
|
92
|
+
// the isConnected() flag that consumers check).
|
|
93
|
+
await db.connect();
|
|
94
|
+
// Call optional model registrations callback
|
|
95
|
+
if (options?.modelRegistrations) {
|
|
96
|
+
await options.modelRegistrations(db, blockStore);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
success: true,
|
|
100
|
+
backend: {
|
|
101
|
+
blockStore,
|
|
102
|
+
db,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
108
|
+
return {
|
|
109
|
+
success: false,
|
|
110
|
+
error: `Database initialization failed: ${message}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=databaseInit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"databaseInit.js","sourceRoot":"","sources":["../../../../brightchain-node-express-suite/src/lib/databaseInit.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AA6EH,0DA4EC;AAlJD,kEAIsC;AACtC,wCAA2C;AAC3C,2BAA8C;AAC9C,0CAA4C;AA4B5C;;;;GAIG;AACH,KAAK,UAAU,eAAe,CAAC,OAAe;IAC5C,IAAI,CAAC;QACH,MAAM,IAAA,iBAAM,EAAC,OAAO,EAAE,cAAW,CAAC,IAAI,GAAG,cAAW,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;IAAC,MA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brightchain-lib';
|
|
2
|
+
import { PlatformID } from '@digitaldefiance/ecies-lib';
|
|
3
|
+
import { DocumentStore } from './document-store';
|
|
4
|
+
export type BlockDocumentStoreOptions = {
|
|
5
|
+
blockStore?: IBlockStore;
|
|
6
|
+
storePath?: string;
|
|
7
|
+
blockSize?: BlockSize;
|
|
8
|
+
useMemory?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Optional QuorumService for encryption support
|
|
11
|
+
*/
|
|
12
|
+
quorumService?: IQuorumService<PlatformID>;
|
|
13
|
+
/**
|
|
14
|
+
* Optional factory function to create a disk-backed block store.
|
|
15
|
+
* This replaces the direct DiskBlockAsyncStore import, allowing
|
|
16
|
+
* consumers (e.g., api-lib) to inject their own disk store implementation.
|
|
17
|
+
*/
|
|
18
|
+
diskBlockStoreFactory?: (options: {
|
|
19
|
+
storePath: string;
|
|
20
|
+
blockSize: BlockSize;
|
|
21
|
+
}) => IBlockStore;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Create a BlockDocumentStore backed by either a provided BlockStore, a disk store, or an in-memory store.
|
|
25
|
+
* Optionally supports encryption via QuorumService.
|
|
26
|
+
*
|
|
27
|
+
* For disk-backed stores, provide a `diskBlockStoreFactory` callback that creates the appropriate
|
|
28
|
+
* IBlockStore implementation (e.g., DiskBlockAsyncStore from api-lib).
|
|
29
|
+
*/
|
|
30
|
+
export declare function createBlockDocumentStore(options: BlockDocumentStoreOptions): DocumentStore;
|
|
31
|
+
//# sourceMappingURL=block-document-store-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-document-store-factory.d.ts","sourceRoot":"","sources":["../../../../../brightchain-node-express-suite/src/lib/datastore/block-document-store-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,cAAc,EAEf,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;IAC3C;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE;QAChC,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,SAAS,CAAC;KACtB,KAAK,WAAW,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,yBAAyB,GACjC,aAAa,CA6Bf"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBlockDocumentStore = createBlockDocumentStore;
|
|
4
|
+
const brightchain_lib_1 = require("@brightchain/brightchain-lib");
|
|
5
|
+
const block_document_store_1 = require("./block-document-store");
|
|
6
|
+
/**
|
|
7
|
+
* Create a BlockDocumentStore backed by either a provided BlockStore, a disk store, or an in-memory store.
|
|
8
|
+
* Optionally supports encryption via QuorumService.
|
|
9
|
+
*
|
|
10
|
+
* For disk-backed stores, provide a `diskBlockStoreFactory` callback that creates the appropriate
|
|
11
|
+
* IBlockStore implementation (e.g., DiskBlockAsyncStore from api-lib).
|
|
12
|
+
*/
|
|
13
|
+
function createBlockDocumentStore(options) {
|
|
14
|
+
const blockSize = options.blockSize ?? brightchain_lib_1.BlockSize.Small;
|
|
15
|
+
if (options.blockStore) {
|
|
16
|
+
return new block_document_store_1.BlockDocumentStore(options.blockStore, options.quorumService);
|
|
17
|
+
}
|
|
18
|
+
if (options.useMemory) {
|
|
19
|
+
const memoryStore = new brightchain_lib_1.MemoryBlockStore(blockSize);
|
|
20
|
+
return new block_document_store_1.BlockDocumentStore(memoryStore, options.quorumService);
|
|
21
|
+
}
|
|
22
|
+
if (options.storePath) {
|
|
23
|
+
if (!options.diskBlockStoreFactory) {
|
|
24
|
+
throw new Error('createBlockDocumentStore requires a diskBlockStoreFactory when using storePath. ' +
|
|
25
|
+
'Provide a factory function that creates an IBlockStore for disk-backed storage.');
|
|
26
|
+
}
|
|
27
|
+
const diskStore = options.diskBlockStoreFactory({
|
|
28
|
+
storePath: options.storePath,
|
|
29
|
+
blockSize,
|
|
30
|
+
});
|
|
31
|
+
return new block_document_store_1.BlockDocumentStore(diskStore, options.quorumService);
|
|
32
|
+
}
|
|
33
|
+
throw new Error('createBlockDocumentStore requires a blockStore, storePath (with diskBlockStoreFactory), or useMemory=true');
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=block-document-store-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-document-store-factory.js","sourceRoot":"","sources":["../../../../../brightchain-node-express-suite/src/lib/datastore/block-document-store-factory.ts"],"names":[],"mappings":";;AAqCA,4DA+BC;AApED,kEAKsC;AAEtC,iEAA4D;AAuB5D;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,OAAkC;IAElC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,2BAAS,CAAC,KAAK,CAAC;IAEvD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,OAAO,IAAI,yCAAkB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,MAAM,WAAW,GAAG,IAAI,kCAAgB,CAAC,SAAS,CAAC,CAAC;QACpD,OAAO,IAAI,yCAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CACb,kFAAkF;gBAChF,iFAAiF,CACpF,CAAC;QACJ,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAC9C,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,SAAS;SACV,CAAC,CAAC;QACH,OAAO,IAAI,yCAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,IAAI,KAAK,CACb,2GAA2G,CAC5G,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { IBlockStore, IQuorumService } from '@brightchain/brightchain-lib';
|
|
2
|
+
import { HexString, IIdProvider, Member, PlatformID } from '@digitaldefiance/ecies-lib';
|
|
3
|
+
import { DocumentCollection, DocumentId, DocumentRecord, IBrightDbDocumentStore, 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 IBrightDbDocumentStore {
|
|
172
|
+
private readonly blockStore;
|
|
173
|
+
private readonly quorumService?;
|
|
174
|
+
private readonly collections;
|
|
175
|
+
private readonly storeId;
|
|
176
|
+
private readonly generateId;
|
|
177
|
+
private _connected;
|
|
178
|
+
constructor(blockStore: IBlockStore, quorumService?: IQuorumService<TID> | undefined, idProvider?: IIdProvider<TID>);
|
|
179
|
+
/**
|
|
180
|
+
* Attempt to resolve the ID provider from the global ServiceProvider.
|
|
181
|
+
* Returns undefined if the ServiceProvider is not yet initialized.
|
|
182
|
+
*/
|
|
183
|
+
private resolveIdProvider;
|
|
184
|
+
collection<T extends DocumentRecord>(name: string): DocumentCollection<T>;
|
|
185
|
+
/**
|
|
186
|
+
* Get a collection with encryption support
|
|
187
|
+
* @param name - The collection name
|
|
188
|
+
* @returns The collection with encryption methods available
|
|
189
|
+
*/
|
|
190
|
+
encryptedCollection<T extends DocumentRecord>(name: string): BlockCollection<T, TID>;
|
|
191
|
+
connect(): Promise<void>;
|
|
192
|
+
disconnect(): Promise<void>;
|
|
193
|
+
isConnected(): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Retrieve a collection by model name.
|
|
196
|
+
* Alias for collection() to match upstream's IDocumentStore.getModel() pattern.
|
|
197
|
+
*/
|
|
198
|
+
getModel<T extends DocumentRecord>(modelName: string): DocumentCollection<T>;
|
|
199
|
+
}
|
|
200
|
+
export {};
|
|
201
|
+
//# sourceMappingURL=block-document-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-document-store.d.ts","sourceRoot":"","sources":["../../../../../brightchain-node-express-suite/src/lib/datastore/block-document-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,cAAc,EAEf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,SAAS,EACT,WAAW,EACX,MAAM,EACN,UAAU,EACX,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,cAAc,EAEd,sBAAsB,EACtB,YAAY,EAEb,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,GAAG,SAAS,UAAU,GAAG,UAAU;IACxE;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB;;OAEG;IACH,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;IAClB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB,CAAC,GAAG,SAAS,UAAU,GAAG,UAAU;IAC1E;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;CACvC;AAED;;GAEG;AACH,UAAU,yBAAyB;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAC7B,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM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