@arcote.tech/arc-host 0.1.8 → 0.1.10
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/host.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +104 -3196
- package/dist/index.js.map +89 -0
- package/dist/postgresAdapter.d.ts +3 -0
- package/dist/postgresAdapter.d.ts.map +1 -0
- package/host.ts +21 -22
- package/index.ts +2 -0
- package/package.json +7 -4
- package/postgresAdapter.ts +50 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresAdapter.d.ts","sourceRoot":"","sources":["../postgresAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EAEtB,MAAM,kBAAkB,CAAC;AAqC1B,eAAO,MAAM,wBAAwB,qBACjB,MAAM,KACvB,gBAKF,CAAC"}
|
package/host.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ArcCollection,
|
|
3
2
|
MasterDataStorage,
|
|
4
3
|
Model,
|
|
5
4
|
QueryBuilderContext,
|
|
6
5
|
QueryCache,
|
|
7
|
-
type ArcCollectionAny,
|
|
8
6
|
type ArcContextAny,
|
|
9
7
|
type AuthContext,
|
|
10
8
|
type DatabaseAdapter,
|
|
@@ -407,6 +405,7 @@ class RTCHost implements RealTimeCommunicationAdapter {
|
|
|
407
405
|
backpressureLimit: 16 * 1024 * 1024,
|
|
408
406
|
},
|
|
409
407
|
port: 5005,
|
|
408
|
+
idleTimeout: 30,
|
|
410
409
|
});
|
|
411
410
|
}
|
|
412
411
|
|
|
@@ -451,26 +450,26 @@ class RTCHost implements RealTimeCommunicationAdapter {
|
|
|
451
450
|
// const client = await this.clientPromise;
|
|
452
451
|
const syncResults: { store: string; items: any[] }[] = [];
|
|
453
452
|
|
|
454
|
-
for (const collection of this.context.elements
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
453
|
+
// for (const collection of this.context.elements
|
|
454
|
+
// .filter(
|
|
455
|
+
// (element) => element instanceof ArcCollection,
|
|
456
|
+
// // || element instanceof ArcIndexedCollection,
|
|
457
|
+
// )
|
|
458
|
+
// .concat([{ name: "state" } as unknown as ArcCollectionAny])) {
|
|
459
|
+
// // const result = await client
|
|
460
|
+
// // .db(process.env.MONGODB_DB)
|
|
461
|
+
// // .collection(collection.name)
|
|
462
|
+
// // .find(where)
|
|
463
|
+
// // .toArray();
|
|
464
|
+
// // const prepareDeleted = result.map((item) => {
|
|
465
|
+
// // if (item.deleted) return { _id: item._id, deleted: true };
|
|
466
|
+
// // return item;
|
|
467
|
+
// // });
|
|
468
|
+
// // syncResults.push({
|
|
469
|
+
// // store: collection.name,
|
|
470
|
+
// // items: prepareDeleted,
|
|
471
|
+
// // });
|
|
472
|
+
// }
|
|
474
473
|
|
|
475
474
|
return new Response(
|
|
476
475
|
JSON.stringify({
|
package/index.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { type ArcContextAny } from "@arcote.tech/arc";
|
|
|
2
2
|
import { rtcHostFactory } from "./host";
|
|
3
3
|
import { sqliteAdapterFactory } from "./sqliteAdapter";
|
|
4
4
|
|
|
5
|
+
export { postgreSQLAdapterFactory } from "./postgresAdapter";
|
|
6
|
+
|
|
5
7
|
export function hostLiveModel<C extends ArcContextAny>(
|
|
6
8
|
context: C,
|
|
7
9
|
options: { db: string; version: number },
|
package/package.json
CHANGED
|
@@ -4,21 +4,24 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.10",
|
|
8
8
|
"private": false,
|
|
9
9
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@arcote.tech/arc": "latest",
|
|
12
11
|
"jsonwebtoken": "^9.0.2"
|
|
13
12
|
},
|
|
14
13
|
"scripts": {
|
|
15
|
-
"build": "rm -rf dist && bun build ./index.ts --target=bun --outdir=dist && bun run build:declaration",
|
|
14
|
+
"build": "rm -rf dist && bun build ./index.ts --target=bun --outdir=dist --sourcemap --external @arcote.tech/arc && bun run build:declaration",
|
|
16
15
|
"build:declaration": "tsc --emitDeclarationOnly --declarationMap --project tsconfig.types.json",
|
|
17
16
|
"postbuild": "rimraf tsconfig.types.tsbuildinfo",
|
|
18
17
|
"type-check": "tsc",
|
|
19
18
|
"dev": "nodemon --ignore dist -e ts,tsx --exec 'bun run build'"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
|
-
"@types/jsonwebtoken": "^9.0.7"
|
|
21
|
+
"@types/jsonwebtoken": "^9.0.7",
|
|
22
|
+
"@types/bun": "^1.2.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@arcote.tech/arc": "latest"
|
|
23
26
|
}
|
|
24
27
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPostgreSQLAdapterFactory,
|
|
3
|
+
type ArcContextAny,
|
|
4
|
+
type DBAdapterFactory,
|
|
5
|
+
type PostgreSQLDatabase,
|
|
6
|
+
} from "@arcote.tech/arc";
|
|
7
|
+
import { SQL } from "bun";
|
|
8
|
+
|
|
9
|
+
class BunPostgreSQLDatabase implements PostgreSQLDatabase {
|
|
10
|
+
private connectionString: string;
|
|
11
|
+
private sql: SQL;
|
|
12
|
+
constructor(connectionString: string) {
|
|
13
|
+
this.connectionString = connectionString;
|
|
14
|
+
this.sql = new SQL(this.connectionString);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async exec(query: string, params?: any[]): Promise<any> {
|
|
18
|
+
try {
|
|
19
|
+
const result = await this.sql.unsafe(query, params);
|
|
20
|
+
return result;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error("PostgreSQL error:", error, query, params);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async execBatch(
|
|
28
|
+
queries: Array<{ sql: string; params?: any[] }>,
|
|
29
|
+
): Promise<any> {
|
|
30
|
+
try {
|
|
31
|
+
return await this.sql.transaction(async (tx) => {
|
|
32
|
+
for (const query of queries) {
|
|
33
|
+
await tx.unsafe(query.sql, query.params);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error("PostgreSQL batch transaction error:", error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const postgreSQLAdapterFactory = (
|
|
44
|
+
connectionString: string,
|
|
45
|
+
): DBAdapterFactory => {
|
|
46
|
+
return async (context: ArcContextAny) => {
|
|
47
|
+
const pgDb = new BunPostgreSQLDatabase(connectionString);
|
|
48
|
+
return createPostgreSQLAdapterFactory(pgDb)(context);
|
|
49
|
+
};
|
|
50
|
+
};
|