Skip to content

Commit

Permalink
Refactor for initial JSR release
Browse files Browse the repository at this point in the history
  • Loading branch information
jollytoad committed Jul 3, 2024
1 parent 4363a76 commit 093eb18
Show file tree
Hide file tree
Showing 37 changed files with 830 additions and 276 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Deno
uses: denoland/setup-deno@v1

- name: Verify formatting
run: deno fmt --check

- name: Run linter
run: deno task lint

- name: Run TypeScript checking
run: deno task check

- name: Run tests
run: deno task test

- name: Publish dry run
run: deno publish --dry-run
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish

on:
workflow_run:
workflows: [ci]
types: [completed]
branches: [main]

jobs:
publish:
runs-on: ubuntu-latest

if: ${{ github.event.workflow_run.conclusion == 'success' }}

permissions:
contents: read
id-token: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Deno
uses: denoland/setup-deno@v1

- name: Publish package
run: deno publish
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true,
"deno.importMap": "./_test/import_map.web_storage.json",
"editor.defaultFormatter": "denoland.vscode-deno",
"editor.tabSize": 2
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0]

- Initial release on JSR
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Mark Gibson
Copyright (c) 2024 Mark Gibson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
66 changes: 4 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,9 @@
# Pluggable Storage Modules for Deno
# Pluggable Storage Modules

NOTE: This is an experimental module.
NOTE: This is an experimental library.

Each module here provides the same interface to a hierarchical key -> value
storage mechanism. So they can be imported directly or as swappable interface
via an import map, for example:
via an import map.

```json
{
"imports": {
"$store": "https://deno.land/x/storage_modules/deno_fs.ts"
}
}
```

## Functions

Each function takes a hierarchical key as an array of strings. It's up to the
storage module how those are translated to the underlying storage. But it may be
best to assume the first level key to be a grouping level, eg. a database name.

Any JSON serializable value can be stored.

See the [types](./types.ts) for a description of the module interface.

## Modules

### web_storage.ts

This uses `localStorage` of the standard
[Web Storage](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API)
API.

The parts of the key are joined with a `/` to form a single key string for use
with the `localStorage` API.

Import mapping: `"$store": "https://deno.land/x/storage_modules/web_storage.ts"`

### deno_fs.ts

This stores values in individual files under a directory hierarchy via
[Deno fs](https://deno.land/api?s=Deno.readTextFile) calls. By default this is
under a `.store` dir under the current working dir. This can be overridden via
the environment var `STORE_FS_ROOT`.

Each level of the key becomes a directory up to the last segment which becomes a
JSON file.

eg: `["one", "two", "three"]` -> `.store/one/two/three.json`

Import mapping: `"$store": "https://deno.land/x/storage_modules/deno_fs.ts"`

### deno_kv.ts

Use the [Deno KV](https://deno.land/manual/runtime/kv) API for storage.

Import mapping: `"$store": "https://deno.land/x/storage_modules/deno_kv.ts"`

### deno_kv_fs.ts

Combination of a readonly `deno_fs.ts` and `deno_kv.ts`, allowing fallback or
immutable storage in the filesystem, and mutable storage via the KV store.

By default the filesystem takes priority, and cannot be overridden by KV values,
unless the env var `STORE_PRIMARY` is set to `kv`, in which case the KV always
overrides filesystem values.
See [./store/README.md] for more details.
5 changes: 0 additions & 5 deletions _test/import_map.deno_fs.json

This file was deleted.

5 changes: 0 additions & 5 deletions _test/import_map.deno_kv.json

This file was deleted.

5 changes: 0 additions & 5 deletions _test/import_map.deno_kv_fs.json

This file was deleted.

5 changes: 0 additions & 5 deletions _test/import_map.web_storage.json

This file was deleted.

30 changes: 24 additions & 6 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
{
"unstable": [
"kv"
],
"tasks": {
"test:web_storage": "deno test --check --import-map=./_test/import_map.web_storage.json",
"test:deno_fs": "deno test --check --allow-read --allow-write --allow-env --import-map=./_test/import_map.deno_fs.json",
"test:deno_kv": "deno test --check --unstable --allow-env --import-map=./_test/import_map.deno_kv.json",
"test:deno_kv_fs": "deno test --check --unstable --allow-read --allow-env --import-map=./_test/import_map.deno_kv_fs.json",
"test": "deno task test:web_storage; deno task test:deno_fs; deno task test:deno_kv; deno task test:deno_kv_fs",
"check": "deno fmt && deno lint && deno task test"
"test": "deno test --allow-env --allow-read --allow-write --allow-net",
"reload": "deno cache --reload **/*.ts jsr:@check/deps",
"check": "deno check **/*.ts",
"lint": "deno lint",
"ok": "deno fmt && deno task lint && deno task check && deno task test && deno publish --dry-run --allow-dirty",
"outdated": "deno run --allow-read=. --allow-net=jsr.io,registry.npmjs.org jsr:@check/deps",
"lock": "rm -f deno.lock && deno task check"
},
"workspaces": [
"./store",
"./store-common",
"./store-deno-fs",
"./store-deno-kv",
"./store-deno-kv-fs",
"./store-web-storage"
],
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.0-rc.3",
"@std/fs": "jsr:@std/fs@^1.0.0-rc.3",
"@std/path": "jsr:@std/path@^1.0.0-rc.3",
"@std/url": "jsr:@std/url@^1.0.0-rc.2"
}
}
138 changes: 45 additions & 93 deletions deno.lock

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

10 changes: 10 additions & 0 deletions store-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Common types and utilities for Pluggable Storage Modules

See [@jollytoad/store](https://jsr.io/@jollytoad/store) for the bigger picture.

This package provides the storage module interface definition and some reusable
utility function for use by implementations.

- [the interface](./types.ts)
- [key conversion utils](./key-utils.ts)
- [test utils](./test-storage-module.ts)
9 changes: 9 additions & 0 deletions store-common/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@jollytoad/store-common",
"version": "0.1.0",
"exports": {
"./key-utils": "./key-utils.ts",
"./test-storage-module": "./test-storage-module.ts",
"./types": "./types.ts"
}
}
Loading

0 comments on commit 093eb18

Please sign in to comment.