udsl-sdk 1.0.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/dist/client.d.ts +6 -0
- package/dist/client.js +28 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +17 -0
- package/dist/localStore.d.ts +3 -0
- package/dist/localStore.js +15 -0
- package/dist/recovery.d.ts +2 -0
- package/dist/recovery.js +24 -0
- package/dist/sync.d.ts +10 -0
- package/dist/sync.js +48 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +24 -0
- package/dist/types.d.ts +0 -0
- package/dist/types.js +1 -0
- package/package.json +27 -0
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Client = void 0;
|
|
13
|
+
class Client {
|
|
14
|
+
constructor(baseUrl, apiKey) {
|
|
15
|
+
this.baseUrl = baseUrl;
|
|
16
|
+
this.apiKey = apiKey;
|
|
17
|
+
}
|
|
18
|
+
request(path_1) {
|
|
19
|
+
return __awaiter(this, arguments, void 0, function* (path, options = {}) {
|
|
20
|
+
const res = yield fetch(`${this.baseUrl}${path}`, Object.assign(Object.assign({}, options), { headers: {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
"x-api-key": this.apiKey,
|
|
23
|
+
} }));
|
|
24
|
+
return res.json();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Client = Client;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UDSL = void 0;
|
|
4
|
+
const sync_1 = require("./sync");
|
|
5
|
+
let config;
|
|
6
|
+
exports.UDSL = {
|
|
7
|
+
init(cfg) {
|
|
8
|
+
config = cfg;
|
|
9
|
+
sync_1.syncWrite.init(cfg);
|
|
10
|
+
},
|
|
11
|
+
save(key, value) {
|
|
12
|
+
return sync_1.syncWrite.save(key, value);
|
|
13
|
+
},
|
|
14
|
+
get(key) {
|
|
15
|
+
return sync_1.syncGet.get(key);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveLocal = saveLocal;
|
|
4
|
+
exports.getLocal = getLocal;
|
|
5
|
+
exports.getAllLocal = getAllLocal;
|
|
6
|
+
const store = new Map();
|
|
7
|
+
function saveLocal(key, value) {
|
|
8
|
+
store.set(key, value);
|
|
9
|
+
}
|
|
10
|
+
function getLocal(key) {
|
|
11
|
+
return store.get(key);
|
|
12
|
+
}
|
|
13
|
+
function getAllLocal() {
|
|
14
|
+
return store;
|
|
15
|
+
}
|
package/dist/recovery.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.recover = recover;
|
|
13
|
+
const localStore_1 = require("./localStore");
|
|
14
|
+
function recover(client) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const localData = (0, localStore_1.getAllLocal)();
|
|
17
|
+
for (const [key, value] of localData.entries()) {
|
|
18
|
+
yield client.request("/data/write", {
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: JSON.stringify({ key, value }),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
package/dist/sync.d.ts
ADDED
package/dist/sync.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.syncGet = exports.syncWrite = void 0;
|
|
13
|
+
const client_1 = require("./client");
|
|
14
|
+
const localStore_1 = require("./localStore");
|
|
15
|
+
let client;
|
|
16
|
+
exports.syncWrite = {
|
|
17
|
+
init(config) {
|
|
18
|
+
client = new client_1.Client(config.baseUrl, config.apiKey);
|
|
19
|
+
},
|
|
20
|
+
save(key, value) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
try {
|
|
23
|
+
const res = yield client.request("/data/write", {
|
|
24
|
+
method: "POST",
|
|
25
|
+
body: JSON.stringify({ key, value }),
|
|
26
|
+
});
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
// fallback to local storage
|
|
31
|
+
(0, localStore_1.saveLocal)(key, value);
|
|
32
|
+
return { offline: true };
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
exports.syncGet = {
|
|
38
|
+
get(key) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
return yield client.request(`/data/state/${key}`);
|
|
42
|
+
}
|
|
43
|
+
catch (_a) {
|
|
44
|
+
return (0, localStore_1.getLocal)(key);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
};
|
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const index_1 = require("./index");
|
|
13
|
+
index_1.UDSL.init({
|
|
14
|
+
baseUrl: "http://localhost:3001",
|
|
15
|
+
apiKey: "test-key-123",
|
|
16
|
+
});
|
|
17
|
+
function run() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
yield index_1.UDSL.save("doc1", { text: "Hello SDK" });
|
|
20
|
+
const data = yield index_1.UDSL.get("doc1");
|
|
21
|
+
console.log("DATA:", data);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
run();
|
package/dist/types.d.ts
ADDED
|
File without changes
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "udsl-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Crash-safe data recovery SDK (WAL + Snapshot based)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"recovery",
|
|
16
|
+
"wal",
|
|
17
|
+
"snapshot",
|
|
18
|
+
"crash-recovery",
|
|
19
|
+
"offline-first",
|
|
20
|
+
"sdk"
|
|
21
|
+
],
|
|
22
|
+
"author": "Om Ghadage",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^6.0.3"
|
|
26
|
+
}
|
|
27
|
+
}
|