document-drive 3.3.0-dev.11 → 3.3.0-dev.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/processors/processor-manager.js +5 -5
- package/dist/src/processors/processor-manager.js.map +1 -1
- package/dist/src/processors/relational.d.ts +62 -0
- package/dist/src/processors/relational.d.ts.map +1 -0
- package/dist/src/processors/relational.js +60 -0
- package/dist/src/processors/relational.js.map +1 -0
- package/dist/src/processors/types.d.ts +14 -5
- package/dist/src/processors/types.d.ts.map +1 -1
- package/dist/src/processors/utils.d.ts +30 -0
- package/dist/src/processors/utils.d.ts.map +1 -0
- package/dist/src/processors/utils.js +74 -0
- package/dist/src/processors/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/dist/src/processors/operational-processor.d.ts +0 -72
- package/dist/src/processors/operational-processor.d.ts.map +0 -1
- package/dist/src/processors/operational-processor.js +0 -84
- package/dist/src/processors/operational-processor.js.map +0 -1
- package/dist/src/utils/hash.d.ts +0 -3
- package/dist/src/utils/hash.d.ts.map +0 -1
- package/dist/src/utils/hash.js +0 -31
- package/dist/src/utils/hash.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-drive",
|
|
3
|
-
"version": "3.3.0-dev.
|
|
3
|
+
"version": "3.3.0-dev.13",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@helia/mfs": "^4.0.3",
|
|
32
32
|
"@prisma/client": "5.17.0",
|
|
33
|
+
"@sindresorhus/fnv1a": "^3.1.0",
|
|
33
34
|
"change-case": "^5.4.4",
|
|
34
35
|
"exponential-backoff": "^3.1.1",
|
|
35
36
|
"graphql": "^16.11.0",
|
|
@@ -47,9 +48,9 @@
|
|
|
47
48
|
"sqlite3": "^5.1.7",
|
|
48
49
|
"uuid": "^11.0.5",
|
|
49
50
|
"zod": "^3.24.3",
|
|
50
|
-
"@powerhousedao/codegen": "3.3.0-dev.
|
|
51
|
-
"@powerhousedao/config": "3.3.0-dev.
|
|
52
|
-
"document-model": "3.3.0-dev.
|
|
51
|
+
"@powerhousedao/codegen": "3.3.0-dev.13",
|
|
52
|
+
"@powerhousedao/config": "3.3.0-dev.13",
|
|
53
|
+
"document-model": "3.3.0-dev.13"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@powerhousedao/analytics-engine-core": "^0.5.0",
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { type ListenerFilter } from "#drive-document-model/module";
|
|
2
|
-
import { type PHDocument } from "document-model";
|
|
3
|
-
import { type QueryCreator } from "kysely";
|
|
4
|
-
import { type InternalTransmitterUpdate } from "../server/listener/transmitter/internal.js";
|
|
5
|
-
import { type IOperationalStore, type IProcessor } from "./types.js";
|
|
6
|
-
export type IOperationalQueryMethods = "selectFrom" | "selectNoFrom" | "with" | "withRecursive";
|
|
7
|
-
export type IOperationalQueryBuilder<Schema = unknown> = Pick<QueryCreator<Schema>, IOperationalQueryMethods> & {
|
|
8
|
-
withSchema: (schema: string) => IOperationalQueryBuilder<Schema>;
|
|
9
|
-
};
|
|
10
|
-
export type OperationalProcessorFilter = ListenerFilter;
|
|
11
|
-
export interface IOperationalProcessor<TDatabaseSchema = unknown> extends IProcessor {
|
|
12
|
-
namespace: string;
|
|
13
|
-
query: IOperationalQueryBuilder<TDatabaseSchema>;
|
|
14
|
-
filter: OperationalProcessorFilter;
|
|
15
|
-
initAndUpgrade(): Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
export declare function createNamespacedDb<T>(namespace: string, db: IOperationalStore, options?: {
|
|
18
|
-
hashNamespace?: boolean;
|
|
19
|
-
}): Promise<IOperationalStore<ExtractProcessorSchema<T>>>;
|
|
20
|
-
export declare function createNamespacedQueryBuilder<Schema>(processor: OperationalProcessorClass<Schema>, driveId: string, db: IOperationalStore, options?: {
|
|
21
|
-
hashNamespace?: boolean;
|
|
22
|
-
}): IOperationalQueryBuilder<Schema>;
|
|
23
|
-
export declare function isOperationalProcessor(p: IProcessor): p is IOperationalProcessor;
|
|
24
|
-
export type ExtractProcessorSchema<TProcessor> = TProcessor extends OperationalProcessor<infer TSchema> ? TSchema : never;
|
|
25
|
-
export type OperationalProcessorClass<TSchema> = (new (...args: any[]) => OperationalProcessor<TSchema>) & typeof OperationalProcessor<TSchema>;
|
|
26
|
-
declare const IS_OPERATIONAL_PROCESSOR: unique symbol;
|
|
27
|
-
/**
|
|
28
|
-
* Base class for operational processors that require a relational database storage.
|
|
29
|
-
* This class abstracts database initialization, migration management, and resource cleanup,
|
|
30
|
-
* allowing derived classes to focus on business logic.
|
|
31
|
-
*/
|
|
32
|
-
export declare abstract class OperationalProcessor<TDatabaseSchema = unknown> implements IOperationalProcessor<TDatabaseSchema> {
|
|
33
|
-
protected _namespace: string;
|
|
34
|
-
protected _filter: OperationalProcessorFilter;
|
|
35
|
-
protected operationalStore: IOperationalStore<TDatabaseSchema>;
|
|
36
|
-
constructor(_namespace: string, _filter: OperationalProcessorFilter, operationalStore: IOperationalStore<TDatabaseSchema>);
|
|
37
|
-
static [IS_OPERATIONAL_PROCESSOR]: boolean;
|
|
38
|
-
static is(p: unknown): p is OperationalProcessor;
|
|
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<TSchema>(this: OperationalProcessorClass<TSchema>, driveId: string, db: IOperationalStore<any>): IOperationalQueryBuilder<TSchema>;
|
|
45
|
-
/**
|
|
46
|
-
* Returns the filter for the processor.
|
|
47
|
-
* This method can be overridden by derived classes to provide a custom filter.
|
|
48
|
-
*/
|
|
49
|
-
get filter(): OperationalProcessorFilter;
|
|
50
|
-
/**
|
|
51
|
-
* Returns the namespace used by the processor.
|
|
52
|
-
*/
|
|
53
|
-
get namespace(): string;
|
|
54
|
-
get query(): IOperationalQueryBuilder<TDatabaseSchema>;
|
|
55
|
-
/**
|
|
56
|
-
* Abstract method that derived classes must implement.
|
|
57
|
-
* This method is meant to be called on subclasses to initialize and upgrade the database.
|
|
58
|
-
*/
|
|
59
|
-
abstract initAndUpgrade(): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Abstract method that derived classes must implement.
|
|
62
|
-
* This is where the business logic for processing document operations should be implemented.
|
|
63
|
-
*/
|
|
64
|
-
abstract onStrands<TDocument extends PHDocument>(strands: InternalTransmitterUpdate<TDocument>[]): 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=operational-processor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operational-processor.d.ts","sourceRoot":"","sources":["../../../src/processors/operational-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,MAAM,wBAAwB,GAChC,YAAY,GACZ,cAAc,GACd,MAAM,GACN,eAAe,CAAC;AAEpB,MAAM,MAAM,wBAAwB,CAAC,MAAM,GAAG,OAAO,IAAI,IAA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"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { hash } from "#utils/hash";
|
|
2
|
-
export async function createNamespacedDb(namespace, db, options) {
|
|
3
|
-
// hash the namespace to avoid too long namespaces
|
|
4
|
-
const hashNamespace = options?.hashNamespace ?? true;
|
|
5
|
-
const hashValue = hashNamespace ? hash(namespace) : namespace;
|
|
6
|
-
await db.schema.createSchema(hashValue).ifNotExists().execute();
|
|
7
|
-
const schemaOperationalStore = db.withSchema(hashValue);
|
|
8
|
-
return schemaOperationalStore;
|
|
9
|
-
}
|
|
10
|
-
export function createNamespacedQueryBuilder(processor, driveId, db, options) {
|
|
11
|
-
const namespace = processor.getNamespace(driveId);
|
|
12
|
-
const hashNamespace = options?.hashNamespace ?? true;
|
|
13
|
-
const hashValue = hashNamespace ? hash(namespace) : namespace;
|
|
14
|
-
const namespacedDb = db.withSchema(hashValue);
|
|
15
|
-
return operationalStoreToQueryBuilder(namespacedDb);
|
|
16
|
-
}
|
|
17
|
-
export function isOperationalProcessor(p) {
|
|
18
|
-
return OperationalProcessor.is(p);
|
|
19
|
-
}
|
|
20
|
-
function operationalStoreToQueryBuilder(query) {
|
|
21
|
-
return {
|
|
22
|
-
selectFrom: query.selectFrom.bind(query),
|
|
23
|
-
selectNoFrom: query.selectNoFrom.bind(query),
|
|
24
|
-
with: query.with.bind(query),
|
|
25
|
-
withRecursive: query.withRecursive.bind(query),
|
|
26
|
-
withSchema: (schema) => operationalStoreToQueryBuilder(query.withSchema(schema)),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
const IS_OPERATIONAL_PROCESSOR = Symbol.for("ph.IS_OPERATIONAL_PROCESSOR");
|
|
30
|
-
/**
|
|
31
|
-
* Base class for operational processors that require a relational database storage.
|
|
32
|
-
* This class abstracts database initialization, migration management, and resource cleanup,
|
|
33
|
-
* allowing derived classes to focus on business logic.
|
|
34
|
-
*/
|
|
35
|
-
export class OperationalProcessor {
|
|
36
|
-
_namespace;
|
|
37
|
-
_filter;
|
|
38
|
-
operationalStore;
|
|
39
|
-
constructor(_namespace, _filter, operationalStore) {
|
|
40
|
-
this._namespace = _namespace;
|
|
41
|
-
this._filter = _filter;
|
|
42
|
-
this.operationalStore = operationalStore;
|
|
43
|
-
}
|
|
44
|
-
static [IS_OPERATIONAL_PROCESSOR] = true;
|
|
45
|
-
static is(p) {
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
47
|
-
let proto = Object.getPrototypeOf(p);
|
|
48
|
-
while (proto) {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
50
|
-
if (proto.constructor?.[IS_OPERATIONAL_PROCESSOR])
|
|
51
|
-
return true;
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
53
|
-
proto = Object.getPrototypeOf(proto);
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns the namespace for a given drive id.
|
|
59
|
-
* This method can be overridden by derived classes to provide a custom namespace.
|
|
60
|
-
*/
|
|
61
|
-
static getNamespace(driveId) {
|
|
62
|
-
return `${this.name}_${driveId.replaceAll("-", "_")}`;
|
|
63
|
-
}
|
|
64
|
-
static query(driveId, db) {
|
|
65
|
-
return createNamespacedQueryBuilder(this, driveId, db);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Returns the filter for the processor.
|
|
69
|
-
* This method can be overridden by derived classes to provide a custom filter.
|
|
70
|
-
*/
|
|
71
|
-
get filter() {
|
|
72
|
-
return this._filter;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Returns the namespace used by the processor.
|
|
76
|
-
*/
|
|
77
|
-
get namespace() {
|
|
78
|
-
return this._namespace;
|
|
79
|
-
}
|
|
80
|
-
get query() {
|
|
81
|
-
return operationalStoreToQueryBuilder(this.operationalStore);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=operational-processor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operational-processor.js","sourceRoot":"","sources":["../../../src/processors/operational-processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AA4BnC,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,SAAiB,EACjB,EAAqB,EACrB,OAEC;IAED,kDAAkD;IAClD,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,IAAI,CAAC;IACrD,MAAM,SAAS,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9D,MAAM,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,CAAC;IAChE,MAAM,sBAAsB,GAAG,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACxD,OAAO,sBAAsE,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,SAA4C,EAC5C,OAAe,EACf,EAAqB,EACrB,OAEC;IAED,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,IAAI,CAAC;IACrD,MAAM,SAAS,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9D,MAAM,YAAY,GAAG,EAAE,CAAC,UAAU,CAAC,SAAS,CAA8B,CAAC;IAC3E,OAAO,8BAA8B,CAAC,YAAY,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,CAAa;IAEb,OAAO,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAKD,SAAS,8BAA8B,CACrC,KAAiC;IAEjC,OAAO;QACL,UAAU,EAAE,KAAK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E,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,KAAK,CAEV,OAAe,EACf,EAA0B;QAE1B,OAAO,4BAA4B,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;;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,8BAA8B,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC/D,CAAC"}
|
package/dist/src/utils/hash.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/utils/hash.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC;AAE1C,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,EACX,MAAM,SAAK,EACX,SAAS,GAAE,cAA6B,UAUzC"}
|
package/dist/src/utils/hash.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export function hash(str, length = 12, algorithm = "MurmurHash") {
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
3
|
-
if (algorithm === "MurmurHash") {
|
|
4
|
-
const hash = murmurHash64(str);
|
|
5
|
-
return toBase62(hash, length);
|
|
6
|
-
}
|
|
7
|
-
else {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
9
|
-
throw new Error(`Unsupported hashing algorithm: ${algorithm}`);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
// MurmurHash64 implementation
|
|
13
|
-
function murmurHash64(input) {
|
|
14
|
-
let h = 0xcbf29ce484222325n; // FNV-1a 64-bit offset basis
|
|
15
|
-
const prime = 0x100000001b3n;
|
|
16
|
-
for (let i = 0; i < input.length; i++) {
|
|
17
|
-
h ^= BigInt(input.charCodeAt(i));
|
|
18
|
-
h *= prime;
|
|
19
|
-
}
|
|
20
|
-
return h & 0xffffffffffffffffn; // 64-bit mask
|
|
21
|
-
}
|
|
22
|
-
function toBase62(num, length = 12) {
|
|
23
|
-
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
24
|
-
let out = "";
|
|
25
|
-
while (num > 0n && out.length < length) {
|
|
26
|
-
out = chars[Number(num % 62n)] + out;
|
|
27
|
-
num /= 62n;
|
|
28
|
-
}
|
|
29
|
-
return out.padStart(length, "0");
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=hash.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../src/utils/hash.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI,CAClB,GAAW,EACX,MAAM,GAAG,EAAE,EACX,YAA4B,YAAY;IAExC,uEAAuE;IACvE,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,4EAA4E;QAC5E,MAAM,IAAI,KAAK,CAAC,kCAAkC,SAAS,EAAE,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED,8BAA8B;AAC9B,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,CAAC,GAAG,mBAAmB,CAAC,CAAC,6BAA6B;IAC1D,MAAM,KAAK,GAAG,cAAc,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC,IAAI,K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