@pithy-sh/storage 0.3.0 → 0.4.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/capability.d.ts +12 -3
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +35 -9
- package/dist/config/config.d.ts +20 -4
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +23 -6
- package/dist/data/storageObject.d.ts +12 -0
- package/dist/data/storageObject.d.ts.map +1 -1
- package/dist/data/storageObject.js +13 -2
- package/dist/data/tables.js +1 -1
- package/dist/error/errors.js +2 -2
- package/dist/http/handlers.d.ts +45 -14
- package/dist/http/handlers.d.ts.map +1 -1
- package/dist/http/handlers.js +169 -66
- package/dist/http/responses.d.ts +6 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +2 -1
- package/dist/http/routes.d.ts +13 -2
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +37 -9
- package/dist/http/schemas.d.ts +6 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +6 -5
- package/dist/http/scopes.d.ts +25 -0
- package/dist/http/scopes.d.ts.map +1 -0
- package/dist/http/scopes.js +32 -0
- package/dist/http/serve.d.ts +5 -2
- package/dist/http/serve.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/migrations/0002_ownership.d.ts +5 -0
- package/dist/migrations/0002_ownership.d.ts.map +1 -0
- package/dist/migrations/0002_ownership.js +114 -0
- package/dist/object/cloudflare.d.ts +2 -1
- package/dist/object/cloudflare.d.ts.map +1 -1
- package/dist/object/cloudflare.js +2 -2
- package/dist/provision/provisionStorage.d.ts +14 -2
- package/dist/provision/provisionStorage.d.ts.map +1 -1
- package/dist/provision/provisionStorage.js +19 -4
- package/dist/provision/resolveStorageConfig.js +1 -1
- package/dist/quota/ceiling.d.ts +36 -0
- package/dist/quota/ceiling.d.ts.map +1 -0
- package/dist/quota/ceiling.js +31 -0
- package/dist/quota/quota.d.ts +24 -7
- package/dist/quota/quota.d.ts.map +1 -1
- package/dist/quota/quota.js +40 -12
- package/dist/secret/bundleToken.d.ts +24 -0
- package/dist/secret/bundleToken.d.ts.map +1 -0
- package/dist/secret/bundleToken.js +74 -0
- package/dist/secret/registry.d.ts +5 -1
- package/dist/secret/registry.d.ts.map +1 -1
- package/dist/secret/registry.js +7 -3
- package/dist/seeds/example.d.ts.map +1 -1
- package/dist/seeds/example.js +3 -0
- package/dist/test-utils/liveStorage.d.ts.map +1 -1
- package/dist/test-utils/liveStorage.js +5 -2
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +5 -5
- package/pithy.manifest.json +20 -10
- package/src/capability.ts +52 -8
- package/src/config/config.ts +24 -6
- package/src/data/storageObject.ts +22 -6
- package/src/error/errors.ts +2 -2
- package/src/http/handlers.ts +212 -79
- package/src/http/responses.ts +13 -1
- package/src/http/routes.ts +64 -10
- package/src/http/schemas.ts +10 -4
- package/src/http/scopes.ts +39 -0
- package/src/http/serve.ts +5 -2
- package/src/index.ts +2 -0
- package/src/migrations/0002_ownership.ts +176 -0
- package/src/object/cloudflare.ts +2 -2
- package/src/provision/provisionStorage.ts +22 -3
- package/src/quota/ceiling.ts +44 -0
- package/src/quota/quota.ts +63 -20
- package/src/secret/bundleToken.ts +81 -0
- package/src/secret/registry.ts +6 -8
- package/src/seeds/example.ts +3 -0
- package/src/test-utils/liveStorage.ts +3 -6
- package/src/version.generated.ts +1 -1
package/src/quota/quota.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import { PithyError } from "@pithy-sh/core/src/error/pithyError";
|
|
4
5
|
import { sql } from "kysely";
|
|
5
6
|
import type { StorageObjectRow, StorageObjectStatus } from "../data/storageObject";
|
|
6
7
|
import { STORAGE_OBJECTS_TABLE, type StorageDatabase } from "../data/tables";
|
|
@@ -44,6 +45,10 @@ import { StorageQuotaExceededError } from "../error/errors";
|
|
|
44
45
|
*
|
|
45
46
|
* A `null` limit is unlimited and skips the query entirely. A `null` owner (a system object) has no
|
|
46
47
|
* quota — there is no principal to bill it to.
|
|
48
|
+
*
|
|
49
|
+
* **Whose bytes are summed is the ceiling's to say.** A configured `bytesPerOwner` is per owner. An
|
|
50
|
+
* organization's plan is the organization's, so a check carrying `organizationId` sums every row held for
|
|
51
|
+
* that organization, whoever uploaded it — counted per member, the plan's number would be per member.
|
|
47
52
|
*/
|
|
48
53
|
|
|
49
54
|
/** What a quota check needs. */
|
|
@@ -52,8 +57,19 @@ export interface QuotaCheck {
|
|
|
52
57
|
db: StorageDatabase;
|
|
53
58
|
/** The owner the bytes are billed to. Null is a system object, which no quota applies to. */
|
|
54
59
|
ownerId: string | null;
|
|
55
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* The organization the ceiling covers, when it is an organization's. Set, the sum is every row held for it
|
|
62
|
+
* rather than the owner's alone. The row being written must be held for it too, or it would never count.
|
|
63
|
+
*/
|
|
64
|
+
organizationId?: string;
|
|
65
|
+
/** The ceiling in bytes — the configured `bytesPerOwner`, or a plan's. Null is unlimited. */
|
|
56
66
|
limitBytes: number | null;
|
|
67
|
+
/**
|
|
68
|
+
* Whether `limitBytes` is an enforced `storageBytes` meter's. True, a refusal is the plan's own —
|
|
69
|
+
* `payments/quota_exceeded` at 402, as the `emails` and `mediaItems` meters refuse — because the remedy
|
|
70
|
+
* is a bigger tier or a pinned number, not a config edit. Absent or false, it is `storage/quota_exceeded`.
|
|
71
|
+
*/
|
|
72
|
+
metered?: boolean;
|
|
57
73
|
/** The bytes this upload declares — what the pending row is about to reserve. */
|
|
58
74
|
additionalBytes: number;
|
|
59
75
|
}
|
|
@@ -84,17 +100,24 @@ export interface QuotaSettlement extends QuotaCheck {
|
|
|
84
100
|
*/
|
|
85
101
|
export const QUOTA_COUNTED_STATUSES: readonly StorageObjectStatus[] = ["pending", "stored"];
|
|
86
102
|
|
|
103
|
+
/** The column and value a sum is keyed on: the organization's rows where the ceiling is one's, the owner's otherwise. */
|
|
104
|
+
function heldBy(ownerId: string, organizationId: string | undefined): ["ownerId" | "organizationId", string] {
|
|
105
|
+
return organizationId === undefined ? ["ownerId", ownerId] : ["organizationId", organizationId];
|
|
106
|
+
}
|
|
107
|
+
|
|
87
108
|
/**
|
|
88
|
-
* Bytes an owner currently holds
|
|
89
|
-
* rows are excluded — they hold no bytes
|
|
109
|
+
* Bytes an owner currently holds — or, with `organizationId`, every byte held for that organization:
|
|
110
|
+
* every `pending` reservation plus every `stored` object. `failed` rows are excluded — they hold no bytes
|
|
111
|
+
* and reserve nothing.
|
|
90
112
|
*/
|
|
91
|
-
export async function usedBytes(db: StorageDatabase, ownerId: string): Promise<number> {
|
|
113
|
+
export async function usedBytes(db: StorageDatabase, ownerId: string, organizationId?: string): Promise<number> {
|
|
114
|
+
const [column, holder] = heldBy(ownerId, organizationId);
|
|
92
115
|
const row = await db
|
|
93
116
|
.selectFrom(STORAGE_OBJECTS_TABLE)
|
|
94
117
|
// `size` is nullable (a caller may not declare one), and SUM over no rows is NULL — coalesce both
|
|
95
118
|
// to zero here rather than letting a null leak into arithmetic.
|
|
96
119
|
.select(sql<number>`coalesce(sum(size), 0)`.as("used"))
|
|
97
|
-
.where(
|
|
120
|
+
.where(column, "=", holder)
|
|
98
121
|
.where("status", "in", [...QUOTA_COUNTED_STATUSES])
|
|
99
122
|
.executeTakeFirst();
|
|
100
123
|
return Number(row?.used ?? 0);
|
|
@@ -111,7 +134,25 @@ function assertDeclaredSize(additionalBytes: number): void {
|
|
|
111
134
|
}
|
|
112
135
|
|
|
113
136
|
/**
|
|
114
|
-
*
|
|
137
|
+
* The refusal for a write past `check`'s ceiling: the plan's where the ceiling is a meter's, storage's own
|
|
138
|
+
* where it is the configured `bytesPerOwner`. `detail` is throw-site context and never crosses the wire.
|
|
139
|
+
*/
|
|
140
|
+
function quotaRefusal(check: QuotaCheck, detail: string): PithyError {
|
|
141
|
+
if (!check.metered) return new StorageQuotaExceededError({ detail });
|
|
142
|
+
return new PithyError({
|
|
143
|
+
code: "payments/quota_exceeded",
|
|
144
|
+
status: 402,
|
|
145
|
+
message: "This plan's storage allowance is used up.",
|
|
146
|
+
action:
|
|
147
|
+
"Delete something first, upgrade the plan, or pin a larger storageBytes allowance for this subject from the control plane.",
|
|
148
|
+
params: { meter: "storageBytes", limit: check.limitBytes ?? 0 },
|
|
149
|
+
detail,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Throw `storage/quota_exceeded` when this upload would put the owner over their limit — or
|
|
155
|
+
* `payments/quota_exceeded` when the limit is a metered plan's ({@link QuotaCheck.metered}). The
|
|
115
156
|
* comparison is `used + additional > limit`, so an upload landing exactly on the limit is allowed —
|
|
116
157
|
* a quota is a ceiling you may reach, not one you must stay under.
|
|
117
158
|
*
|
|
@@ -124,17 +165,18 @@ export async function assertWithinQuota(check: QuotaCheck): Promise<void> {
|
|
|
124
165
|
if (check.limitBytes === null || check.ownerId === null) return;
|
|
125
166
|
assertDeclaredSize(check.additionalBytes);
|
|
126
167
|
|
|
127
|
-
const used = await usedBytes(check.db, check.ownerId);
|
|
168
|
+
const used = await usedBytes(check.db, check.ownerId, check.organizationId);
|
|
128
169
|
if (used + check.additionalBytes > check.limitBytes) {
|
|
129
|
-
throw
|
|
130
|
-
|
|
131
|
-
|
|
170
|
+
throw quotaRefusal(
|
|
171
|
+
check,
|
|
172
|
+
`owner would hold ${used + check.additionalBytes} bytes against a limit of ${check.limitBytes}`,
|
|
173
|
+
);
|
|
132
174
|
}
|
|
133
175
|
}
|
|
134
176
|
|
|
135
177
|
/**
|
|
136
178
|
* Insert a storage row **only if** it fits inside the owner's quota, and throw
|
|
137
|
-
* `storage/quota_exceeded` when it does not.
|
|
179
|
+
* `storage/quota_exceeded` (or a metered plan's `payments/quota_exceeded`) when it does not.
|
|
138
180
|
*
|
|
139
181
|
* The sum and the write are one statement — `INSERT … SELECT <values> WHERE (SELECT sum(size) …) <=
|
|
140
182
|
* limit - additional` — because two statements cannot be made to hold a reservation without a
|
|
@@ -152,6 +194,7 @@ export async function insertReservingQuota(reservation: QuotaReservation): Promi
|
|
|
152
194
|
return;
|
|
153
195
|
}
|
|
154
196
|
assertDeclaredSize(additionalBytes);
|
|
197
|
+
const [column, holder] = heldBy(ownerId, reservation.organizationId);
|
|
155
198
|
|
|
156
199
|
// The column list is read off the encoded record rather than spelled out, so a new column on
|
|
157
200
|
// `StorageObject` is carried here without an edit — and stays camelCase, which `CamelCasePlugin`
|
|
@@ -166,7 +209,7 @@ export async function insertReservingQuota(reservation: QuotaReservation): Promi
|
|
|
166
209
|
eb
|
|
167
210
|
.selectFrom(STORAGE_OBJECTS_TABLE)
|
|
168
211
|
.select(sql<number>`coalesce(sum(size), 0)`.as("used"))
|
|
169
|
-
.where(
|
|
212
|
+
.where(column, "=", holder)
|
|
170
213
|
.where("status", "in", [...QUOTA_COUNTED_STATUSES]),
|
|
171
214
|
"<=",
|
|
172
215
|
limitBytes - additionalBytes,
|
|
@@ -181,15 +224,13 @@ export async function insertReservingQuota(reservation: QuotaReservation): Promi
|
|
|
181
224
|
.executeTakeFirst();
|
|
182
225
|
|
|
183
226
|
if (!inserted) {
|
|
184
|
-
throw
|
|
185
|
-
detail: `reservation of ${additionalBytes} bytes lost against a limit of ${limitBytes}`,
|
|
186
|
-
});
|
|
227
|
+
throw quotaRefusal(reservation, `reservation of ${additionalBytes} bytes lost against a limit of ${limitBytes}`);
|
|
187
228
|
}
|
|
188
229
|
}
|
|
189
230
|
|
|
190
231
|
/**
|
|
191
232
|
* Rewrite one row **only if** the bytes it newly claims still fit inside the owner's quota, and throw
|
|
192
|
-
* `storage/quota_exceeded` when they do not.
|
|
233
|
+
* `storage/quota_exceeded` (or a metered plan's `payments/quota_exceeded`) when they do not.
|
|
193
234
|
*
|
|
194
235
|
* This is {@link insertReservingQuota}'s other half, and it exists for the identical reason. A
|
|
195
236
|
* completion measures what R2 actually holds against what the pending row reserved, and the difference
|
|
@@ -212,6 +253,7 @@ export async function updateSettlingQuota(settlement: QuotaSettlement): Promise<
|
|
|
212
253
|
return;
|
|
213
254
|
}
|
|
214
255
|
assertDeclaredSize(additionalBytes);
|
|
256
|
+
const [column, holder] = heldBy(ownerId, settlement.organizationId);
|
|
215
257
|
|
|
216
258
|
const updated = await db
|
|
217
259
|
.updateTable(STORAGE_OBJECTS_TABLE)
|
|
@@ -224,7 +266,7 @@ export async function updateSettlingQuota(settlement: QuotaSettlement): Promise<
|
|
|
224
266
|
eb
|
|
225
267
|
.selectFrom(STORAGE_OBJECTS_TABLE)
|
|
226
268
|
.select(sql<number>`coalesce(sum(size), 0)`.as("used"))
|
|
227
|
-
.where(
|
|
269
|
+
.where(column, "=", holder)
|
|
228
270
|
.where("status", "in", [...QUOTA_COUNTED_STATUSES]),
|
|
229
271
|
"<=",
|
|
230
272
|
limitBytes - additionalBytes,
|
|
@@ -234,8 +276,9 @@ export async function updateSettlingQuota(settlement: QuotaSettlement): Promise<
|
|
|
234
276
|
.executeTakeFirst();
|
|
235
277
|
|
|
236
278
|
if (!updated) {
|
|
237
|
-
throw
|
|
238
|
-
|
|
239
|
-
|
|
279
|
+
throw quotaRefusal(
|
|
280
|
+
settlement,
|
|
281
|
+
`settlement of ${additionalBytes} further bytes lost against a limit of ${limitBytes}`,
|
|
282
|
+
);
|
|
240
283
|
}
|
|
241
284
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type CapabilitySettings,
|
|
6
|
+
SettingsAccountIncomplete,
|
|
7
|
+
type SettingsFinding,
|
|
8
|
+
type UnansweredEnvironment,
|
|
9
|
+
} from "@pithy-sh/core/src/capability/settings";
|
|
10
|
+
import { remedy } from "@pithy-sh/core/src/cli/command";
|
|
11
|
+
import { LOCAL_ENVIRONMENT } from "@pithy-sh/core/src/naming/environment";
|
|
12
|
+
import { runtimeTokenSecretName } from "@pithy-sh/secrets/src/provision/provisionSecrets";
|
|
13
|
+
import type { ManagedEnvironment } from "@pithy-sh/secrets/src/scope";
|
|
14
|
+
|
|
15
|
+
/** The field an R2 bundle carried a Cloudflare API token in, before #728. */
|
|
16
|
+
export const R2_BUNDLE_TOKEN_FIELD = "apiToken";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* **The app Workers move first.** A Worker on the kit before #728 requires the token in this bundle, and the
|
|
20
|
+
* new kit reads the old bundle as well as the new one. So deploying the app on this kit, then rewriting, has
|
|
21
|
+
* no gap; the other order has one.
|
|
22
|
+
*/
|
|
23
|
+
const UPGRADE_FIRST = "Deploy your app Workers on this kit first. An older one cannot read the rewritten bundle.";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* **Nothing to revoke.** The bundle's token was the bootstrap one unless the operator passed another, and the
|
|
27
|
+
* one they passed was the R2 token the S3 key pair derives from: an R2 access key is a Cloudflare API token,
|
|
28
|
+
* its id the key id. Revoking that parent invalidates the pair the rewritten bundle still signs with.
|
|
29
|
+
*/
|
|
30
|
+
const KEEP_THE_TOKEN =
|
|
31
|
+
"Keep that token. It is your bootstrap one, or the R2 token the key pair derives from, and revoking that breaks the pair.";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* **`pithy doctor`'s check for a Cloudflare API token still stored in an R2 bundle (#728).**
|
|
35
|
+
*
|
|
36
|
+
* Until #728, `pithy storage provision` and `pithy media provision` wrote a Cloudflare API token into the
|
|
37
|
+
* R2 bundle beside the key pair — the bootstrap one, unless the operator passed another. Nothing reads it:
|
|
38
|
+
* the object store signs every call with the pair. It is still a credential the application holds, and a
|
|
39
|
+
* deployed application holds one, `runtime`. The provision rewrites the bundle whole, so re-running it — once
|
|
40
|
+
* the app Workers run this kit — is the fix. The token itself stays: see {@link KEEP_THE_TOKEN}.
|
|
41
|
+
*
|
|
42
|
+
* Asked once `runtime` is minted in an environment, which is the mark that it has taken the upgrade, the
|
|
43
|
+
* way media's check for its own supplied token is. The bundle is sealed under a key that never leaves the
|
|
44
|
+
* manager, so the manager is asked whether it carries the field — a bit, never the value. `dev` has no
|
|
45
|
+
* manager and is never asked.
|
|
46
|
+
*/
|
|
47
|
+
export function bundleTokenCheck(options: { secret: string; provision: string }): CapabilitySettings {
|
|
48
|
+
return {
|
|
49
|
+
local: () => [],
|
|
50
|
+
async account(context) {
|
|
51
|
+
const findings: SettingsFinding[] = [];
|
|
52
|
+
const unanswered: UnansweredEnvironment[] = [];
|
|
53
|
+
const provision = remedy(options.provision, { flags: { "--worker": context.workerDirectory } });
|
|
54
|
+
for (const { name: environment } of context.environments) {
|
|
55
|
+
if (environment === LOCAL_ENVIRONMENT) continue;
|
|
56
|
+
try {
|
|
57
|
+
const runtime = runtimeTokenSecretName(context.project, environment as ManagedEnvironment);
|
|
58
|
+
if (!(await context.account.storeEntry(runtime))) continue;
|
|
59
|
+
const carries = await context.account.vaultSecretField({
|
|
60
|
+
name: options.secret,
|
|
61
|
+
environment,
|
|
62
|
+
field: R2_BUNDLE_TOKEN_FIELD,
|
|
63
|
+
});
|
|
64
|
+
if (!carries) continue;
|
|
65
|
+
} catch (cause) {
|
|
66
|
+
unanswered.push({ environment, cause });
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
findings.push({
|
|
70
|
+
setting: `${options.secret} ${R2_BUNDLE_TOKEN_FIELD}`,
|
|
71
|
+
environment,
|
|
72
|
+
problem: `${options.secret} still holds a Cloudflare API token beside the R2 key pair. Nothing reads it, and the application holds one token: runtime.`,
|
|
73
|
+
action: `${UPGRADE_FIRST} ${provision.say((command) => `Then run ${command} to rewrite the bundle without it.`)} ${KEEP_THE_TOKEN}`,
|
|
74
|
+
...(provision.fix === undefined ? {} : { fix: String(provision.fix) }),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (unanswered.length > 0) throw new SettingsAccountIncomplete(findings, unanswered);
|
|
78
|
+
return findings;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
package/src/secret/registry.ts
CHANGED
|
@@ -27,6 +27,11 @@ import { z } from "zod";
|
|
|
27
27
|
* The credentials one R2 bucket is addressed and presigned with. Composed from
|
|
28
28
|
* {@link R2Credentials} rather than redeclaring the key pair — that shape is `@pithy-sh/cloudflare`'s
|
|
29
29
|
* to define, and `CloudflareR2Manager` validates its config against it.
|
|
30
|
+
*
|
|
31
|
+
* **No Cloudflare API token (#728).** A deployed application holds one, `runtime`, and the object store
|
|
32
|
+
* needs none: every operation is S3, signed with the key pair. The bundle carried the token the pair
|
|
33
|
+
* derives from until then; a bundle written before parses, the parse drops it, and the next provision
|
|
34
|
+
* rewrites the bundle without it.
|
|
30
35
|
*/
|
|
31
36
|
export const R2StorageCredentials = R2Credentials.extend({
|
|
32
37
|
accountId: z
|
|
@@ -39,14 +44,7 @@ export const R2StorageCredentials = R2Credentials.extend({
|
|
|
39
44
|
.min(1)
|
|
40
45
|
.meta({ multiline: false })
|
|
41
46
|
.describe("The R2 bucket name every presigned URL and server-side object call targets."),
|
|
42
|
-
|
|
43
|
-
.string()
|
|
44
|
-
.min(1)
|
|
45
|
-
.meta({ multiline: false })
|
|
46
|
-
.describe(
|
|
47
|
-
"The R2-scoped Cloudflare API token the key pair was derived from. Carried alongside because an R2 S3 access key IS a CF API token — the id is the key id, the SHA-256 of the value is the secret — so whatever provisions the pair already holds it, and `CloudflareR2Manager` needs it to prove bucket access.",
|
|
48
|
-
),
|
|
49
|
-
}).describe("The account, key pair, scoped token, and bucket name the object store presigns and addresses R2 with.");
|
|
47
|
+
}).describe("The account, key pair, and bucket name the object store presigns and addresses R2 with.");
|
|
50
48
|
export type R2StorageCredentials = z.output<typeof R2StorageCredentials>;
|
|
51
49
|
|
|
52
50
|
/**
|
package/src/seeds/example.ts
CHANGED
|
@@ -77,6 +77,7 @@ export const storageExampleSeed: SeedSet = defineSeed({
|
|
|
77
77
|
key: demoKey(NOTES_ID),
|
|
78
78
|
path: "notes/analytical-engine.txt",
|
|
79
79
|
ownerId: EXAMPLE_ADA.id,
|
|
80
|
+
organizationId: null,
|
|
80
81
|
contentType: "text/plain",
|
|
81
82
|
size: byteLength(NOTES_ID),
|
|
82
83
|
visibility: "private",
|
|
@@ -91,6 +92,7 @@ export const storageExampleSeed: SeedSet = defineSeed({
|
|
|
91
92
|
key: demoKey(PLAN_ID),
|
|
92
93
|
path: "plans/compiler.txt",
|
|
93
94
|
ownerId: EXAMPLE_GRACE.id,
|
|
95
|
+
organizationId: null,
|
|
94
96
|
contentType: "text/plain",
|
|
95
97
|
size: byteLength(PLAN_ID),
|
|
96
98
|
visibility: "private",
|
|
@@ -105,6 +107,7 @@ export const storageExampleSeed: SeedSet = defineSeed({
|
|
|
105
107
|
key: demoKey(README_ID),
|
|
106
108
|
path: "public/readme.txt",
|
|
107
109
|
ownerId: EXAMPLE_ADA.id,
|
|
110
|
+
organizationId: null,
|
|
108
111
|
contentType: "text/plain",
|
|
109
112
|
size: byteLength(README_ID),
|
|
110
113
|
visibility: "public",
|
|
@@ -12,6 +12,7 @@ import { configureSharedSecrets } from "@pithy-sh/secrets/src/sharedSecretsStore
|
|
|
12
12
|
import { STORAGE_MIGRATION_ORDER } from "../capability";
|
|
13
13
|
import { type StorageDatabase, storageDatabase } from "../data/tables";
|
|
14
14
|
import { storage_0001_objects } from "../migrations/0001_objects";
|
|
15
|
+
import { storage_0002_ownership } from "../migrations/0002_ownership";
|
|
15
16
|
import { ObjectListing, ObjectMetadata, type ObjectStore, objectStore } from "../object/store";
|
|
16
17
|
import { type R2StorageCredentials, STORAGE_R2_SECRET, storageSecretsRegistry } from "../secret/registry";
|
|
17
18
|
|
|
@@ -201,11 +202,7 @@ export async function withLiveBucket<T>(
|
|
|
201
202
|
const bucketName = uniqueName("storage");
|
|
202
203
|
const manager = clients.r2({ ...r2, bucketName });
|
|
203
204
|
const open = new Map<string, OpenUpload>();
|
|
204
|
-
const store = liveObjectStore(
|
|
205
|
-
{ ...r2, accountId: creds.accountId, apiToken: creds.apiToken, bucket: bucketName },
|
|
206
|
-
manager,
|
|
207
|
-
open,
|
|
208
|
-
);
|
|
205
|
+
const store = liveObjectStore({ ...r2, accountId: creds.accountId, bucket: bucketName }, manager, open);
|
|
209
206
|
|
|
210
207
|
return withThrowawayResource(
|
|
211
208
|
() => provisioner.createBucket(bucketName),
|
|
@@ -226,7 +223,7 @@ function storageMigrations() {
|
|
|
226
223
|
database: "app",
|
|
227
224
|
namespace: "storage",
|
|
228
225
|
order: STORAGE_MIGRATION_ORDER,
|
|
229
|
-
migrations: { "0001_objects": storage_0001_objects },
|
|
226
|
+
migrations: { "0001_objects": storage_0001_objects, "0002_ownership": storage_0002_ownership },
|
|
230
227
|
},
|
|
231
228
|
]);
|
|
232
229
|
const provider = registry.app;
|
package/src/version.generated.ts
CHANGED