-
-
Notifications
You must be signed in to change notification settings - Fork 410
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
Schema for Expressions #718
Open
bkeepers
wants to merge
47
commits into
main
Choose a base branch
from
expressions-schema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+322
−380
Open
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
523859b
Replace specs for expressions with shared library
bkeepers 10fa1b4
Move expressions schemas into this repo
bkeepers a72ae35
Make Ruby 2.6 happy
bkeepers 87c3de4
Use vitest to run tests
bkeepers 0d065b5
Shuffle around somethings in schema.json and rename defs
bkeepers ee46fab
Add Min/Max functions
bkeepers 6a2e622
Rename url-unfriendly defs
bkeepers 08b03c1
Move expression examples out of test dir
bkeepers 5004b6f
Initial docs for implementing functions
bkeepers 4c35f3e
Run JS lint/tests
bkeepers c51eda3
Add not about running tests to expression docs
bkeepers 50dc917
Fix README formatting
bkeepers 6262795
Remove use of path
bkeepers 4a10eaf
Simplfy schemas by making implementation cast function arguments to a…
bkeepers 48308dd
Add json_schemer as a dependency
bkeepers 81a1d65
Fix JS lint
bkeepers b8279c5
Validate schemas in strict mode
bkeepers 270f290
$defs => definitions for draft 7
bkeepers 8f69da4
Build sourcemaps
bkeepers a498b3a
Add explorer to inspect information about the schema
bkeepers a2c501a
Add simple js expression model
bkeepers a3b2076
Add validate method to Expression/Constant
bkeepers ad07179
Add simple schema class to browse and validate schemas
bkeepers d96ec78
Add proxying back to schema to resolve refs
bkeepers d134ae6
Add/Subtract/Multiply/Divide functions
bkeepers b4e7035
Fix bug where ajv eagerly resolves ref in array items
bkeepers 7c5016b
use exported Schema class where possible
bkeepers 26a08f3
Pair schema with expression and constant
bkeepers 82cf6ac
Add operator keyword to schemas
bkeepers 3f6d241
Allow null as a constant
bkeepers cfecaf5
Specify json_schemer version number
bkeepers e3b32c4
JS: Define expression.add(…) to build new expression
bkeepers 0848411
Add parent to expressions, refactor
bkeepers 639d2a7
Use external package for schemas
bkeepers 8aa356c
Merge branch 'main' into expressions-schema
bkeepers 6512d63
Add flipper-expressions-schema as separate gem for now
bkeepers 21a0806
Merge remote-tracking branch 'origin/main' into expressions-schema
bkeepers 9725f56
Ensure schemas are downloaded
bkeepers 8e1bfb1
Ensure node is setup before bundling
bkeepers 7fc02ff
Revert renaming of ci job
bkeepers 15099b9
English properly
bkeepers 6640afc
Don't auth to install npm/gems from github
bkeepers ed90c55
Try using the gem post_install hook to avoid issue with GitHub Actions
bkeepers 6350f0e
Remove actions/cache, just rely on ruby/node actions for caching
bkeepers b36dd09
Run npm install before setting up ruby
bkeepers 5470e59
Rename expressions repo
bkeepers afb896a
Merge remote-tracking branch 'origin/main' into expressions-schema
bkeepers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -21,4 +21,5 @@ log | |
.sass-cache | ||
bin | ||
.DS_Store | ||
node_modules | ||
.tool-versions |
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
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
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,34 @@ | ||
# -*- encoding: utf-8 -*- | ||
require File.expand_path('../lib/flipper/version', __FILE__) | ||
require File.expand_path('../lib/flipper/metadata', __FILE__) | ||
|
||
Gem::Specification.new do |gem| | ||
SCHEMAS_DIR = File.expand_path("node_modules/@flippercloud.io/expressions/schemas", __dir__) | ||
|
||
# Ensure schemas are downloaded loaded as a git dependency | ||
unless File.exist?(SCHEMAS_DIR) | ||
warn "Getting schemas from @flippercloud.io/expressions..." | ||
Dir.chdir(__dir__) { exec "npm install --silent" } | ||
end | ||
|
||
gem.authors = ['John Nunemaker'] | ||
gem.email = '[email protected]' | ||
gem.summary = 'ActiveRecord adapter for Flipper' | ||
gem.license = 'MIT' | ||
gem.homepage = 'https://www.flippercloud.io/docs/expressions' | ||
|
||
gem.files = [ | ||
'package.json', | ||
'package-lock.json', | ||
'lib/flipper-expressions-schema.rb', | ||
'lib/flipper/expression/schema.rb', | ||
'lib/flipper/version.rb', | ||
] + Dir['node_modules/@flippercloud.io/expressions/schemas/*.json'] | ||
gem.name = 'flipper-expressions-schema' | ||
gem.require_paths = ['lib'] | ||
gem.version = Flipper::VERSION | ||
gem.metadata = Flipper::METADATA | ||
|
||
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" | ||
gem.add_dependency 'json_schemer', '~> 1.0' | ||
end |
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
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 @@ | ||
require "flipper/expression/schema" |
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
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
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,33 @@ | ||
require "json_schemer" | ||
|
||
module Flipper | ||
class Expression | ||
class Schema < JSONSchemer::Schema::Draft7 | ||
PATH = Pathname.new(File.expand_path("../../../node_modules/@flippercloud.io/expressions", __dir__)) | ||
|
||
def self.schemas | ||
@schemas ||= | ||
Hash[ | ||
PATH | ||
.glob("schemas/*.json") | ||
.map { |path| [File.basename(path), JSON.parse(File.read(path))] } | ||
] | ||
end | ||
|
||
def self.examples | ||
PATH | ||
.glob("examples/*.json") | ||
.map { |path| [File.basename(path), JSON.parse(File.read(path))] } | ||
end | ||
|
||
def initialize(schema = self.class.schemas["schema.json"]) | ||
super( | ||
schema, | ||
insert_property_defaults: true, | ||
ref_resolver: | ||
lambda { |url| self.class.schemas[File.basename(url.path)] } | ||
) | ||
end | ||
end | ||
end | ||
end |
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,9 @@ | ||
module Flipper | ||
module Expressions | ||
class Add | ||
def self.call(left, right) | ||
left + right | ||
end | ||
end | ||
end | ||
end |
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,9 @@ | ||
module Flipper | ||
module Expressions | ||
class Divide | ||
def self.call(left, right) | ||
left / right | ||
end | ||
end | ||
end | ||
end |
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
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,11 @@ | ||
require "flipper/expression" | ||
|
||
module Flipper | ||
module Expressions | ||
class Max | ||
def self.call(*args) | ||
args.max | ||
end | ||
end | ||
end | ||
end |
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,11 @@ | ||
require "flipper/expression" | ||
|
||
module Flipper | ||
module Expressions | ||
class Min | ||
def self.call(*args) | ||
args.min | ||
end | ||
end | ||
end | ||
end |
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,9 @@ | ||
module Flipper | ||
module Expressions | ||
class Multiply | ||
def self.call(left, right) | ||
left * right | ||
end | ||
end | ||
end | ||
end |
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
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
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,9 @@ | ||
module Flipper | ||
module Expressions | ||
class Subtract | ||
def self.call(left, right) | ||
left - right | ||
end | ||
end | ||
end | ||
end |
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"@flippercloud.io/expressions": "github:flippercloud/expressions.js" | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
flipper-expression-schemas
? The ruby class isFlipper::Expression::Schema
to avoid conflicts with functions declared inFlipper::Expressions::*
, but maybe those should be renamed toFlipper::Function::*
. The JS package is@flippercloud.io/expressions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you just wondering if it should be plural? I think matching to ruby is fine even if singular.