-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/readable-recordHook-error-messages
- Loading branch information
Showing
20 changed files
with
490 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ | |
"devDependencies": { | ||
"express": "^4.18.2" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
Oops, something went wrong.