Skip to content

Commit

Permalink
wasm-pack
Browse files Browse the repository at this point in the history
  • Loading branch information
rorymalcolm committed Jan 27, 2024
1 parent e67808f commit 7f161cb
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
working-directory: ./parquet-generator

steps:
- uses: jetli/[email protected]
with:
version: 'latest'
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/vitest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/[email protected]
- run: yarn
- run: yarn build
- run: yarn test
21 changes: 21 additions & 0 deletions compactor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "compactor",
"version": "0.0.0",
"private": true,
"scripts": {
"deploy": "wrangler publish",
"start": "wrangler dev",
"build:wasm": "wasm-pack build ../parquet-generator/ --out-dir ../parquet-generator/pkg/",
"build": "npm run build:wasm && tsc"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230419.0",
"@types/uuid": "^9.0.7",
"typescript": "^5.0.4",
"wrangler": "^3.0.0"
},
"dependencies": {
"parquet-schema-validator": "0.0.0",
"parquet-generator": "0.1.0",
}
}
56 changes: 56 additions & 0 deletions compactor/src/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { ParquetSchema } from 'parquet-types';
import { ValueResult, ErrorsToResponse, SafeJSONParse } from 'rerrors';

export interface Env {
LAKESIDE_BUCKET: R2Bucket;
}

const getSchema = async (env: Env): Promise<ValueResult<ParquetSchema>> => {
const schema = await env.LAKESIDE_BUCKET.get(`schema/schema.json`);
if (!schema) {
return {
success: false,
errors: ['No schema'],
};
}

const schemaText = await schema?.text();
const schemaJSON = SafeJSONParse(schemaText);
if (!schemaJSON.success) {
return {
success: false,
errors: ['Schema is not valid JSON'],
};
}

const parseResult = ParquetSchema.safeParse(schemaJSON.value);
if (parseResult.success) {
return {
success: true,
value: parseResult.data,
};
}

return {
success: false,
errors: [JSON.stringify(parseResult.error)],
};
};

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const schemaResult = await getSchema(env);
if (!schemaResult.success) {
return ErrorsToResponse(schemaResult.errors);
}

try {
if (request.method === 'POST') {

}
return new Response('', { status: 405 });
} catch (e) {
return new Response('failed to process request', { status: 500 });
}
},
};
18 changes: 18 additions & 0 deletions compactor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"jsx": "react" /* Specify what JSX code is generated. */,
"module": "es2022" /* Specify what module code is generated. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"types": ["@cloudflare/workers-types"] /* Specify type package names to be included without being referenced in a source file. */,
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
"checkJs": false /* Enable error reporting in type-checked JavaScript files. */,
"noEmit": true /* Disable emitting files from a compilation. */,
"isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
"allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
39 changes: 39 additions & 0 deletions compactor/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name = "compactor"
main = "src/worker.ts"
compatibility_date = "2023-10-02"

# # KV Namespace binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/kv
# [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# # Durable Object binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
# [[durable_objects]]
# binding = "MY_DURABLE_OBJECT"
# class_name = "MyDurableObject"

# # Bucket binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/kv#bucket
[[r2_buckets]]
binding = "LAKESIDE_BUCKET"
bucket_name = "lakeside"

# # Service binding - For more information: https://developers.cloudflare.com/workers/platform/services
# [[routes]]
# binding = "MY_SERVICE"
# pattern = "/api/*"
# script = "api.js"

# # Queue binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/queues
# [[queues]]
# binding = "MY_QUEUE"
# name = "my-queue"
# zone_id = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

# [env.production]
# MY_VARIABLE = "production_value"

# [env.staging]
# MY_VARIABLE = "staging_value"

# [env.shared]
# SHARED_VARIABLE = "shared_value"
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
},
"scripts": {
"deploy": "deno run --allow-read --allow-net --allow-run scripts/deploy.ts",
"test": "vitest"
"test": "vitest",
"build:wasm": "wasm-pack build parquet-generator/ --out-dir parquet-generator/pkg/",
"build": "npm run build:wasm"
}
}

0 comments on commit 7f161cb

Please sign in to comment.