@powerhousedao/shared 6.0.0-dev.47
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/README.md +15 -0
- package/dist/document-model/core/actions.d.ts +62 -0
- package/dist/document-model/core/actions.d.ts.map +1 -0
- package/dist/document-model/core/actions.js +2 -0
- package/dist/document-model/core/actions.js.map +1 -0
- package/dist/document-model/core/constants.d.ts +6 -0
- package/dist/document-model/core/constants.d.ts.map +1 -0
- package/dist/document-model/core/constants.js +8 -0
- package/dist/document-model/core/constants.js.map +1 -0
- package/dist/document-model/core/documents.d.ts +102 -0
- package/dist/document-model/core/documents.d.ts.map +1 -0
- package/dist/document-model/core/documents.js +2 -0
- package/dist/document-model/core/documents.js.map +1 -0
- package/dist/document-model/core/operations.d.ts +74 -0
- package/dist/document-model/core/operations.d.ts.map +1 -0
- package/dist/document-model/core/operations.js +2 -0
- package/dist/document-model/core/operations.js.map +1 -0
- package/dist/document-model/core/ph-types.d.ts +7 -0
- package/dist/document-model/core/ph-types.d.ts.map +1 -0
- package/dist/document-model/core/ph-types.js +2 -0
- package/dist/document-model/core/ph-types.js.map +1 -0
- package/dist/document-model/core/signatures.d.ts +52 -0
- package/dist/document-model/core/signatures.d.ts.map +1 -0
- package/dist/document-model/core/signatures.js +2 -0
- package/dist/document-model/core/signatures.js.map +1 -0
- package/dist/document-model/core/state.d.ts +38 -0
- package/dist/document-model/core/state.d.ts.map +1 -0
- package/dist/document-model/core/state.js +2 -0
- package/dist/document-model/core/state.js.map +1 -0
- package/dist/document-model/core/types.d.ts +533 -0
- package/dist/document-model/core/types.d.ts.map +1 -0
- package/dist/document-model/core/types.js +2 -0
- package/dist/document-model/core/types.js.map +1 -0
- package/dist/document-model/core/upgrades.d.ts +24 -0
- package/dist/document-model/core/upgrades.d.ts.map +1 -0
- package/dist/document-model/core/upgrades.js +2 -0
- package/dist/document-model/core/upgrades.js.map +1 -0
- package/dist/document-model/index.d.ts +5 -0
- package/dist/document-model/index.d.ts.map +1 -0
- package/dist/document-model/index.js +3 -0
- package/dist/document-model/index.js.map +1 -0
- package/dist/document-model/types.d.ts +97 -0
- package/dist/document-model/types.d.ts.map +1 -0
- package/dist/document-model/types.js +2 -0
- package/dist/document-model/types.js.map +1 -0
- package/dist/processors/constants.d.ts +4 -0
- package/dist/processors/constants.d.ts.map +1 -0
- package/dist/processors/constants.js +4 -0
- package/dist/processors/constants.js.map +1 -0
- package/dist/processors/index.d.ts +5 -0
- package/dist/processors/index.d.ts.map +1 -0
- package/dist/processors/index.js +4 -0
- package/dist/processors/index.js.map +1 -0
- package/dist/processors/relational/types.d.ts +72 -0
- package/dist/processors/relational/types.d.ts.map +1 -0
- package/dist/processors/relational/types.js +45 -0
- package/dist/processors/relational/types.js.map +1 -0
- package/dist/processors/relational/utils.d.ts +29 -0
- package/dist/processors/relational/utils.d.ts.map +1 -0
- package/dist/processors/relational/utils.js +67 -0
- package/dist/processors/relational/utils.js.map +1 -0
- package/dist/processors/types.d.ts +76 -0
- package/dist/processors/types.d.ts.map +1 -0
- package/dist/processors/types.js +2 -0
- package/dist/processors/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ProcessorFactoryBuilder } from "../processors/types.js";
|
|
2
|
+
import type { Action } from "./core/actions.js";
|
|
3
|
+
import type { PHDocument } from "./core/documents.js";
|
|
4
|
+
import type { PHBaseState } from "./core/state.js";
|
|
5
|
+
import type { AssertIsDocumentOfType, AssertIsStateOfType, CreateDocument, CreateState, EditorModule, ID, ImportScriptModule, IsDocumentOfType, IsStateOfType, LoadFromInput, Manifest, Reducer, SaveToFileHandle, SubgraphModule } from "./core/types.js";
|
|
6
|
+
import type { UpgradeManifest } from "./core/upgrades.js";
|
|
7
|
+
export type State = {
|
|
8
|
+
examples: CodeExample[];
|
|
9
|
+
initialValue: string;
|
|
10
|
+
schema: string;
|
|
11
|
+
};
|
|
12
|
+
export type ScopeState = {
|
|
13
|
+
global: State;
|
|
14
|
+
local: State;
|
|
15
|
+
};
|
|
16
|
+
export type DocumentModelUtils<TState extends PHBaseState = PHBaseState> = {
|
|
17
|
+
fileExtension: string;
|
|
18
|
+
createState: CreateState<TState>;
|
|
19
|
+
createDocument: CreateDocument<TState>;
|
|
20
|
+
loadFromInput: LoadFromInput<TState>;
|
|
21
|
+
saveToFileHandle: SaveToFileHandle;
|
|
22
|
+
isStateOfType: IsStateOfType<TState>;
|
|
23
|
+
assertIsStateOfType: AssertIsStateOfType<TState>;
|
|
24
|
+
isDocumentOfType: IsDocumentOfType<TState>;
|
|
25
|
+
assertIsDocumentOfType: AssertIsDocumentOfType<TState>;
|
|
26
|
+
};
|
|
27
|
+
export type DocumentModelModule<TState extends PHBaseState = PHBaseState> = {
|
|
28
|
+
/** optional version field, should be made required */
|
|
29
|
+
version?: number;
|
|
30
|
+
reducer: Reducer<TState>;
|
|
31
|
+
actions: Record<string, (...args: any[]) => Action>;
|
|
32
|
+
utils: DocumentModelUtils<TState>;
|
|
33
|
+
documentModel: DocumentModelPHState;
|
|
34
|
+
};
|
|
35
|
+
export type DocumentModelLib<TState extends PHBaseState = PHBaseState> = {
|
|
36
|
+
manifest: Manifest;
|
|
37
|
+
documentModels: DocumentModelModule<TState>[];
|
|
38
|
+
editors: EditorModule[];
|
|
39
|
+
subgraphs: SubgraphModule[];
|
|
40
|
+
importScripts: ImportScriptModule[];
|
|
41
|
+
upgradeManifests: UpgradeManifest<readonly number[]>[];
|
|
42
|
+
processorFactory: ProcessorFactoryBuilder;
|
|
43
|
+
};
|
|
44
|
+
export type Author = {
|
|
45
|
+
name: string;
|
|
46
|
+
website: string | null;
|
|
47
|
+
};
|
|
48
|
+
export type OperationErrorSpecification = {
|
|
49
|
+
code: string | null;
|
|
50
|
+
description: string | null;
|
|
51
|
+
id: ID;
|
|
52
|
+
name: string | null;
|
|
53
|
+
template: string | null;
|
|
54
|
+
};
|
|
55
|
+
export type CodeExample = {
|
|
56
|
+
id: ID;
|
|
57
|
+
value: string;
|
|
58
|
+
};
|
|
59
|
+
export type OperationSpecification = {
|
|
60
|
+
description: string | null;
|
|
61
|
+
errors: OperationErrorSpecification[];
|
|
62
|
+
examples: CodeExample[];
|
|
63
|
+
id: ID;
|
|
64
|
+
name: string | null;
|
|
65
|
+
reducer: string | null;
|
|
66
|
+
schema: string | null;
|
|
67
|
+
template: string | null;
|
|
68
|
+
scope: string;
|
|
69
|
+
};
|
|
70
|
+
export type ModuleSpecification = {
|
|
71
|
+
description: string | null;
|
|
72
|
+
id: ID;
|
|
73
|
+
name: string;
|
|
74
|
+
operations: OperationSpecification[];
|
|
75
|
+
};
|
|
76
|
+
export type DocumentSpecification = {
|
|
77
|
+
changeLog: string[];
|
|
78
|
+
modules: ModuleSpecification[];
|
|
79
|
+
state: ScopeState;
|
|
80
|
+
version: number;
|
|
81
|
+
};
|
|
82
|
+
export type DocumentModelGlobalState = {
|
|
83
|
+
author: Author;
|
|
84
|
+
description: string;
|
|
85
|
+
extension: string;
|
|
86
|
+
id: string;
|
|
87
|
+
name: string;
|
|
88
|
+
specifications: DocumentSpecification[];
|
|
89
|
+
};
|
|
90
|
+
export type DocumentModelLocalState = {};
|
|
91
|
+
export type DocumentModelPHState = PHBaseState & {
|
|
92
|
+
global: DocumentModelGlobalState;
|
|
93
|
+
local: DocumentModelLocalState;
|
|
94
|
+
};
|
|
95
|
+
export type DocumentModelDocument = PHDocument<DocumentModelPHState>;
|
|
96
|
+
export type DocumentModelDocumentModelModule = DocumentModelModule<DocumentModelPHState>;
|
|
97
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../document-model/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;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model/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../processors/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,qCAAsC,CAAC;AAClE,eAAO,MAAM,oCAAoC,kBAAkB,CAAC;AACpE,eAAO,MAAM,mCAAmC,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../processors/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,aAAa,CAAU,CAAC;AAClE,MAAM,CAAC,MAAM,oCAAoC,GAAG,eAAe,CAAC;AACpE,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../processors/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,mBAAmB,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../processors/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { OperationWithContext } from "@powerhousedao/shared/document-model";
|
|
2
|
+
import type { Kysely, QueryCreator } from "kysely";
|
|
3
|
+
import type { IProcessor, ProcessorFilter } from "../types.js";
|
|
4
|
+
export type IRelationalQueryMethods = "selectFrom" | "selectNoFrom" | "with" | "withRecursive";
|
|
5
|
+
export type IRelationalQueryBuilder<Schema = unknown> = Pick<QueryCreator<Schema>, IRelationalQueryMethods> & {
|
|
6
|
+
withSchema: (schema: string) => IRelationalQueryBuilder<Schema>;
|
|
7
|
+
};
|
|
8
|
+
export type HashAlgorithms = "fnv1a";
|
|
9
|
+
export type IBaseRelationalDb<Schema = unknown> = Kysely<Schema>;
|
|
10
|
+
/**
|
|
11
|
+
* The standardized relational database interface for relational db processors.
|
|
12
|
+
* This abstraction provides type-safe database operations while hiding the underlying
|
|
13
|
+
* database framework implementation details.
|
|
14
|
+
**/
|
|
15
|
+
export type IRelationalDb<Schema = unknown> = IBaseRelationalDb<Schema> & {
|
|
16
|
+
createNamespace<NamespaceSchema>(namespace: string): Promise<IRelationalDb<ExtractProcessorSchemaOrSelf<NamespaceSchema>>>;
|
|
17
|
+
queryNamespace<NamespaceSchema>(namespace: string): IRelationalQueryBuilder<NamespaceSchema>;
|
|
18
|
+
};
|
|
19
|
+
export type ExtractProcessorSchemaOrSelf<TProcessor> = TProcessor extends RelationalDbProcessor<infer TSchema> ? TSchema : TProcessor;
|
|
20
|
+
export type RelationalDbProcessorClass<TSchema> = typeof RelationalDbProcessor<TSchema>;
|
|
21
|
+
export interface IRelationalDbProcessor<TDatabaseSchema = unknown> extends IProcessor {
|
|
22
|
+
namespace: string;
|
|
23
|
+
query: IRelationalQueryBuilder<TDatabaseSchema>;
|
|
24
|
+
filter: ProcessorFilter;
|
|
25
|
+
initAndUpgrade(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
declare const IS_RELATIONAL_DB_PROCESSOR: unique symbol;
|
|
28
|
+
/**
|
|
29
|
+
* Base class for relational db processors that require a relational database storage.
|
|
30
|
+
* This class abstracts database initialization, migration management, and resource cleanup,
|
|
31
|
+
* allowing derived classes to focus on business logic.
|
|
32
|
+
*/
|
|
33
|
+
export declare abstract class RelationalDbProcessor<TDatabaseSchema = unknown> implements IRelationalDbProcessor<TDatabaseSchema> {
|
|
34
|
+
protected _namespace: string;
|
|
35
|
+
protected _filter: ProcessorFilter;
|
|
36
|
+
protected relationalDb: IRelationalDb<TDatabaseSchema>;
|
|
37
|
+
constructor(_namespace: string, _filter: ProcessorFilter, relationalDb: IRelationalDb<TDatabaseSchema>);
|
|
38
|
+
static [IS_RELATIONAL_DB_PROCESSOR]: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the namespace for a given drive id.
|
|
41
|
+
* This method can be overridden by derived classes to provide a custom namespace.
|
|
42
|
+
*/
|
|
43
|
+
static getNamespace(driveId: string): string;
|
|
44
|
+
static query<Schema>(this: RelationalDbProcessorClass<Schema>, driveId: string, db: IRelationalDb<any>): IRelationalQueryBuilder<Schema>;
|
|
45
|
+
/**
|
|
46
|
+
* Processes a list of operations with context.
|
|
47
|
+
* Called when operations match this processor's filter.
|
|
48
|
+
*/
|
|
49
|
+
abstract onOperations(operations: OperationWithContext[]): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the filter for the processor.
|
|
52
|
+
* This method can be overridden by derived classes to provide a custom filter.
|
|
53
|
+
*/
|
|
54
|
+
get filter(): ProcessorFilter;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the namespace used by the processor.
|
|
57
|
+
*/
|
|
58
|
+
get namespace(): string;
|
|
59
|
+
get query(): IRelationalQueryBuilder<TDatabaseSchema>;
|
|
60
|
+
/**
|
|
61
|
+
* Abstract method that derived classes must implement.
|
|
62
|
+
* This method is meant to be called on subclasses to initialize and upgrade the database.
|
|
63
|
+
*/
|
|
64
|
+
abstract initAndUpgrade(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Called when the processor is disconnected.
|
|
67
|
+
* This method is meant to be overridden by subclasses to clean up resources.
|
|
68
|
+
*/
|
|
69
|
+
abstract onDisconnect(): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../processors/relational/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC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
+
const IS_RELATIONAL_DB_PROCESSOR = Symbol.for("ph.IS_RELATIONAL_DB_PROCESSOR");
|
|
3
|
+
/**
|
|
4
|
+
* Base class for relational db processors that require a relational database storage.
|
|
5
|
+
* This class abstracts database initialization, migration management, and resource cleanup,
|
|
6
|
+
* allowing derived classes to focus on business logic.
|
|
7
|
+
*/
|
|
8
|
+
export class RelationalDbProcessor {
|
|
9
|
+
_namespace;
|
|
10
|
+
_filter;
|
|
11
|
+
relationalDb;
|
|
12
|
+
constructor(_namespace, _filter, relationalDb) {
|
|
13
|
+
this._namespace = _namespace;
|
|
14
|
+
this._filter = _filter;
|
|
15
|
+
this.relationalDb = relationalDb;
|
|
16
|
+
}
|
|
17
|
+
static [IS_RELATIONAL_DB_PROCESSOR] = true;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the namespace for a given drive id.
|
|
20
|
+
* This method can be overridden by derived classes to provide a custom namespace.
|
|
21
|
+
*/
|
|
22
|
+
static getNamespace(driveId) {
|
|
23
|
+
return `${this.name}_${driveId.replaceAll("-", "_")}`;
|
|
24
|
+
}
|
|
25
|
+
static query(driveId, db) {
|
|
26
|
+
return db.queryNamespace(this.getNamespace(driveId));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the filter for the processor.
|
|
30
|
+
* This method can be overridden by derived classes to provide a custom filter.
|
|
31
|
+
*/
|
|
32
|
+
get filter() {
|
|
33
|
+
return this._filter;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the namespace used by the processor.
|
|
37
|
+
*/
|
|
38
|
+
get namespace() {
|
|
39
|
+
return this._namespace;
|
|
40
|
+
}
|
|
41
|
+
get query() {
|
|
42
|
+
return relationalDbToQueryBuilder(this.relationalDb);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../processors/relational/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAgDxD,MAAM,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,OAAgB,qBAAqB;IAI7B;IACA;IACA;IAHZ,YACY,UAAkB,EAClB,OAAwB,EACxB,YAA4C;QAF5C,eAAU,GAAV,UAAU,CAAQ;QAClB,YAAO,GAAP,OAAO,CAAiB;QACxB,iBAAY,GAAZ,YAAY,CAAgC;IACrD,CAAC;IAEJ,MAAM,CAAC,CAAC,0BAA0B,CAAC,GAAG,IAAI,CAAC;IAE3C;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,OAAe;QACjC,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,KAAK,CAEV,OAAe,EACf,EAAsB;QAEtB,OAAO,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC;IAQD;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,0BAA0B,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IBaseRelationalDb, IRelationalDb, IRelationalQueryBuilder } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Hashes a string to a lowercase base-26 string.
|
|
4
|
+
* @param str The string to hash.
|
|
5
|
+
* @param length The length of the hash. Defaults to 10.
|
|
6
|
+
* @param algorithm The hashing algorithm to use. Defaults to "fnv1a".
|
|
7
|
+
* @returns The hashed string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function hashNamespace(str: string, length?: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a RelationalDb instance with namespace support.
|
|
12
|
+
* @param baseDb The base RelationalDb instance to enhance.
|
|
13
|
+
* @param baseOptions The default options for namespace creation. Hashes namespace by default.
|
|
14
|
+
* @returns The enhanced RelationalDb instance.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createRelationalDb<Schema>(baseDb: IBaseRelationalDb<Schema>, baseOptions?: NamespaceOptions): IRelationalDb<Schema>;
|
|
17
|
+
type NamespaceOptions = {
|
|
18
|
+
hashNamespace?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function createNamespacedDb<Schema>(db: IBaseRelationalDb<any>, namespace: string, options?: NamespaceOptions): Promise<IRelationalDb<Schema>>;
|
|
21
|
+
export declare function createNamespacedQueryBuilder<Schema>(db: IBaseRelationalDb<any>, namespace: string, options?: NamespaceOptions): IRelationalQueryBuilder<Schema>;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a query builder for a RelationalDb instance.
|
|
24
|
+
* @param query The RelationalDb instance to convert.
|
|
25
|
+
* @returns The IRelationalQueryBuilder instance.
|
|
26
|
+
*/
|
|
27
|
+
export declare function relationalDbToQueryBuilder<TSchema>(query: IBaseRelationalDb<TSchema>): IRelationalQueryBuilder<TSchema>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../processors/relational/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAIpB;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAK,UAMrD;AAaD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EACvC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,EACjC,WAAW,CAAC,EAAE,gBAAgB,GAC7B,aAAa,CAAC,MAAM,CAAC,CAwBvB;AAED,KAAK,gBAAgB,GAAG;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,MAAM,EAC7C,EAAE,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAOhC;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EACjD,EAAE,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,gBAAgB,GACzB,uBAAuB,CAAC,MAAM,CAAC,CAKjC;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAChD,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAChC,uBAAuB,CAAC,OAAO,CAAC,CASlC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fnv1a from "@sindresorhus/fnv1a";
|
|
2
|
+
const SUPPORTED_SIZES = [32, 64, 128, 256, 512, 1024];
|
|
3
|
+
const LOG2_26 = Math.log2(26); //
|
|
4
|
+
/**
|
|
5
|
+
* Hashes a string to a lowercase base-26 string.
|
|
6
|
+
* @param str The string to hash.
|
|
7
|
+
* @param length The length of the hash. Defaults to 10.
|
|
8
|
+
* @param algorithm The hashing algorithm to use. Defaults to "fnv1a".
|
|
9
|
+
* @returns The hashed string.
|
|
10
|
+
*/
|
|
11
|
+
export function hashNamespace(str, length = 10) {
|
|
12
|
+
const requiredBits = Math.ceil(length * LOG2_26);
|
|
13
|
+
const bitSize = SUPPORTED_SIZES.find((size) => size && size >= requiredBits) ?? 1024;
|
|
14
|
+
const hash = fnv1a(str, { size: bitSize });
|
|
15
|
+
return toBase26(hash, length);
|
|
16
|
+
}
|
|
17
|
+
// converts hash to lowercase letters
|
|
18
|
+
function toBase26(num, length = 10) {
|
|
19
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyz";
|
|
20
|
+
let out = "";
|
|
21
|
+
while (num > 0n && out.length < length) {
|
|
22
|
+
out = alphabet[Number(num % 26n)] + out;
|
|
23
|
+
num /= 26n;
|
|
24
|
+
}
|
|
25
|
+
return out.padStart(length, "a"); // optional padding
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a RelationalDb instance with namespace support.
|
|
29
|
+
* @param baseDb The base RelationalDb instance to enhance.
|
|
30
|
+
* @param baseOptions The default options for namespace creation. Hashes namespace by default.
|
|
31
|
+
* @returns The enhanced RelationalDb instance.
|
|
32
|
+
*/
|
|
33
|
+
export function createRelationalDb(baseDb, baseOptions) {
|
|
34
|
+
const relationalDb = baseDb;
|
|
35
|
+
relationalDb.createNamespace = (namespace, options) => createNamespacedDb(baseDb, namespace, options ?? baseOptions);
|
|
36
|
+
relationalDb.queryNamespace = (namespace, options) => createNamespacedQueryBuilder(baseDb, namespace, options ?? baseOptions);
|
|
37
|
+
return relationalDb;
|
|
38
|
+
}
|
|
39
|
+
export async function createNamespacedDb(db, namespace, options) {
|
|
40
|
+
// hash the namespace to avoid too long namespaces
|
|
41
|
+
const shouldHash = options?.hashNamespace ?? true;
|
|
42
|
+
const hashValue = shouldHash ? hashNamespace(namespace) : namespace;
|
|
43
|
+
await db.schema.createSchema(hashValue).ifNotExists().execute();
|
|
44
|
+
const schemaRelationalDb = db.withSchema(hashValue);
|
|
45
|
+
return schemaRelationalDb;
|
|
46
|
+
}
|
|
47
|
+
export function createNamespacedQueryBuilder(db, namespace, options) {
|
|
48
|
+
const shouldHash = options?.hashNamespace ?? true;
|
|
49
|
+
const hashValue = shouldHash ? hashNamespace(namespace) : namespace;
|
|
50
|
+
const namespacedDb = db.withSchema(hashValue);
|
|
51
|
+
return relationalDbToQueryBuilder(namespacedDb);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns a query builder for a RelationalDb instance.
|
|
55
|
+
* @param query The RelationalDb instance to convert.
|
|
56
|
+
* @returns The IRelationalQueryBuilder instance.
|
|
57
|
+
*/
|
|
58
|
+
export function relationalDbToQueryBuilder(query) {
|
|
59
|
+
return {
|
|
60
|
+
selectFrom: query.selectFrom.bind(query),
|
|
61
|
+
selectNoFrom: query.selectNoFrom.bind(query),
|
|
62
|
+
with: query.with.bind(query),
|
|
63
|
+
withRecursive: query.withRecursive.bind(query),
|
|
64
|
+
withSchema: (schema) => relationalDbToQueryBuilder(query.withSchema(schema)),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../processors/relational/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,qBAAqB,CAAC;AAOxC,MAAM,eAAe,GAAsB,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AACzE,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;AACjC;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,MAAM,GAAG,EAAE;IACpD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC;IACjD,MAAM,OAAO,GACX,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,IAAI,YAAY,CAAC,IAAI,IAAI,CAAC;IACvE,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC;AA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C;IAChE,MAAM,kBAAkB,GAAG,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACpD,OAAO,kBAA2C,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,EAA0B,EAC1B,SAAiB,EACjB,OAA0B;IAE1B,MAAM,UAAU,GAAG,OAAO,EAAE,aAAa,IAAI,IAAI,CAAC;IAClD,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACpE,MAAM,YAAY,GAAG,EAAE,CAAC,UAAU,CAAC,SAAS,CAA0B,CAAC;IACvE,OAAO,0BAA0B,CAAC,YAAY,CAAC,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACxC,KAAiC;IAEjC,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;QACxC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC;QAC5C,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAC5B,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9C,UAAU,EAAE,CAAC,MAAc,EAAE,EAAE,CAC7B,0BAA0B,CAAU,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;KAChE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { IAnalyticsStore } from "@powerhousedao/analytics-engine-core";
|
|
2
|
+
import type { OperationWithContext } from "@powerhousedao/shared/document-model";
|
|
3
|
+
import type { PHDocumentHeader } from "../document-model/core/documents.js";
|
|
4
|
+
import type { PROCESSOR_APPS } from "./constants.js";
|
|
5
|
+
import type { IRelationalDb } from "./relational/types.js";
|
|
6
|
+
export interface IProcessorHostModule {
|
|
7
|
+
analyticsStore: IAnalyticsStore;
|
|
8
|
+
relationalDb: IRelationalDb;
|
|
9
|
+
processorApp: ProcessorApp;
|
|
10
|
+
config?: Map<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Filter for matching operations to processors.
|
|
14
|
+
* All fields are optional arrays - when provided, operations must match at least one value in each specified field.
|
|
15
|
+
* When a field is undefined or empty, it matches all values for that field.
|
|
16
|
+
*/
|
|
17
|
+
export type ProcessorFilter = {
|
|
18
|
+
documentType?: string[];
|
|
19
|
+
scope?: string[];
|
|
20
|
+
branch?: string[];
|
|
21
|
+
documentId?: string[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Describes an object that can process operations.
|
|
25
|
+
*/
|
|
26
|
+
export interface IProcessor {
|
|
27
|
+
/**
|
|
28
|
+
* Processes a list of operations with context.
|
|
29
|
+
* Called when operations match this processor's filter.
|
|
30
|
+
*/
|
|
31
|
+
onOperations(operations: OperationWithContext[]): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Called when the processor is disconnected.
|
|
34
|
+
* Used to clean up any resources allocated during processor creation.
|
|
35
|
+
*/
|
|
36
|
+
onDisconnect(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Relates a processor to its filter configuration.
|
|
40
|
+
*/
|
|
41
|
+
export type ProcessorRecord = {
|
|
42
|
+
processor: IProcessor;
|
|
43
|
+
filter: ProcessorFilter;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* A factory function that creates processor records for a given drive.
|
|
47
|
+
* Called once per drive when the drive is first detected or when the factory is registered.
|
|
48
|
+
*/
|
|
49
|
+
export type ProcessorFactory = (driveHeader: PHDocumentHeader, processorApp?: ProcessorApp) => ProcessorRecord[] | Promise<ProcessorRecord[]>;
|
|
50
|
+
/** Takes a processor host module and builds processor factories using its context */
|
|
51
|
+
export type ProcessorFactoryBuilder = (module: IProcessorHostModule) => Promise<(driveHeader: PHDocumentHeader) => Promise<ProcessorRecord[]>>;
|
|
52
|
+
/**
|
|
53
|
+
* Manages processor creation and destruction based on drive operations.
|
|
54
|
+
*/
|
|
55
|
+
export interface IProcessorManager {
|
|
56
|
+
/**
|
|
57
|
+
* Registers a processor factory.
|
|
58
|
+
* Immediately creates processors for all existing drives.
|
|
59
|
+
*/
|
|
60
|
+
registerFactory(identifier: string, factory: ProcessorFactory): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Unregisters a processor factory and disconnects all processors it created.
|
|
63
|
+
*/
|
|
64
|
+
unregisterFactory(identifier: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Gets all registered factory identifiers.
|
|
67
|
+
*/
|
|
68
|
+
getFactoryIdentifiers(): string[];
|
|
69
|
+
/**
|
|
70
|
+
* Gets all processor records for a specific drive.
|
|
71
|
+
*/
|
|
72
|
+
getProcessorsForDrive(driveId: string): ProcessorRecord[];
|
|
73
|
+
}
|
|
74
|
+
export type ProcessorApp = (typeof PROCESSOR_APPS)[number];
|
|
75
|
+
export type ProcessorApps = readonly ProcessorApp[];
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../processors/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,eAAe,CAAC;IAChC,YAAY,EAAE,aAAa,CAAC;IAC5B,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,GAA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