@json-cms/cli

json-cms

Usage no npm install needed!

<script type="module">
  import jsonCmsCli from 'https://cdn.skypack.dev/@json-cms/cli';
</script>

README

@json-cms/cli

Usage

json-cms <OPERATION> <ARGUMENTS>

Operations

create-collection

Arguments

  • --name <STRING> name of the collection (validation is decodeURIComponent(name) === encodeURIComponent)
  • --schema-file <STRING> path to a file with the JSON schema relative to where the command is executed

Example

json-cms create-collection --name test_1 --schema-file schema.json

create-key

Arguments

  • --comment <STRING> (optional) to remember what is it is used for

Example

json-cms create-key --comment "For my app"

returns

{
  "key": "4688f608-15b5-4784-841f-e6c3f81213c0"
}

delete-collection

Arguments

  • --name <STRING> the collection you want to delete

Example

json-cms delete-collection --name test_1

returns

{
  "deletedCollection": "test_1"
}

delete-key

Arguments

  • --key <STRING> the key you want to delete

Example

json-cms delete-key --key 4688f608-15b5-4784-841f-e6c3f81213c0

returns

{
  "deletedKey": "4688f608-15b5-4784-841f-e6c3f81213c0"
}

get-collection

Arguments

  • --name <STRING> the name of the collection
  • --access (optional) to see the keys that have access to the collection
  • --data (optional) to see the content of the collection
  • --schema (optional) to see the JSON schema of the collection

Example

json-cms get-collection --name test_1 --access --data --schema

returns

{
  "collection": "test_1",
  "access": [
    {
      "key": "4688f608-15b5-4784-841f-e6c3f81213c0",
      "comment": "For my app",
      "get": true,
      "post": true,
      "patch": false,
      "put": false,
      "delete": false
    }
  ],
  "data": [
    {
      "test": "hello world"
    }
  ],
  "schema": {
    "type": "object",
    "properties": {
      "test": {
        "type": "string"
      }
    }
  }
}

get-key

Arguments

  • --key <STRING> the key you want to see

Example

json-cms get-key --key 4688f608-15b5-4784-841f-e6c3f81213c0

returns

{
  "key": "4688f608-15b5-4784-841f-e6c3f81213c0",
  "comment": "For my app",
  "access": [
    {
      "collection": "test_1",
      "get": true,
      "post": true,
      "patch": false,
      "put": false,
      "delete": false
    }
  ]
}

init-db

Create the database tables.

list-collections

Example

json-cms list-collections

returns

{
  "collections": [
    "test_1"
  ]
}

list-keys

Example

json-cms list-keys

returns

{
  "keys": [
    {
      "key": "4688f608-15b5-4784-841f-e6c3f81213c0",
      "comment": "For my app"
    }
  ]
}

set-access

Arguments

  • --key <STRING> the key to which you want to give access to a collection
  • --collection <STRING> the collection name
  • --methods <STRING> the allowed methods, comma-separated, no spaces

This will override existing access for that key / collection pair. If the key can already do GET and you want to add POST --methods must be get,post.

Example

json-cms set-access \
--key 4688f608-15b5-4784-841f-e6c3f81213c0 \
--collection test_1  \
--methods get,post

returns

{
  "access": "set",
  "collection": "test_1",
  "key": "4688f608-15b5-4784-841f-e6c3f81213c0 ",
  "methods": [
    "get",
    "post"
  ]
}

If the key already had access to the collection access would have been updated.