silosdk 0.0.1 → 0.0.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/source.cjs +161 -0
- package/dist/source.d.cts +29 -0
- package/dist/source.d.mts +29 -0
- package/dist/source.mjs +161 -0
- package/package.json +19 -21
- package/README.md +0 -3
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/cli/d1.cjs +0 -93
- package/dist/cli/d1.mjs +0 -92
- package/dist/cli/index.cjs +0 -93
- package/dist/cli/index.d.cts +0 -1
- package/dist/cli/index.d.mts +0 -1
- package/dist/cli/index.mjs +0 -94
- package/dist/cli/init.cjs +0 -134
- package/dist/cli/init.mjs +0 -133
- package/dist/cli/kv.cjs +0 -63
- package/dist/cli/kv.mjs +0 -60
- package/dist/cli/r2.cjs +0 -83
- package/dist/cli/r2.mjs +0 -82
- package/dist/cli/wrangler.cjs +0 -93
- package/dist/cli/wrangler.mjs +0 -89
- package/dist/local/adapters/cloudflare.cjs +0 -200
- package/dist/local/adapters/cloudflare.d.cts +0 -50
- package/dist/local/adapters/cloudflare.d.mts +0 -50
- package/dist/local/adapters/cloudflare.mjs +0 -200
- package/dist/local/auth-context.cjs +0 -14
- package/dist/local/auth-context.d.cts +0 -7
- package/dist/local/auth-context.d.mts +0 -7
- package/dist/local/auth-context.mjs +0 -12
- package/dist/local/auth.cjs +0 -109
- package/dist/local/auth.d.cts +0 -26
- package/dist/local/auth.d.mts +0 -26
- package/dist/local/auth.mjs +0 -99
- package/dist/local/commit.cjs +0 -350
- package/dist/local/commit.d.cts +0 -59
- package/dist/local/commit.d.mts +0 -59
- package/dist/local/commit.mjs +0 -349
- package/dist/local/config.cjs +0 -17
- package/dist/local/config.mjs +0 -15
- package/dist/local/index.cjs +0 -16
- package/dist/local/index.d.cts +0 -10
- package/dist/local/index.d.mts +0 -10
- package/dist/local/index.mjs +0 -9
- package/dist/local/provider.cjs +0 -204
- package/dist/local/provider.d.cts +0 -25
- package/dist/local/provider.d.mts +0 -25
- package/dist/local/provider.mjs +0 -203
- package/dist/local/query-store.cjs +0 -276
- package/dist/local/query-store.mjs +0 -274
- package/dist/local/storage.cjs +0 -71
- package/dist/local/storage.d.cts +0 -7
- package/dist/local/storage.d.mts +0 -7
- package/dist/local/storage.mjs +0 -68
- package/dist/local/sync.cjs +0 -124
- package/dist/local/sync.d.cts +0 -36
- package/dist/local/sync.d.mts +0 -36
- package/dist/local/sync.mjs +0 -122
- package/dist/local/view.cjs +0 -257
- package/dist/local/view.d.cts +0 -24
- package/dist/local/view.d.mts +0 -24
- package/dist/local/view.mjs +0 -254
- package/dist/package.cjs +0 -11
- package/dist/package.mjs +0 -5
- package/dist/schema/index.cjs +0 -276
- package/dist/schema/index.d.cts +0 -207
- package/dist/schema/index.d.mts +0 -207
- package/dist/schema/index.mjs +0 -265
- package/dist/server/auth.cjs +0 -132
- package/dist/server/auth.d.cts +0 -49
- package/dist/server/auth.d.mts +0 -49
- package/dist/server/auth.mjs +0 -122
- package/dist/server/d1.cjs +0 -120
- package/dist/server/d1.mjs +0 -116
- package/dist/server/do.cjs +0 -132
- package/dist/server/do.d.cts +0 -21
- package/dist/server/do.d.mts +0 -21
- package/dist/server/do.mjs +0 -131
- package/dist/server/index.cjs +0 -355
- package/dist/server/index.d.cts +0 -65
- package/dist/server/index.d.mts +0 -65
- package/dist/server/index.mjs +0 -348
- package/dist/server/protect.cjs +0 -34
- package/dist/server/protect.d.cts +0 -32
- package/dist/server/protect.d.mts +0 -32
- package/dist/server/protect.mjs +0 -33
- package/dist/server/r2.cjs +0 -58
- package/dist/server/r2.d.cts +0 -4
- package/dist/server/r2.d.mts +0 -4
- package/dist/server/r2.mjs +0 -53
package/dist/cli/index.cjs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const require_wrangler = require('./wrangler.cjs');
|
|
3
|
-
const require_init = require('./init.cjs');
|
|
4
|
-
const require_d1 = require('./d1.cjs');
|
|
5
|
-
const require_kv = require('./kv.cjs');
|
|
6
|
-
const require_r2 = require('./r2.cjs');
|
|
7
|
-
|
|
8
|
-
//#region src/cli/index.ts
|
|
9
|
-
const [, , command, ...args] = process.argv;
|
|
10
|
-
function usage() {
|
|
11
|
-
console.log(`Usage: silo <command>
|
|
12
|
-
|
|
13
|
-
Commands:
|
|
14
|
-
init Scaffold silo/ directory into the current project
|
|
15
|
-
dev Start Cloudflare Worker in dev mode (wrangler dev)
|
|
16
|
-
deploy Deploy Cloudflare Worker (wrangler deploy)
|
|
17
|
-
logs Tail live Worker logs (wrangler tail)
|
|
18
|
-
d1 create Create D1 database and patch wrangler.jsonc
|
|
19
|
-
kv create Create SILO_SESSIONS KV namespace and patch wrangler.jsonc
|
|
20
|
-
kv create --id Manually patch wrangler.jsonc with an existing KV namespace id
|
|
21
|
-
r2 create Create R2 bucket and patch wrangler.jsonc
|
|
22
|
-
r2 create --name Manually patch wrangler.jsonc with an existing bucket name
|
|
23
|
-
secret put <key> Set a wrangler secret (e.g. RESEND_API_KEY)
|
|
24
|
-
`);
|
|
25
|
-
}
|
|
26
|
-
async function main() {
|
|
27
|
-
switch (command) {
|
|
28
|
-
case "init":
|
|
29
|
-
await require_init.runInit();
|
|
30
|
-
break;
|
|
31
|
-
case "dev":
|
|
32
|
-
await require_wrangler.runWrangler(["dev", ...args]);
|
|
33
|
-
break;
|
|
34
|
-
case "deploy":
|
|
35
|
-
await require_wrangler.runWrangler(["deploy", ...args]);
|
|
36
|
-
break;
|
|
37
|
-
case "logs":
|
|
38
|
-
await require_wrangler.runWrangler(["tail", ...args]);
|
|
39
|
-
break;
|
|
40
|
-
case "d1": {
|
|
41
|
-
const subcommand = args[0];
|
|
42
|
-
if (subcommand === "create") await require_d1.runD1(args.slice(1));
|
|
43
|
-
else {
|
|
44
|
-
console.error(`Unknown d1 subcommand: ${subcommand ?? "(none)"}`);
|
|
45
|
-
console.error("Available: silo d1 create");
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case "kv": {
|
|
51
|
-
const subcommand = args[0];
|
|
52
|
-
if (subcommand === "create") {
|
|
53
|
-
const idFlag = args.indexOf("--id");
|
|
54
|
-
if (idFlag !== -1 && args[idFlag + 1]) require_kv.runKvPatch(args[idFlag + 1]);
|
|
55
|
-
else await require_kv.runKvCreate();
|
|
56
|
-
} else {
|
|
57
|
-
console.error(`Unknown kv subcommand: ${subcommand ?? "(none)"}`);
|
|
58
|
-
console.error("Available: silo kv create [--id <namespace-id>]");
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case "r2": {
|
|
64
|
-
const subcommand = args[0];
|
|
65
|
-
if (subcommand === "create") await require_r2.runR2(args.slice(1));
|
|
66
|
-
else {
|
|
67
|
-
console.error(`Unknown r2 subcommand: ${subcommand ?? "(none)"}`);
|
|
68
|
-
console.error("Available: silo r2 create [--name <bucket-name>]");
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case "secret":
|
|
74
|
-
if (args[0] === "put" && args[1]) await require_kv.runSecretPut(args[1]);
|
|
75
|
-
else {
|
|
76
|
-
console.error("Usage: silo secret put <KEY>");
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
default:
|
|
81
|
-
usage();
|
|
82
|
-
if (command) {
|
|
83
|
-
console.error(`Unknown command: ${command}`);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
main().catch((err) => {
|
|
89
|
-
console.error(err instanceof Error ? err.message : String(err));
|
|
90
|
-
process.exit(1);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
//#endregion
|
package/dist/cli/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/cli/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/cli/index.mjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { runWrangler } from "./wrangler.mjs";
|
|
3
|
-
import { runInit } from "./init.mjs";
|
|
4
|
-
import { runD1 } from "./d1.mjs";
|
|
5
|
-
import { runKvCreate, runKvPatch, runSecretPut } from "./kv.mjs";
|
|
6
|
-
import { runR2 } from "./r2.mjs";
|
|
7
|
-
|
|
8
|
-
//#region src/cli/index.ts
|
|
9
|
-
const [, , command, ...args] = process.argv;
|
|
10
|
-
function usage() {
|
|
11
|
-
console.log(`Usage: silo <command>
|
|
12
|
-
|
|
13
|
-
Commands:
|
|
14
|
-
init Scaffold silo/ directory into the current project
|
|
15
|
-
dev Start Cloudflare Worker in dev mode (wrangler dev)
|
|
16
|
-
deploy Deploy Cloudflare Worker (wrangler deploy)
|
|
17
|
-
logs Tail live Worker logs (wrangler tail)
|
|
18
|
-
d1 create Create D1 database and patch wrangler.jsonc
|
|
19
|
-
kv create Create SILO_SESSIONS KV namespace and patch wrangler.jsonc
|
|
20
|
-
kv create --id Manually patch wrangler.jsonc with an existing KV namespace id
|
|
21
|
-
r2 create Create R2 bucket and patch wrangler.jsonc
|
|
22
|
-
r2 create --name Manually patch wrangler.jsonc with an existing bucket name
|
|
23
|
-
secret put <key> Set a wrangler secret (e.g. RESEND_API_KEY)
|
|
24
|
-
`);
|
|
25
|
-
}
|
|
26
|
-
async function main() {
|
|
27
|
-
switch (command) {
|
|
28
|
-
case "init":
|
|
29
|
-
await runInit();
|
|
30
|
-
break;
|
|
31
|
-
case "dev":
|
|
32
|
-
await runWrangler(["dev", ...args]);
|
|
33
|
-
break;
|
|
34
|
-
case "deploy":
|
|
35
|
-
await runWrangler(["deploy", ...args]);
|
|
36
|
-
break;
|
|
37
|
-
case "logs":
|
|
38
|
-
await runWrangler(["tail", ...args]);
|
|
39
|
-
break;
|
|
40
|
-
case "d1": {
|
|
41
|
-
const subcommand = args[0];
|
|
42
|
-
if (subcommand === "create") await runD1(args.slice(1));
|
|
43
|
-
else {
|
|
44
|
-
console.error(`Unknown d1 subcommand: ${subcommand ?? "(none)"}`);
|
|
45
|
-
console.error("Available: silo d1 create");
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case "kv": {
|
|
51
|
-
const subcommand = args[0];
|
|
52
|
-
if (subcommand === "create") {
|
|
53
|
-
const idFlag = args.indexOf("--id");
|
|
54
|
-
if (idFlag !== -1 && args[idFlag + 1]) runKvPatch(args[idFlag + 1]);
|
|
55
|
-
else await runKvCreate();
|
|
56
|
-
} else {
|
|
57
|
-
console.error(`Unknown kv subcommand: ${subcommand ?? "(none)"}`);
|
|
58
|
-
console.error("Available: silo kv create [--id <namespace-id>]");
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case "r2": {
|
|
64
|
-
const subcommand = args[0];
|
|
65
|
-
if (subcommand === "create") await runR2(args.slice(1));
|
|
66
|
-
else {
|
|
67
|
-
console.error(`Unknown r2 subcommand: ${subcommand ?? "(none)"}`);
|
|
68
|
-
console.error("Available: silo r2 create [--name <bucket-name>]");
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case "secret":
|
|
74
|
-
if (args[0] === "put" && args[1]) await runSecretPut(args[1]);
|
|
75
|
-
else {
|
|
76
|
-
console.error("Usage: silo secret put <KEY>");
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
default:
|
|
81
|
-
usage();
|
|
82
|
-
if (command) {
|
|
83
|
-
console.error(`Unknown command: ${command}`);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
main().catch((err) => {
|
|
89
|
-
console.error(err instanceof Error ? err.message : String(err));
|
|
90
|
-
process.exit(1);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
//#endregion
|
|
94
|
-
export { };
|
package/dist/cli/init.cjs
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_wrangler = require('./wrangler.cjs');
|
|
3
|
-
let node_fs = require("node:fs");
|
|
4
|
-
let node_readline = require("node:readline");
|
|
5
|
-
let node_path = require("node:path");
|
|
6
|
-
|
|
7
|
-
//#region src/cli/init.ts
|
|
8
|
-
function indexTemplate() {
|
|
9
|
-
return `import { createServer, SyncObject } from 'silosdk/server'
|
|
10
|
-
// import { createAuth, otpProvider, customProvider } from 'silosdk/server'
|
|
11
|
-
// TODO: import your view definitions here
|
|
12
|
-
// import { Post, Message } from '../src/schema'
|
|
13
|
-
|
|
14
|
-
export { SyncObject }
|
|
15
|
-
|
|
16
|
-
// Option A — built-in OTP auth
|
|
17
|
-
// const auth = createAuth({
|
|
18
|
-
// providers: [
|
|
19
|
-
// otpProvider({
|
|
20
|
-
// sendOTP: async (to, code) => {
|
|
21
|
-
// // Send \`code\` to \`to\` via any transport (email, SMS, etc.)
|
|
22
|
-
// },
|
|
23
|
-
// }),
|
|
24
|
-
// ],
|
|
25
|
-
// })
|
|
26
|
-
|
|
27
|
-
// Option B — BYO auth (Clerk, Supabase, JWT, etc.)
|
|
28
|
-
// const auth = createAuth({
|
|
29
|
-
// providers: customProvider(async (token) => {
|
|
30
|
-
// // Validate token and return { id } or null
|
|
31
|
-
// return null // TODO: implement
|
|
32
|
-
// }),
|
|
33
|
-
// })
|
|
34
|
-
|
|
35
|
-
export default createServer({
|
|
36
|
-
views: [
|
|
37
|
-
// Post, Message, ...
|
|
38
|
-
],
|
|
39
|
-
// auth,
|
|
40
|
-
})
|
|
41
|
-
`;
|
|
42
|
-
}
|
|
43
|
-
function wranglerTemplate(serverName, dbName) {
|
|
44
|
-
return `{
|
|
45
|
-
"name": "${serverName}",
|
|
46
|
-
"main": "index.ts",
|
|
47
|
-
"compatibility_date": "2025-01-01",
|
|
48
|
-
"durable_objects": {
|
|
49
|
-
"bindings": [
|
|
50
|
-
{ "name": "SILO_SYNC", "class_name": "SyncObject" }
|
|
51
|
-
]
|
|
52
|
-
},
|
|
53
|
-
"migrations": [
|
|
54
|
-
{ "tag": "v1", "new_sqlite_classes": ["SyncObject"] }
|
|
55
|
-
],
|
|
56
|
-
"d1_databases": [
|
|
57
|
-
{
|
|
58
|
-
"binding": "SILO_DB",
|
|
59
|
-
"database_name": "${dbName}",
|
|
60
|
-
"database_id": "TODO: run \`silo d1 create\` and paste the id here"
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
"kv_namespaces": [
|
|
64
|
-
{
|
|
65
|
-
"binding": "SILO_SESSIONS",
|
|
66
|
-
"id": "TODO: run \`silo kv create\` and paste the id here"
|
|
67
|
-
}
|
|
68
|
-
],
|
|
69
|
-
"r2_buckets": [
|
|
70
|
-
{
|
|
71
|
-
"binding": "SILO_STORAGE",
|
|
72
|
-
"bucket_name": "TODO: run \`silo r2 create\` and paste the name here"
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
}
|
|
78
|
-
function prompt(rl, question) {
|
|
79
|
-
return new Promise((resolve$1) => {
|
|
80
|
-
rl.question(question, (answer) => resolve$1(answer.trim()));
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function readPackageName() {
|
|
84
|
-
try {
|
|
85
|
-
const raw = (0, node_fs.readFileSync)((0, node_path.resolve)(require_wrangler.projectRoot(), "package.json"), "utf8");
|
|
86
|
-
const pkg = JSON.parse(raw);
|
|
87
|
-
return typeof pkg.name === "string" && pkg.name ? pkg.name : null;
|
|
88
|
-
} catch {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async function runInit() {
|
|
93
|
-
const defaultServerName = readPackageName() ?? "my-app";
|
|
94
|
-
const rl = (0, node_readline.createInterface)({
|
|
95
|
-
input: process.stdin,
|
|
96
|
-
output: process.stdout
|
|
97
|
-
});
|
|
98
|
-
let serverName;
|
|
99
|
-
let dbName;
|
|
100
|
-
try {
|
|
101
|
-
serverName = await prompt(rl, `Server name [${defaultServerName}]: `) || defaultServerName;
|
|
102
|
-
const defaultDbName = `${serverName}-db`;
|
|
103
|
-
dbName = await prompt(rl, `D1 database name [${defaultDbName}]: `) || defaultDbName;
|
|
104
|
-
} finally {
|
|
105
|
-
rl.close();
|
|
106
|
-
}
|
|
107
|
-
const dir = require_wrangler.siloDir();
|
|
108
|
-
const indexPath = (0, node_path.resolve)(dir, "index.ts");
|
|
109
|
-
const wranglerPath = (0, node_path.resolve)(dir, "wrangler.jsonc");
|
|
110
|
-
if ((0, node_fs.existsSync)(indexPath) || (0, node_fs.existsSync)(wranglerPath)) {
|
|
111
|
-
console.error("Error: silo/ directory already contains files. Remove them first or edit them manually.");
|
|
112
|
-
process.exit(1);
|
|
113
|
-
}
|
|
114
|
-
if (!(0, node_fs.existsSync)(dir)) (0, node_fs.mkdirSync)(dir, { recursive: true });
|
|
115
|
-
(0, node_fs.writeFileSync)(indexPath, indexTemplate(), "utf8");
|
|
116
|
-
(0, node_fs.writeFileSync)(wranglerPath, wranglerTemplate(serverName, dbName), "utf8");
|
|
117
|
-
console.log(`
|
|
118
|
-
Scaffolded silo/:
|
|
119
|
-
silo/index.ts — server entry point
|
|
120
|
-
silo/wrangler.jsonc — Cloudflare config
|
|
121
|
-
|
|
122
|
-
Next steps:
|
|
123
|
-
1. Import your views in silo/index.ts and configure auth
|
|
124
|
-
(built-in OTP via createAuth, or BYO via customProvider)
|
|
125
|
-
2. Run \`silo d1 create\` to create the D1 database and patch wrangler.jsonc
|
|
126
|
-
3. Run \`silo kv create\` to create the SILO_SESSIONS KV namespace
|
|
127
|
-
4. Run \`silo r2 create\` to create the SILO_STORAGE R2 bucket
|
|
128
|
-
5. Run \`silo dev\` to start the Worker locally
|
|
129
|
-
6. Run \`silo deploy\` to deploy to Cloudflare
|
|
130
|
-
`);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
//#endregion
|
|
134
|
-
exports.runInit = runInit;
|
package/dist/cli/init.mjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { projectRoot, siloDir } from "./wrangler.mjs";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { createInterface } from "node:readline";
|
|
4
|
-
import { resolve } from "node:path";
|
|
5
|
-
|
|
6
|
-
//#region src/cli/init.ts
|
|
7
|
-
function indexTemplate() {
|
|
8
|
-
return `import { createServer, SyncObject } from 'silosdk/server'
|
|
9
|
-
// import { createAuth, otpProvider, customProvider } from 'silosdk/server'
|
|
10
|
-
// TODO: import your view definitions here
|
|
11
|
-
// import { Post, Message } from '../src/schema'
|
|
12
|
-
|
|
13
|
-
export { SyncObject }
|
|
14
|
-
|
|
15
|
-
// Option A — built-in OTP auth
|
|
16
|
-
// const auth = createAuth({
|
|
17
|
-
// providers: [
|
|
18
|
-
// otpProvider({
|
|
19
|
-
// sendOTP: async (to, code) => {
|
|
20
|
-
// // Send \`code\` to \`to\` via any transport (email, SMS, etc.)
|
|
21
|
-
// },
|
|
22
|
-
// }),
|
|
23
|
-
// ],
|
|
24
|
-
// })
|
|
25
|
-
|
|
26
|
-
// Option B — BYO auth (Clerk, Supabase, JWT, etc.)
|
|
27
|
-
// const auth = createAuth({
|
|
28
|
-
// providers: customProvider(async (token) => {
|
|
29
|
-
// // Validate token and return { id } or null
|
|
30
|
-
// return null // TODO: implement
|
|
31
|
-
// }),
|
|
32
|
-
// })
|
|
33
|
-
|
|
34
|
-
export default createServer({
|
|
35
|
-
views: [
|
|
36
|
-
// Post, Message, ...
|
|
37
|
-
],
|
|
38
|
-
// auth,
|
|
39
|
-
})
|
|
40
|
-
`;
|
|
41
|
-
}
|
|
42
|
-
function wranglerTemplate(serverName, dbName) {
|
|
43
|
-
return `{
|
|
44
|
-
"name": "${serverName}",
|
|
45
|
-
"main": "index.ts",
|
|
46
|
-
"compatibility_date": "2025-01-01",
|
|
47
|
-
"durable_objects": {
|
|
48
|
-
"bindings": [
|
|
49
|
-
{ "name": "SILO_SYNC", "class_name": "SyncObject" }
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
"migrations": [
|
|
53
|
-
{ "tag": "v1", "new_sqlite_classes": ["SyncObject"] }
|
|
54
|
-
],
|
|
55
|
-
"d1_databases": [
|
|
56
|
-
{
|
|
57
|
-
"binding": "SILO_DB",
|
|
58
|
-
"database_name": "${dbName}",
|
|
59
|
-
"database_id": "TODO: run \`silo d1 create\` and paste the id here"
|
|
60
|
-
}
|
|
61
|
-
],
|
|
62
|
-
"kv_namespaces": [
|
|
63
|
-
{
|
|
64
|
-
"binding": "SILO_SESSIONS",
|
|
65
|
-
"id": "TODO: run \`silo kv create\` and paste the id here"
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
"r2_buckets": [
|
|
69
|
-
{
|
|
70
|
-
"binding": "SILO_STORAGE",
|
|
71
|
-
"bucket_name": "TODO: run \`silo r2 create\` and paste the name here"
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
}
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
function prompt(rl, question) {
|
|
78
|
-
return new Promise((resolve$1) => {
|
|
79
|
-
rl.question(question, (answer) => resolve$1(answer.trim()));
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function readPackageName() {
|
|
83
|
-
try {
|
|
84
|
-
const raw = readFileSync(resolve(projectRoot(), "package.json"), "utf8");
|
|
85
|
-
const pkg = JSON.parse(raw);
|
|
86
|
-
return typeof pkg.name === "string" && pkg.name ? pkg.name : null;
|
|
87
|
-
} catch {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async function runInit() {
|
|
92
|
-
const defaultServerName = readPackageName() ?? "my-app";
|
|
93
|
-
const rl = createInterface({
|
|
94
|
-
input: process.stdin,
|
|
95
|
-
output: process.stdout
|
|
96
|
-
});
|
|
97
|
-
let serverName;
|
|
98
|
-
let dbName;
|
|
99
|
-
try {
|
|
100
|
-
serverName = await prompt(rl, `Server name [${defaultServerName}]: `) || defaultServerName;
|
|
101
|
-
const defaultDbName = `${serverName}-db`;
|
|
102
|
-
dbName = await prompt(rl, `D1 database name [${defaultDbName}]: `) || defaultDbName;
|
|
103
|
-
} finally {
|
|
104
|
-
rl.close();
|
|
105
|
-
}
|
|
106
|
-
const dir = siloDir();
|
|
107
|
-
const indexPath = resolve(dir, "index.ts");
|
|
108
|
-
const wranglerPath = resolve(dir, "wrangler.jsonc");
|
|
109
|
-
if (existsSync(indexPath) || existsSync(wranglerPath)) {
|
|
110
|
-
console.error("Error: silo/ directory already contains files. Remove them first or edit them manually.");
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
114
|
-
writeFileSync(indexPath, indexTemplate(), "utf8");
|
|
115
|
-
writeFileSync(wranglerPath, wranglerTemplate(serverName, dbName), "utf8");
|
|
116
|
-
console.log(`
|
|
117
|
-
Scaffolded silo/:
|
|
118
|
-
silo/index.ts — server entry point
|
|
119
|
-
silo/wrangler.jsonc — Cloudflare config
|
|
120
|
-
|
|
121
|
-
Next steps:
|
|
122
|
-
1. Import your views in silo/index.ts and configure auth
|
|
123
|
-
(built-in OTP via createAuth, or BYO via customProvider)
|
|
124
|
-
2. Run \`silo d1 create\` to create the D1 database and patch wrangler.jsonc
|
|
125
|
-
3. Run \`silo kv create\` to create the SILO_SESSIONS KV namespace
|
|
126
|
-
4. Run \`silo r2 create\` to create the SILO_STORAGE R2 bucket
|
|
127
|
-
5. Run \`silo dev\` to start the Worker locally
|
|
128
|
-
6. Run \`silo deploy\` to deploy to Cloudflare
|
|
129
|
-
`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
//#endregion
|
|
133
|
-
export { runInit };
|
package/dist/cli/kv.cjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_wrangler = require('./wrangler.cjs');
|
|
3
|
-
let node_fs = require("node:fs");
|
|
4
|
-
let node_path = require("node:path");
|
|
5
|
-
|
|
6
|
-
//#region src/cli/kv.ts
|
|
7
|
-
async function runKvCreate() {
|
|
8
|
-
const dir = require_wrangler.siloDir();
|
|
9
|
-
console.log("Creating KV namespace SILO_SESSIONS...");
|
|
10
|
-
const { stdout, code } = await require_wrangler.runWranglerCaptured([
|
|
11
|
-
"kv",
|
|
12
|
-
"namespace",
|
|
13
|
-
"create",
|
|
14
|
-
"SILO_SESSIONS"
|
|
15
|
-
]);
|
|
16
|
-
if (code !== 0) {
|
|
17
|
-
console.error("Failed to create KV namespace. Check wrangler output above.");
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
const match = stdout.match(/"id"\s*:\s*"([a-f0-9]{32})"/) ?? stdout.match(/id\s*=\s*"([a-f0-9]{32})"/) ?? stdout.match(/id[^a-f0-9]*([a-f0-9]{32})/);
|
|
21
|
-
if (!match) {
|
|
22
|
-
console.error(`Could not parse KV namespace id from wrangler output.
|
|
23
|
-
Run: silo kv create --id <namespace-id> to set it manually.
|
|
24
|
-
|
|
25
|
-
Wrangler output:\n${stdout}`);
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
const id = match[1];
|
|
29
|
-
patchWrangler(dir, id);
|
|
30
|
-
console.log(`KV namespace created (id: ${id}) and patched into wrangler.jsonc`);
|
|
31
|
-
}
|
|
32
|
-
function runKvPatch(id) {
|
|
33
|
-
patchWrangler(require_wrangler.siloDir(), id);
|
|
34
|
-
console.log(`Patched wrangler.jsonc with KV namespace id: ${id}`);
|
|
35
|
-
}
|
|
36
|
-
function patchWrangler(dir, id) {
|
|
37
|
-
const wranglerPath = (0, node_path.resolve)(dir, "wrangler.jsonc");
|
|
38
|
-
let raw;
|
|
39
|
-
try {
|
|
40
|
-
raw = (0, node_fs.readFileSync)(wranglerPath, "utf8");
|
|
41
|
-
} catch {
|
|
42
|
-
console.error(`Could not read ${wranglerPath}`);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
const patched = raw.replace(/("binding"\s*:\s*"SILO_SESSIONS"[^}]*"id"\s*:\s*)"[^"]*"/s, `$1"${id}"`);
|
|
46
|
-
if (patched === raw) {
|
|
47
|
-
console.warn("Could not find SILO_SESSIONS id placeholder in wrangler.jsonc — edit it manually.");
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
(0, node_fs.writeFileSync)(wranglerPath, patched, "utf8");
|
|
51
|
-
}
|
|
52
|
-
async function runSecretPut(key) {
|
|
53
|
-
await require_wrangler.runWrangler([
|
|
54
|
-
"secret",
|
|
55
|
-
"put",
|
|
56
|
-
key
|
|
57
|
-
]);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
//#endregion
|
|
61
|
-
exports.runKvCreate = runKvCreate;
|
|
62
|
-
exports.runKvPatch = runKvPatch;
|
|
63
|
-
exports.runSecretPut = runSecretPut;
|
package/dist/cli/kv.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { runWrangler, runWranglerCaptured, siloDir } from "./wrangler.mjs";
|
|
2
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
|
|
5
|
-
//#region src/cli/kv.ts
|
|
6
|
-
async function runKvCreate() {
|
|
7
|
-
const dir = siloDir();
|
|
8
|
-
console.log("Creating KV namespace SILO_SESSIONS...");
|
|
9
|
-
const { stdout, code } = await runWranglerCaptured([
|
|
10
|
-
"kv",
|
|
11
|
-
"namespace",
|
|
12
|
-
"create",
|
|
13
|
-
"SILO_SESSIONS"
|
|
14
|
-
]);
|
|
15
|
-
if (code !== 0) {
|
|
16
|
-
console.error("Failed to create KV namespace. Check wrangler output above.");
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
const match = stdout.match(/"id"\s*:\s*"([a-f0-9]{32})"/) ?? stdout.match(/id\s*=\s*"([a-f0-9]{32})"/) ?? stdout.match(/id[^a-f0-9]*([a-f0-9]{32})/);
|
|
20
|
-
if (!match) {
|
|
21
|
-
console.error(`Could not parse KV namespace id from wrangler output.
|
|
22
|
-
Run: silo kv create --id <namespace-id> to set it manually.
|
|
23
|
-
|
|
24
|
-
Wrangler output:\n${stdout}`);
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
const id = match[1];
|
|
28
|
-
patchWrangler(dir, id);
|
|
29
|
-
console.log(`KV namespace created (id: ${id}) and patched into wrangler.jsonc`);
|
|
30
|
-
}
|
|
31
|
-
function runKvPatch(id) {
|
|
32
|
-
patchWrangler(siloDir(), id);
|
|
33
|
-
console.log(`Patched wrangler.jsonc with KV namespace id: ${id}`);
|
|
34
|
-
}
|
|
35
|
-
function patchWrangler(dir, id) {
|
|
36
|
-
const wranglerPath = resolve(dir, "wrangler.jsonc");
|
|
37
|
-
let raw;
|
|
38
|
-
try {
|
|
39
|
-
raw = readFileSync(wranglerPath, "utf8");
|
|
40
|
-
} catch {
|
|
41
|
-
console.error(`Could not read ${wranglerPath}`);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
const patched = raw.replace(/("binding"\s*:\s*"SILO_SESSIONS"[^}]*"id"\s*:\s*)"[^"]*"/s, `$1"${id}"`);
|
|
45
|
-
if (patched === raw) {
|
|
46
|
-
console.warn("Could not find SILO_SESSIONS id placeholder in wrangler.jsonc — edit it manually.");
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
writeFileSync(wranglerPath, patched, "utf8");
|
|
50
|
-
}
|
|
51
|
-
async function runSecretPut(key) {
|
|
52
|
-
await runWrangler([
|
|
53
|
-
"secret",
|
|
54
|
-
"put",
|
|
55
|
-
key
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
export { runKvCreate, runKvPatch, runSecretPut };
|
package/dist/cli/r2.cjs
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_wrangler = require('./wrangler.cjs');
|
|
3
|
-
let node_fs = require("node:fs");
|
|
4
|
-
let node_path = require("node:path");
|
|
5
|
-
|
|
6
|
-
//#region src/cli/r2.ts
|
|
7
|
-
async function runR2(args) {
|
|
8
|
-
const nameFlag = args.indexOf("--name");
|
|
9
|
-
if (nameFlag !== -1) {
|
|
10
|
-
const bucketName = args[nameFlag + 1];
|
|
11
|
-
if (!bucketName) {
|
|
12
|
-
console.error("Error: --name requires a bucket name");
|
|
13
|
-
process.exit(1);
|
|
14
|
-
}
|
|
15
|
-
runR2Patch(bucketName);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
await runR2Create();
|
|
19
|
-
}
|
|
20
|
-
async function runR2Create() {
|
|
21
|
-
const wranglerPath = (0, node_path.resolve)(require_wrangler.siloDir(), "wrangler.jsonc");
|
|
22
|
-
let source;
|
|
23
|
-
try {
|
|
24
|
-
source = (0, node_fs.readFileSync)(wranglerPath, "utf8");
|
|
25
|
-
} catch {
|
|
26
|
-
console.error("Error: silo/wrangler.jsonc not found. Run `silo init` first.");
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
const bucketName = extractBucketName(source);
|
|
30
|
-
if (!bucketName) {
|
|
31
|
-
console.error("Error: Could not determine R2 bucket name from silo/wrangler.jsonc.");
|
|
32
|
-
console.error("Use: silo r2 create --name <bucket-name> to patch manually.");
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
console.log(`Creating R2 bucket: ${bucketName} ...`);
|
|
36
|
-
try {
|
|
37
|
-
await require_wrangler.runWrangler([
|
|
38
|
-
"r2",
|
|
39
|
-
"bucket",
|
|
40
|
-
"create",
|
|
41
|
-
bucketName
|
|
42
|
-
]);
|
|
43
|
-
} catch (err) {
|
|
44
|
-
console.error("wrangler r2 bucket create failed.");
|
|
45
|
-
process.exit(1);
|
|
46
|
-
}
|
|
47
|
-
runR2Patch(bucketName);
|
|
48
|
-
console.log(`R2 bucket created and patched: ${bucketName}`);
|
|
49
|
-
}
|
|
50
|
-
function runR2Patch(bucketName) {
|
|
51
|
-
const wranglerPath = (0, node_path.resolve)(require_wrangler.siloDir(), "wrangler.jsonc");
|
|
52
|
-
let source;
|
|
53
|
-
try {
|
|
54
|
-
source = (0, node_fs.readFileSync)(wranglerPath, "utf8");
|
|
55
|
-
} catch {
|
|
56
|
-
console.error("Error: silo/wrangler.jsonc not found. Run `silo init` first.");
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
const replaced = source.replace(/("binding"\s*:\s*"SILO_STORAGE"[^}]*"bucket_name"\s*:\s*)"[^"]*"/s, `$1"${bucketName}"`);
|
|
60
|
-
if (replaced !== source) {
|
|
61
|
-
(0, node_fs.writeFileSync)(wranglerPath, replaced, "utf8");
|
|
62
|
-
console.log(`Patched silo/wrangler.jsonc with R2 bucket_name = "${bucketName}"`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const insertion = `,\n "r2_buckets": [\n {\n "binding": "SILO_STORAGE",\n "bucket_name": "${bucketName}"\n }\n ]\n`;
|
|
66
|
-
const lastBrace = source.lastIndexOf("}");
|
|
67
|
-
if (lastBrace === -1) {
|
|
68
|
-
console.error("Error: Invalid JSONC in silo/wrangler.jsonc");
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
(0, node_fs.writeFileSync)(wranglerPath, source.slice(0, lastBrace) + insertion + source.slice(lastBrace), "utf8");
|
|
72
|
-
console.log(`Added r2_buckets to silo/wrangler.jsonc with bucket_name = "${bucketName}"`);
|
|
73
|
-
}
|
|
74
|
-
function extractBucketName(source) {
|
|
75
|
-
const existing = source.match(/"binding"\s*:\s*"SILO_STORAGE"[^}]*"bucket_name"\s*:\s*"([^"]+)"/s)?.[1];
|
|
76
|
-
if (existing && !existing.startsWith("TODO:")) return existing;
|
|
77
|
-
const workerName = source.match(/"name"\s*:\s*"([^"]+)"/)?.[1];
|
|
78
|
-
if (!workerName) return null;
|
|
79
|
-
return `${workerName}-storage`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
|
-
exports.runR2 = runR2;
|