Skip to content

Commit

Permalink
Merge branch 'main' into feat/readable-recordHook-error-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbrugger committed Nov 20, 2023
2 parents f9cf411 + 7599800 commit 8b7a9f1
Show file tree
Hide file tree
Showing 20 changed files with 490 additions and 16 deletions.
12 changes: 10 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
"singleQuote": true,
"jsxSingleQuote": true,
"trailingComma": "es5",
"semi": false
}
"semi": false,
"overrides": [
{
"files": "*.yml",
"options": {
"parser": "yaml"
}
}
]
}
72 changes: 68 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion plugins/json-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"devDependencies": {
"express": "^4.18.2"
}
}
}
15 changes: 15 additions & 0 deletions plugins/yaml-schema/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @flatfile/plugin-convert-yaml-schema

## 0.0.2

### Patch Changes

- 0d5f2c1: Introducing the @flatfile/plugin-convert-yaml-schema plugin to configure Flatfile Spaces based on a provided YAML Schema.
DRY up and release YAML plugin, remove accidental edits to JSON plugin.
- Updated dependencies [0d5f2c1]
- @flatfile/util-fetch-schema@0.0.2
- @flatfile/utils-testing@0.0.6

## 0.0.1

### Patch Changes
7 changes: 7 additions & 0 deletions plugins/yaml-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @flatfile/plugin-convert-yaml-schema

This package automatically converts YAML Schema to the Flatfile Blueprint, a powerful DDL (Data Definition Language) created by Flatfile with a focus on validation and data preparation.

## Get Started

Follow [this guide](https://flatfile.com/docs/plugins/schemas/convert-yaml-schema) to learn how to use the plugin.
43 changes: 43 additions & 0 deletions plugins/yaml-schema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@flatfile/plugin-convert-yaml-schema",
"version": "0.0.2",
"description": "A plugin for converting YAML Schema definitions to Flatfile Blueprint.",
"registryMetadata": {
"category": "schema-converters"
},
"engines": {
"node": ">= 16"
},
"source": "src/index.ts",
"main": "dist/main.js",
"module": "dist/module.mjs",
"types": "dist/types.d.ts",
"scripts": {
"build": "parcel build",
"dev": "parcel watch",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
},
"keywords": [],
"author": "Flatfile, Inc.",
"repository": {
"type": "git",
"url": "https://github.com/FlatFilers/flatfile-plugins.git",
"directory": "plugins/yaml-schema"
},
"license": "ISC",
"dependencies": {
"@flatfile/api": "^1.5.33",
"@flatfile/plugin-convert-json-schema": "^0.0.4",
"@flatfile/plugin-json-schema": "^0.0.2",
"@flatfile/plugin-space-configure": "^0.1.5",
"@flatfile/util-fetch-schema": "^0.0.2",
"@flatfile/utils-testing": "^0.0.6",
"@hyperjump/json-schema": "^1.6.4",
"axios": "^1.5.1",
"js-yaml": "^4.1.0"
},
"devDependencies": {
"express": "^4.18.2"
}
}
76 changes: 76 additions & 0 deletions plugins/yaml-schema/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Flatfile } from '@flatfile/api'
import { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
import { generateFields } from '@flatfile/plugin-convert-json-schema'
import {
Setup,
SetupFactory,
configureSpace,
} from '@flatfile/plugin-space-configure'
import type {
ModelToSheetConfig,
PartialWorkbookConfig,
} from '@flatfile/util-fetch-schema'
import { getSchemas } from '@flatfile/util-fetch-schema/src'
import jsYaml from 'js-yaml'

export async function generateSetup(
models?: ModelToSheetConfig[],
schemas?: any[],
options?: {
workbookConfig?: PartialWorkbookConfig
debug?: boolean
}
): Promise<SetupFactory> {
const sheets = await Promise.all(
models.map(async (model: ModelToSheetConfig, i) => {
const data = schemas[i]
const fields = await generateFields(data)
return {
name: model?.name || data.title,
...(data?.description && { description: data.description }),
fields,
...model,
}
})
)
const setup: Setup = {
workbooks: [
{
name: options?.workbookConfig?.name || 'YAML Schema Workbook',
sheets,
},
],
...options?.workbookConfig,
}
if (options?.debug) {
console.dir(setup, { depth: null })
}
return setup
}

export function configureSpaceWithYamlSchema(
models?: ModelToSheetConfig[],
options?: {
workbookConfig?: PartialWorkbookConfig
debug?: boolean
},
callback?: (
event: FlatfileEvent,
workbookIds: string[],
tick: (progress: number, message?: string) => Promise<Flatfile.JobResponse>
) => any | Promise<any>
) {
return async function (listener: FlatfileListener) {
const schemas = await getSchemas(models)
listener.use(
configureSpace(
await generateSetup(
models,
schemas.map((schema) => jsYaml.load(schema)),
options
),
callback
)
)
}
}
29 changes: 29 additions & 0 deletions plugins/yaml-schema/tests/exampleData.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$id: 'https://localhost:3000/yaml'
description: 'A basic set of YAML Schema to test data type conversions simply'
type: 'object'
title: 'ExampleData'
properties:
stringColumn:
description: 'A column for strings!'
type: 'string'

integerColumn:
description: 'A column for integers!'
type: 'integer'

arrayColumn:
description: 'A column for string arrays!'
type: 'array'
items:
type: 'string'

objectColumn:
description: 'A column for nested columns containing numbers and strings!'
type: 'object'
properties:
nestedUniqueNumberColumn:
description: 'A column for unique numbers!'
type: 'number'
uniqueItems: true
nestedStringColumn:
type: 'string'
Loading

0 comments on commit 8b7a9f1

Please sign in to comment.