Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Space with YAML Plugin #312

Merged
merged 31 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0ac349a
initial commit for YAML Schema Plugin
madaley1 Nov 7, 2023
90c8cd7
add dependency
madaley1 Nov 7, 2023
55e71cf
fix: remove changes to JSON-schema meant for YAML-schema
madaley1 Nov 7, 2023
12d7c41
fix: changeset
madaley1 Nov 7, 2023
6658edb
fix: improper changeset
madaley1 Nov 7, 2023
0ff9148
fix: restore json-schema readme
madaley1 Nov 7, 2023
27b64e4
fix: remove console.dir
madaley1 Nov 7, 2023
eef9e35
extract server to testing utils to DRY things up
madaley1 Nov 7, 2023
dd3b127
Update plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts
madaley1 Nov 9, 2023
c910647
feat/fix: DRY up YAML Schema plugin and add fetch util
madaley1 Nov 9, 2023
ca7007e
Merge branch 'feat/yaml-schema-implementation' of https://github.com/…
madaley1 Nov 9, 2023
cf84375
changeset
madaley1 Nov 13, 2023
0bedfaf
undo changes to JSON-schema
madaley1 Nov 13, 2023
0b80a1a
Merge branch 'main' into feat/yaml-schema-implementation
madaley1 Nov 13, 2023
86cb87c
Update plugins/yaml-schema/src/index.ts
madaley1 Nov 13, 2023
ec5b264
Update changeset per Carls suggestion
madaley1 Nov 13, 2023
1f8b9c9
Update plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts
madaley1 Nov 13, 2023
8caec57
Update plugins/yaml-schema/tests/exampleData.yml
madaley1 Nov 13, 2023
719a2c6
Update plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts
madaley1 Nov 13, 2023
74284af
Update plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts
madaley1 Nov 13, 2023
bc6efe7
Update plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts
madaley1 Nov 13, 2023
359873c
Update plugins/yaml-schema/tests/exampleData.yml
madaley1 Nov 13, 2023
e8ba31d
Merge branch 'feat/yaml-schema-implementation' of https://github.com/…
madaley1 Nov 13, 2023
6fbfec8
update changeset and undo package changes
madaley1 Nov 13, 2023
c2f227a
update tests to work
madaley1 Nov 13, 2023
02865bf
Merge branch 'main' into feat/yaml-schema-implementation
madaley1 Nov 13, 2023
afe0532
fix issue with `npm i`
madaley1 Nov 13, 2023
72e79ef
add dependencies
madaley1 Nov 13, 2023
8ab4c20
be more specific about the exports to solve error
madaley1 Nov 13, 2023
b1890d4
temporary code additions while json-schema remains unchanged
madaley1 Nov 13, 2023
52b80ba
Apply suggestions from code review
carlbrugger Nov 16, 2023
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
8 changes: 8 additions & 0 deletions .changeset/yellow-rats-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@flatfile/plugin-convert-json-schema': patch
carlbrugger marked this conversation as resolved.
Show resolved Hide resolved
'@flatfile/plugin-convert-yaml-schema': patch
'@flatfile/util-fetch-schema': patch
'@flatfile/utils-testing': patch
---
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.
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"
}
}
}
5 changes: 5 additions & 0 deletions plugins/yaml-schema/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @flatfile/plugin-yaml-schema
carlbrugger marked this conversation as resolved.
Show resolved Hide resolved

## 0.0.1

### Patch Changes
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
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.1",
"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.1",
"@flatfile/utils-testing": "^0.0.5",
"@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 || 'JSON Schema Workbook',
carlbrugger marked this conversation as resolved.
Show resolved Hide resolved
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