@ascorbic/pds 0.2.0 → 0.2.2
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/cli.js +188 -211
- package/dist/index.js +38 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5573,6 +5573,19 @@ function invalidRecordError(c, err, prefix) {
|
|
|
5573
5573
|
message: prefix ? `${prefix}: ${message}` : message
|
|
5574
5574
|
}, 400);
|
|
5575
5575
|
}
|
|
5576
|
+
/**
|
|
5577
|
+
* Check if an error is an AccountDeactivated error and return appropriate HTTP 403 response.
|
|
5578
|
+
* @param c - Hono context for creating the response
|
|
5579
|
+
* @param err - The error to check (expected format: "AccountDeactivated: <message>")
|
|
5580
|
+
* @returns HTTP 403 Response with AccountDeactivated error type, or null if not a deactivation error
|
|
5581
|
+
*/
|
|
5582
|
+
function checkAccountDeactivatedError(c, err) {
|
|
5583
|
+
if ((err instanceof Error ? err.message : String(err)).startsWith("AccountDeactivated:")) return c.json({
|
|
5584
|
+
error: "AccountDeactivated",
|
|
5585
|
+
message: "Account is deactivated. Call activateAccount to enable writes."
|
|
5586
|
+
}, 403);
|
|
5587
|
+
return null;
|
|
5588
|
+
}
|
|
5576
5589
|
async function describeRepo(c, accountDO) {
|
|
5577
5590
|
const repo = c.req.query("repo");
|
|
5578
5591
|
if (!repo) return c.json({
|
|
@@ -5687,8 +5700,14 @@ async function createRecord(c, accountDO) {
|
|
|
5687
5700
|
} catch (err) {
|
|
5688
5701
|
return invalidRecordError(c, err);
|
|
5689
5702
|
}
|
|
5690
|
-
|
|
5691
|
-
|
|
5703
|
+
try {
|
|
5704
|
+
const result = await accountDO.rpcCreateRecord(collection, rkey, record);
|
|
5705
|
+
return c.json(result);
|
|
5706
|
+
} catch (err) {
|
|
5707
|
+
const deactivatedError = checkAccountDeactivatedError(c, err);
|
|
5708
|
+
if (deactivatedError) return deactivatedError;
|
|
5709
|
+
throw err;
|
|
5710
|
+
}
|
|
5692
5711
|
}
|
|
5693
5712
|
async function deleteRecord(c, accountDO) {
|
|
5694
5713
|
const { repo, collection, rkey } = await c.req.json();
|
|
@@ -5700,12 +5719,18 @@ async function deleteRecord(c, accountDO) {
|
|
|
5700
5719
|
error: "InvalidRepo",
|
|
5701
5720
|
message: `Invalid repository: ${repo}`
|
|
5702
5721
|
}, 400);
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5722
|
+
try {
|
|
5723
|
+
const result = await accountDO.rpcDeleteRecord(collection, rkey);
|
|
5724
|
+
if (!result) return c.json({
|
|
5725
|
+
error: "RecordNotFound",
|
|
5726
|
+
message: `Record not found: ${collection}/${rkey}`
|
|
5727
|
+
}, 404);
|
|
5728
|
+
return c.json(result);
|
|
5729
|
+
} catch (err) {
|
|
5730
|
+
const deactivatedError = checkAccountDeactivatedError(c, err);
|
|
5731
|
+
if (deactivatedError) return deactivatedError;
|
|
5732
|
+
throw err;
|
|
5733
|
+
}
|
|
5709
5734
|
}
|
|
5710
5735
|
async function putRecord(c, accountDO) {
|
|
5711
5736
|
const { repo, collection, rkey, record } = await c.req.json();
|
|
@@ -5726,6 +5751,8 @@ async function putRecord(c, accountDO) {
|
|
|
5726
5751
|
const result = await accountDO.rpcPutRecord(collection, rkey, record);
|
|
5727
5752
|
return c.json(result);
|
|
5728
5753
|
} catch (err) {
|
|
5754
|
+
const deactivatedError = checkAccountDeactivatedError(c, err);
|
|
5755
|
+
if (deactivatedError) return deactivatedError;
|
|
5729
5756
|
return c.json({
|
|
5730
5757
|
error: "InvalidRequest",
|
|
5731
5758
|
message: err instanceof Error ? err.message : String(err)
|
|
@@ -5758,6 +5785,8 @@ async function applyWrites(c, accountDO) {
|
|
|
5758
5785
|
const result = await accountDO.rpcApplyWrites(writes);
|
|
5759
5786
|
return c.json(result);
|
|
5760
5787
|
} catch (err) {
|
|
5788
|
+
const deactivatedError = checkAccountDeactivatedError(c, err);
|
|
5789
|
+
if (deactivatedError) return deactivatedError;
|
|
5761
5790
|
return c.json({
|
|
5762
5791
|
error: "InvalidRequest",
|
|
5763
5792
|
message: err instanceof Error ? err.message : String(err)
|
|
@@ -6048,7 +6077,7 @@ async function resetMigration(c, accountDO) {
|
|
|
6048
6077
|
|
|
6049
6078
|
//#endregion
|
|
6050
6079
|
//#region package.json
|
|
6051
|
-
var version = "0.2.
|
|
6080
|
+
var version = "0.2.2";
|
|
6052
6081
|
|
|
6053
6082
|
//#endregion
|
|
6054
6083
|
//#region src/index.ts
|