hyperchess-store 0.1.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.
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ // HyperChess Core — hyperchess-store
3
+ // File: packages/store/src/types/game-store.ts
4
+ // Version: 1.0.0
5
+ // Copyright (c) 2026 HyperChess Developer Team
6
+ /**
7
+ * Check if a game store is reachable, without letting a backend failure escape.
8
+ *
9
+ * Wraps `isHealthy()` so that a driver-level throw (connection refused, expired
10
+ * credentials) reads as "offline" rather than crashing the caller — the intended
11
+ * use is an availability probe on a sync path, not error reporting.
12
+ *
13
+ * @param store - Store to probe.
14
+ * @returns `true` only if `isHealthy()` resolved `true`; `false` if it resolved
15
+ * `false` or threw.
16
+ */
17
+ export async function isStoreOnline(store) {
18
+ try {
19
+ return await store.isHealthy();
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ /**
26
+ * Copy games from one store into another, one record at a time.
27
+ *
28
+ * Best-effort and non-transactional: a game that fails to save is logged and
29
+ * skipped so a single bad record cannot abort the whole sync, which matters when
30
+ * draining an offline queue on reconnect. Records are not deleted from the
31
+ * source, so this is a copy rather than a move.
32
+ *
33
+ * @param fromStore - Source of truth to read from.
34
+ * @param toStore - Destination the games are written into.
35
+ * @param options - `userId` restricts the copy to one owner's games;
36
+ * `overwrite` deletes the destination record first so the source version wins
37
+ * outright instead of being merged by the destination's upsert semantics.
38
+ * @returns How many games were saved successfully — may be fewer than the number
39
+ * read from the source.
40
+ */
41
+ export async function syncStores(fromStore, toStore, options) {
42
+ const games = await fromStore.listGames({
43
+ userId: options?.userId,
44
+ });
45
+ let syncedCount = 0;
46
+ for (const game of games) {
47
+ try {
48
+ if (options?.overwrite) {
49
+ // Delete if exists, then save
50
+ try {
51
+ await toStore.deleteGame(game.id);
52
+ }
53
+ catch {
54
+ // Game doesn't exist in target, that's ok
55
+ }
56
+ }
57
+ await toStore.saveGame(game);
58
+ syncedCount++;
59
+ }
60
+ catch (error) {
61
+ console.warn(`Failed to sync game ${game.id}:`, error);
62
+ }
63
+ }
64
+ return syncedCount;
65
+ }
66
+ //# sourceMappingURL=game-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"game-store.js","sourceRoot":"","sources":["../../src/types/game-store.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,qCAAqC;AACrC,+CAA+C;AAC/C,iBAAiB;AACjB,+CAA+C;AA+E/C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAgB;IAClD,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,SAAoB,EACpB,OAAkB,EAClB,OAAkD;IAElD,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,SAAS,CAAC;QACtC,MAAM,EAAE,OAAO,EAAE,MAAM;KACxB,CAAC,CAAC;IAEH,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,IAAI,OAAO,EAAE,SAAS,EAAE,CAAC;gBACvB,8BAA8B;gBAC9B,IAAI,CAAC;oBACH,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACpC,CAAC;gBAAC,MAAM,CAAC;oBACP,0CAA0C;gBAC5C,CAAC;YACH,CAAC;YAED,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7B,WAAW,EAAE,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,uBAAuB,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "hyperchess-store",
3
+ "version": "0.1.0",
4
+ "description": "HyperChess game storage abstraction - works with any backend",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./postgres": {
14
+ "import": "./dist/adapters/postgres.js",
15
+ "types": "./dist/adapters/postgres.d.ts"
16
+ },
17
+ "./sqlite": {
18
+ "import": "./dist/adapters/sqlite.js",
19
+ "types": "./dist/adapters/sqlite.d.ts"
20
+ },
21
+ "./firebase": {
22
+ "import": "./dist/adapters/firebase.js",
23
+ "types": "./dist/adapters/firebase.d.ts"
24
+ },
25
+ "./supabase": {
26
+ "import": "./dist/adapters/supabase.js",
27
+ "types": "./dist/adapters/supabase.d.ts"
28
+ },
29
+ "./memory": {
30
+ "import": "./dist/adapters/memory.js",
31
+ "types": "./dist/adapters/memory.d.ts"
32
+ }
33
+ },
34
+ "peerDependencies": {
35
+ "pg": "^8.0.0",
36
+ "better-sqlite3": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0",
37
+ "firebase": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0",
38
+ "@supabase/supabase-js": "^2.0.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "pg": {
42
+ "optional": true
43
+ },
44
+ "better-sqlite3": {
45
+ "optional": true
46
+ },
47
+ "firebase": {
48
+ "optional": true
49
+ },
50
+ "@supabase/supabase-js": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "dependencies": {
55
+ "hyperchess-core": "0.1.0"
56
+ },
57
+ "devDependencies": {
58
+ "firebase": "^12.0.0",
59
+ "typescript": "^5.2.0",
60
+ "vitest": "^0.34.0"
61
+ },
62
+ "files": [
63
+ "dist",
64
+ "README.md"
65
+ ],
66
+ "keywords": [
67
+ "hyperchess",
68
+ "storage",
69
+ "database",
70
+ "postgres",
71
+ "sqlite",
72
+ "firebase",
73
+ "supabase"
74
+ ],
75
+ "author": "HyperChess Contributors",
76
+ "license": "GPL-3.0-or-later",
77
+ "repository": {
78
+ "type": "git",
79
+ "url": "git+https://github.com/KyrpyDev/hyperchess-core.git",
80
+ "directory": "packages/store"
81
+ },
82
+ "homepage": "https://github.com/KyrpyDev/hyperchess-core#readme",
83
+ "bugs": {
84
+ "url": "https://github.com/KyrpyDev/hyperchess-core/issues"
85
+ },
86
+ "publishConfig": {
87
+ "access": "public"
88
+ },
89
+ "engines": {
90
+ "node": ">=18"
91
+ },
92
+ "scripts": {
93
+ "build": "tsc",
94
+ "test": "vitest run",
95
+ "test:watch": "vitest"
96
+ }
97
+ }