Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
542 changes: 542 additions & 0 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

30 changes: 0 additions & 30 deletions .github/workflows/node.js.yml

This file was deleted.

1 change: 1 addition & 0 deletions all.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'functionalscript/fs/emergent_testing/all.test.js'
29 changes: 29 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 74 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
"main": "server.f.ts",
"scripts": {
"test": "tsc && fjs t",
"start": "fjs r ./server.f.ts"
"start": "fjs r ./server.f.ts",
"update": "npx npm-check-updates -u && npm install && deno install && bun install && fjs i",
"cov": "node --test --experimental-test-coverage --test-coverage-include=**/*.f.ts"
},
"dependencies": {
"functionalscript": "^0.11.10"
"functionalscript": "0.29.0"
},
"devDependencies": {
"typescript": "^5.9.3"
"@playwright/test": "1.60.0",
"typescript": "6.0.3"
}
}
65 changes: 65 additions & 0 deletions proof.f.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { assert, assertEq } from 'functionalscript/fs/asserts/module.f.js'
import { utf8, utf8ToString } from 'functionalscript/fs/text/module.f.js'
import { vec8 } from 'functionalscript/fs/types/bit_vec/module.f.js'
import type { IncomingMessage } from 'functionalscript/fs/effects/node/module.f.js'
import { virtual, emptyState } from 'functionalscript/fs/effects/node/virtual/module.f.js'
import { listener } from './server.f.ts'

const request = (url: string): IncomingMessage => ({
method: 'GET',
url,
headers: {},
body: vec8(0n),
})

const runRequest = (url: string, root = emptyState.root) =>
virtual({ ...emptyState, root })(listener(request(url)))

const bodyText = (url: string, root = emptyState.root) => {
const [state, response] = runRequest(url, root)
return [state, response, utf8ToString(response.body)] as const
}

const includes = (s: string) => (part: string) => {
assert(s.includes(part), [part, s])
}

export const proof = {
servesFiles: () => {
const file = utf8('body { color: green; }\n')
const [state, response] = runRequest('/main.css', { 'main.css': file })

assertEq(response.status, 200)
assertEq(utf8ToString(response.body), 'body { color: green; }\n')
includes(state.stdout)('reading ./main.css\n')
includes(state.stdout)('served: 23 bytes\n')
},
ignoresQueryString: () => {
const file = utf8('ok')
const [_, response] = runRequest('/main.css?cache=bust', { 'main.css': file })

assertEq(response.status, 200)
assertEq(utf8ToString(response.body), 'ok')
},
rendersDirectoryListing: () => {
const [state, response, body] = bodyText('/docs', {
docs: {
'a.txt': utf8('A'),
nested: {},
},
})

assertEq(response.status, 200)
includes(body)('<link rel="stylesheet" href="/main.css">')
includes(body)('<pre><a href="/docs/a.txt">a.txt</a>\n<a href="/docs/nested">nested/</a>\n</pre>')
includes(state.stdout)('reading ./docs\n')
includes(state.stdout)('served: ')
},
missingPaths404: () => {
const [state, response] = runRequest('/missing')

assertEq(response.status, 404)
assertEq(utf8ToString(response.body), '404 not found')
assertEq(state.stdout, 'reading ./missing\nserved: 13 bytes\n')
},
}
30 changes: 11 additions & 19 deletions server.f.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { utf8 } from 'functionalscript/text/module.f.js'
import { length, type Vec } from 'functionalscript/types/bit_vec/module.f.js'
import { pure } from 'functionalscript/types/effects/module.f.js'
import { utf8 } from 'functionalscript/fs/text/module.f.js'
import { empty, length, type Vec } from 'functionalscript/fs/types/bit_vec/module.f.js'
import { pure } from 'functionalscript/fs/effects/module.f.js'
import {
createServer,
listen,
Expand All @@ -12,11 +12,11 @@ import {
readdir,
type IoResult,
type Dirent,
} from 'functionalscript/types/effects/node/module.f.js'
import { htmlToString } from 'functionalscript/html/module.f.js'
import { concat } from 'functionalscript/path/module.f.js'
} from 'functionalscript/fs/effects/node/module.f.js'
import { htmlUtf8 } from 'functionalscript/fs/html/module.f.js'
import { concat } from 'functionalscript/fs/path/module.f.js'

const listener = ({ url }: IncomingMessage) => {
export const listener = ({ url }: IncomingMessage) => {
const path = url.split('?')[0] ?? ''
const file = '.' + path

Expand All @@ -25,22 +25,14 @@ const listener = ({ url }: IncomingMessage) => {
return [['a', { href }, name + (isFile ? '' : '/')], '\n'] as const
}

const dirPage = (v: readonly Dirent[]) => htmlToString(
['html',
['head',
['link', { rel: 'stylesheet', href: '/main.css' }]
],
['body',
['pre',
...v.flatMap(dirLink)
]
]
])
const dirPage = (v: readonly Dirent[]) => htmlUtf8
(['link', { rel: 'stylesheet', href: '/main.css' }])
(['pre', ...v.flatMap(dirLink)])

const orReadDir = (r: IoResult<Vec>) => r[0] === 'ok'
? pure(r)
: readdir(file, {})
.step(([s, v]) => pure([s, utf8(s === 'ok' ? dirPage(v) : '')] as const))
.step(([s, v]) => pure([s, s === 'ok' ? dirPage(v) : empty] as const))

return log(`reading ${file}`)
.step(() => readFile(file))
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
// Recommended Options
"strict": true,
"jsx": "react-jsx",
"verbatimModuleSyntax": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"allowImportingTsExtensions": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true,
Expand Down
Loading