@tinycloud/operations 0.4.0-beta.10 → 0.4.0-beta.11

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.
@@ -2,7 +2,7 @@ import { PermissionEntry } from '@tinycloud/sdk-core';
2
2
  import { z } from 'zod';
3
3
  import { O as OperationSpaceResolver } from './authority-ofwbEqmj.cjs';
4
4
  export { e as evaluateAuthority } from './authority-ofwbEqmj.cjs';
5
- import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-CjuEjE-M.cjs';
5
+ import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-eWtDSMeI.cjs';
6
6
 
7
7
  /** The shared wire schema for SDK PermissionEntry values, including signed ReCap caveats. */
8
8
  declare const PermissionEntrySchema: z.ZodObject<{
@@ -2,7 +2,7 @@ import { PermissionEntry } from '@tinycloud/sdk-core';
2
2
  import { z } from 'zod';
3
3
  import { O as OperationSpaceResolver } from './authority-ofwbEqmj.js';
4
4
  export { e as evaluateAuthority } from './authority-ofwbEqmj.js';
5
- import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-CjuEjE-M.js';
5
+ import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-eWtDSMeI.js';
6
6
 
7
7
  /** The shared wire schema for SDK PermissionEntry values, including signed ReCap caveats. */
8
8
  declare const PermissionEntrySchema: z.ZodObject<{
@@ -42,6 +42,17 @@ function operationError(code, message, options = {}) {
42
42
  ...options.details === void 0 ? {} : { details: options.details }
43
43
  };
44
44
  }
45
+ function storageFullOperationError(error) {
46
+ if (typeof error !== "object" || error === null) return void 0;
47
+ const { code, meta } = error;
48
+ if (code !== "STORAGE_QUOTA_EXCEEDED" && code !== "STORAGE_LIMIT_REACHED") return void 0;
49
+ const account = typeof meta === "object" && meta !== null ? meta.account : void 0;
50
+ return operationError(
51
+ "STORAGE_QUOTA_EXCEEDED",
52
+ code === "STORAGE_LIMIT_REACHED" ? `This write is larger than the TinyCloud storage left, so nothing was written. Reading still works. ${MANAGE_STORAGE}` : `TinyCloud storage is full, so nothing was written. Reading still works. ${MANAGE_STORAGE}`,
53
+ { retryable: false, ...account === void 0 ? {} : { details: { account } } }
54
+ );
55
+ }
45
56
  function isOperationErrorCode(value) {
46
57
  return typeof value === "string" && OPERATION_ERROR_CODES.includes(value);
47
58
  }
@@ -67,7 +78,7 @@ function sanitizeOperationError(error) {
67
78
  ...candidate.details === void 0 ? {} : { details: candidate.details }
68
79
  });
69
80
  }
70
- var OPERATION_ERROR_CODES, OperationInvocationError;
81
+ var OPERATION_ERROR_CODES, MANAGE_STORAGE, OperationInvocationError;
71
82
  var init_errors = __esm({
72
83
  "src/errors.ts"() {
73
84
  "use strict";
@@ -90,6 +101,7 @@ var init_errors = __esm({
90
101
  "ENCRYPTION_NETWORK_UNRESOLVED",
91
102
  "NODE_UNREACHABLE",
92
103
  "NODE_ERROR",
104
+ "STORAGE_QUOTA_EXCEEDED",
93
105
  "KV_NOT_FOUND",
94
106
  "KV_PRECONDITION_FAILED",
95
107
  "KV_CONFLICT",
@@ -103,6 +115,7 @@ var init_errors = __esm({
103
115
  "OUTPUT_INVALID",
104
116
  "INTERNAL_ERROR"
105
117
  ];
118
+ MANAGE_STORAGE = "Do not retry: the owner must free up space or upgrade at https://account.tinycloud.xyz/billing.";
106
119
  OperationInvocationError = class extends Error {
107
120
  constructor(operationError2) {
108
121
  super(operationError2.message);
@@ -2532,6 +2545,8 @@ function kvFailure(error, action) {
2532
2545
  if (error.code === "KV_RESPONSE_TOO_LARGE") {
2533
2546
  return { status: "error", error: operationError("KV_RESPONSE_TOO_LARGE", `The TinyCloud KV value exceeds ${MAX_KV_VALUE_BYTES} bytes.`) };
2534
2547
  }
2548
+ const storageFull = storageFullOperationError(error);
2549
+ if (storageFull) return { status: "error", error: storageFull };
2535
2550
  return nodeFailure(action);
2536
2551
  }
2537
2552
  function nodeFailure(action) {
@@ -3150,7 +3165,7 @@ async function executeSqlDml(context, input) {
3150
3165
  const runtime = runtimeContext2(context);
3151
3166
  const space = resolveSqlSpace(runtime, input.space);
3152
3167
  const result = await runtimeNode2(runtime).sqlForSpace(space).db(input.database).execute(input.sql, input.params.map(decodeSqlInputValue));
3153
- if (!result.ok) return authorizationFailure(result.error, "execute the SQLite statement") ?? sqlMutationFailure();
3168
+ if (!result.ok) return authorizationFailure(result.error, "execute the SQLite statement") ?? sqlMutationFailure(result.error);
3154
3169
  const normalized = normalizeExecuteResult(result.data);
3155
3170
  return {
3156
3171
  status: "ok",
@@ -3164,7 +3179,7 @@ async function executeSqlDml(context, input) {
3164
3179
  };
3165
3180
  } catch (error) {
3166
3181
  if (error instanceof OperationInvocationError) return { status: "error", error: error.operationError };
3167
- return authorizationFailure(error, "execute the SQLite statement") ?? sqlMutationFailure();
3182
+ return authorizationFailure(error, "execute the SQLite statement") ?? sqlMutationFailure(error);
3168
3183
  }
3169
3184
  }
3170
3185
  function isSingleReadQuery(sql) {
@@ -3341,7 +3356,9 @@ function sqlServiceFailure(error, action) {
3341
3356
  }
3342
3357
  return nodeFailure2(action);
3343
3358
  }
3344
- function sqlMutationFailure() {
3359
+ function sqlMutationFailure(error) {
3360
+ const storageFull = storageFullOperationError(error);
3361
+ if (storageFull) return { status: "error", error: storageFull };
3345
3362
  return {
3346
3363
  status: "error",
3347
3364
  error: operationError(
@@ -4590,8 +4607,19 @@ var SAFE_ERROR_DETAIL_POLICIES = {
4590
4607
  DELEGATION_HOST_MISMATCH: {
4591
4608
  expectedHost: safeOriginHost,
4592
4609
  artifactHost: safeOriginHost
4610
+ },
4611
+ STORAGE_QUOTA_EXCEEDED: {
4612
+ account: safeStorageAccount
4593
4613
  }
4594
4614
  };
4615
+ function safeStorageAccount(value) {
4616
+ if (!isRecord(value)) return void 0;
4617
+ const { usedBytes, limitBytes, plan } = value;
4618
+ if (!Number.isSafeInteger(usedBytes) || usedBytes < 0 || !Number.isSafeInteger(limitBytes) || limitBytes <= 0) {
4619
+ return void 0;
4620
+ }
4621
+ return typeof plan === "string" && /^[A-Za-z0-9][A-Za-z0-9 _.-]{0,31}$/.test(plan) ? { usedBytes, limitBytes, plan } : { usedBytes, limitBytes };
4622
+ }
4595
4623
  function redactSafeErrorDetails(code, details) {
4596
4624
  const policy = SAFE_ERROR_DETAIL_POLICIES[code];
4597
4625
  if (policy === void 0) return void 0;