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
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
exit 1
fi

fossa:
needs: [validate_branch_name]
uses: ./.github/workflows/fossa.yaml

code_validation:
needs: [validate_branch_name]
uses: ./.github/workflows/code-validation.yaml
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/fossa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Fossa Compliance Check

on:
workflow_call:

jobs:
fossa:
runs-on: [self-hosted, ubuntu-22-04, regular]

if: github.actor != 'dependabot[bot]'

steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Install FOSSA CLI
run: |
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash

- name: Run FOSSA Analysis
env:
FOSSA_API_KEY: ${{ secrets.FOSSA_PUB_API_KEY }}
run: fossa analyze

- name: Run FOSSA Test
env:
FOSSA_API_KEY: ${{ secrets.FOSSA_PUB_API_KEY }}
run: fossa test
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "fastedge-runtime/spidermonkey/gecko-dev"]
path = fastedge-runtime/spidermonkey/gecko-dev
url = https://github.com/bytecodealliance/gecko-dev.git
[submodule "fastedge-runtime/cbindings/wit-interface/wit"]
path = fastedge-runtime/cbindings/wit-interface/wit
url = https://github.com/G-Core/FastEdge-wit.git
[submodule "runtime/StarlingMonkey"]
path = runtime/StarlingMonkey
url = https://github.com/bytecodealliance/StarlingMonkey.git
[submodule "runtime/FastEdge-wit"]
path = runtime/FastEdge-wit
url = https://github.com/G-Core/FastEdge-wit.git
68 changes: 67 additions & 1 deletion docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
integrations: [
starlight({
title: '@gcoredev/fastedge-sdk-js',
customCss: ['./src/styles/custom.css'],
social: {
github: 'https://github.com/G-Core/FastEdge-sdk-js',
},
Expand Down Expand Up @@ -47,7 +48,72 @@ export default defineConfig({
{
label: 'Reference',
collapsed: true,
autogenerate: { directory: 'reference' },
items: [
{
label: 'Overview',
link: `${import.meta.env.BASE_URL}reference/overview/`,
},
{
label: 'FastEdge::env',
link: `${import.meta.env.BASE_URL}reference/fastedge/env/`,
},
{
label: 'FastEdge::secret',
collapsed: true,
items: [
{
label: 'getSecret',
link: `${import.meta.env.BASE_URL}reference/fastedge/secret/get-secret/`,
},
{
label: 'getSecretEffectiveAt',
link: `${
import.meta.env.BASE_URL
}reference/fastedge/secret/get-secret-effective-at/`,
},
],
},
{
label: 'FastEdge::kv',
collapsed: true,
items: [
{
label: 'KvStore.open()',
link: `${import.meta.env.BASE_URL}reference/fastedge/kv/open/`,
},
{
label: 'KV Instance',
collapsed: true,
items: [
{
label: 'get / scan',
link: `${import.meta.env.BASE_URL}reference/fastedge/kv/key-value/`,
},
{
label: 'zrange / zscan',
link: `${import.meta.env.BASE_URL}reference/fastedge/kv/zset/`,
},
{
label: 'bfExists',
link: `${import.meta.env.BASE_URL}reference/fastedge/kv/bloom-filter/`,
},
],
},
],
},
{
label: 'Headers',
link: `${import.meta.env.BASE_URL}reference/headers/`,
},
{
label: 'Request',
link: `${import.meta.env.BASE_URL}reference/request/`,
},
{
label: 'Response',
link: `${import.meta.env.BASE_URL}reference/response/`,
},
],
},
{
label: 'Migrating',
Expand Down
15 changes: 15 additions & 0 deletions docs/examples/kv-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { KvStore } from 'fastedge::kv';

async function eventHandler(event) {
try {
const myStore = KvStore.open('kv-store-name-as-defined-on-app');
const value = myStore.get('key');
return new Response(`The KV Store responded with: ${value}`);
} catch (error) {
return Response.json({ error: error.message }, { status: 500 });
}
}

addEventListener('fetch', (event) => {
event.respondWith(eventHandler(event));
});
12 changes: 12 additions & 0 deletions docs/src/content/docs/examples/kv-store.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Key-value Store
description: An example using KV Store.
prev:
link: /FastEdge-sdk-js/examples/main-examples/
label: Back to examples
---

import { Code } from '@astrojs/starlight/components';
import importedCode from '/examples/kv-store.js?raw';

<Code code={importedCode} lang='js' title='docs/examples/kv-store.js' />
4 changes: 4 additions & 0 deletions docs/src/content/docs/examples/main-examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ More examples will be added to the examples-repo as we build out more functional
title='Environment variables and secrets'
href='/FastEdge-sdk-js/examples/variables-and-secrets/'
/>
<LinkCard
title='Key-value Store'
href='/FastEdge-sdk-js/examples/kv-store/'
/>
</CardGrid>
48 changes: 48 additions & 0 deletions docs/src/content/docs/reference/fastedge/kv/bloom-filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Bloom Filter accessors
description: How to access Bloom Filter values from a FastEdge Kv Instance.
---

To access Bloom Filter values in a KV Store. First create a `KV Instance` using `KvStore.open()`

This instance will then provide the `bfExists` method you can use to verify if a value exists.

## zrangeByScore

```js
import { KvStore } from 'fastedge::kv';

async function eventHandler(event) {
try {
const myStore = KvStore.open('kv-store-name-as-defined-on-app');
const hasItem = myStore.bfExists('key', 'value');
return new Response(`The KV Store responded with: ${hasItem}`);
} catch (error) {
return Response.json({ error: error.message }, { status: 500 });
}
}

addEventListener('fetch', (event) => {
event.respondWith(eventHandler(event));
});
```

```js title="SYNTAX"
storeInstance.bfExists(key, value);
```

##### Parameters

- `key` (required)

A string containing the key you want to retrieve the values from.

- `value` (required)

A string representing the value you want to check for existence.


##### Return Value

`boolean`. It returns `true` if the Bloom Filter contains the value.

80 changes: 80 additions & 0 deletions docs/src/content/docs/reference/fastedge/kv/key-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: Key-value accessors
description: How to access Key-value pairs from a FastEdge Kv Instance.
---

To access key-value pairs in a KV Store. First create a `KV Instance` using `KvStore.open()`

This instance will then provide the `get` and `scan` methods you can use to access key-value pairs.

## get

```js
import { KvStore } from 'fastedge::kv';

async function eventHandler(event) {
try {
const myStore = KvStore.open('kv-store-name-as-defined-on-app');
const value = myStore.get('key');
return new Response(`The KV Store responded with: ${value}`);
} catch (error) {
return Response.json({ error: error.message }, { status: 500 });
}
}

addEventListener('fetch', (event) => {
event.respondWith(eventHandler(event));
});
```

```js title="SYNTAX"
storeInstance.get(key);
```

##### Parameters

- `key` (required)

A string containing the key you want to retrieve the value of.

##### Return Value

An `ArrayBuffer` of the value for the given key. If the key does not exist, null is returned.

## scan

```js
import { KvStore } from 'fastedge::kv';

async function eventHandler(event) {
try {
const myStore = KvStore.open('kv-store-name-as-defined-on-app');
const results = myStore.scan('pre*');
return new Response(`The KV Store responded with: ${results.join(', ')}`);
} catch (error) {
return Response.json({ error: error.message }, { status: 500 });
}
}

addEventListener('fetch', (event) => {
event.respondWith(eventHandler(event));
});
```

```js title="SYNTAX"
storeInstance.scan(pattern);
```

##### Parameters

- `pattern` (required)

A string containing the prefix pattern match.

**Note**: This is a prefix match, it must contain the wildcard `*`. In the given example it matches
all keys that start with `pre`

##### Return Value

An `Array<string>` of all the keys that match the given pattern. If no `matches` are found it
returns an empty array.
46 changes: 46 additions & 0 deletions docs/src/content/docs/reference/fastedge/kv/open.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: KV Stores
description: How to use FastEdge Key-Value Stores.
---

### KV Store Open

How to access Key-value Stores within FastEdge.

```js
import { KvStore } from 'fastedge::kv';

async function eventHandler(event) {
try {
const myStore = KvStore.open('kv-store-name-as-defined-on-app');
const value = myStore.get('key');
return new Response(`The KV Store responded with: ${value}`);
} catch (error) {
return Response.json({ error: error.message }, { status: 500 });
}
}

addEventListener('fetch', (event) => {
event.respondWith(eventHandler(event));
});
```

```js title="SYNTAX"
KvStore.open(kvStoreName);
```

##### Parameters

- `kvStoreName` (required)

A string containing the name of the store you want to open.

##### Return Value

A `KV Instance` that lets you interact with the store. It provides:

- get
- scan
- zrangeByScore
- zscan
- bfExists
Loading