0.0.21 • Published 8 months ago

fauna-schema-tools v0.0.21

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

fauna-schema-tools

A set of tools for working with FaunaDB schema definitions.

Commands

link

Merge schema files and link functions. See Function Linking for more information.

fauna-schema-tools link
> Merge schema files and link functions

ARGUMENTS:
  <schema path>     - Path to schema files (globs are supported)
  [...schema paths] - Additional paths to schema files

FLAGS:
  --watch, -w - Watch for changes and rebuild
  --push, -p  - Push schema to db
  --help, -h  - show help

OPTIONS:
  --types-out, -t <str>  - Output path for ts types file [optional]
  --names-out, -n <str>  - Output path for ts function names map file [optional]
  --schema-out, -s <str> - Output path for combined fsl file [optional]
  --key, -k <str>        - Fauna key [optional]
  --endpoint, -e <str>   - Fauna endpoint (defaults to https://db.fauna.com if key is set, otherwise https://localhost:8443) [optional]
  --retain, -r <number>  - Number of function revisions to retain [optional]

format

Format schema files.

> Format a schema file

ARGUMENTS:
  [...schema paths] - Paths to schema files (globs are supported)

FLAGS:
  --write, -w - Write changes to file
  --help, -h  - show help

Library

When importing the library, the wasm module must be initialized. Depending on your environment, you may need to use different methods to load the wasm file:

import { init } from "fauna-schema-tools";
import wasm from "fauna-schema-tools/wasm-embedded";

init(wasm);

// or use a dynamic import
init((await import("fauna-schema-tools/wasm-embedded")).default);

// or even read the wasm file directly!
init(
  await fs.readFile(
    typeof require !== "undefined"
      ? require.resolve("fauna-schema-tools/wasm")
      : import.meta.resolve("fauna-schema-tools/wasm"),
  ),
);

// or somehow preload the module
declare const module: WebAssembly.Module;
init(module);

Function Linking

Function linking allows you to have atomic function names that won't change the behavior of your live application when you update your schema.

This is done by generating a hash based on the function's body and including it in the function's name. All references in the schema to the function are updated to use the new name.

When combined with the --retain option, you can safely push schema changes to your database without affecting your live application.

When calling a function from a query in your application, use the --names-out option to generate a module that exports the names of the functions. Then it can be used like this:

import { fql } from "fauna";
import { myFunction } from "./functions_gen";

fql`${myFunction}()`;
0.0.21

8 months ago

0.0.20

8 months ago

0.0.17

8 months ago

0.0.18

8 months ago

0.0.19

8 months ago

0.0.14

8 months ago

0.0.15

8 months ago

0.0.16

8 months ago

0.0.12

8 months ago

0.0.13

8 months ago

0.0.10

9 months ago

0.0.11

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.5

10 months ago

0.0.6

9 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago