@swelte/create 0.0.0-stage → 0.2.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.
Files changed (45) hide show
  1. package/LICENSE-MIT +21 -0
  2. package/README.md +21 -2
  3. package/bin/create.js +7 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +132 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/prompts.d.ts +9 -0
  9. package/dist/prompts.d.ts.map +1 -0
  10. package/dist/prompts.js +45 -0
  11. package/dist/prompts.js.map +1 -0
  12. package/dist/scaffold.d.ts +16 -0
  13. package/dist/scaffold.d.ts.map +1 -0
  14. package/dist/scaffold.js +149 -0
  15. package/dist/scaffold.js.map +1 -0
  16. package/package.json +64 -4
  17. package/templates/base/README.md +65 -0
  18. package/templates/base/assets/README.md +12 -0
  19. package/templates/base/gitignore +8 -0
  20. package/templates/base/index.html +12 -0
  21. package/templates/base/package.json +51 -0
  22. package/templates/base/src/lib/README.md +10 -0
  23. package/templates/base/src/lib/index.ts +2 -0
  24. package/templates/base/src/routes/+error.svelte +14 -0
  25. package/templates/base/src/routes/+page.svelte +12 -0
  26. package/templates/base/src/routes/+page.v +7 -0
  27. package/templates/base/svelte.config.js +34 -0
  28. package/templates/base/tsconfig.json +27 -0
  29. package/templates/base/vite.config.ts +28 -0
  30. package/templates/lib/src/lib/hello/api.v +15 -0
  31. package/templates/lib/src/lib/hello.d.ts +4 -0
  32. package/templates/lib/src/routes/+page.svelte +36 -0
  33. package/templates/lib/src/routes/+page.v +9 -0
  34. package/templates/sample/src/lib/backend/secrets.v +12 -0
  35. package/templates/sample/src/lib/crypto/hash.v +13 -0
  36. package/templates/sample/src/routes/+page.svelte +179 -0
  37. package/templates/sample/src/routes/+page.v +22 -0
  38. package/templates/sample/src/routes/admin/+page.svelte +23 -0
  39. package/templates/sample/src/routes/admin/+page.v +8 -0
  40. package/templates/sample/src/routes/admin/+route.svelte +10 -0
  41. package/templates/sample/src/routes/admin/+route.v +15 -0
  42. package/templates/sample/src/routes/api/greet.v +127 -0
  43. package/templates/sample/src/routes/api/sibling.v +14 -0
  44. package/templates/sample/src/routes/files/[...rest].v +8 -0
  45. package/templates/sample/src/routes/users/[id].v +8 -0
@@ -0,0 +1,127 @@
1
+ // Swelte API route `/api/greet`. V struct -> TS interface projection.
2
+ module greet
3
+
4
+ import json
5
+ import time
6
+
7
+ pub struct Session {
8
+ pub:
9
+ id string
10
+ user string
11
+ remember bool
12
+ expires_at time.Time
13
+ }
14
+
15
+ pub struct LoginArgs {
16
+ pub:
17
+ payload string
18
+ }
19
+
20
+ // login is HTTP (sets the sess cookie) → a verb, not @[rpc].
21
+ // @[rpc] stays protocol-ignorant: typed args in, typed value out (or throw → reject).
22
+ @[post]
23
+ pub fn login(req SwelteRequest) !SwelteResponse {
24
+ payload := req.form['payload'] or { req.query['payload'] or { '' } }
25
+ if payload == '' {
26
+ return error('missing payload')
27
+ }
28
+ sess := Session{
29
+ id: 'sess_' + payload
30
+ user: payload
31
+ remember: true
32
+ expires_at: time.now()
33
+ }
34
+ mut res := SwelteResponse{ status: 200, headers: {'Content-Type': 'application/json'}, body: json.encode(sess) }
35
+ res.cookies << SwelteCookie{ name: 'sess', value: sess.id, path: '/', http_only: true, same_site: 'Lax', max_age: 604800 }
36
+ return res
37
+ }
38
+
39
+ @[get]
40
+ pub fn get_greeting(req SwelteRequest) string {
41
+ name := req.query['payload'] or { '""' }
42
+ return 'Hello, ' + name.trim('"') + '! from Swelte V backend'
43
+ }
44
+
45
+ @[delete('session')]
46
+ pub fn kill_session(req SwelteRequest) string {
47
+ return 'killed'
48
+ }
49
+
50
+ @[delete]
51
+ pub fn wipe_sessions(req SwelteRequest) string {
52
+ return 'wiped'
53
+ }
54
+
55
+ // Slow probe (roadmap §11): sleeps `?ms=` ms so the handler-timeout
56
+ // watchdog can be exercised (SWELTE_HANDLER_TIMEOUT_MS).
57
+ @[get('slow')]
58
+ pub fn slow_probe(req SwelteRequest) string {
59
+ ms_str := req.query['ms'] or { '' }
60
+ ms := ms_str.int()
61
+ if ms > 0 {
62
+ time.sleep(time.millisecond * ms)
63
+ }
64
+ return 'slow-ok'
65
+ }
66
+
67
+ @[post('upload')]
68
+ pub fn upload_file(req SwelteRequest) !string {
69
+ names := req.files['file'] or { return error('missing file') }
70
+ if names == '' {
71
+ return error('missing file')
72
+ }
73
+ return 'got:' + names
74
+ }
75
+
76
+ // SSE probe (roadmap §14, emit mode): GET + Accept: text/event-stream
77
+ // takes over the conn; each `emit` flushes one frame immediately —
78
+ // sleeps pace the frames (real incremental flush, nothing buffered).
79
+ // Plain JSON GETs keep hitting `get_greeting` above.
80
+ @[sse]
81
+ pub fn tick_stream(req SwelteRequest, emit fn (string) bool) {
82
+ n := req.query['n'] or { '3' }
83
+ w := req.query['wait_ms'] or { '0' }
84
+ mut count := n.int()
85
+ if count < 1 {
86
+ count = 1
87
+ }
88
+ if count > 50 {
89
+ count = 50
90
+ }
91
+ wait := w.int()
92
+ for i in 1 .. count + 1 {
93
+ if wait > 0 && wait <= 10000 {
94
+ time.sleep(time.millisecond * wait)
95
+ }
96
+ if !emit('tick ${i}') {
97
+ return
98
+ }
99
+ }
100
+ }
101
+
102
+ // Binary probe: serves bytes with Content-Type passthrough.
103
+ @[get('pdf')]
104
+ pub fn serve_pdf(req SwelteRequest) SwelteResponse {
105
+ _ = req
106
+ data := 'PDF-fixture'.bytes()
107
+ mut res := swelte_bytes(data, 'application/pdf')
108
+ res.headers['Content-Disposition'] = 'attachment; filename="doc.pdf"'
109
+ return res
110
+ }
111
+
112
+ // Status sugar probe: (int, string) -> status+text.
113
+ @[get('created')]
114
+ pub fn make_created(req SwelteRequest) (int, string) {
115
+ _ = req
116
+ return 201, 'created'
117
+ }
118
+
119
+ // Pure rpc: protocol-ignorant typed call (works in #routes/ fetch AND #lib/ WASM).
120
+ // No HTTP types allowed (no SwelteRequest/SwelteResponse/[]u8/(int,string)) — throw → TS reject.
121
+ @[rpc]
122
+ pub fn greet_pure(args LoginArgs) !Session {
123
+ if args.payload == '' {
124
+ return error('missing payload')
125
+ }
126
+ return Session{ id: 'pure_' + args.payload, user: args.payload, remember: false, expires_at: time.now() }
127
+ }
@@ -0,0 +1,14 @@
1
+ // Shared helper fixture (roadmap §17): UNIQUE basename across the project,
2
+ // so editors resolve `./sibling.v` to the real signature (ambiguous
3
+ // basenames like `+page.v` keep the `*.v` fallback — use `#`-aliases).
4
+ module sibling
5
+
6
+ pub struct GreetIn {
7
+ pub:
8
+ name string
9
+ }
10
+
11
+ @[rpc]
12
+ pub fn g(args GreetIn) string {
13
+ return 'hi ' + args.name
14
+ }
@@ -0,0 +1,8 @@
1
+ // Swelte catch-all fixture (roadmap item 8).
2
+ module files_rest
3
+
4
+ @[get]
5
+ pub fn file_detail(req SwelteRequest) string {
6
+ rest := req.params['rest'] or { '' }
7
+ return 'files:' + rest
8
+ }
@@ -0,0 +1,8 @@
1
+ // Swelte dynamic-segment fixture (roadmap item 8).
2
+ module users_id
3
+
4
+ @[get]
5
+ pub fn user_detail(req SwelteRequest) string {
6
+ id := req.params['id'] or { '' }
7
+ return 'user:' + id
8
+ }