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 14 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
---

DRY up YAML plugin, remove accidental edits to JSON plugin
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions .changeset/young-bottles-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@flatfile/plugin-convert-yaml-schema': patch
---

Introducing the @flatfile/plugin-convert-yaml-schema plugin to configure Flatfile Spaces based on a provided YAML Schema.
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
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"
}
}
]
}
63 changes: 60 additions & 3 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion plugins/json-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
"dependencies": {
"@flatfile/api": "^1.5.33",
"@flatfile/plugin-space-configure": "^0.1.5",
"@flatfile/util-fetch-schema": "^0.0.1",
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
"@hyperjump/json-schema": "^1.6.4",
"axios": "^1.5.1"
},
"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.
40 changes: 40 additions & 0 deletions plugins/yaml-schema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"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-json-schema": "^0.0.2",
"@flatfile/plugin-space-configure": "^0.1.5",
"@hyperjump/json-schema": "^1.6.4",
"axios": "^1.5.1",
"js-yaml": "^4.1.0"
},
"devDependencies": {
"express": "^4.18.2"
}
}
37 changes: 37 additions & 0 deletions plugins/yaml-schema/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Flatfile } from '@flatfile/api'
import { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
import { generateSetup } from '@flatfile/plugin-convert-json-schema'
import { 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 function configureSpaceWithYamlSchema(
models?: ModelToSheetConfig[],
options?: {
workbookConfig?: PartialWorkbookConfig
debug?: boolean
},
callback?: (
event: FlatfileEvent,
workbookIds: string[],
tick: (progress?: number, message?: string) => Promise<Flatfile.JobResponse>
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
) => 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/json'
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
description: 'A basic set of JSON Schema to test data type conversions simply'
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
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'
99 changes: 99 additions & 0 deletions plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import api from '@flatfile/api'
import { deleteSpace, setupListener, setupSpace, startServer, stopServer } from '@flatfile/utils-testing'
import express from 'express'
import fs from 'fs'
import path from 'path'
import { configureSpaceWithYamlSchema } from '../src'

const app = express()
const port = 8080
const url = `http://localhost:${port}/`

let server

describe('configureSpaceWithJsonSchema() e2e', () => {
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
const pureDataSchema = fs.readFileSync(
path.resolve(__dirname, './exampleData.yml'),
'utf-8'
)

const expectedWorkbookData = {
name: 'JSON Schema Workbook',
carlbrugger marked this conversation as resolved.
Show resolved Hide resolved
labels: [],
sheets: [
{
name: 'ExampleData',
config: {
name: 'ExampleData',
description:
'A basic set of JSON Schema to test data type conversions simply',
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
fields: [
{
type: 'string',
key: 'stringColumn',
label: 'stringColumn',
description: 'A column for strings!',
},
{
type: 'number',
key: 'integerColumn',
label: 'integerColumn',
description: 'A column for integers!',
},
{
type: 'enum',
config: { options: [] },
key: 'arrayColumn',
label: 'arrayColumn',
description: 'An enum of Selected Values',
},
{
type: 'number',
key: 'objectColumn_nestedUniqueNumberColumn',
label: 'objectColumn_nestedUniqueNumberColumn',
description: 'A column for unique numbers!',
},
{
type: 'string',
key: 'objectColumn_nestedStringColumn',
label: 'objectColumn_nestedStringColumn',
},
],
},
},
],
}

let spaceId: string
const listener = setupListener()

beforeAll(async () => {
console.log(`Starting temporary server on port ${port}`)
server = startServer(app, port, pureDataSchema)
console.log('Setting up Space and Retrieving spaceId')

await listener.use(configureSpaceWithYamlSchema([{ sourceUrl: url }]))

const space = await setupSpace()
spaceId = space.id
})

afterAll(async () => {
stopServer(server)
await deleteSpace(spaceId)
})

it('should configure a space and correctly format and flatten the JSON Schema', async () => {
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
console.log('starting configuration')
madaley1 marked this conversation as resolved.
Show resolved Hide resolved
await listener.waitFor('job:ready', 1, 'space:configure')

const space = await api.spaces.get(spaceId)
const workspace = await api.workbooks.get(space.data.primaryWorkbookId)
const workspaceData = workspace.data

expect(workspaceData.name).toBe(expectedWorkbookData.name)
expect(workspaceData.sheets[0].config).toMatchObject(
expectedWorkbookData.sheets[0].config
)
})
})
1 change: 1 addition & 0 deletions utils/fetch-schema/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @flatfile/util-fetch-schema
8 changes: 8 additions & 0 deletions utils/fetch-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @flatfile/util-fetch-schema

This utility will provide a utility for fetching schemas from remote storage locations.

## Get Started

Follow [this guide](https://flatfile.com/docs/plugins/utilities/fetch-schema) to learn how to use the utility.

Loading