glyph-server 0.0.0-stage → 0.3.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-APACHE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The Glyph contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,88 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Glyph CLI
2
+
3
+ ```sh
4
+ npm install --global glyph-server
5
+ glyph help
6
+ glyph version
7
+ ```
8
+
9
+ Node.js 22+ is required. Installation downloads the exact matching native release,
10
+ checks its SHA-256 and version, and supports Windows x64, macOS x64/arm64 and glibc
11
+ Linux x64/arm64. Rust is not required. `glyph-server` remains a compatibility alias.
12
+
13
+ ## Your own server
14
+
15
+ ```sh
16
+ glyph setup cloudflare
17
+ glyph deploy --config glyph-cloudflare/wrangler.json
18
+ ```
19
+
20
+ The guided setup uses **your** Cloudflare account, creates a D1 database, applies
21
+ the included migrations and deploys the prebuilt Worker. R2 media/image storage
22
+ is optional and off unless selected; enable R2 in your own account first. It
23
+ never copies Glyph's production domains, database IDs or secrets. The password
24
+ is hashed locally; Wrangler stores the hash as a secret. Sign in to your own
25
+ Cloudflare account when prompted. No Rust, Git checkout or separate desktop
26
+ repository is required.
27
+
28
+ The setup uses the documented [D1 creation/migration commands](https://developers.cloudflare.com/d1/wrangler-commands/)
29
+ and optional [R2 bucket commands](https://developers.cloudflare.com/workers/wrangler/commands/r2/).
30
+ For YouTube, deploy your own [companion](https://github.com/glyphmusic/companion)
31
+ and set `YTDLP_SERVICE_URL` / `YTDLP_SERVICE_TOKEN` with Wrangler's secret commands
32
+ against your generated config. Without a companion the key-free sources still work.
33
+
34
+ To host a native server instead: `glyph setup`, then `glyph serve` or
35
+ `glyph service install`. Install yt-dlp and FFmpeg for YouTube/encoded audio;
36
+ native r-dlp can be selected through `GLYPH_RDLP_PATH`. Cloudflare accounts/sync
37
+ use D1; the native server currently has no account storage backend.
38
+
39
+ ## Manage and inspect
40
+
41
+ ```sh
42
+ glyph remote login https://your-server.example
43
+ glyph version all
44
+ glyph version server
45
+ glyph version companion
46
+ glyph version r-dlp
47
+ glyph check companion
48
+ glyph check r-dlp
49
+ glyph check all
50
+ glyph remote limits --require-account true
51
+ ```
52
+
53
+ The remembered server is used automatically; pass `--server <url>` to select
54
+ another server, or `--local` to inspect this machine's companion and tools.
55
+ Companion checks include the running Glyph version, enabled/ready state and the
56
+ installed r-dlp, yt-dlp and FFmpeg versions. Installed tool versions are distinct
57
+ from an image tag or an already-loaded persistent worker.
58
+
59
+ ## Updates
60
+
61
+ ```sh
62
+ glyph update # npm CLI update
63
+ glyph update cli --check
64
+ glyph update server --check
65
+ glyph update server # authenticated native-server update
66
+ glyph update companion --check
67
+ glyph update companion
68
+ glyph update r-dlp --check
69
+ glyph update r-dlp
70
+ glyph update server --worker-config glyph-cloudflare/wrangler.json
71
+ glyph check companion --compose-dir /path/to/companion-project
72
+ glyph update companion --compose-dir /path/to/companion-project
73
+ ```
74
+
75
+ The Worker update applies your configured migrations and deploys the bundled
76
+ Worker using your Cloudflare login. A remote native update replaces its verified
77
+ binary and reports when a restart is required; verify the running version after
78
+ restarting. Docker images should be updated/recreated through their deployment
79
+ instead of modifying binaries inside an immutable container. The CLI does not
80
+ claim a running process was updated merely because a file was replaced.
81
+
82
+ r-dlp updates use its own release/checksum manifest and reload the extractor pool
83
+ after installation. An old companion without management endpoints must first be
84
+ updated through its deployment. npm-managed native processes are upgraded with
85
+ `glyph update cli` and restarted through the updated CLI, preserving the old
86
+ versioned executable while it is running.
87
+
88
+ Source, licenses and releases: https://github.com/glyphmusic/server
package/bin/glyph.cjs ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const {spawnSync} = require('node:child_process');
4
+ const path = require('node:path');
5
+ async function main() {
6
+ const args = process.argv.slice(2);
7
+ if((args[0]==='update' && ['cli','--help',undefined].includes(args[1]) || args[0]==='self-update') && args.includes('--help')) {
8
+ console.log('glyph update [cli] [--check]\nUpdates the npm CLI package. Running servers are left running.');return;
9
+ }
10
+ if(['version','check','update'].includes(args[0]) && ['companion','r-dlp'].includes(args[1]) && args.includes('--compose-dir')) {
11
+ if(args.length!==4 || args[2]!=='--compose-dir' || !args[3]) throw new Error('Usage: glyph check|version|update companion|r-dlp --compose-dir /path/to/project');
12
+ require('../lib/companion.cjs').manage(args[3],args[0]==='update');return;
13
+ }
14
+ if ((args[0] === 'update' && (!args[1] || args[1] === 'cli')) || args[0] === 'self-update') {
15
+ const offset=args[1]==='cli'?2:1;
16
+ if(args.slice(offset).some(arg=>arg!=='--check') || args.slice(offset).length>1) throw new Error('Usage: glyph update [cli] [--check]');
17
+ const check = args.includes('--check');
18
+ if (check) {
19
+ const result = process.platform === 'win32'
20
+ ? spawnSync(process.env.ComSpec || 'cmd.exe',['/d','/s','/c','npm view glyph-server version'],{stdio:'inherit'})
21
+ : spawnSync('npm',['view','glyph-server','version'],{stdio:'inherit'});
22
+ if (result.error) throw result.error;
23
+ console.log(`Installed CLI: ${require('../package.json').version}`);
24
+ process.exitCode = result.status ?? 1; return;
25
+ }
26
+ // No native child is running during replacement. Existing servers use
27
+ // their versioned cache copy and keep running until explicitly restarted.
28
+ const result = process.platform === 'win32'
29
+ ? spawnSync(process.env.ComSpec || 'cmd.exe',['/d','/s','/c','npm install --global glyph-server@latest'],{stdio:'inherit'})
30
+ : spawnSync('npm',['install','--global','glyph-server@latest'],{stdio:'inherit'});
31
+ if (result.error) throw result.error;
32
+ if (result.status === 0) {
33
+ const file=await require('../lib/install.cjs').install();
34
+ const verified=spawnSync(file,['--version'],{stdio:'inherit'});
35
+ if(verified.status!==0) throw new Error('npm finished, but the installed CLI could not be verified');
36
+ console.log('CLI updated and verified. Running servers/companions retain their current version until restarted.');
37
+ }
38
+ process.exitCode = result.status ?? 1; return;
39
+ }
40
+ if (args[0] === 'setup' && args[1] === 'cloudflare') {
41
+ if(args.includes('--help')) {console.log('glyph setup cloudflare [--dir project-directory]\nCreates your own Cloudflare resources and deploys the included Worker.');return;}
42
+ if(args.length!==2 && !(args.length===4 && args[2]==='--dir')) throw new Error('Usage: glyph setup cloudflare [--dir project-directory]');
43
+ const readline=require('node:readline/promises').createInterface({input:process.stdin,output:process.stdout});
44
+ const question=text=>readline.question(text); question.close=()=>readline.close();
45
+ try {await require('../lib/cloudflare.cjs').setup({dir:args[3]?path.resolve(args[3]):undefined,question});}
46
+ finally {readline.close();}
47
+ return;
48
+ }
49
+ if (args[0] === 'deploy' || (args[0] === 'update' && args[1] === 'server' && args.includes('--worker-config'))) {
50
+ const flag=args[0]==='deploy'?'--config':'--worker-config';
51
+ const index=args.indexOf(flag);
52
+ if(args.includes('--help')) {console.log('glyph deploy [--config wrangler.json]\nglyph update server --worker-config wrangler.json');return;}
53
+ const offset=args[0]==='deploy'?1:2;
54
+ if(args.length!==offset && !(args.length===offset+2 && index===offset && args[index+1])) throw new Error(`Usage: glyph deploy --config /path/to/wrangler.json`);
55
+ const fallback=require('node:fs').existsSync('wrangler.json')?'wrangler.json':'glyph-cloudflare/wrangler.json';
56
+ await require('../lib/cloudflare.cjs').deploy(args[index+1] && index>=0 ? args[index+1] : fallback);
57
+ return;
58
+ }
59
+ const file = await require('../lib/install.cjs').install();
60
+ const result = spawnSync(file,args,{stdio:'inherit',env:{...process.env,GLYPH_NPM_MANAGED:'1'}});
61
+ if (result.error) throw result.error;
62
+ process.exitCode = result.status ?? 1;
63
+ if(result.status===0 && (args[0]==='help' || args.includes('--help'))) console.log('\nWith npm: glyph setup cloudflare [--dir directory] | glyph deploy [--config wrangler.json]\nCloudflare update: glyph update server --worker-config wrangler.json');
64
+ }
65
+ main().catch(error => {console.error(`glyph: ${error.message}`);process.exitCode=1;});
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ require('../lib/install.cjs').install().catch(error => { console.error(`Glyph installation failed: ${error.message}`); process.exitCode = 1; });
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const root = path.resolve(__dirname,'../..');
5
+ for (const name of ['LICENSE-MIT','LICENSE-APACHE']) fs.copyFileSync(path.join(root,name),path.resolve(__dirname,'..',name));
6
+ const worker = path.join(root,'crates/glyph-server-worker/build');
7
+ fs.mkdirSync(path.resolve(__dirname,'../worker'),{recursive:true});
8
+ for (const name of ['index.js','index_bg.wasm']) {
9
+ if (!fs.existsSync(path.join(worker,name))) throw new Error('Build the Worker before packing the npm release');
10
+ fs.copyFileSync(path.join(worker,name),path.resolve(__dirname,'../worker',name));
11
+ }
12
+
13
+ fs.cpSync(path.join(root,'crates/glyph-server-worker/migrations'),path.resolve(__dirname,'../worker/migrations'),{recursive:true});
14
+ fs.writeFileSync(path.resolve(__dirname,'../worker/package.json'),JSON.stringify({type:'module'}));
@@ -0,0 +1,111 @@
1
+ 'use strict';
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const {spawnSync} = require('node:child_process');
5
+ const pkg = require('../package.json');
6
+ function wrangler(args,{capture=false}={}) {
7
+ let command='npx', prefix=[];
8
+ if(process.platform==='win32') {
9
+ const roots=[path.dirname(process.execPath),...(process.env.PATH||'').split(path.delimiter)];
10
+ const candidates=roots.map(root=>path.join(root,'node_modules/npm/bin/npx-cli.js'));
11
+ if(process.env.npm_execpath) candidates.unshift(path.join(path.dirname(process.env.npm_execpath),'npx-cli.js'));
12
+ const script=candidates.find(file=>fs.existsSync(file));
13
+ if(!script) throw new Error('Cannot locate npx. Install Node.js with npm and reopen your terminal.');
14
+ command=process.execPath;prefix=[script];
15
+ }
16
+ const result=spawnSync(command,[...prefix,'--yes','wrangler@4',...args],{
17
+ stdio:capture?['inherit','pipe','inherit']:'inherit',encoding:'utf8',maxBuffer:4*1024*1024
18
+ });
19
+ if(result.error) throw result.error;
20
+ if(result.status!==0) throw new Error(`Wrangler ${args.slice(0,2).join(' ')} failed. Your configuration/resources were retained; fix the reported error and rerun.`);
21
+ if(capture) {process.stdout.write(result.stdout);return result.stdout;}
22
+ return '';
23
+ }
24
+ function template(name,origin) {
25
+ if(!/^[a-z][a-z0-9-]{2,47}$/.test(name)) throw new Error('Worker name: 3–48 lowercase letters, digits or hyphens; start with a letter.');
26
+ if(origin) {const u=new URL(origin);if(u.protocol!=='https:' || u.username || u.password || u.pathname!=='/' || u.search || u.hash) throw new Error('Use a public HTTPS origin without a path or credentials.');origin=u.origin;}
27
+ return {name,main:'.glyph/worker/index.js',compatibility_date:'2025-01-01',workers_dev:true,
28
+ ...(origin && !new URL(origin).hostname.endsWith('.workers.dev')?{routes:[{pattern:new URL(origin).hostname,custom_domain:true}]}:{}),
29
+ vars:{RATE_LIMIT_PER_MIN:'60',...(origin?{PUBLIC_ORIGIN:origin}:{})},
30
+ triggers:{crons:['* * * * *']}};
31
+ }
32
+ function copyPayload(dir) {
33
+ const source=path.resolve(__dirname,'../worker');
34
+ if(!fs.existsSync(path.join(source,'index_bg.wasm'))) throw new Error('Prebuilt Worker missing. Install an official npm release or run the repository prepack build.');
35
+ const output=path.join(dir,'.glyph');fs.mkdirSync(output,{recursive:true});
36
+ fs.cpSync(source,path.join(output,'worker'),{recursive:true});
37
+ }
38
+ function readConfig(file) {
39
+ try{return JSON.parse(fs.readFileSync(file,'utf8'));}catch {throw new Error(`Cannot read generated JSON config ${file}; use a valid wrangler.json.`);}
40
+ }
41
+ async function setup({dir=path.resolve('glyph-cloudflare'),question,run=wrangler}={}) {
42
+ const config=path.join(dir,'wrangler.json');
43
+ const existing=fs.existsSync(config)?readConfig(config):null;
44
+ const name=existing?.name || (await question('Worker name [glyph-api]: ')).trim() || 'glyph-api';
45
+ const origin=existing?.vars?.PUBLIC_ORIGIN || (await question('Public HTTPS origin (Enter: detect workers.dev after deployment): ')).trim();
46
+ const data=existing || template(name,origin);
47
+ const r2=!existing && /^y(es)?$/i.test((await question('Enable R2 audio/image storage? Requires R2 enabled in YOUR Cloudflare account [y/N]: ')).trim());
48
+ console.log(`This creates a Worker and D1 database in YOUR Cloudflare account, writes ${config}, and deploys Glyph ${pkg.version}.`);
49
+ if(!/^y(es)?$/i.test((await question('Continue? [y/N]: ')).trim())) return;
50
+ // Release terminal input before Wrangler's own login and secret prompts.
51
+ question.close?.();
52
+ fs.mkdirSync(dir,{recursive:true});copyPayload(dir);
53
+ if(!existing) fs.writeFileSync(config,JSON.stringify(data,null,2)+'\n',{flag:'wx'});
54
+ const gitignore=path.join(dir,'.gitignore');
55
+ if(!fs.existsSync(gitignore)) fs.writeFileSync(gitignore,'.glyph/\n.wrangler/\n.dev.vars\n.env\n');
56
+ const common=['--config',config];
57
+ run(['login',...common]);
58
+ if(!readConfig(config).d1_databases?.some(db=>db.binding==='GLYPH_DB')) {
59
+ run(['d1','create',`${name}-accounts`,'--binding','GLYPH_DB','--update-config',...common]);
60
+ }
61
+ const current=readConfig(config);
62
+ const db=current.d1_databases?.find(db=>db.binding==='GLYPH_DB');
63
+ if(!db?.database_id) throw new Error('Wrangler did not bind GLYPH_DB; add the reported database ID to wrangler.json and rerun.');
64
+ db.migrations_dir='.glyph/worker/migrations';
65
+ fs.writeFileSync(config,JSON.stringify(current,null,2)+'\n');
66
+ if(r2) run(['r2','bucket','create',`${name}-media`,'--binding','GLYPH_COVERS','--update-config',...common]);
67
+ // Existing command prompts without echo and computes Argon2 locally; no
68
+ // plaintext admin password is persisted in the deployment project.
69
+ const binary=await require('./install.cjs').install();
70
+ const hashed=spawnSync(binary,['hash-password'],{stdio:['inherit','pipe','inherit'],encoding:'utf8'});
71
+ if(hashed.status!==0 || !hashed.stdout.trim().startsWith('$argon2')) throw new Error('Admin password hashing failed; rerun setup.');
72
+ const hashFile=path.join(dir,'.glyph',`admin-hash-${require('node:crypto').randomUUID()}.json`);
73
+ let created=false;
74
+ try {
75
+ fs.writeFileSync(hashFile,JSON.stringify({ADMIN_PASSWORD_HASH:hashed.stdout.trim()}),{mode:0o600,flag:'wx'});
76
+ created=true;
77
+ run(['secret','bulk',hashFile,...common]);
78
+ } finally {if(created) fs.rmSync(hashFile,{force:true});}
79
+ await deploy(config,{run});
80
+ }
81
+ async function deploy(file,{run=wrangler,copy=copyPayload,healthFetch=fetch}={}) {
82
+ file=path.resolve(file);const dir=path.dirname(file);
83
+ copy(dir);
84
+ // Generated projects use the bundled migrations. For existing TOML projects,
85
+ // Wrangler uses the owner's explicitly configured migrations directory.
86
+ if(path.basename(file)==='wrangler.json') {
87
+ const config=readConfig(file);
88
+ const db=config.d1_databases?.find(db=>db.binding==='GLYPH_DB');
89
+ if(db) db.migrations_dir='.glyph/worker/migrations';
90
+ config.main='.glyph/worker/index.js';delete config.build;
91
+ fs.writeFileSync(file,JSON.stringify(config,null,2)+'\n');
92
+ }
93
+ run(['d1','migrations','apply','GLYPH_DB','--remote','--config',file]);
94
+ let output=run(['deploy',path.join(dir,'.glyph/worker/index.js'),'--config',file],{capture:true});
95
+ let config=path.basename(file)==='wrangler.json'?readConfig(file):null;
96
+ let origin=config?.vars?.PUBLIC_ORIGIN;
97
+ if(config && !origin) {
98
+ origin=output.match(/https:\/\/[a-z0-9.-]+\.workers\.dev\b/i)?.[0];
99
+ if(!origin) throw new Error('Deployment completed; set PUBLIC_ORIGIN to its HTTPS URL in wrangler.json and run glyph deploy again to enable accounts.');
100
+ config.vars={...config.vars,PUBLIC_ORIGIN:origin};fs.writeFileSync(file,JSON.stringify(config,null,2)+'\n');
101
+ run(['deploy',path.join(dir,'.glyph/worker/index.js'),'--config',file]);
102
+ }
103
+ if(origin) {
104
+ const response=await healthFetch(`${origin}/v1/health`,{signal:AbortSignal.timeout(15000)});
105
+ const health=await response.json();
106
+ if(!response.ok || health.server_version!==pkg.version) throw new Error(`Deployed, but running version ${health.server_version||'unknown'} does not match ${pkg.version}; verify before retrying.`);
107
+ if(config?.d1_databases?.some(db=>db.binding==='GLYPH_DB') && !health.accounts) throw new Error('Deployed, but accounts are unavailable. Check PUBLIC_ORIGIN and GLYPH_DB before using this instance.');
108
+ console.log(`Verified Glyph ${health.server_version}: ${origin}\nNext: glyph remote login ${origin}`);
109
+ } else console.log('Deployment finished. Check your configured public URL with glyph version server --server <url>.');
110
+ }
111
+ module.exports={wrangler,template,setup,deploy,copyPayload};
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+ const {spawnSync}=require('node:child_process');
3
+ const path=require('node:path');
4
+ function docker(args,{capture=false,optional=false}={}) {
5
+ const result=spawnSync('docker',args,{encoding:'utf8',stdio:capture?['ignore','pipe','pipe']:'inherit',maxBuffer:4*1024*1024});
6
+ if(result.error || result.status!==0) {
7
+ if(optional) return null;
8
+ throw new Error(`Docker ${args[0]} failed. Check Docker access and your Compose project; no other services are updated.`);
9
+ }
10
+ return capture?result.stdout.trim():'';
11
+ }
12
+ function manage(dir,apply,{run=docker}={}) {
13
+ const compose=['compose','--project-directory',path.resolve(dir)];
14
+ const config=JSON.parse(run([...compose,'config','--format','json'],{capture:true}));
15
+ const image=config.services?.companion?.image;
16
+ if(!image) throw new Error('This Compose project needs a companion service with an image reference.');
17
+ let expected;
18
+ if(apply) {
19
+ run([...compose,'pull','companion']);
20
+ expected=run(['image','inspect',image,'--format','{{.Id}}'],{capture:true});
21
+ run([...compose,'up','-d','--no-deps','--wait','companion']);
22
+ }
23
+ const id=run([...compose,'ps','-q','companion'],{capture:true});
24
+ if(!id || id.split(/\s+/).length!==1) throw new Error('Expected exactly one running companion container.');
25
+ const state=JSON.parse(run(['inspect',id,'--format','{{json .}}'],{capture:true}));
26
+ if(!state.State?.Running || state.State.Health && state.State.Health.Status!=='healthy') throw new Error('Companion container is not healthy.');
27
+ if(expected && state.Image!==expected) throw new Error('Running companion image does not match the pulled image; update was not verified.');
28
+ const glyph=run(['exec',id,'glyph','--version'],{capture:true,optional:true})
29
+ || run(['exec',id,'glyph-server','--version'],{capture:true});
30
+ const rdlp=run(['exec',id,'r-dlp','--version'],{capture:true,optional:true});
31
+ const health=state.State.Health?.Status;
32
+ console.log(`Companion: ${glyph}\nr-dlp: ${rdlp||'not installed'}\nImage: ${state.Image}\n${apply?'Pulled configured image is running.':'Container is running.'} Health: ${health||'no healthcheck configured'}`);
33
+ return {glyph,rdlp,image:state.Image,health};
34
+ }
35
+ module.exports={manage,docker};
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const os = require('node:os');
5
+ const zlib = require('node:zlib');
6
+ const crypto = require('node:crypto');
7
+ const { spawnSync } = require('node:child_process');
8
+ const pkg = require('../package.json');
9
+ const MAX = 128 * 1024 * 1024;
10
+
11
+ function target(platform = process.platform, arch = process.arch) {
12
+ const targets = { 'win32-x64': 'x86_64-pc-windows-msvc', 'linux-x64': 'x86_64-unknown-linux-gnu',
13
+ 'linux-arm64': 'aarch64-unknown-linux-gnu', 'darwin-x64': 'x86_64-apple-darwin', 'darwin-arm64': 'aarch64-apple-darwin' };
14
+ const value = targets[`${platform}-${arch}`];
15
+ if (!value) throw new Error(`Unsupported platform ${platform}/${arch}. Download a compatible Glyph release instead.`);
16
+ if (platform === process.platform && platform === 'linux' && process.report?.getReport().header.glibcVersionRuntime === undefined) {
17
+ throw new Error('This Glyph build needs glibc Linux; Alpine/musl is not supported.');
18
+ }
19
+ return value;
20
+ }
21
+ function checksum(text, name) {
22
+ const entries = text.trim().split(/\r?\n/).map(line => line.match(/^([a-fA-F0-9]{64})\s+\*?(.+)$/))
23
+ .filter(m => m && m[2] === name);
24
+ if (entries.length !== 1) throw new Error(`No unique SHA-256 checksum for ${name}`);
25
+ return entries[0][1].toLowerCase();
26
+ }
27
+ // Parse into memory, never extract archive paths onto the filesystem.
28
+ function unpack(bytes, zip, names) {
29
+ if (zip) {
30
+ let eocd = -1;
31
+ for (let i = bytes.length - 22; i >= Math.max(0,bytes.length - 65557); i--) {
32
+ if (bytes.readUInt32LE(i) === 0x06054b50) { eocd = i; break; }
33
+ }
34
+ if (eocd < 0) throw new Error('Invalid ZIP archive');
35
+ let at = bytes.readUInt32LE(eocd + 16);
36
+ for (let n = 0; n < bytes.readUInt16LE(eocd + 10); n++) {
37
+ if (at + 46 > bytes.length || bytes.readUInt32LE(at) !== 0x02014b50) throw new Error('Invalid ZIP directory');
38
+ const nameLen = bytes.readUInt16LE(at + 28);
39
+ const name = bytes.subarray(at + 46,at + 46 + nameLen).toString();
40
+ const method = bytes.readUInt16LE(at + 10);
41
+ const size = bytes.readUInt32LE(at + 24);
42
+ const compressed = bytes.readUInt32LE(at + 20);
43
+ const local = bytes.readUInt32LE(at + 42);
44
+ if (names.includes(name)) {
45
+ if (size > MAX || local + 30 > bytes.length || bytes.readUInt32LE(local) !== 0x04034b50) throw new Error('Invalid ZIP member');
46
+ const start = local + 30 + bytes.readUInt16LE(local + 26) + bytes.readUInt16LE(local + 28);
47
+ if (start + compressed > bytes.length) throw new Error('Truncated ZIP member');
48
+ const raw = bytes.subarray(start,start + compressed);
49
+ const result = method === 0 ? raw : method === 8 ? zlib.inflateRawSync(raw,{maxOutputLength:MAX}) : null;
50
+ if (!result || result.length !== size) throw new Error('Unsupported or invalid ZIP member');
51
+ return result;
52
+ }
53
+ at += 46 + nameLen + bytes.readUInt16LE(at + 30) + bytes.readUInt16LE(at + 32);
54
+ }
55
+ } else {
56
+ const tar = zlib.gunzipSync(bytes,{maxOutputLength:MAX});
57
+ for (let at = 0; at + 512 <= tar.length;) {
58
+ const name = tar.subarray(at,at + 100).toString().split('\0')[0].replace(/^\.\//,'');
59
+ const prefix = tar.subarray(at + 345,at + 500).toString().split('\0')[0];
60
+ const size = parseInt(tar.subarray(at + 124,at + 136).toString().replace(/\0.*$/,'').trim() || '0',8);
61
+ if (!Number.isSafeInteger(size) || size < 0 || at + 512 + size > tar.length) throw new Error('Invalid TAR member');
62
+ if (!prefix && names.includes(name) && [0,48].includes(tar[at + 156])) return tar.subarray(at + 512,at + 512 + size);
63
+ at += 512 + Math.ceil(size / 512) * 512;
64
+ }
65
+ }
66
+ throw new Error('Glyph executable missing from release archive');
67
+ }
68
+ async function download(url, max = MAX) {
69
+ const response = await fetch(url,{signal:AbortSignal.timeout(120000)});
70
+ if (!response.ok) throw new Error(`Release download failed (HTTP ${response.status}). This CLI version must have a published GitHub release.`);
71
+ const chunks = []; let size = 0;
72
+ for await (const bytes of response.body) {
73
+ size += bytes.length;
74
+ if (size > max) throw new Error('Release download exceeds size limit');
75
+ chunks.push(bytes);
76
+ }
77
+ return Buffer.concat(chunks);
78
+ }
79
+ function executable() {
80
+ const base = process.platform === 'win32' ? (process.env.LOCALAPPDATA || os.homedir()) : (process.env.XDG_CACHE_HOME || path.join(os.homedir(),'.cache'));
81
+ return path.join(base,'glyph','cli',pkg.version,target(),process.platform === 'win32' ? 'glyph.exe' : 'glyph');
82
+ }
83
+ function verify(file, expected = pkg.version) {
84
+ const result = spawnSync(file,['--version'],{encoding:'utf8',timeout:10000,windowsHide:true});
85
+ return result.status === 0 && result.stdout.trim() === `glyph ${expected}`;
86
+ }
87
+ async function install() {
88
+ const file = executable();
89
+ if (fs.existsSync(file) && verify(file)) return file;
90
+ const name = `glyph-server-${pkg.version}-${target()}.${process.platform === 'win32' ? 'zip' : 'tar.gz'}`;
91
+ const base = `https://github.com/glyphmusic/server/releases/download/v${pkg.version}`;
92
+ const [archive, manifest] = await Promise.all([download(`${base}/${name}`),download(`${base}/SHA256SUMS.txt`,65536)]);
93
+ const hash = crypto.createHash('sha256').update(archive).digest('hex');
94
+ if (hash !== checksum(manifest.toString(),name)) throw new Error('SHA-256 mismatch; installation aborted');
95
+ const binary = unpack(archive,process.platform === 'win32',['glyph','glyph.exe','glyph-server','glyph-server.exe']);
96
+ fs.mkdirSync(path.dirname(file),{recursive:true,mode:0o700});
97
+ const staged = `${file}.${process.pid}.${crypto.randomBytes(6).toString('hex')}.new${process.platform === 'win32' ? '.exe' : ''}`;
98
+ try {
99
+ fs.writeFileSync(staged,binary,{mode:0o755,flag:'wx'});
100
+ if (!verify(staged)) throw new Error('Downloaded executable has the wrong Glyph version');
101
+ fs.renameSync(staged,file);
102
+ } finally { fs.rmSync(staged,{force:true}); }
103
+ return file;
104
+ }
105
+ module.exports = {target,checksum,unpack,download,executable,verify,install};
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "glyph-server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "Glyph CLI: install, diagnose and manage Glyph servers and companions",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": { "type": "git", "url": "git+https://github.com/glyphmusic/server.git" },
7
+ "engines": { "node": ">=22" },
8
+ "bin": { "glyph": "bin/glyph.cjs", "glyph-server": "bin/glyph.cjs" },
9
+ "files": ["bin/", "lib/", "worker/", "README.md", "LICENSE-MIT", "LICENSE-APACHE"],
10
+ "scripts": {
11
+ "postinstall": "node bin/install.cjs",
12
+ "test": "node --test test/*.test.cjs",
13
+ "prepack": "node bin/prepack.cjs"
14
+ },
15
+ "publishConfig": { "access": "public" }
16
+ }
@@ -0,0 +1,5 @@
1
+ import{WorkerEntrypoint as Rt}from"cloudflare:workers";var Y=globalThis.__worker_init_state={criticalError:!1,instanceId:0};import nt from"./index_bg.wasm";var A=class{constructor(){throw new Error("cannot invoke `new` directly")}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,ht.unregister(this),t}free(){let t=this.__destroy_into_raw();f();try{c.__wbg_containerstartupoptions_free(t,0)}catch(e){a(e)}}get enableInternet(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_containerstartupoptions_enableInternet(this.__wbg_ptr)}catch(e){a(e)}return t===16777215?void 0:t!==0}get entrypoint(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_containerstartupoptions_entrypoint(this.__wbg_ptr)}catch(n){a(n)}var e=st(t[0],t[1]);return c.__wbindgen_free(t[0],t[1]*4,4),e}get env(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_containerstartupoptions_env(this.__wbg_ptr)}catch(e){a(e)}return t}set enableInternet(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),u(t)||l(t),f();try{c.__wbg_set_containerstartupoptions_enableInternet(this.__wbg_ptr,u(t)?16777215:t?1:0)}catch(e){a(e)}}set entrypoint(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let e=N(t,c.__wbindgen_malloc),n=m;f();try{c.__wbg_set_containerstartupoptions_entrypoint(this.__wbg_ptr,e,n)}catch(o){a(o)}}set env(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),f();try{c.__wbg_set_containerstartupoptions_env(this.__wbg_ptr,t)}catch(e){a(e)}}};Symbol.dispose&&(A.prototype[Symbol.dispose]=A.prototype.free);var z=class{constructor(){throw new Error("cannot invoke `new` directly")}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,pt.unregister(this),t}free(){let t=this.__destroy_into_raw();f();try{c.__wbg_intounderlyingbytesource_free(t,0)}catch(e){a(e)}}get autoAllocateChunkSize(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.intounderlyingbytesource_autoAllocateChunkSize(this.__wbg_ptr)}catch(e){a(e)}return t>>>0}cancel(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let t=this.__destroy_into_raw();s(t),f();try{c.intounderlyingbytesource_cancel(t)}catch(e){a(e)}}pull(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let e;f();try{e=c.intounderlyingbytesource_pull(this.__wbg_ptr,t)}catch(n){a(n)}return e}start(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),f();try{c.intounderlyingbytesource_start(this.__wbg_ptr,t)}catch(e){a(e)}}get type(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.intounderlyingbytesource_type(this.__wbg_ptr)}catch(e){a(e)}return wt[t]}};Symbol.dispose&&(z.prototype[Symbol.dispose]=z.prototype.free);var P=class{constructor(){throw new Error("cannot invoke `new` directly")}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,yt.unregister(this),t}free(){let t=this.__destroy_into_raw();f();try{c.__wbg_intounderlyingsink_free(t,0)}catch(e){a(e)}}abort(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let e=this.__destroy_into_raw();s(e);let n;f();try{n=c.intounderlyingsink_abort(e,t)}catch(o){a(o)}return n}close(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let t=this.__destroy_into_raw();s(t);let e;f();try{e=c.intounderlyingsink_close(t)}catch(n){a(n)}return e}write(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let e;f();try{e=c.intounderlyingsink_write(this.__wbg_ptr,t)}catch(n){a(n)}return e}};Symbol.dispose&&(P.prototype[Symbol.dispose]=P.prototype.free);var M=class _{constructor(){throw new Error("cannot invoke `new` directly")}static __wrap(t){let e=Object.create(_.prototype);return e.__wbg_ptr=t,Object.defineProperty(e,"__wbg_inst",{value:g,writable:!0}),Z.register(e,{ptr:t,instance:g},e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Z.unregister(this),t}free(){let t=this.__destroy_into_raw();f();try{c.__wbg_intounderlyingsource_free(t,0)}catch(e){a(e)}}cancel(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let t=this.__destroy_into_raw();s(t),f();try{c.intounderlyingsource_cancel(t)}catch(e){a(e)}}pull(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let e;f();try{e=c.intounderlyingsource_pull(this.__wbg_ptr,t)}catch(n){a(n)}return e}};Symbol.dispose&&(M.prototype[Symbol.dispose]=M.prototype.free);var x=class _{constructor(){throw new Error("cannot invoke `new` directly")}static __wrap(t){let e=Object.create(_.prototype);return e.__wbg_ptr=t,Object.defineProperty(e,"__wbg_inst",{value:g,writable:!0}),tt.register(e,{ptr:t,instance:g},e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,tt.unregister(this),t}free(){let t=this.__destroy_into_raw();f();try{c.__wbg_minifyconfig_free(t,0)}catch(e){a(e)}}get css(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_minifyconfig_css(this.__wbg_ptr)}catch(e){a(e)}return t!==0}get html(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_minifyconfig_html(this.__wbg_ptr)}catch(e){a(e)}return t!==0}get js(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_minifyconfig_js(this.__wbg_ptr)}catch(e){a(e)}return t!==0}set css(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),l(t),f();try{c.__wbg_set_minifyconfig_css(this.__wbg_ptr,t)}catch(e){a(e)}}set html(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),l(t),f();try{c.__wbg_set_minifyconfig_html(this.__wbg_ptr,t)}catch(e){a(e)}}set js(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),l(t),f();try{c.__wbg_set_minifyconfig_js(this.__wbg_ptr,t)}catch(e){a(e)}}};Symbol.dispose&&(x.prototype[Symbol.dispose]=x.prototype.free);var R=class{constructor(){throw new Error("cannot invoke `new` directly")}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,vt.unregister(this),t}free(){let t=this.__destroy_into_raw();f();try{c.__wbg_r2range_free(t,0)}catch(e){a(e)}}get length(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_r2range_length(this.__wbg_ptr)}catch(e){a(e)}return t[0]===0?void 0:t[1]}get offset(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_r2range_offset(this.__wbg_ptr)}catch(e){a(e)}return t[0]===0?void 0:t[1]}get suffix(){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr);let t;f();try{t=c.__wbg_get_r2range_suffix(this.__wbg_ptr)}catch(e){a(e)}return t[0]===0?void 0:t[1]}set length(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),u(t)||s(t),f();try{c.__wbg_set_r2range_length(this.__wbg_ptr,!u(t),u(t)?0:t)}catch(e){a(e)}}set offset(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),u(t)||s(t),f();try{c.__wbg_set_r2range_offset(this.__wbg_ptr,!u(t),u(t)?0:t)}catch(e){a(e)}}set suffix(t){if(this.__wbg_inst!==void 0&&this.__wbg_inst!==g)throw new Error("Invalid stale object from previous Wasm instance");if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");s(this.__wbg_ptr),u(t)||s(t),f();try{c.__wbg_set_r2range_suffix(this.__wbg_ptr,!u(t),u(t)?0:t)}catch(e){a(e)}}};Symbol.dispose&&(R.prototype[Symbol.dispose]=R.prototype.free);function U(){g++,I=null,j=null,S=null,typeof numBytesDecoded<"u"&&(numBytesDecoded=0),typeof m<"u"&&(m=0),K=!1,C=!1,H=new WebAssembly.Instance(nt,ct()),c=H.exports,c.__wbindgen_start()}function rt(){let _;f();try{_=c.__worker_init_state()}catch(t){a(t)}return _}function _t(_,t,e){let n;f();try{n=c.fetch(_,t,e)}catch(o){a(o)}return n}function ot(_,t,e){let n;f();try{n=c.scheduled(_,t,e)}catch(o){a(o)}return n}function ct(){return{__proto__:null,"./index_bg.js":{__proto__:null,__wbg_Error_30c8987f7c2ed4e2:function(){return r(function(t,e){return Error(h(t,e))},arguments)},__wbg_Number_14af1003b8dd5ead:function(){return r(function(t){return Number(t)},arguments)},__wbg_String_8564e559799eccda:function(){return r(function(t,e){let n=String(e),o=p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg___wbindgen_bigint_get_as_i64_a2383202b9353e4c:function(t,e){let n=e,o=typeof n=="bigint"?n:void 0;u(o)||Et(o),b().setBigInt64(t+8,u(o)?BigInt(0):o,!0),b().setInt32(t+0,!u(o),!0)},__wbg___wbindgen_boolean_get_5b446f51afd21013:function(t){let e=t,n=typeof e=="boolean"?e:void 0;return u(n)||l(n),u(n)?16777215:n?1:0},__wbg___wbindgen_debug_string_4687d8d8c2017d52:function(t,e){let n=$(e),o=p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},__wbg___wbindgen_in_92f62ee1427d9e49:function(t,e){let n=t in e;return l(n),n},__wbg___wbindgen_is_bigint_b123553bed3bb382:function(t){let e=typeof t=="bigint";return l(e),e},__wbg___wbindgen_is_function_1f9d30630b8b1d3d:function(t){let e=typeof t=="function";return l(e),e},__wbg___wbindgen_is_null_e343b7d08827ba72:function(t){let e=t===null;return l(e),e},__wbg___wbindgen_is_null_or_undefined_f9435d56bdcc06df:function(t){let e=t==null;return l(e),e},__wbg___wbindgen_is_object_3c45d4f2dde4e749:function(t){let e=t,n=typeof e=="object"&&e!==null;return l(n),n},__wbg___wbindgen_is_string_90b56bc79aad6f6c:function(t){let e=typeof t=="string";return l(e),e},__wbg___wbindgen_is_undefined_8865fb403f8fe9d8:function(t){let e=t===void 0;return l(e),e},__wbg___wbindgen_jsval_eq_02babf21faa37971:function(t,e){let n=t===e;return l(n),n},__wbg___wbindgen_jsval_loose_eq_677f21e468d6b461:function(t,e){let n=t==e;return l(n),n},__wbg___wbindgen_number_get_2e0e7dee9f701a71:function(t,e){let n=e,o=typeof n=="number"?n:void 0;u(o)||s(o),b().setFloat64(t+8,u(o)?0:o,!0),b().setInt32(t+0,!u(o),!0)},__wbg___wbindgen_reinit_3f79fdb34dee3ea9:function(){C=!0},__wbg___wbindgen_string_get_0380ccaa2f57f0d9:function(t,e){let n=e,o=typeof n=="string"?n:void 0;var i=u(o)?0:p(o,c.__wbindgen_malloc,c.__wbindgen_realloc),d=m;b().setInt32(t+4,d,!0),b().setInt32(t+0,i,!0)},__wbg___wbindgen_throw_41e9ee4f547fc59a:function(t,e){throw new WebAssembly.Exception(J,[new Error(h(t,e))])},__wbg__wbg_cb_unref_dcc1a90847f04c41:function(){return r(function(t){t._wbg_cb_unref()},arguments)},__wbg_all_2228d6712e7ddb97:function(){return r(function(t){return t.all()},arguments)},__wbg_arrayBuffer_7b8b2e9be0285525:function(){return r(function(t){return t.arrayBuffer()},arguments)},__wbg_batch_6b58fc32d9c19d60:function(){return r(function(t,e){return t.batch(e)},arguments)},__wbg_bind_1f842289d2018ed8:function(){return r(function(t,e){return t.bind(...e)},arguments)},__wbg_bodyUsed_3527d29edfc2c752:function(){return r(function(t){let e=t.bodyUsed;return l(e),e},arguments)},__wbg_body_4792166cb351f162:function(){return r(function(t){let e=t.body;return u(e)?0:v(e)},arguments)},__wbg_body_4e088733babc630d:function(){return r(function(t){let e=t.body;return u(e)?0:v(e)},arguments)},__wbg_body_a3a2b558805a2b84:function(){return r(function(t){return t.body},arguments)},__wbg_buffer_56ec2905a66f58b9:function(){return r(function(t){return t.buffer},arguments)},__wbg_byobRequest_54f7ce41d584549a:function(){return r(function(t){let e=t.byobRequest;return u(e)?0:v(e)},arguments)},__wbg_byteLength_9f985b8373f1f3fe:function(){return r(function(t){let e=t.byteLength;return s(e),e},arguments)},__wbg_byteOffset_0bd5a6a03553639c:function(){return r(function(t){let e=t.byteOffset;return s(e),e},arguments)},__wbg_cacheControl_6ea9be880720803d:function(){return r(function(t,e){let n=e.cacheControl;var o=u(n)?0:p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_cacheExpiry_ee9de6a8c623e1a8:function(){return r(function(t){let e=t.cacheExpiry;return u(e)?0:v(e)},arguments)},__wbg_caches_0c4f8c535a6a0595:function(){return r(function(t){return t.caches},arguments)},__wbg_call_1875a20c43a36133:function(){return r(function(t,e,n,o){return t.call(e,n,o)},arguments)},__wbg_call_187d372bd5fdd4aa:function(){return r(function(t,e,n){return t.call(e,n)},arguments)},__wbg_call_939a2607c4484b0b:function(){return r(function(t,e,n,o,i){return t.call(e,n,o,i)},arguments)},__wbg_cancel_7c2a08c8db4c73f3:function(){return r(function(t){return t.cancel()},arguments)},__wbg_catch_92594c2d17f55f12:function(){return r(function(t,e){return t.catch(e)},arguments)},__wbg_cause_19276d032a32d4bd:function(){return r(function(t){return t.cause},arguments)},__wbg_cf_909bcfb212a8822c:function(){return r(function(t){let e=t.cf;return u(e)?0:v(e)},arguments)},__wbg_cf_b47fe5ff6d015a0d:function(){return r(function(t){let e=t.cf;return u(e)?0:v(e)},arguments)},__wbg_clearTimeout_d49a4afcd9b218b7:function(){return r(function(t,e){t.clearTimeout(e)},arguments)},__wbg_clone_0bde657d3f85c2d1:function(){return r(function(t){return t.clone()},arguments)},__wbg_clone_946565396b302dfb:function(){return r(function(t){return t.clone()},arguments)},__wbg_close_185286988f30f252:function(){return r(function(t){t.close()},arguments)},__wbg_close_748f26698dabe269:function(){return r(function(t){t.close()},arguments)},__wbg_constructor_076176ce0f386e16:function(){return r(function(t){return t.constructor},arguments)},__wbg_contentDisposition_07447c7ffe1f25b9:function(){return r(function(t,e){let n=e.contentDisposition;var o=u(n)?0:p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_contentEncoding_0a83e35746c3ada7:function(){return r(function(t,e){let n=e.contentEncoding;var o=u(n)?0:p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_contentLanguage_ac8796c815bdf6a7:function(){return r(function(t,e){let n=e.contentLanguage;var o=u(n)?0:p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_contentType_e59097c6037d86e1:function(){return r(function(t,e){let n=e.contentType;var o=u(n)?0:p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_country_e8b34ad6526ea4f9:function(){return r(function(t,e){let n=e.country;var o=u(n)?0:p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_cron_76b7eba30bc0443e:function(){return r(function(t,e){let n=e.cron,o=p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_crypto_38df2bab126b63dc:function(){return r(function(t){return t.crypto},arguments)},__wbg_cursor_1c9a92814964774c:function(){return r(function(t,e){let n=e.cursor;var o=u(n)?0:p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_customMetadata_9734802d06bda433:function(){return r(function(t){return t.customMetadata},arguments)},__wbg_default_15d5007f8b46e0bc:function(){return r(function(t){return t.default},arguments)},__wbg_delete_4a8ee012c43b86c0:function(){return r(function(t,e,n){let o,i;try{return o=e,i=n,t.delete(h(e,n))}finally{f();try{c.__wbindgen_free(o,i,1)}catch(d){a(d)}}},arguments)},__wbg_delete_4f3412b083521508:function(){return r(function(t,e,n){var o=st(e,n);return c.__wbindgen_free(e,n*4,4),t.delete(o)},arguments)},__wbg_done_b41a1d26cdb37fb6:function(){return r(function(t){let e=t.done;return l(e),e},arguments)},__wbg_enqueue_4a01c128f9a0de16:function(){return r(function(t,e){t.enqueue(e)},arguments)},__wbg_entries_b55ec7e0dc443355:function(){return r(function(t){return t.entries()},arguments)},__wbg_error_757e9472f8410341:function(){return r(function(t,e){let n,o;try{n=t,o=e,console.error(h(t,e))}finally{f();try{c.__wbindgen_free(n,o,1)}catch(i){a(i)}}},arguments)},__wbg_error_a30e98d44009f1bb:function(){return r(function(t,e){console.error(t,e)},arguments)},__wbg_error_c9cf3fc2064683a9:function(){return r(function(t){console.error(t)},arguments)},__wbg_fetch_0e46da8cf7c730e4:function(){return r(function(t,e,n,o){return t.fetch(h(e,n),o)},arguments)},__wbg_fetch_7b5de4f88137a4dc:function(){return r(function(t,e,n){return t.fetch(e,n)},arguments)},__wbg_first_3f7220e4ae4ce878:function(){return r(function(t,e,n){return t.first(e===0?void 0:h(e,n))},arguments)},__wbg_getRandomValues_c44a50d8cfdaebeb:function(){return r(function(t,e){t.getRandomValues(e)},arguments)},__wbg_getReader_bf34f92ee19c42b4:function(){return r(function(t){return t.getReader()},arguments)},__wbg_getTime_f5a55efff2585d5d:function(){return r(function(t){return t.getTime()},arguments)},__wbg_get_31af05bd4842a84f:function(){return r(function(t,e){return Reflect.get(t,e)},arguments)},__wbg_get_6c896e0571ddae51:function(){return r(function(t,e){return t[e>>>0]},arguments)},__wbg_get_834ef2d65b3b5c73:function(){return r(function(t,e,n,o){let i,d;try{return i=e,d=n,t.get(h(e,n),o)}finally{f();try{c.__wbindgen_free(i,d,1)}catch(w){a(w)}}},arguments)},__wbg_get_88983e33467eae60:function(){return r(function(t,e){let n=Reflect.get(t,e);return u(n)?0:v(n)},arguments)},__wbg_get_done_7020b91c987365c7:function(){return r(function(t){let e=t.done;return u(e)||l(e),u(e)?16777215:e?1:0},arguments)},__wbg_get_f75619e20cb68514:function(){return r(function(t,e,n,o){let i=e.get(h(n,o));var d=u(i)?0:p(i,c.__wbindgen_malloc,c.__wbindgen_realloc),w=m;b().setInt32(t+4,w,!0),b().setInt32(t+0,d,!0)},arguments)},__wbg_get_unchecked_288889d017702237:function(){return r(function(t,e){return t[e>>>0]},arguments)},__wbg_get_value_87fbd6ad1283f2e7:function(){return r(function(t){return t.value},arguments)},__wbg_get_with_ref_key_6412cf3094599694:function(){return r(function(t,e){return t[e]},arguments)},__wbg_headers_6930a8bd09b630de:function(){return r(function(t){return t.headers},arguments)},__wbg_headers_eba93595f8944c2f:function(){return r(function(t){return t.headers},arguments)},__wbg_httpMetadata_529f7924a4f73fdd:function(){return r(function(t){return t.httpMetadata},arguments)},__wbg_instanceId_9b67ff33ae8bef8a:function(){return r(function(t){let e=t.instanceId;return s(e),e},arguments)},__wbg_instanceof_ArrayBuffer_a99f175873e5d9b8:function(){return r(function(t){let e;try{e=t instanceof ArrayBuffer}catch{e=!1}let n=e;return l(n),n},arguments)},__wbg_instanceof_Error_80a725f81f2e102d:function(){return r(function(t){let e;try{e=t instanceof Error}catch{e=!1}let n=e;return l(n),n},arguments)},__wbg_instanceof_ReadableStream_e2d77912575119ab:function(){return r(function(t){let e;try{e=t instanceof ReadableStream}catch{e=!1}let n=e;return l(n),n},arguments)},__wbg_instanceof_Response_b8758567269c30b2:function(){return r(function(t){let e;try{e=t instanceof Response}catch{e=!1}let n=e;return l(n),n},arguments)},__wbg_instanceof_Uint8Array_828cef2aaacafc31:function(){return r(function(t){let e;try{e=t instanceof Uint8Array}catch{e=!1}let n=e;return l(n),n},arguments)},__wbg_isArray_e15a2ff68ffdbef2:function(){return r(function(t){let e=Array.isArray(t);return l(e),e},arguments)},__wbg_isSafeInteger_717808ad6a54bd9e:function(){return r(function(t){let e=Number.isSafeInteger(t);return l(e),e},arguments)},__wbg_key_84de5b594a30a514:function(){return r(function(t,e){let n=e.key,o=p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_keys_440be172f17c0265:function(){return r(function(t){return Object.keys(t)},arguments)},__wbg_keys_bac434c8972731d5:function(){return r(function(t){return t.keys()},arguments)},__wbg_length_7f3c00c40364105e:function(){return r(function(t){let e=t.length;return s(e),e},arguments)},__wbg_length_d4bdea10311bd9cf:function(){return r(function(t){let e=t.length;return s(e),e},arguments)},__wbg_list_9f5101697159e282:function(){return r(function(t,e){return t.list(e)},arguments)},__wbg_log_17c30ef363c61cf4:function(){return r(function(t){console.log(t)},arguments)},__wbg_match_4ddd34bd7a34ad07:function(){return r(function(t,e,n,o){return t.match(h(e,n),o)},arguments)},__wbg_match_c2e851fa5be0ea84:function(){return r(function(t,e,n){return t.match(e,n)},arguments)},__wbg_message_5f8387f0c32b90a7:function(){return r(function(t){return t.message},arguments)},__wbg_meta_594bb85654c055e4:function(){return r(function(t){return t.meta},arguments)},__wbg_method_6d02ee0808a7de31:function(){return r(function(t,e){let n=e.method,o=p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_minifyconfig_new:function(){return r(function(t){return x.__wrap(t)},arguments)},__wbg_msCrypto_bd5a034af96bcba6:function(){return r(function(t){return t.msCrypto},arguments)},__wbg_name_e2eac7cdfa054f65:function(){return r(function(t){return t.name},arguments)},__wbg_name_f9b814d78e8e299f:function(){return r(function(t){return t.name},arguments)},__wbg_new_0_72d020f0c63443d4:function(){return r(function(){return new Date},arguments)},__wbg_new_1dbf7428bba60a42:function(){return r(function(t){return new Uint8Array(t)},arguments)},__wbg_new_227d7c05414eb861:function(){return r(function(){return new Error},arguments)},__wbg_new_28744009d011f847:function(){return r(function(){return new Map},arguments)},__wbg_new_343a093a3c2ffb4e:function(){return r(function(t,e){return new Error(h(t,e))},arguments)},__wbg_new_617a8cdb8bb1130e:function(){return r(function(){return new Object},arguments)},__wbg_new_83ca405eae412a62:function(){return r(function(){return new Headers},arguments)},__wbg_new_big_int_84cdc69174f81f5b:function(){return r(function(t){return new FixedLengthStream(t)},arguments)},__wbg_new_ee2291f50781bf1d:function(){return r(function(){return new Array},arguments)},__wbg_new_f569a2e335eed0bb:function(){return r(function(t){return new FixedLengthStream(t>>>0)},arguments)},__wbg_new_from_slice_9a868026ffa4208a:function(){return r(function(t,e){return new Uint8Array(O(t,e))},arguments)},__wbg_new_typed_b01cb72a8af741a3:function(){return r(function(t,e){try{var n={a:t,b:e},o=(d,w)=>{let y=n.a;n.a=0;try{return dt(y,n.b,d,w)}finally{n.a=y}};return new Promise(o)}finally{n.a=0}},arguments)},__wbg_new_with_byte_offset_and_length_2f5d7fc2a828b74d:function(){return r(function(t,e,n){return new Uint8Array(t,e>>>0,n>>>0)},arguments)},__wbg_new_with_headers_7eaf3e64bd3f0a23:function(){return r(function(t){return new Headers(t)},arguments)},__wbg_new_with_into_underlying_source_a57cfcc7c705351c:function(){return r(function(t,e){return new ReadableStream(M.__wrap(t),e)},arguments)},__wbg_new_with_length_3da0ad195f6f63ba:function(){return r(function(t){return new Uint8Array(t>>>0)},arguments)},__wbg_new_with_opt_buffer_source_and_init_c1b859a23c80afca:function(){return r(function(t,e){return new Response(t,e)},arguments)},__wbg_new_with_opt_readable_stream_and_init_df114f2d364f216d:function(){return r(function(t,e){return new Response(t,e)},arguments)},__wbg_new_with_opt_str_and_init_33bef1b272950372:function(){return r(function(t,e,n){return new Response(t===0?void 0:h(t,e),n)},arguments)},__wbg_new_with_str_and_init_4618dee4e950224f:function(){return r(function(t,e,n){return new Request(h(t,e),n)},arguments)},__wbg_next_f4aac29c42af995c:function(){return r(function(t){return t.next()},arguments)},__wbg_node_84ea875411254db1:function(){return r(function(t){return t.node},arguments)},__wbg_now_aa4ccb83129e9e55:function(){return r(function(){return Date.now()},arguments)},__wbg_objects_5b390b93a9ffcef3:function(){return r(function(t,e){let n=e.objects,o=N(n,c.__wbindgen_malloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_pipeTo_ac05d32161ffb42c:function(){return r(function(t,e){return t.pipeTo(e)},arguments)},__wbg_prepare_6fe68a8990920f81:function(){return r(function(t,e,n){return t.prepare(h(e,n))},arguments)},__wbg_process_44c7a14e11e9f69e:function(){return r(function(t){return t.process},arguments)},__wbg_prototypesetcall_bc27214492979395:function(){return r(function(t,e,n){Uint8Array.prototype.set.call(O(t,e),n)},arguments)},__wbg_push_2baf45db356cf468:function(){return r(function(t,e){let n=t.push(e);return s(n),n},arguments)},__wbg_put_867461fd552109b2:function(){return r(function(t,e,n){return t.put(e,n)},arguments)},__wbg_put_bbca42771defa466:function(){return r(function(t,e,n,o){return t.put(h(e,n),o)},arguments)},__wbg_put_ece41e2507acd81b:function(){return r(function(t,e,n,o,i){let d,w;try{return d=e,w=n,t.put(h(e,n),o,i)}finally{f();try{c.__wbindgen_free(d,w,1)}catch(y){a(y)}}},arguments)},__wbg_queueMicrotask_9833f9a49df95a49:function(){return r(function(t){return t.queueMicrotask},arguments)},__wbg_queueMicrotask_a72f977e97f23c5f:function(){return r(function(t){queueMicrotask(t)},arguments)},__wbg_randomFillSync_6c25eac9869eb53c:function(){return r(function(t,e){t.randomFillSync(e)},arguments)},__wbg_read_2a943774344c9728:function(){return r(function(t){return t.read()},arguments)},__wbg_readable_4d43535945ae9ca0:function(){return r(function(t){return t.readable},arguments)},__wbg_region_539ec060a01aca98:function(){return r(function(t,e){let n=e.region;var o=u(n)?0:p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_releaseLock_eb64cd83aa9fcfe4:function(){return r(function(t){t.releaseLock()},arguments)},__wbg_require_b4edbdcf3e2a1ef0:function(){return r(function(){return module.require},arguments)},__wbg_resolve_0076e10020304ede:function(){return r(function(t){return Promise.resolve(t)},arguments)},__wbg_respond_c102fabcc79e5ef0:function(){return r(function(t,e){t.respond(e>>>0)},arguments)},__wbg_results_a5533c886ed43a9a:function(){return r(function(t){let e=t.results;return u(e)?0:v(e)},arguments)},__wbg_run_0ef9f3480a049b01:function(){return r(function(t){return t.run()},arguments)},__wbg_run_6e1f787af721bfe6:function(){return r(function(t,e,n){try{var o={a:e,b:n},i=()=>{let w=o.a;o.a=0;try{return ft(w,o.b)}finally{o.a=w}};let d=t.run(i);return l(d),d}finally{o.a=0}},arguments)},__wbg_scheduledTime_d6f16c8277d5313d:function(){return r(function(t){return t.scheduledTime},arguments)},__wbg_setTimeout_7fb1e1fe294b6ad9:function(){return r(function(t,e,n){let o=t.setTimeout(e,n);return s(o),o},arguments)},__wbg_set_145a351398b48c65:function(){return r(function(t,e,n){let o=Reflect.set(t,e,n);return l(o),o},arguments)},__wbg_set_575d3ddb70fe831d:function(){return r(function(t,e,n){t.set(O(e,n))},arguments)},__wbg_set_6ae97e73113c4f0b:function(){return r(function(t,e,n){return t.set(e,n)},arguments)},__wbg_set_6be42768c690e380:function(){return r(function(t,e,n){t[e]=n},arguments)},__wbg_set_af5932e3f78b5648:function(){return r(function(t,e,n,o,i){t.set(h(e,n),h(o,i))},arguments)},__wbg_set_bea140a88be9b277:function(){return r(function(t,e,n){t[e>>>0]=n},arguments)},__wbg_set_body_1fb0f1008bfc7df6:function(){return r(function(t,e){t.body=e},arguments)},__wbg_set_cache_7507c4cc5938ccc7:function(){return r(function(t,e){t.cache=lt[e]},arguments)},__wbg_set_criticalError_3904d60fe2a0b05b:function(){return r(function(t,e){t.criticalError=e!==0},arguments)},__wbg_set_headers_40ad33dcf016613f:function(){return r(function(t,e){t.headers=e},arguments)},__wbg_set_headers_69ef7c46a2e6c742:function(){return r(function(t,e){t.headers=e},arguments)},__wbg_set_high_water_mark_3a96edf83df7e06c:function(){return r(function(t,e){t.highWaterMark=e},arguments)},__wbg_set_ignore_method_5b0a1aa453c4d6d2:function(){return r(function(t,e){t.ignoreMethod=e!==0},arguments)},__wbg_set_instanceId_9ad5caac0a4e519c:function(){return r(function(t,e){t.instanceId=e>>>0},arguments)},__wbg_set_method_dcb32343247ec427:function(){return r(function(t,e,n){t.method=h(e,n)},arguments)},__wbg_set_redirect_cc128ab2411da334:function(){return r(function(t,e){t.redirect=mt[e]},arguments)},__wbg_set_signal_2dbd377604627f26:function(){return r(function(t,e){t.signal=e},arguments)},__wbg_set_status_678f122cbe435d95:function(){return r(function(t,e){t.status=e},arguments)},__wbg_size_023ff299b19aa360:function(){return r(function(t){return t.size},arguments)},__wbg_slice_6da4cdc5d543fcd0:function(){return r(function(t,e){let n=e.slice(),o=N(n,c.__wbindgen_malloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_stack_3b0d974bbf31e44f:function(){return r(function(t,e){let n=e.stack,o=p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_static_accessor_CREATE_TASK_7e310091636beacc:function(){return r(function(){let t=typeof console>"u"?null:console?.createTask;return u(t)?0:v(t)},arguments)},__wbg_static_accessor_GLOBAL_266715b9d96ba635:function(){return r(function(){let t=typeof global>"u"?null:global;return u(t)?0:v(t)},arguments)},__wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179:function(){return r(function(){let t=typeof globalThis>"u"?null:globalThis;return u(t)?0:v(t)},arguments)},__wbg_static_accessor_INIT_STATE_e3fce2ad8a08e94e:function(){return r(function(){return Y},arguments)},__wbg_static_accessor_SELF_0b583911f537483a:function(){return r(function(){let t=typeof self>"u"?null:self;return u(t)?0:v(t)},arguments)},__wbg_static_accessor_WINDOW_d7f903d1508cbdc4:function(){return r(function(){let t=typeof window>"u"?null:window;return u(t)?0:v(t)},arguments)},__wbg_status_ce0a98d3c57125f3:function(){return r(function(t){let e=t.status;return s(e),e},arguments)},__wbg_subarray_002b94d5e13d1411:function(){return r(function(t,e,n){return t.subarray(e>>>0,n>>>0)},arguments)},__wbg_then_c949d5a25a4e78f8:function(){return r(function(t,e,n){return t.then(e,n)},arguments)},__wbg_then_e71170d78fcf8954:function(){return r(function(t,e){return t.then(e)},arguments)},__wbg_truncated_cc05a4223c013ee9:function(){return r(function(t){let e=t.truncated;return l(e),e},arguments)},__wbg_uploaded_19ec3882ff291aab:function(){return r(function(t){return t.uploaded},arguments)},__wbg_url_7bfada5c2297bc70:function(){return r(function(t,e){let n=e.url,o=p(n,c.__wbindgen_malloc,c.__wbindgen_realloc),i=m;b().setInt32(t+4,i,!0),b().setInt32(t+0,o,!0)},arguments)},__wbg_value_f3c585ee8f5ba40c:function(){return r(function(t){return t.value},arguments)},__wbg_versions_276b2795b1c6a219:function(){return r(function(t){return t.versions},arguments)},__wbg_view_9c570f33e8d6ab96:function(){return r(function(t){let e=t.view;return u(e)?0:v(e)},arguments)},__wbg_waitUntil_c51e37673c596e00:function(){return r(function(t,e){t.waitUntil(e)},arguments)},__wbg_webSocket_2b7e8e9549bed673:function(){return r(function(t){let e=t.webSocket;return u(e)?0:v(e)},arguments)},__wbg_writable_44735d15a1cee85d:function(){return r(function(t){return t.writable},arguments)},__wbindgen_generic_0000000000000001:function(){return r(function(t,e){return D(t,e,gt)},arguments)},__wbindgen_generic_0000000000000002:function(){return r(function(t,e){return D(t,e,bt)},arguments)},__wbindgen_generic_0000000000000003:function(){return r(function(t,e){return D(t,e,at)},arguments)},__wbindgen_generic_0000000000000004:function(){return r(function(t){return t},arguments)},__wbindgen_generic_0000000000000005:function(){return r(function(t){return t},arguments)},__wbindgen_generic_0000000000000006:function(){return r(function(t,e){return O(t,e)},arguments)},__wbindgen_generic_0000000000000007:function(){return r(function(t,e){return h(t,e)},arguments)},__wbindgen_generic_0000000000000008:function(){return r(function(t){return BigInt.asUintN(64,t)},arguments)},__wbindgen_init_externref_table:function(){let t=c.__wbindgen_externrefs,e=t.grow(4);t.set(0,void 0),t.set(e+0,void 0),t.set(e+1,null),t.set(e+2,!0),t.set(e+3,!1)},__wbindgen_jstag:WebAssembly.JSTag,__wbindgen_rethrow_critical:function(t){throw new Error("Critical error",{cause:t})}}}}var J=new WebAssembly.Tag({parameters:["externref"]}),B,K=!1;function it(){K=!0;try{let _=G()[c.__abort_handler.value/4];_&&c.__wbindgen_export.get(_)()}catch{}}function a(_){throw _ instanceof WebAssembly.Exception&&_.is(J)?_.getArg(J,0):(G()[B]=1,it(),_)}function f(){if(B??=c.__instance_terminated.value/4,G()[B]){if(K||it(),C){U();return}throw new Error("Module terminated")}else C&&U()}function at(_,t){s(_),s(t),f();try{c.wasm_bindgen_c4ceaed92c40d81e___convert__closures_____invoke_______true_(_,t)}catch(e){a(e)}}function ft(_,t){s(_),s(t);let e;f();try{e=c.wasm_bindgen_c4ceaed92c40d81e___convert__closures_____invoke___bool__true_(_,t)}catch(n){a(n)}return e!==0}function bt(_,t,e){s(_),s(t),f();try{c.wasm_bindgen_c4ceaed92c40d81e___convert__closures_____invoke___wasm_bindgen_c4ceaed92c40d81e___JsValue______true_(_,t,e)}catch(n){a(n)}}function gt(_,t,e){s(_),s(t);let n;f();try{n=c.wasm_bindgen_c4ceaed92c40d81e___convert__closures_____invoke___wasm_bindgen_c4ceaed92c40d81e___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_c4ceaed92c40d81e___JsError___true_(_,t,e)}catch(o){a(o)}if(n[1])throw It(n[0])}function dt(_,t,e,n){s(_),s(t),f();try{c.wasm_bindgen_c4ceaed92c40d81e___convert__closures_____invoke___js_sys_39645a1f55c401c1___Function_fn_wasm_bindgen_c4ceaed92c40d81e___JsValue_____wasm_bindgen_c4ceaed92c40d81e___sys__Undefined___js_sys_39645a1f55c401c1___Function_fn_wasm_bindgen_c4ceaed92c40d81e___JsValue_____wasm_bindgen_c4ceaed92c40d81e___sys__Undefined_______true_(_,t,e,n)}catch(o){a(o)}}var wt=["bytes"],lt=["default","no-store","reload","no-cache","force-cache","only-if-cached"],mt=["follow","error","manual"],g=0,ht=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(({ptr:_,instance:t})=>{t===g&&c.__wbg_containerstartupoptions_free(_,1)}),pt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(({ptr:_,instance:t})=>{t===g&&c.__wbg_intounderlyingbytesource_free(_,1)}),yt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(({ptr:_,instance:t})=>{t===g&&c.__wbg_intounderlyingsink_free(_,1)}),Z=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(({ptr:_,instance:t})=>{t===g&&c.__wbg_intounderlyingsource_free(_,1)}),tt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(({ptr:_,instance:t})=>{t===g&&c.__wbg_minifyconfig_free(_,1)}),vt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(({ptr:_,instance:t})=>{t===g&&c.__wbg_r2range_free(_,1)});function v(_){let t=c.__externref_table_alloc();return c.__wbindgen_externrefs.set(t,_),t}function Et(_){if(typeof _!="bigint")throw new Error(`expected a bigint argument, found ${typeof _}`)}function l(_){if(typeof _!="boolean")throw new Error(`expected a boolean argument, found ${typeof _}`)}function s(_){if(typeof _!="number")throw new Error(`expected a number argument, found ${typeof _}`)}var et=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(_=>{_.instance===g&&c.__wbindgen_destroy_closure(_.a,_.b)});function $(_){let t=typeof _;if(t=="number"||t=="boolean"||_==null)return`${_}`;if(t=="string")return`"${_}"`;if(t=="symbol"){let o=_.description;return o==null?"Symbol":`Symbol(${o})`}if(t=="function"){let o=_.name;return typeof o=="string"&&o.length>0?`Function(${o})`:"Function"}if(Array.isArray(_)){let o=_.length,i="[";o>0&&(i+=$(_[0]));for(let d=1;d<o;d++)i+=", "+$(_[d]);return i+="]",i}let e=/\[object ([^\]]+)\]/.exec(toString.call(_)),n;if(e&&e.length>1)n=e[1];else return toString.call(_);if(n=="Object")try{return"Object("+JSON.stringify(_)+")"}catch{return"Object"}return _ instanceof Error?`${_.name}: ${_.message}
2
+ ${_.stack}`:n}function st(_,t){_=_>>>0;let e=b(),n=[];for(let o=_;o<_+4*t;o+=4)n.push(c.__wbindgen_externrefs.get(e.getUint32(o,!0)));return c.__externref_drop_slice(_,t),n}function O(_,t){return _=_>>>0,W().subarray(_/1,_/1+t)}var I=null;function b(){return(I===null||I.buffer.detached===!0||I.buffer.detached===void 0&&I.buffer!==c.memory.buffer)&&(I=new DataView(c.memory.buffer)),I}var j=null;function G(){return(j===null||j.byteLength===0)&&(j=new Int32Array(c.memory.buffer)),j}function h(_,t){return xt(_>>>0,t)}var S=null;function W(){return(S===null||S.byteLength===0)&&(S=new Uint8Array(c.memory.buffer)),S}function u(_){return _==null}function r(_,t){try{return _.apply(this,t)}catch(e){let n=(function(){try{return e instanceof Error?`${e.message}
3
+
4
+ Stack:
5
+ ${e.stack}`:e.toString()}catch{return"<failed to stringify thrown value>"}})();throw console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:",n),e}}function D(_,t,e){let n={a:_,b:t,cnt:1,instance:g},o=(...i)=>{if(n.instance!==g)throw new Error("Cannot invoke closure from previous WASM instance");n.cnt++;let d=n.a;n.a=0;try{return e(d,n.b,...i)}finally{n.a=d,o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{--n.cnt===0&&(c.__wbindgen_destroy_closure(n.a,n.b),n.a=0,et.unregister(n))},et.register(o,n,n),o}function N(_,t){let e=t(_.length*4,4)>>>0;for(let n=0;n<_.length;n++){let o=v(_[n]);b().setUint32(e+4*n,o,!0)}return m=_.length,e}function p(_,t,e){if(typeof _!="string")throw new Error(`expected a string argument, found ${typeof _}`);if(e===void 0){let w=T.encode(_),y=t(w.length,1)>>>0;return W().subarray(y,y+w.length).set(w),m=w.length,y}let n=_.length,o=t(n,1)>>>0,i=W(),d=0;for(;d<n;d++){let w=_.charCodeAt(d);if(w>127)break;i[o+d]=w}if(d!==n){d!==0&&(_=_.slice(d)),o=e(o,n,n=d+_.length*3,1)>>>0;let w=W().subarray(o+d,o+n),y=T.encodeInto(_,w);if(y.read!==_.length)throw new Error("failed to pass whole string");d+=y.written,o=e(o,n,d,1)>>>0}return m=d,o}var C=!1;function It(_){let t=c.__wbindgen_externrefs.get(_);return c.__externref_table_dealloc(_),t}var ut=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});ut.decode();function xt(_,t){return ut.decode(W().subarray(_,_+t))}var T=new TextEncoder;"encodeInto"in T||(T.encodeInto=function(_,t){let e=T.encode(_);return t.set(e),{read:_.length,written:e.length}});var m=0,H=new WebAssembly.Instance(nt,ct()),c=H.exports;c.__wbindgen_start();Error.stackTraceLimit=100;var E=rt();function Q(){E.criticalError&&(console.log("Reinitializing Wasm application"),U(),E.criticalError=!1,E.instanceId++)}addEventListener("error",_=>{X(_.error)});function X(_){_ instanceof WebAssembly.RuntimeError&&(console.error("Critical",_),E.criticalError=!0)}var k=class extends Rt{};k.prototype.fetch=function(t){return _t.call(this,t,this.env,this.ctx)};k.prototype.scheduled=function(t){return ot.call(this,t,this.env,this.ctx)};k.prototype.__wasm=c;var kt={set:(_,t,e,n)=>Reflect.set(_.instance,t,e,n),has:(_,t)=>Reflect.has(_.instance,t),deleteProperty:(_,t)=>Reflect.deleteProperty(_.instance,t),apply:(_,t,e)=>Reflect.apply(_.instance,t,e),construct:(_,t,e)=>Reflect.construct(_.instance,t,e),getPrototypeOf:_=>Reflect.getPrototypeOf(_.instance),setPrototypeOf:(_,t)=>Reflect.setPrototypeOf(_.instance,t),isExtensible:_=>Reflect.isExtensible(_.instance),preventExtensions:_=>Reflect.preventExtensions(_.instance),getOwnPropertyDescriptor:(_,t)=>Reflect.getOwnPropertyDescriptor(_.instance,t),defineProperty:(_,t,e)=>Reflect.defineProperty(_.instance,t,e),ownKeys:_=>Reflect.ownKeys(_.instance)},L={construct(_,t,e){try{Q();let n={instance:Reflect.construct(_,t,e),instanceId:E.instanceId,ctor:_,args:t,newTarget:e};return new Proxy(n,{...kt,get(o,i,d){o.instanceId!==E.instanceId&&(o.instance=Reflect.construct(o.ctor,o.args,o.newTarget),o.instanceId=E.instanceId);let w=Reflect.get(o.instance,i,d);return typeof w!="function"?w:w.constructor===Function?new Proxy(w,{apply(y,V,q){Q();try{return y.apply(V,q)}catch(F){throw X(F),F}}}):new Proxy(w,{async apply(y,V,q){Q();try{return await y.apply(V,q)}catch(F){throw X(F),F}}})}})}catch(n){throw E.criticalError=!0,n}}},Tt=new Proxy(k,L),Mt=new Proxy(A,L),Ot=new Proxy(x,L),zt=new Proxy(R,L);export{Mt as ContainerStartupOptions,Ot as MinifyConfig,zt as R2Range,Tt as default};
Binary file
@@ -0,0 +1,70 @@
1
+ -- Accounts & sync (see docs/ACCOUNTS.md in the app repo).
2
+ -- Apply with: npx wrangler d1 migrations apply glyph --remote
3
+
4
+ CREATE TABLE IF NOT EXISTS users (
5
+ id TEXT PRIMARY KEY,
6
+ handle TEXT NOT NULL UNIQUE,
7
+ created_at INTEGER NOT NULL,
8
+ device_limit INTEGER NOT NULL DEFAULT 5,
9
+ rev INTEGER NOT NULL DEFAULT 0,
10
+ purged_rev INTEGER NOT NULL DEFAULT 0,
11
+ recovery_hash TEXT NOT NULL,
12
+ handle_changed_at INTEGER NOT NULL DEFAULT 0
13
+ );
14
+
15
+ -- Released handles stay blocked for a while.
16
+ CREATE TABLE IF NOT EXISTS handle_holds (
17
+ handle TEXT PRIMARY KEY,
18
+ until INTEGER NOT NULL
19
+ );
20
+
21
+ CREATE TABLE IF NOT EXISTS passkeys (
22
+ cred_id TEXT PRIMARY KEY,
23
+ user_id TEXT NOT NULL,
24
+ alg INTEGER NOT NULL,
25
+ public_key TEXT NOT NULL,
26
+ sign_count INTEGER NOT NULL DEFAULT 0,
27
+ created_at INTEGER NOT NULL
28
+ );
29
+ CREATE INDEX IF NOT EXISTS passkeys_user ON passkeys(user_id);
30
+
31
+ CREATE TABLE IF NOT EXISTS devices (
32
+ id TEXT PRIMARY KEY,
33
+ user_id TEXT NOT NULL,
34
+ name TEXT NOT NULL,
35
+ platform TEXT NOT NULL,
36
+ created_at INTEGER NOT NULL,
37
+ last_seen INTEGER NOT NULL,
38
+ access_hash TEXT NOT NULL UNIQUE,
39
+ access_exp INTEGER NOT NULL,
40
+ refresh_hash TEXT NOT NULL UNIQUE,
41
+ refresh_exp INTEGER NOT NULL
42
+ );
43
+ CREATE INDEX IF NOT EXISTS devices_user ON devices(user_id);
44
+
45
+ CREATE TABLE IF NOT EXISTS logins (
46
+ id TEXT PRIMARY KEY,
47
+ poll_hash TEXT NOT NULL,
48
+ user_code TEXT NOT NULL UNIQUE,
49
+ device_name TEXT NOT NULL,
50
+ platform TEXT NOT NULL,
51
+ challenge TEXT,
52
+ pending_handle TEXT,
53
+ pending_user_id TEXT,
54
+ user_id TEXT,
55
+ page_hash TEXT,
56
+ expires INTEGER NOT NULL
57
+ );
58
+
59
+ CREATE TABLE IF NOT EXISTS sync_items (
60
+ user_id TEXT NOT NULL,
61
+ kind TEXT NOT NULL,
62
+ key TEXT NOT NULL,
63
+ value TEXT,
64
+ updated_at INTEGER NOT NULL,
65
+ device_id TEXT NOT NULL,
66
+ deleted INTEGER NOT NULL DEFAULT 0,
67
+ rev INTEGER NOT NULL,
68
+ PRIMARY KEY (user_id, kind, key)
69
+ );
70
+ CREATE INDEX IF NOT EXISTS sync_items_rev ON sync_items(user_id, rev);
@@ -0,0 +1,7 @@
1
+ -- Handle + password sign-in. The client sends an Argon2id-derived key; the
2
+ -- server keeps its salt and a SHA-256 of the key, never the password.
3
+ ALTER TABLE users ADD COLUMN pw_salt TEXT;
4
+ ALTER TABLE users ADD COLUMN pw_hash TEXT;
5
+
6
+ -- A login row can add a passkey to an existing account instead of signing in.
7
+ ALTER TABLE logins ADD COLUMN link INTEGER NOT NULL DEFAULT 0;
@@ -0,0 +1,8 @@
1
+ -- Device limits are operator settings (glyph-server remote accounts …):
2
+ -- users.device_limit 0 = server default, kept in settings.default_device_limit.
3
+ CREATE TABLE IF NOT EXISTS settings (
4
+ key TEXT PRIMARY KEY,
5
+ value TEXT NOT NULL
6
+ );
7
+ -- Limits were picked by clients until now; reset them to the default.
8
+ UPDATE users SET device_limit = 0;
@@ -0,0 +1,12 @@
1
+ -- Short playlist links (/p/<id>). Each belongs to the account that made it
2
+ -- and is deleted with it.
3
+ CREATE TABLE IF NOT EXISTS shares (
4
+ id TEXT PRIMARY KEY,
5
+ owner_id TEXT NOT NULL,
6
+ code TEXT NOT NULL,
7
+ name TEXT NOT NULL DEFAULT '',
8
+ songs INTEGER NOT NULL DEFAULT 0,
9
+ kind TEXT NOT NULL DEFAULT 'playlist',
10
+ created_at INTEGER NOT NULL
11
+ );
12
+ CREATE INDEX IF NOT EXISTS shares_owner ON shares (owner_id);
@@ -0,0 +1,12 @@
1
+ -- Profiles: picture, banner and what other users may see (all off by default).
2
+ -- playlists: JSON array of shown playlist ids; recent: JSON array of songs.
3
+ CREATE TABLE IF NOT EXISTS profiles (
4
+ user_id TEXT PRIMARY KEY,
5
+ public INTEGER NOT NULL DEFAULT 0,
6
+ show_recent INTEGER NOT NULL DEFAULT 0,
7
+ playlists TEXT NOT NULL DEFAULT '[]',
8
+ avatar TEXT,
9
+ banner TEXT,
10
+ recent TEXT,
11
+ updated_at INTEGER NOT NULL DEFAULT 0
12
+ );
@@ -0,0 +1,2 @@
1
+ -- Approximate region/country only; no IP address, GPS or precise coordinates.
2
+ ALTER TABLE devices ADD COLUMN approximate_location TEXT;
@@ -0,0 +1,6 @@
1
+ -- Settings changed at runtime through the admin API (`glyph-server remote limits`,
2
+ -- `remote companion on|off`). One JSON value per key.
3
+ CREATE TABLE IF NOT EXISTS server_settings (
4
+ key TEXT PRIMARY KEY,
5
+ value TEXT NOT NULL
6
+ );
@@ -0,0 +1,8 @@
1
+ -- Companion audio kept in R2 (`audio/youtube/<id>`): size and age, so the
2
+ -- Worker can hold the total under `audio_cache_max_gb` (oldest go first).
3
+ CREATE TABLE IF NOT EXISTS audio_cache (
4
+ key TEXT PRIMARY KEY,
5
+ size INTEGER NOT NULL,
6
+ created INTEGER NOT NULL
7
+ );
8
+ CREATE INDEX IF NOT EXISTS audio_cache_created ON audio_cache (created);
@@ -0,0 +1,7 @@
1
+ -- Atomic quotas and temporary bans, shared across Worker instances/locations.
2
+ CREATE TABLE IF NOT EXISTS abuse_limits (
3
+ key TEXT PRIMARY KEY,
4
+ count INTEGER NOT NULL,
5
+ expires INTEGER NOT NULL
6
+ );
7
+ CREATE INDEX IF NOT EXISTS abuse_limits_expiry ON abuse_limits(expires);
@@ -0,0 +1,11 @@
1
+ -- Account all R2 objects; only audio/ and covers/ are automatically evictable.
2
+ ALTER TABLE audio_cache ADD COLUMN state TEXT NOT NULL DEFAULT 'ready';
3
+ ALTER TABLE audio_cache ADD COLUMN generation TEXT NOT NULL DEFAULT 'legacy';
4
+ ALTER TABLE audio_cache ADD COLUMN hits INTEGER NOT NULL DEFAULT 0;
5
+ ALTER TABLE audio_cache ADD COLUMN last_access INTEGER NOT NULL DEFAULT 0;
6
+ ALTER TABLE audio_cache ADD COLUMN seen INTEGER NOT NULL DEFAULT 0;
7
+ CREATE TABLE audio_cache_inventory (
8
+ id INTEGER PRIMARY KEY CHECK(id=1), cursor TEXT, ready INTEGER NOT NULL DEFAULT 0,
9
+ scan_id INTEGER NOT NULL DEFAULT 0, finished INTEGER NOT NULL DEFAULT 0
10
+ );
11
+ INSERT INTO audio_cache_inventory(id) VALUES (1);
@@ -0,0 +1,10 @@
1
+ CREATE TABLE d1_storage_reservations (
2
+ token TEXT PRIMARY KEY,
3
+ bytes INTEGER NOT NULL CHECK(bytes>0),
4
+ created INTEGER NOT NULL
5
+ );
6
+ CREATE INDEX logins_expires ON logins(expires);
7
+ CREATE INDEX handle_holds_until ON handle_holds(until);
8
+
9
+ CREATE TABLE d1_storage_watermark (id INTEGER PRIMARY KEY CHECK(id=1), bytes INTEGER NOT NULL, revision INTEGER NOT NULL DEFAULT 0);
10
+ INSERT INTO d1_storage_watermark VALUES (1,0,0);
@@ -0,0 +1,8 @@
1
+ CREATE TABLE audio_variants (
2
+ track_id TEXT NOT NULL,
3
+ quality TEXT NOT NULL CHECK(quality IN ('low','standard','high')),
4
+ manifest TEXT NOT NULL,
5
+ created INTEGER NOT NULL,
6
+ PRIMARY KEY(track_id,quality)
7
+ );
8
+ CREATE INDEX audio_variants_created ON audio_variants(created);
@@ -0,0 +1,6 @@
1
+ -- Short leases deduplicate proactive quality preparation across Worker isolates.
2
+ CREATE TABLE IF NOT EXISTS audio_variant_jobs (
3
+ track_id TEXT PRIMARY KEY,
4
+ expires INTEGER NOT NULL
5
+ );
6
+ CREATE INDEX IF NOT EXISTS audio_variant_jobs_expiry ON audio_variant_jobs(expires);
@@ -0,0 +1 @@
1
+ {"type":"module"}