@constructive-io/site-deploy 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.
- package/LICENSE +23 -0
- package/README.md +165 -0
- package/cas-upload.d.ts +59 -0
- package/cas-upload.js +132 -0
- package/content-type.d.ts +15 -0
- package/content-type.js +61 -0
- package/deploy.d.ts +23 -0
- package/deploy.js +266 -0
- package/documents.d.ts +24 -0
- package/documents.js +147 -0
- package/esm/cas-upload.js +126 -0
- package/esm/content-type.js +57 -0
- package/esm/deploy.js +262 -0
- package/esm/documents.js +137 -0
- package/esm/index.js +25 -0
- package/esm/manifest.js +100 -0
- package/esm/types.js +22 -0
- package/esm/walk.js +49 -0
- package/index.d.ts +27 -0
- package/index.js +42 -0
- package/manifest.d.ts +48 -0
- package/manifest.js +109 -0
- package/package.json +47 -0
- package/types.d.ts +191 -0
- package/types.js +26 -0
- package/walk.d.ts +16 -0
- package/walk.js +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2025 Constructive <developers@constructive.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# @constructive-io/site-deploy
|
|
2
|
+
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center" width="100%">
|
|
8
|
+
<a href="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml">
|
|
9
|
+
<img height="20" src="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/constructive-io/constructive/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@constructive-io/site-deploy"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=packages%2Fsite-deploy%2Fpackage.json"/></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
Deploy a static build as an immutable Constructive release.
|
|
16
|
+
|
|
17
|
+
A deploy is **bytes plus one manifest**: every file's bytes go to the site's
|
|
18
|
+
bucket at `cas/sha256/<hash>`, and one `siteRelease` row maps logical paths to
|
|
19
|
+
those hashes. Writing that row commits the manifest into the site's own merkle
|
|
20
|
+
store, so the returned commit id *is* the release — publishing, rolling back and
|
|
21
|
+
previewing are pointer moves the server owns.
|
|
22
|
+
|
|
23
|
+
This package is the client half of that, which every consumer would otherwise
|
|
24
|
+
write itself: walk, hash, upload only what is missing, and commit one manifest.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { deploySite } from '@constructive-io/site-deploy';
|
|
30
|
+
|
|
31
|
+
const result = await deploySite({
|
|
32
|
+
api, // GraphQL executor for the tenant API
|
|
33
|
+
siteId,
|
|
34
|
+
databaseId, // required on a site's first deploy
|
|
35
|
+
bucketKey: 'site-docs',
|
|
36
|
+
source: './dist', // a directory, or the files themselves
|
|
37
|
+
publish: true, // move site.activeCommitId when it lands
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log(result.commitId, result.uploaded, result.skipped);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Deploy a branch preview instead of going live:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const { previewUrl } = await deploySite({
|
|
47
|
+
api,
|
|
48
|
+
siteId,
|
|
49
|
+
bucketKey: 'site-docs',
|
|
50
|
+
source: './dist',
|
|
51
|
+
preview: 'pr-42', // → preview/pr-42
|
|
52
|
+
previewApex: 'preview.example.com', // provisions pr-42--<site>.preview.example.com
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Roll back — the same pointer move, to an older commit:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { deployNames, publishCommit } from '@constructive-io/site-deploy';
|
|
60
|
+
|
|
61
|
+
await publishCommit(api, deployNames(), siteId, previousCommitId);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## What it does
|
|
65
|
+
|
|
66
|
+
1. **Walks and hashes** the build, normalizing paths to POSIX and including
|
|
67
|
+
dotfiles (`.well-known/…` ships); exclude explicitly with `ignore`.
|
|
68
|
+
2. **Detects content types** by extension, falling back to
|
|
69
|
+
`application/octet-stream` rather than guessing. Override with `contentTypes`.
|
|
70
|
+
3. **Registers the bytes** in batches (`batchSize`, default 100) and PUTs only
|
|
71
|
+
the files the server reports as *not* deduplicated, with bounded concurrency
|
|
72
|
+
and retries — so a one-file change re-uploads one file.
|
|
73
|
+
4. **Verifies** every returned key is the `cas/sha256/<hash>` it asked for.
|
|
74
|
+
5. **Writes the manifest**: creates the site's release row on the first deploy,
|
|
75
|
+
patches it after, and asserts the trigger stamped a `commitId`/`storeId`.
|
|
76
|
+
6. **Optionally publishes** and/or points `preview/<name>` at the new commit, as
|
|
77
|
+
separate steps.
|
|
78
|
+
|
|
79
|
+
Ordering is the contract: bytes land before the manifest names them, and the
|
|
80
|
+
manifest lands before anything points at it. A failure anywhere throws a
|
|
81
|
+
`DeployError` with a `code` and leaves the live site untouched — an upload
|
|
82
|
+
failure never becomes a published manifest with holes in it.
|
|
83
|
+
|
|
84
|
+
Pass `onProgress` for `hashed` / `diffed` / `uploaded` / `manifest` / `preview` /
|
|
85
|
+
`published` events, `dryRun` to hash and diff only, and `skipIfUnchanged` to
|
|
86
|
+
reuse the live release when the tree already matches it.
|
|
87
|
+
|
|
88
|
+
## Related
|
|
89
|
+
|
|
90
|
+
- [`@constructive-io/upload-client`](../upload-client) — the generic presigned
|
|
91
|
+
upload primitives this builds on.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Education and Tutorials
|
|
96
|
+
|
|
97
|
+
1. 🚀 [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
|
|
98
|
+
Get started with modular databases in minutes. Install prerequisites and deploy your first module.
|
|
99
|
+
|
|
100
|
+
2. 📦 [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
|
|
101
|
+
Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
|
|
102
|
+
|
|
103
|
+
3. ✏️ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
|
|
104
|
+
Master the workflow for adding, organizing, and managing database changes with pgpm.
|
|
105
|
+
|
|
106
|
+
4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
|
|
107
|
+
Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
|
|
108
|
+
|
|
109
|
+
5. ⚡ [Supabase Testing](https://constructive.io/learn/supabase)
|
|
110
|
+
Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
|
|
111
|
+
|
|
112
|
+
6. 💧 [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
|
|
113
|
+
Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
|
|
114
|
+
|
|
115
|
+
7. 🔧 [Troubleshooting](https://constructive.io/learn/troubleshooting)
|
|
116
|
+
Common issues and solutions for pgpm, PostgreSQL, and testing.
|
|
117
|
+
|
|
118
|
+
## Related Constructive Tooling
|
|
119
|
+
|
|
120
|
+
### 📦 Package Management
|
|
121
|
+
|
|
122
|
+
* [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
|
|
123
|
+
|
|
124
|
+
### 🧪 Testing
|
|
125
|
+
|
|
126
|
+
* [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
|
|
127
|
+
* [pglite-test](https://github.com/constructive-io/constructive/tree/main/postgres/pglite-test): **🪶 Drop-in pgsql-test replacement backed by PGlite** — in-process Postgres, no server required, instance-per-suite isolation.
|
|
128
|
+
* [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
|
|
129
|
+
* [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
|
|
130
|
+
* [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
|
|
131
|
+
* [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
|
|
132
|
+
|
|
133
|
+
### 🧠 Parsing & AST
|
|
134
|
+
|
|
135
|
+
* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
136
|
+
* [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
137
|
+
* [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
|
|
138
|
+
* [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
|
|
139
|
+
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
140
|
+
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
141
|
+
|
|
142
|
+
### 📚 Documentation & Skills
|
|
143
|
+
|
|
144
|
+
* [constructive-skills](https://github.com/constructive-io/constructive-skills): **📖 Platform documentation and AI agent skills** — feature catalog, blueprint reference, SDK guides (i18n, billing, limits, events, uploads, security, entities, search, AI), and deployment guides.
|
|
145
|
+
|
|
146
|
+
Install skills for AI coding agents:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# All platform skills (security, blueprints, codegen, billing, etc.)
|
|
150
|
+
npx skills add constructive-io/constructive-skills
|
|
151
|
+
|
|
152
|
+
# Individual repo skills (pgpm, testing, CLI, search, etc.)
|
|
153
|
+
npx skills add https://github.com/constructive-io/constructive --skill pgpm
|
|
154
|
+
npx skills add https://github.com/constructive-io/constructive --skill constructive-testing
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Credits
|
|
158
|
+
|
|
159
|
+
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
|
160
|
+
|
|
161
|
+
## Disclaimer
|
|
162
|
+
|
|
163
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
164
|
+
|
|
165
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
package/cas-upload.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-addressed bulk upload.
|
|
3
|
+
*
|
|
4
|
+
* The generic pieces come from `@constructive-io/upload-client` (a presigned
|
|
5
|
+
* PUT); what is added here is the part a static release needs: many files in
|
|
6
|
+
* one round trip, explicit `cas/sha256/<hash>` keys, and skipping every file
|
|
7
|
+
* the server already has. That skip is the whole incremental-deploy win — a
|
|
8
|
+
* one-file change re-uploads one file however large the site is.
|
|
9
|
+
*/
|
|
10
|
+
import type { HashedFile } from './manifest';
|
|
11
|
+
import type { GraphQLExecutor, PutObject } from './types';
|
|
12
|
+
export interface UploadCasOptions {
|
|
13
|
+
/** Executor for the storage target. */
|
|
14
|
+
storage: GraphQLExecutor;
|
|
15
|
+
/** Bulk upload mutation field name, e.g. `uploadFiles`. */
|
|
16
|
+
mutation: string;
|
|
17
|
+
/** Bucket key of the site's bucket. */
|
|
18
|
+
bucketKey: string;
|
|
19
|
+
/** Files per mutation call. */
|
|
20
|
+
batchSize: number;
|
|
21
|
+
/** Parallel PUTs. */
|
|
22
|
+
concurrency: number;
|
|
23
|
+
/** Retries per PUT. */
|
|
24
|
+
retries: number;
|
|
25
|
+
putObject?: PutObject;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
onUploaded?: (file: HashedFile) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface UploadCasResult {
|
|
30
|
+
uploaded: number;
|
|
31
|
+
skipped: number;
|
|
32
|
+
bytesUploaded: number;
|
|
33
|
+
}
|
|
34
|
+
/** The bytes the server does not have yet, as told by the bulk mutation. */
|
|
35
|
+
export interface CasDiff {
|
|
36
|
+
/** Files whose bytes must be PUT, paired with their presigned URL. */
|
|
37
|
+
missing: {
|
|
38
|
+
file: HashedFile;
|
|
39
|
+
uploadUrl: string;
|
|
40
|
+
}[];
|
|
41
|
+
/** Files the server already had. */
|
|
42
|
+
deduplicated: HashedFile[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Register every file and learn which bytes are missing.
|
|
46
|
+
*
|
|
47
|
+
* Batched because the server caps files per call; one failed batch fails the
|
|
48
|
+
* whole diff rather than leaving a half-registered release.
|
|
49
|
+
*/
|
|
50
|
+
export declare function diffCas(files: HashedFile[], options: UploadCasOptions): Promise<CasDiff>;
|
|
51
|
+
/**
|
|
52
|
+
* PUT the missing bytes.
|
|
53
|
+
*
|
|
54
|
+
* Any file that cannot be uploaded after its retries aborts the deploy: a
|
|
55
|
+
* manifest written over a partial upload is a site with holes in it.
|
|
56
|
+
*/
|
|
57
|
+
export declare function uploadMissing(diff: CasDiff, options: UploadCasOptions): Promise<UploadCasResult>;
|
|
58
|
+
export declare function throwIfAborted(signal?: AbortSignal): void;
|
|
59
|
+
export declare function errorMessage(err: unknown): string;
|
package/cas-upload.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content-addressed bulk upload.
|
|
4
|
+
*
|
|
5
|
+
* The generic pieces come from `@constructive-io/upload-client` (a presigned
|
|
6
|
+
* PUT); what is added here is the part a static release needs: many files in
|
|
7
|
+
* one round trip, explicit `cas/sha256/<hash>` keys, and skipping every file
|
|
8
|
+
* the server already has. That skip is the whole incremental-deploy win — a
|
|
9
|
+
* one-file change re-uploads one file however large the site is.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.diffCas = diffCas;
|
|
13
|
+
exports.uploadMissing = uploadMissing;
|
|
14
|
+
exports.throwIfAborted = throwIfAborted;
|
|
15
|
+
exports.errorMessage = errorMessage;
|
|
16
|
+
const upload_client_1 = require("@constructive-io/upload-client");
|
|
17
|
+
const documents_1 = require("./documents");
|
|
18
|
+
const manifest_1 = require("./manifest");
|
|
19
|
+
const types_1 = require("./types");
|
|
20
|
+
/**
|
|
21
|
+
* Register every file and learn which bytes are missing.
|
|
22
|
+
*
|
|
23
|
+
* Batched because the server caps files per call; one failed batch fails the
|
|
24
|
+
* whole diff rather than leaving a half-registered release.
|
|
25
|
+
*/
|
|
26
|
+
async function diffCas(files, options) {
|
|
27
|
+
const mutation = (0, documents_1.buildBulkUploadMutation)(options.mutation);
|
|
28
|
+
const missing = [];
|
|
29
|
+
const deduplicated = [];
|
|
30
|
+
for (let offset = 0; offset < files.length; offset += options.batchSize) {
|
|
31
|
+
throwIfAborted(options.signal);
|
|
32
|
+
const batch = files.slice(offset, offset + options.batchSize);
|
|
33
|
+
const data = await options.storage(mutation, {
|
|
34
|
+
input: {
|
|
35
|
+
bucketKey: options.bucketKey,
|
|
36
|
+
files: batch.map((file) => ({
|
|
37
|
+
contentHash: file.hash,
|
|
38
|
+
contentType: file.contentType,
|
|
39
|
+
size: file.size,
|
|
40
|
+
filename: file.path.slice(file.path.lastIndexOf('/') + 1),
|
|
41
|
+
key: file.key,
|
|
42
|
+
})),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const payload = (data[options.mutation] ?? null);
|
|
46
|
+
const results = payload?.files;
|
|
47
|
+
if (!results || results.length !== batch.length) {
|
|
48
|
+
throw new types_1.DeployError('UPLOAD_FAILED', `${options.mutation} returned ${results?.length ?? 0} results for ${batch.length} files`);
|
|
49
|
+
}
|
|
50
|
+
results.forEach((result, index) => {
|
|
51
|
+
const file = batch[index];
|
|
52
|
+
// The server does not enforce the CAS key form yet, so a mismatch here
|
|
53
|
+
// would publish a manifest pointing at bytes nobody can serve.
|
|
54
|
+
if (result.key !== file.key || !manifest_1.CAS_KEY_PATTERN.test(result.key)) {
|
|
55
|
+
throw new types_1.DeployError('KEY_MISMATCH', `Expected key "${file.key}" for "${file.path}", server returned "${result.key}"`);
|
|
56
|
+
}
|
|
57
|
+
if (result.deduplicated) {
|
|
58
|
+
deduplicated.push(file);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!result.uploadUrl) {
|
|
62
|
+
throw new types_1.DeployError('UPLOAD_FAILED', `No upload URL for "${file.path}" and deduplicated=false`);
|
|
63
|
+
}
|
|
64
|
+
missing.push({ file, uploadUrl: result.uploadUrl });
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return { missing, deduplicated };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* PUT the missing bytes.
|
|
71
|
+
*
|
|
72
|
+
* Any file that cannot be uploaded after its retries aborts the deploy: a
|
|
73
|
+
* manifest written over a partial upload is a site with holes in it.
|
|
74
|
+
*/
|
|
75
|
+
async function uploadMissing(diff, options) {
|
|
76
|
+
const put = options.putObject ?? defaultPut;
|
|
77
|
+
let bytesUploaded = 0;
|
|
78
|
+
let next = 0;
|
|
79
|
+
const worker = async () => {
|
|
80
|
+
for (;;) {
|
|
81
|
+
throwIfAborted(options.signal);
|
|
82
|
+
const index = next++;
|
|
83
|
+
if (index >= diff.missing.length)
|
|
84
|
+
return;
|
|
85
|
+
const { file, uploadUrl } = diff.missing[index];
|
|
86
|
+
await withRetries(() => put(uploadUrl, file.bytes, file.contentType, options.signal), options.retries, file.path, options.signal);
|
|
87
|
+
bytesUploaded += file.size;
|
|
88
|
+
options.onUploaded?.(file);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const workers = Math.max(1, Math.min(options.concurrency, diff.missing.length));
|
|
92
|
+
await Promise.all(Array.from({ length: workers }, worker));
|
|
93
|
+
return {
|
|
94
|
+
uploaded: diff.missing.length,
|
|
95
|
+
skipped: diff.deduplicated.length,
|
|
96
|
+
bytesUploaded,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const defaultPut = async (url, body, contentType, signal) => {
|
|
100
|
+
// A fresh copy: putToPresignedUrl takes a BodyInit, and a Uint8Array view
|
|
101
|
+
// over a pooled Buffer would send the whole pool.
|
|
102
|
+
const buffer = body.slice().buffer;
|
|
103
|
+
await (0, upload_client_1.putToPresignedUrl)(url, buffer, contentType, signal);
|
|
104
|
+
};
|
|
105
|
+
async function withRetries(attempt, retries, path, signal) {
|
|
106
|
+
let lastError;
|
|
107
|
+
for (let tries = 0; tries <= retries; tries++) {
|
|
108
|
+
throwIfAborted(signal);
|
|
109
|
+
try {
|
|
110
|
+
await attempt();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
lastError = err;
|
|
115
|
+
if (tries === retries)
|
|
116
|
+
break;
|
|
117
|
+
await delay(2 ** tries * 250);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw new types_1.DeployError('UPLOAD_FAILED', `Upload of "${path}" failed after ${retries + 1} attempt(s): ${errorMessage(lastError)}`, lastError);
|
|
121
|
+
}
|
|
122
|
+
function delay(ms) {
|
|
123
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
124
|
+
}
|
|
125
|
+
function throwIfAborted(signal) {
|
|
126
|
+
if (signal?.aborted) {
|
|
127
|
+
throw new types_1.DeployError('ABORTED', 'Deploy was cancelled');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function errorMessage(err) {
|
|
131
|
+
return err instanceof Error ? err.message : String(err);
|
|
132
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension → MIME mapping for static builds.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately small: it covers what a site generator emits. Anything else
|
|
5
|
+
* falls back to `application/octet-stream` rather than being guessed — the
|
|
6
|
+
* manifest's `content_type` is what the edge serves verbatim.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_CONTENT_TYPE = "application/octet-stream";
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the content type of a logical path.
|
|
11
|
+
*
|
|
12
|
+
* @param path - Logical path (`assets/app.js`)
|
|
13
|
+
* @param overrides - Extra or overriding mappings, keyed without the dot
|
|
14
|
+
*/
|
|
15
|
+
export declare function contentTypeFor(path: string, overrides?: Record<string, string>): string;
|
package/content-type.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Extension → MIME mapping for static builds.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately small: it covers what a site generator emits. Anything else
|
|
6
|
+
* falls back to `application/octet-stream` rather than being guessed — the
|
|
7
|
+
* manifest's `content_type` is what the edge serves verbatim.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DEFAULT_CONTENT_TYPE = void 0;
|
|
11
|
+
exports.contentTypeFor = contentTypeFor;
|
|
12
|
+
exports.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
|
13
|
+
const CONTENT_TYPES = {
|
|
14
|
+
avif: 'image/avif',
|
|
15
|
+
css: 'text/css; charset=utf-8',
|
|
16
|
+
csv: 'text/csv; charset=utf-8',
|
|
17
|
+
eot: 'application/vnd.ms-fontobject',
|
|
18
|
+
gif: 'image/gif',
|
|
19
|
+
htm: 'text/html; charset=utf-8',
|
|
20
|
+
html: 'text/html; charset=utf-8',
|
|
21
|
+
ico: 'image/x-icon',
|
|
22
|
+
jpeg: 'image/jpeg',
|
|
23
|
+
jpg: 'image/jpeg',
|
|
24
|
+
js: 'text/javascript; charset=utf-8',
|
|
25
|
+
json: 'application/json; charset=utf-8',
|
|
26
|
+
map: 'application/json; charset=utf-8',
|
|
27
|
+
md: 'text/markdown; charset=utf-8',
|
|
28
|
+
mjs: 'text/javascript; charset=utf-8',
|
|
29
|
+
mp3: 'audio/mpeg',
|
|
30
|
+
mp4: 'video/mp4',
|
|
31
|
+
otf: 'font/otf',
|
|
32
|
+
pdf: 'application/pdf',
|
|
33
|
+
png: 'image/png',
|
|
34
|
+
svg: 'image/svg+xml',
|
|
35
|
+
ttf: 'font/ttf',
|
|
36
|
+
txt: 'text/plain; charset=utf-8',
|
|
37
|
+
wasm: 'application/wasm',
|
|
38
|
+
webm: 'video/webm',
|
|
39
|
+
webmanifest: 'application/manifest+json',
|
|
40
|
+
webp: 'image/webp',
|
|
41
|
+
woff: 'font/woff',
|
|
42
|
+
woff2: 'font/woff2',
|
|
43
|
+
xml: 'application/xml',
|
|
44
|
+
yaml: 'text/yaml; charset=utf-8',
|
|
45
|
+
yml: 'text/yaml; charset=utf-8',
|
|
46
|
+
zip: 'application/zip',
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the content type of a logical path.
|
|
50
|
+
*
|
|
51
|
+
* @param path - Logical path (`assets/app.js`)
|
|
52
|
+
* @param overrides - Extra or overriding mappings, keyed without the dot
|
|
53
|
+
*/
|
|
54
|
+
function contentTypeFor(path, overrides) {
|
|
55
|
+
const base = path.slice(path.lastIndexOf('/') + 1);
|
|
56
|
+
const dot = base.lastIndexOf('.');
|
|
57
|
+
if (dot <= 0)
|
|
58
|
+
return exports.DEFAULT_CONTENT_TYPE;
|
|
59
|
+
const ext = base.slice(dot + 1).toLowerCase();
|
|
60
|
+
return overrides?.[ext] ?? CONTENT_TYPES[ext] ?? exports.DEFAULT_CONTENT_TYPE;
|
|
61
|
+
}
|
package/deploy.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deploy pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Everything below the manifest is server-owned: writing the release row fires
|
|
5
|
+
* the trigger that commits the manifest into the site's own merkle store, so
|
|
6
|
+
* the commit id this returns *is* the release — history, time travel and
|
|
7
|
+
* rollback are then pointer moves, not client bookkeeping.
|
|
8
|
+
*
|
|
9
|
+
* Ordering is the contract: bytes land before the manifest names them, and the
|
|
10
|
+
* manifest lands before anything points at it. A failure anywhere leaves the
|
|
11
|
+
* live site exactly as it was.
|
|
12
|
+
*/
|
|
13
|
+
import type { DeploySiteOptions, DeploySiteResult, GraphQLExecutor, SiteDeployNames } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* Deploy a build as an immutable release.
|
|
16
|
+
*
|
|
17
|
+
* Hashes every file, uploads only the bytes the server does not already have,
|
|
18
|
+
* writes one manifest — and optionally publishes it or points a preview ref at
|
|
19
|
+
* it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function deploySite(options: DeploySiteOptions): Promise<DeploySiteResult>;
|
|
22
|
+
/** Move `site.activeCommitId` — the go-live and the rollback are one thing. */
|
|
23
|
+
export declare function publishCommit(api: GraphQLExecutor, names: SiteDeployNames, siteId: string, commitId: string): Promise<void>;
|