diff --git a/.check.exs b/.check.exs new file mode 100644 index 0000000..865ff7e --- /dev/null +++ b/.check.exs @@ -0,0 +1,21 @@ +[ + ## all available options with default values (see `mix check` docs for description) + # parallel: true, + # skipped: true, + + ## list of tools (see `mix check` docs for defaults) + tools: [ + ## curated tools may be disabled (e.g. the check for compilation warnings) + # {:compiler, false}, + + ## ...or adjusted (e.g. use one-line formatter for more compact credo output) + # {:credo, "mix credo --format oneline"}, + + {:check_formatter, command: "mix spark.formatter --check"} + + ## custom new tools may be added (mix tasks or arbitrary commands) + # {:my_mix_task, command: "mix release", env: %{"MIX_ENV" => "prod"}}, + # {:my_arbitrary_tool, command: "npm test", cd: "assets"}, + # {:my_arbitrary_script, command: ["my_script", "argument with spaces"], cd: "scripts"} + ] +] diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 0000000..a69af8f --- /dev/null +++ b/.credo.exs @@ -0,0 +1,184 @@ +# This file contains the configuration for Credo and you are probably reading +# this after creating it with `mix credo.gen.config`. +# +# If you find anything wrong or unclear in this file, please report an +# issue on GitHub: https://github.com/rrrene/credo/issues +# +%{ + # + # You can have as many configs as you like in the `configs:` field. + configs: [ + %{ + # + # Run any config using `mix credo -C `. If no config name is given + # "default" is used. + # + name: "default", + # + # These are the files included in the analysis: + files: %{ + # + # You can give explicit globs or simply directories. + # In the latter case `**/*.{ex,exs}` will be used. + # + included: [ + "lib/", + "src/", + "test/", + "web/", + "apps/*/lib/", + "apps/*/src/", + "apps/*/test/", + "apps/*/web/" + ], + excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"] + }, + # + # Load and configure plugins here: + # + plugins: [], + # + # If you create your own checks, you must specify the source files for + # them here, so they can be loaded by Credo before running the analysis. + # + requires: [], + # + # If you want to enforce a style guide and need a more traditional linting + # experience, you can change `strict` to `true` below: + # + strict: false, + # + # To modify the timeout for parsing files, change this value: + # + parse_timeout: 5000, + # + # If you want to use uncolored output by default, you can change `color` + # to `false` below: + # + color: true, + # + # You can customize the parameters of any check by adding a second element + # to the tuple. + # + # To disable a check put `false` as second element: + # + # {Credo.Check.Design.DuplicatedCode, false} + # + checks: [ + # + ## Consistency Checks + # + {Credo.Check.Consistency.ExceptionNames, []}, + {Credo.Check.Consistency.LineEndings, []}, + {Credo.Check.Consistency.ParameterPatternMatching, []}, + {Credo.Check.Consistency.SpaceAroundOperators, []}, + {Credo.Check.Consistency.SpaceInParentheses, []}, + {Credo.Check.Consistency.TabsOrSpaces, []}, + + # + ## Design Checks + # + # You can customize the priority of any check + # Priority values are: `low, normal, high, higher` + # + {Credo.Check.Design.AliasUsage, false}, + # You can also customize the exit_status of each check. + # If you don't want TODO comments to cause `mix credo` to fail, just + # set this value to 0 (zero). + # + {Credo.Check.Design.TagTODO, [exit_status: 2]}, + {Credo.Check.Design.TagFIXME, []}, + + # + ## Readability Checks + # + {Credo.Check.Readability.AliasOrder, []}, + {Credo.Check.Readability.FunctionNames, []}, + {Credo.Check.Readability.LargeNumbers, []}, + {Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]}, + {Credo.Check.Readability.ModuleAttributeNames, []}, + {Credo.Check.Readability.ModuleDoc, []}, + {Credo.Check.Readability.ModuleNames, []}, + {Credo.Check.Readability.ParenthesesInCondition, []}, + {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []}, + {Credo.Check.Readability.PredicateFunctionNames, []}, + {Credo.Check.Readability.PreferImplicitTry, []}, + {Credo.Check.Readability.RedundantBlankLines, []}, + {Credo.Check.Readability.Semicolons, []}, + {Credo.Check.Readability.SpaceAfterCommas, []}, + {Credo.Check.Readability.StringSigils, []}, + {Credo.Check.Readability.TrailingBlankLine, []}, + {Credo.Check.Readability.TrailingWhiteSpace, []}, + {Credo.Check.Readability.UnnecessaryAliasExpansion, []}, + {Credo.Check.Readability.VariableNames, []}, + + # + ## Refactoring Opportunities + # + {Credo.Check.Refactor.CondStatements, []}, + {Credo.Check.Refactor.CyclomaticComplexity, false}, + {Credo.Check.Refactor.FunctionArity, [max_arity: 12]}, + {Credo.Check.Refactor.LongQuoteBlocks, []}, + {Credo.Check.Refactor.MapInto, false}, + {Credo.Check.Refactor.MatchInCondition, []}, + {Credo.Check.Refactor.NegatedConditionsInUnless, []}, + {Credo.Check.Refactor.NegatedConditionsWithElse, []}, + {Credo.Check.Refactor.Nesting, [max_nesting: 6]}, + {Credo.Check.Refactor.UnlessWithElse, []}, + {Credo.Check.Refactor.WithClauses, []}, + + # + ## Warnings + # + {Credo.Check.Warning.BoolOperationOnSameValues, []}, + {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []}, + {Credo.Check.Warning.IExPry, []}, + {Credo.Check.Warning.IoInspect, []}, + {Credo.Check.Warning.LazyLogging, false}, + {Credo.Check.Warning.MixEnv, false}, + {Credo.Check.Warning.OperationOnSameValues, []}, + {Credo.Check.Warning.OperationWithConstantResult, []}, + {Credo.Check.Warning.RaiseInsideRescue, []}, + {Credo.Check.Warning.UnusedEnumOperation, []}, + {Credo.Check.Warning.UnusedFileOperation, []}, + {Credo.Check.Warning.UnusedKeywordOperation, []}, + {Credo.Check.Warning.UnusedListOperation, []}, + {Credo.Check.Warning.UnusedPathOperation, []}, + {Credo.Check.Warning.UnusedRegexOperation, []}, + {Credo.Check.Warning.UnusedStringOperation, []}, + {Credo.Check.Warning.UnusedTupleOperation, []}, + {Credo.Check.Warning.UnsafeExec, []}, + + # + # Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`) + + # + # Controversial and experimental checks (opt-in, just replace `false` with `[]`) + # + {Credo.Check.Readability.StrictModuleLayout, false}, + {Credo.Check.Consistency.MultiAliasImportRequireUse, false}, + {Credo.Check.Consistency.UnusedVariableNames, false}, + {Credo.Check.Design.DuplicatedCode, false}, + {Credo.Check.Readability.AliasAs, false}, + {Credo.Check.Readability.MultiAlias, false}, + {Credo.Check.Readability.Specs, false}, + {Credo.Check.Readability.SinglePipe, false}, + {Credo.Check.Readability.WithCustomTaggedTuple, false}, + {Credo.Check.Refactor.ABCSize, false}, + {Credo.Check.Refactor.AppendSingleItem, false}, + {Credo.Check.Refactor.DoubleBooleanNegation, false}, + {Credo.Check.Refactor.ModuleDependencies, false}, + {Credo.Check.Refactor.NegatedIsNil, false}, + {Credo.Check.Refactor.PipeChainStart, false}, + {Credo.Check.Refactor.VariableRebinding, false}, + {Credo.Check.Warning.LeakyEnvironment, false}, + {Credo.Check.Warning.MapGetUnsafePass, false}, + {Credo.Check.Warning.UnsafeToAtom, false} + + # + # Custom checks can be created using `mix credo.gen.check`. + # + ] + } + ] +} diff --git a/.formatter.exs b/.formatter.exs index 01893f4..8305ac6 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -2,7 +2,6 @@ spark_locals_without_parens = [ base: 1, base_entity_path: 1, base_paginator: 1, - before_request: 1, endpoint: 1, endpoint: 2, entity_path: 1, @@ -10,7 +9,6 @@ spark_locals_without_parens = [ field: 2, fields_in: 1, filter_handler: 1, - finch: 1, get_endpoint: 2, get_endpoint: 3, limit_with: 1, diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..7aa6f74 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at zach@zachdaniel.dev. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..1253191 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# Contributing to Ash + +* We have a zero tolerance policy for failure to abide by our code of conduct. It is very standard, but please make sure + you have read it. +* Issues may be opened to propose new ideas, to ask questions, or to file bugs. +* Before working on a feature, please talk to the core team/the rest of the community via a proposal. We are + building something that needs to be cohesive and well thought out across all use cases. Our top priority is + supporting real life use cases like yours, but we have to make sure that we do that in a sustainable way. The + best compromise there is to make sure that discussions are centered around the *use case* for a feature, rather + than the propsed feature itself. diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..a1558f3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,27 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug, needs review +assignees: '' + +-https://hexdocs.pm/ash_json_api_wrapper-- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +A minimal set of resource definitions and calls that can reproduce the bug. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +** Runtime + - Elixir version + - Erlang version + - OS + - Ash version + - any related extension versions + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/proposal.md b/.github/ISSUE_TEMPLATE/proposal.md new file mode 100644 index 0000000..f347dcb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/proposal.md @@ -0,0 +1,36 @@ +--- +name: Proposal +about: Suggest an idea for this project +title: '' +labels: enhancement, needs review +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Express the feature either with a change to resource syntax, or with a change to the resource interface** + +For example + +```elixir + attributes do + attribute :foo, :integer, bar: 10 # <- Adding `bar` here would cause + end +``` + +Or + +```elixir + Api.read(:resource, bar: 10) # <- Adding `bar` here would cause +``` + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..8c13744 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,4 @@ +### Contributor checklist + +- [ ] Bug fixes include regression tests +- [ ] Features include unit/acceptance tests diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml new file mode 100644 index 0000000..0f6cfe0 --- /dev/null +++ b/.github/workflows/elixir.yml @@ -0,0 +1,14 @@ +name: CI +on: + push: + tags: + - "v*" + branches: [main] + pull_request: + branches: [main] + workflow_call: +jobs: + ash-ci: + uses: ash-project/ash/.github/workflows/ash-ci.yml@main + secrets: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} diff --git a/FUNDING.yml b/FUNDING.yml new file mode 100644 index 0000000..b98cb0d --- /dev/null +++ b/FUNDING.yml @@ -0,0 +1 @@ +github: zachdaniel \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4eb51a5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Zachary Scott Daniel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/config/config.exs b/config/config.exs index 13568a8..e6cbe63 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,3 +1,19 @@ import Config config :ash, :use_all_identities_in_manage_relationship?, false + +if Mix.env() == :dev do + config :git_ops, + mix_project: AshJsonApiWrapper.MixProject, + changelog_file: "CHANGELOG.md", + repository_url: "https://github.com/ash-project/ash_json_api_wrapper", + # Instructs the tool to manage your mix version in your `mix.exs` file + # See below for more information + manage_mix_version?: true, + # Instructs the tool to manage the version in your README.md + # Pass in `true` to use `"README.md"` or a string to customize + manage_readme_version: [ + "README.md" + ], + version_tag_prefix: "v" +end diff --git a/documentation/.git_keep b/documentation/.git_keep new file mode 100644 index 0000000..e69de29 diff --git a/lib/data_layer/data_layer.ex b/lib/data_layer/data_layer.ex index 47b7fdb..974edcb 100644 --- a/lib/data_layer/data_layer.ex +++ b/lib/data_layer/data_layer.ex @@ -96,15 +96,6 @@ defmodule AshJsonApiWrapper.DataLayer do AshJsonApiWrapper.Paginator.Builtins ], schema: [ - before_request: [ - type: - {:spark_function_behaviour, AshJsonApiWrapper.Finch.Plug, - {AshJsonApiWrapper.Finch.Plug.Function, 2}}, - doc: """ - A function that takes the finch request and returns the finch request. - Will be called just before the request is made for all requests, but before JSON encoding the body and query encoding the query parameters. - """ - ], base_entity_path: [ type: :string, doc: """ @@ -118,17 +109,11 @@ defmodule AshJsonApiWrapper.DataLayer do A module implementing the `AshJSonApiWrapper.Paginator` behaviour, to allow scanning pages when reading. """ ], - finch: [ + tesla: [ type: :atom, - required: true, + default: AshJsonApiWrapper.DefaultTesla, doc: """ - The name used when setting up your finch supervisor in your Application. - - e.g in this example from finch's readme: - - ```elixir - {Finch, name: MyConfiguredFinch <- this value} - ``` + The Tesla module to use. """ ] ] @@ -143,7 +128,6 @@ defmodule AshJsonApiWrapper.DataLayer do defmodule Query do defstruct [ :api, - :request, :context, :headers, :action, @@ -151,6 +135,9 @@ defmodule AshJsonApiWrapper.DataLayer do :offset, :filter, :runtime_filter, + :path, + :query_params, + :body, :sort, :endpoint, :templates, @@ -211,8 +198,8 @@ defmodule AshJsonApiWrapper.DataLayer do def can?(_, _), do: false @impl true - def resource_to_query(resource) do - %Query{request: Finch.build(:get, AshJsonApiWrapper.DataLayer.Info.endpoint_base(resource))} + def resource_to_query(resource, api \\ nil) do + %Query{path: AshJsonApiWrapper.DataLayer.Info.endpoint_base(resource), api: api} end @impl true @@ -226,7 +213,7 @@ defmodule AshJsonApiWrapper.DataLayer do if query.action do case validate_filter(filter, resource, query.action) do {:ok, {endpoint, templates, instructions}, remaining_filter} -> - {instructions, templates} = + {templates, instructions} = if templates && !Enum.empty?(templates) do {templates, instructions} else @@ -280,11 +267,11 @@ defmodule AshJsonApiWrapper.DataLayer do Enum.map(values, &{:set, field, &1}) end - {instructions, templates} + {templates, instructions} end new_query_params = - Enum.reduce(instructions || [], query.request.query || %{}, fn + Enum.reduce(instructions || [], query.query_params || %{}, fn {:set, field, value}, query -> field = field @@ -303,7 +290,7 @@ defmodule AshJsonApiWrapper.DataLayer do | endpoint: endpoint, templates: templates, runtime_filter: remaining_filter, - request: %{query.request | query: new_query_params} + query_params: new_query_params }} {:error, error} -> @@ -341,10 +328,10 @@ defmodule AshJsonApiWrapper.DataLayer do {:ok, %{ query - | request: %{query.request | query: params, headers: headers}, + | query_params: params, + headers: headers, api: query.api, action: action, - headers: headers, context: context }} end @@ -508,18 +495,15 @@ defmodule AshJsonApiWrapper.DataLayer do {with_attrs, changeset.context[:data_layer][:query_params] || %{}} end - request = - :post - |> Finch.build( - endpoint.path || AshJsonApiWrapper.DataLayer.Info.endpoint_base(resource), - [{"Content-Type", "application/json"}, {"Accept", "application/json"}], - body - ) - |> Map.put(:query, params) + path = endpoint.path || AshJsonApiWrapper.DataLayer.Info.endpoint_base(resource) + headers = [{"Content-Type", "application/json"}, {"Accept", "application/json"}] - with request <- request(request, changeset, resource, endpoint.path), - {:ok, %{status: status} = response} when status >= 200 and status < 300 <- - do_request(request, resource), + with {:ok, %{status: status} = response} when status >= 200 and status < 300 <- + AshJsonApiWrapper.DataLayer.Info.tesla(resource).get(path, + body: body, + query: params, + headers: headers + ), {:ok, body} <- Jason.decode(response.body), {:ok, entities} <- get_entities(body, endpoint, resource), {:ok, processed} <- @@ -527,8 +511,9 @@ defmodule AshJsonApiWrapper.DataLayer do {:ok, Enum.at(processed, 0)} else {:ok, %{status: status} = response} -> + # TODO: add method/query params {:error, - "Received status code #{status} in request #{inspect(request)}. Response: #{inspect(response)}"} + "Received status code #{status} from GET #{path}. Response: #{inspect(response)}"} other -> other @@ -567,18 +552,25 @@ defmodule AshJsonApiWrapper.DataLayer do end def run_query(query, resource, overridden?) do + endpoint = + query.endpoint || AshJsonApiWrapper.DataLayer.Info.endpoint(resource, query.action.name) + + query = + if overridden? do + query + else + %{query | path: endpoint.path} + end + if query.templates do query.templates |> Enum.uniq() |> Task.async_stream( fn template -> - query = %{ - query - | request: fill_template(query.request, template), - templates: nil - } - - run_query(query, resource, true) + query + |> fill_template(template) + |> Map.put(:templates, nil) + |> run_query(resource, true) end, timeout: :infinity ) @@ -596,20 +588,10 @@ defmodule AshJsonApiWrapper.DataLayer do end ) else - endpoint = - query.endpoint || AshJsonApiWrapper.DataLayer.Info.endpoint(resource, query.action.name) - - path = - if overridden? do - query.request.path - else - endpoint.path - end - query = if query.limit do if query.offset && query.offset != 0 do - Logger.warn( + Logger.warning( "ash_json_api_wrapper does not support limits with offsets yet, and so they will both be applied after." ) @@ -619,10 +601,7 @@ defmodule AshJsonApiWrapper.DataLayer do {:param, param} -> %{ query - | request: %{ - query.request - | query: Map.put(query.request.query || %{}, param, query.limit) - } + | query_params: Map.put(query.query_params || %{}, param, query.limit) } _ -> @@ -633,18 +612,18 @@ defmodule AshJsonApiWrapper.DataLayer do query end - with request <- request(query.request, query.context, resource, path), - {:ok, %{status: status} = response} when status >= 200 and status < 300 <- - do_request(request, resource), + with {:ok, %{status: status} = response} when status >= 200 and status < 300 <- + make_request(resource, query), {:ok, body} <- Jason.decode(response.body), - {:ok, entities} <- get_entities(body, endpoint, resource, paginate_with: request) do + {:ok, entities} <- get_entities(body, endpoint, resource, paginate_with: query) do entities |> limit_offset(query) |> process_entities(resource, endpoint) else {:ok, %{status: status} = response} -> + # TODO: more info here {:error, - "Received status code #{status} in request #{inspect(query.request)}. Response: #{inspect(response)}"} + "Received status code #{status} from #{query.path}. Response: #{inspect(response)}"} other -> other @@ -672,23 +651,26 @@ defmodule AshJsonApiWrapper.DataLayer do defp do_sort(other, _), do: other - defp fill_template(request, template) do + defp fill_template(query, template) do template |> List.wrap() - |> Enum.reduce(request, fn - {key, replacement}, request -> + |> Enum.reduce(query, fn + {key, replacement}, query -> %{ - request - | path: String.replace(request.path, ":#{key}", to_string(replacement)) + query + | path: String.replace(query.path, ":#{key}", to_string(replacement)) } - {:set, key, value}, request -> + {:set, key, value}, query -> key = key |> List.wrap() |> Enum.map(&to_string/1) - %{request | query: AshJsonApiWrapper.Helpers.put_at_path(request.query, key, value)} + %{ + query + | query_params: AshJsonApiWrapper.Helpers.put_at_path(query.query_params, key, value) + } end) end @@ -707,108 +689,25 @@ defmodule AshJsonApiWrapper.DataLayer do end end - defp request(request, query_or_changeset, resource, path) do - case AshJsonApiWrapper.DataLayer.Info.before_request(resource) do - {module, opts} -> - module.call(Map.put(request, :path, path), query_or_changeset, opts) + defp make_request(resource, query) do + # log_send(path, query) + AshJsonApiWrapper.DataLayer.Info.tesla(resource).get(query.path, + body: query.body, + query: query.query_params + ) - nil -> - request - |> Map.put(:path, path) - end + # |> log_resp(path, query) end - defp do_request(request, resource) do - request - |> encode_query() - |> encode_body() - |> log_send() - |> make_request(AshJsonApiWrapper.DataLayer.Info.finch(resource)) - |> log_resp() - end + # defp log_send(request) do + # Logger.debug("Sending request: #{inspect(request)}") + # request + # end - defp make_request(request, finch) do - case Finch.request(request, finch) do - {:ok, %{status: code, headers: headers} = response} when code >= 300 and code < 400 -> - headers - # some function to pluck headers - |> get_header("location") - |> case do - nil -> - {:ok, response} - - location -> - raise "Following 300+ status code redirects not yet supported, was redirected to #{location}" - end - - other -> - other - end - end - - defp get_header(headers, name) do - Enum.find_value(headers, fn {key, value} -> - if key == name do - value - end - end) - end - - defp log_send(request) do - Logger.debug("Sending request: #{inspect(request)}") - request - end - - defp log_resp(response) do - Logger.debug("Received response: #{inspect(response)}") - response - end - - defp encode_query(%{query: query} = request) when is_map(query) do - %{request | query: do_encode_query(query)} - end - - defp encode_query(request), do: request - - defp do_encode_query(query) do - query - |> sanitize_for_encoding() - |> URI.encode_query() - end - - defp sanitize_for_encoding(value, acc \\ %{}, prefix \\ nil) - - defp sanitize_for_encoding(value, acc, prefix) when is_map(value) do - value - |> Enum.reduce(acc, fn {key, value}, acc -> - new_prefix = - if prefix do - prefix <> "[#{key}]" - else - to_string(key) - end - - sanitize_for_encoding(value, acc, new_prefix) - end) - end - - defp sanitize_for_encoding(value, acc, prefix) when is_list(value) do - value - |> Enum.with_index() - |> Map.new(fn {value, index} -> - {to_string(index), sanitize_for_encoding(value)} - end) - |> sanitize_for_encoding(acc, prefix) - end - - defp sanitize_for_encoding(value, _acc, nil), do: value - defp sanitize_for_encoding(value, acc, prefix), do: Map.put(acc, prefix, value) - - defp encode_body(%{body: body} = request) when is_map(body) do - %{request | body: Jason.encode!(body)} - end - - defp encode_body(request), do: request + # defp log_resp(response) do + # Logger.debug("Received response: #{inspect(response)}") + # response + # end defp process_entities(entities, resource, endpoint) do Enum.reduce_while(entities, {:ok, []}, fn entity, {:ok, entities} -> @@ -916,29 +815,30 @@ defmodule AshJsonApiWrapper.DataLayer do body, %{paginator: {module, opts}} = endpoint, resource, - request, + paginate_with, entity_callback, bodies ) do - case module.continue(body, Enum.at(bodies, 0), request, opts) do + case module.continue(body, Enum.at(bodies, 0), opts) do :halt -> {:ok, bodies} {:ok, instructions} -> - request = apply_instructions(request, instructions) + query = apply_instructions(paginate_with, instructions) - case do_request(request, resource) do + case make_request(resource, query) do {:ok, %{status: status} = response} when status >= 200 and status < 300 -> with {:ok, new_body} <- Jason.decode(response.body), {:ok, entities} <- entity_callback.(new_body) do - get_all_bodies(new_body, endpoint, resource, request, entity_callback, [ + get_all_bodies(new_body, endpoint, resource, paginate_with, entity_callback, [ entities | bodies ]) end {:ok, %{status: status} = response} -> + # TODO: more info {:error, - "Received status code #{status} in request #{inspect(request)}. Response: #{inspect(response)}"} + "Received status code #{status} in #{query.path}. Response: #{inspect(response)}"} {:error, error} -> {:error, error} @@ -946,23 +846,23 @@ defmodule AshJsonApiWrapper.DataLayer do end end - defp apply_instructions(request, instructions) do - request + defp apply_instructions(query, instructions) do + query |> apply_params(instructions) |> apply_headers(instructions) end - defp apply_params(request, %{params: params}) when is_map(params) do - %{request | query: Ash.Helpers.deep_merge_maps(request.query || %{}, params)} + defp apply_params(query, %{params: params}) when is_map(params) do + %{query | query_params: Ash.Helpers.deep_merge_maps(query.query_params || %{}, params)} end - defp apply_params(request, _), do: request + defp apply_params(query, _), do: query - defp apply_headers(request, %{headers: headers}) when is_map(headers) do + defp apply_headers(query, %{headers: headers}) when is_map(headers) do %{ - request + query | headers: - request.headers + query.headers |> Kernel.||(%{}) |> Map.new() |> Map.merge(headers) @@ -970,7 +870,7 @@ defmodule AshJsonApiWrapper.DataLayer do } end - defp apply_headers(request, _), do: request + defp apply_headers(query, _), do: query defp get_field(resource, endpoint, field) do Enum.find(endpoint.fields || [], &(&1.name == field)) || diff --git a/lib/data_layer/info.ex b/lib/data_layer/info.ex index dbf7ca8..4d65293 100644 --- a/lib/data_layer/info.ex +++ b/lib/data_layer/info.ex @@ -8,9 +8,15 @@ defmodule AshJsonApiWrapper.DataLayer.Info do Extension.get_opt(resource, [:json_api_wrapper, :endpoints], :base, nil, false) end - @spec finch(map | Ash.Resource.t()) :: module | nil - def finch(resource) do - Extension.get_opt(resource, [:json_api_wrapper], :finch, nil, false) + @spec tesla(map | Ash.Resource.t()) :: module | nil + def tesla(resource) do + Extension.get_opt( + resource, + [:json_api_wrapper], + :tesla, + AshJsonApiWrapper.DefaultTesla, + false + ) end @spec base_entity_path(map | Ash.Resource.t()) :: String.t() | nil @@ -23,11 +29,6 @@ defmodule AshJsonApiWrapper.DataLayer.Info do Extension.get_opt(resource, [:json_api_wrapper], :base_paginator, nil, false) end - @spec before_request(map | Ash.Resource.t()) :: AshJsonApiWrapper.Finch.Plug.ref() | nil - def before_request(resource) do - Extension.get_opt(resource, [:json_api_wrapper], :before_request, nil) - end - @spec field(map | Ash.Resource.t(), atom) :: AshJsonApiWrapper.Field.t() | nil def field(resource, name) do resource diff --git a/lib/default_tesla.ex b/lib/default_tesla.ex new file mode 100644 index 0000000..d3bd821 --- /dev/null +++ b/lib/default_tesla.ex @@ -0,0 +1,5 @@ +defmodule AshJsonApiWrapper.DefaultTesla do + use Tesla + + plug(Tesla.Middleware.FollowRedirects) +end diff --git a/lib/finch/plug.ex b/lib/finch/plug.ex deleted file mode 100644 index 363a875..0000000 --- a/lib/finch/plug.ex +++ /dev/null @@ -1,15 +0,0 @@ -defmodule AshJsonApiWrapper.Finch.Plug do - defmacro __using__(_) do - quote do - @behaviour AshJsonApiWrapper.Finch.Plug - end - end - - @type ref :: {module, Keyword.t()} - - @callback call( - request :: Finch.Request.t(), - query_or_changeset :: Ash.Changeset.t() | Ash.Query.t(), - opts :: Keyword.t() - ) :: Finch.Request.t() -end diff --git a/lib/finch/plug/function.ex b/lib/finch/plug/function.ex deleted file mode 100644 index 5bbe251..0000000 --- a/lib/finch/plug/function.ex +++ /dev/null @@ -1,13 +0,0 @@ -defmodule AshJsonApiWrapper.Finch.Plug.Function do - @moduledoc "Function implementation handler for `AshJsonApiWrapper.Finch`" - use AshJsonApiWrapper.Finch.Plug - - @impl AshJsonApiWrapper.Finch.Plug - def call(request, query_or_changeset, fun: {m, f, a}) do - apply(m, f, [request, query_or_changeset | a]) - end - - def call(request, query_or_changeset, fun: fun) do - fun.(request, query_or_changeset) - end -end diff --git a/lib/paginator/continuation_property.ex b/lib/paginator/continuation_property.ex index c33ee8e..c5197d0 100644 --- a/lib/paginator/continuation_property.ex +++ b/lib/paginator/continuation_property.ex @@ -1,9 +1,9 @@ defmodule AshJsonApiWrapper.Paginator.ContinuationProperty do use AshJsonApiWrapper.Paginator - def continue(_response, [], _, _), do: :halt + def continue(_response, [], _), do: :halt - def continue(response, _entities, _request, opts) do + def continue(response, _entities, opts) do case ExJSONPath.eval(response, opts[:get]) do {:ok, [value | _]} when not is_nil(value) -> if opts[:header] do diff --git a/lib/paginator/paginator.ex b/lib/paginator/paginator.ex index 18d8d45..74bce6a 100644 --- a/lib/paginator/paginator.ex +++ b/lib/paginator/paginator.ex @@ -14,7 +14,6 @@ defmodule AshJsonApiWrapper.Paginator do @callback continue( response :: term, entities :: [Ash.Resource.record()], - request :: Finch.Request.t(), opts :: Keyword.t() ) :: {:ok, %{optional(:params) => map, optional(:headers) => map}} | :halt end diff --git a/logos/.gitkeep b/logos/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/logos/.gitkeep @@ -0,0 +1 @@ + diff --git a/logos/cropped-for-header.png b/logos/cropped-for-header.png new file mode 100644 index 0000000..118c318 Binary files /dev/null and b/logos/cropped-for-header.png differ diff --git a/logos/logo-black-text.png b/logos/logo-black-text.png new file mode 100644 index 0000000..536e3d4 Binary files /dev/null and b/logos/logo-black-text.png differ diff --git a/logos/logo-only.png b/logos/logo-only.png new file mode 100644 index 0000000..cf6366e Binary files /dev/null and b/logos/logo-only.png differ diff --git a/logos/logo-white-text.png b/logos/logo-white-text.png new file mode 100644 index 0000000..9180074 Binary files /dev/null and b/logos/logo-white-text.png differ diff --git a/logos/small-logo.png b/logos/small-logo.png new file mode 100644 index 0000000..9fc9aa1 Binary files /dev/null and b/logos/small-logo.png differ diff --git a/mix.exs b/mix.exs index d6baf3d..ab9c7b9 100644 --- a/mix.exs +++ b/mix.exs @@ -1,14 +1,33 @@ defmodule AshJsonApiWrapper.MixProject do use Mix.Project + @description """ + A data layer for building resources backed by external JSON APIs + """ + + @version "0.1.0" + def project do [ app: :ash_json_api_wrapper, - version: "0.1.0", + version: @version, + consolidate_protocols: Mix.env() != :test, elixir: "~> 1.12", aliases: aliases(), start_permanent: Mix.env() == :prod, - deps: deps() + deps: deps(), + package: package(), + elixirc_paths: elixirc_paths(Mix.env()), + dialyzer: [plt_add_apps: [:ash]], + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [ + coveralls: :test, + "coveralls.github": :test + ], + docs: docs(), + description: @description, + source_url: "https://github.com/ash-project/ash_json_api", + homepage_url: "https://github.com/ash-project/ash_json_api" ] end @@ -19,17 +38,103 @@ defmodule AshJsonApiWrapper.MixProject do ] end + defp extras() do + "documentation/**/*.md" + |> Path.wildcard() + |> Enum.map(fn path -> + title = + path + |> Path.basename(".md") + |> String.split(~r/[-_]/) + |> Enum.map(&String.capitalize/1) + |> Enum.join(" ") + |> case do + "F A Q" -> + "FAQ" + + other -> + other + end + + {String.to_atom(path), + [ + title: title + ]} + end) + end + + defp groups_for_extras() do + "documentation/*" + |> Path.wildcard() + |> Enum.map(fn folder -> + name = + folder + |> Path.basename() + |> String.split(~r/[-_]/) + |> Enum.map(&String.capitalize/1) + |> Enum.join(" ") + + {name, folder |> Path.join("**") |> Path.wildcard()} + end) + end + + defp docs do + [ + main: "AshJsonApiWrapper", + source_ref: "v#{@version}", + logo: "logos/small-logo.png", + extra_section: "GUIDES", + spark: [ + extensions: [ + %{ + module: AshJsonApiWrapper.DataLayer, + name: "AshJsonApiWrapper", + target: "Ash.Resource", + type: "DataLayer" + } + ] + ], + extras: extras(), + groups_for_extras: groups_for_extras(), + groups_for_modules: [ + AshJsonApiWrapper: [ + AshJsonApiWrapper, + AshJsonApiWrapper.DataLayer + ], + Introspection: [ + AshJsonApiWrapper.DataLayer.Info + ], + Internals: ~r/.*/ + ] + ] + end + defp aliases do [ + sobelow: "sobelow --skip", + credo: "credo --strict", + docs: ["docs", "ash.replace_doc_links"], "spark.formatter": "spark.formatter --extensions AshJsonApiWrapper.DataLayer" ] end + defp package do + [ + name: :ash_json_api_wrapper, + licenses: ["MIT"], + files: ~w(lib .formatter.exs mix.exs README* LICENSE* + CHANGELOG* documentation), + links: %{ + GitHub: "https://github.com/ash-project/ash_json_api_wrapper" + } + ] + end + # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ash, "~> 2.5"}, - {:finch, "~> 0.14"}, + {:ash, ash_version("2.11.0-rc.3")}, + {:tesla, "~> 1.7"}, {:exjsonpath, "~> 0.1"}, # Dev/Test dependencies {:ex_doc, "~> 0.22", only: :dev, runtime: false}, @@ -43,4 +148,21 @@ defmodule AshJsonApiWrapper.MixProject do {:parse_trans, "3.3.0", only: [:dev, :test], override: true} ] end + + defp ash_version(default_version) do + case System.get_env("ASH_VERSION") do + nil -> default_version + "local" -> [path: "../ash"] + "main" -> [git: "https://github.com/ash-project/ash.git"] + version -> "~> #{version}" + end + end + + defp elixirc_paths(:test) do + elixirc_paths(:dev) ++ ["test/support"] + end + + defp elixirc_paths(_) do + ["lib"] + end end diff --git a/mix.lock b/mix.lock index ca7df20..df4b6e0 100644 --- a/mix.lock +++ b/mix.lock @@ -1,16 +1,16 @@ %{ - "ash": {:hex, :ash, "2.5.2", "018dfaeb78b97810dfbc12d13842dd3fe4b8a797deebd4b9fbe32a9cd4471238", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: true]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:spark, ">= 0.3.0", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "69df569a557f55bb0479cf270ecaf80ef58780fa607e118e2889af1ae4448b45"}, + "ash": {:hex, :ash, "2.10.2", "f2bc2d0238fa658df9d84ce776d3f04c2926e87a517e95b72ce96d7539f3028a", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: true]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:spark, "~> 1.0", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d7bccc87e1d972ce0bfcd06af5d97828c2fc83b8cf1b024e2650f88820d3321"}, "bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, "castore": {:hex, :castore, "0.1.22", "4127549e411bedd012ca3a308dede574f43819fe9394254ca55ab4895abfa1a2", [:mix], [], "hexpm", "c17576df47eb5aa1ee40cc4134316a99f5cad3e215d5c77b8dd3cfef12a22cac"}, "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"}, "credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"}, - "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, + "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, "earmark_parser": {:hex, :earmark_parser, "1.4.16", "607709303e1d4e3e02f1444df0c821529af1c03b8578dfc81bb9cf64553d02b9", [:mix], [], "hexpm", "69fcf696168f5a274dd012e3e305027010658b2d1630cef68421d6baaeaccead"}, - "ecto": {:hex, :ecto, "3.9.4", "3ee68e25dbe0c36f980f1ba5dd41ee0d3eb0873bccae8aeaf1a2647242bffa35", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "de5f988c142a3aa4ec18b85a4ec34a2390b65b24f02385c1144252ff6ff8ee75"}, - "elixir_make": {:hex, :elixir_make, "0.7.3", "c37fdae1b52d2cc51069713a58c2314877c1ad40800a57efb213f77b078a460d", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "24ada3e3996adbed1fa024ca14995ef2ba3d0d17b678b0f3f2b1f66e6ce2b274"}, + "ecto": {:hex, :ecto, "3.10.2", "6b887160281a61aa16843e47735b8a266caa437f80588c3ab80a8a960e6abe37", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6a895778f0d7648a4b34b486af59a1c8009041fbdf2b17f1ac215eb829c60235"}, + "elixir_make": {:hex, :elixir_make, "0.7.7", "7128c60c2476019ed978210c245badf08b03dbec4f24d05790ef791da11aa17c", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "5bc19fff950fad52bbe5f211b12db9ec82c6b34a9647da0c2224b8b8464c7e6c"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ets": {:hex, :ets, "0.8.1", "8ff9bcda5682b98493f8878fc9dbd990e48d566cba8cce59f7c2a78130da29ea", [:mix], [], "hexpm", "6be41b50adb5bc5c43626f25ea2d0af1f4a242fb3fad8d53f0c67c20b78915cc"}, "ex_check": {:hex, :ex_check, "0.12.0", "c0e2919ecc06afeaf62c52d64f3d91bd4bc7dd8deaac5f84becb6278888c967a", [:mix], [], "hexpm", "cfafa8ef97c2596d45a1f19b5794cb5c7f700f25d164d3c9f8d7ec17ee67cf42"}, @@ -18,7 +18,6 @@ "excoveralls": {:hex, :excoveralls, "0.13.4", "7b0baee01fe150ef81153e6ffc0fc68214737f54570dc257b3ca4da8e419b812", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "faae00b3eee35cdf0342c10b669a7c91f942728217d2a7c7f644b24d391e6190"}, "exjsonpath": {:hex, :exjsonpath, "0.9.0", "87e593eb0deb53aa0688ca9f9edc9fb3456aca83c82245f83201ea04d696feba", [:mix], [], "hexpm", "8d7a8e9ba784e1f7a67c6f1074a3ac91a3a79a45969514ee5d95cea5bf749627"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, - "finch": {:hex, :finch, "0.14.0", "619bfdee18fc135190bf590356c4bf5d5f71f916adb12aec94caa3fa9267a4bc", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5459acaf18c4fdb47a8c22fb3baff5d8173106217c8e56c5ba0b93e66501a8dd"}, "gettext": {:hex, :gettext, "0.19.1", "564953fd21f29358e68b91634799d9d26989f8d039d7512622efb3c3b1c97892", [:mix], [], "hexpm", "10c656c0912b8299adba9b061c06947511e3f109ab0d18b44a866a4498e77222"}, "git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"}, "git_ops": {:hex, :git_ops, "2.5.4", "1f303c9952eccfc183631b7c3cceeb6604cb641a40dd29269bcd622416395de9", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "85d1fe718cacad67a7ca1e9e809a6cbb9771c2e9238c96e9aebbb286114f64e0"}, @@ -34,17 +33,18 @@ "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, "mint": {:hex, :mint, "1.4.2", "50330223429a6e1260b2ca5415f69b0ab086141bc76dc2fbf34d7c389a6675b2", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "ce75a5bbcc59b4d7d8d70f8b2fc284b1751ffb35c7b6a6302b5192f8ab4ddd80"}, "mix_test_watch": {:hex, :mix_test_watch, "1.1.0", "330bb91c8ed271fe408c42d07e0773340a7938d8a0d281d57a14243eae9dc8c3", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "52b6b1c476cbb70fd899ca5394506482f12e5f6b0d6acff9df95c7f1e0812ec3"}, - "nimble_options": {:hex, :nimble_options, "0.5.2", "42703307b924880f8c08d97719da7472673391905f528259915782bb346e0a1b", [:mix], [], "hexpm", "4da7f904b915fd71db549bcdc25f8d56f378ef7ae07dc1d372cbe72ba950dce0"}, + "nimble_options": {:hex, :nimble_options, "1.0.2", "92098a74df0072ff37d0c12ace58574d26880e522c22801437151a159392270e", [:mix], [], "hexpm", "fd12a8db2021036ce12a309f26f564ec367373265b53e25403f0ee697380f1b8"}, "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, "nimble_pool": {:hex, :nimble_pool, "0.2.6", "91f2f4c357da4c4a0a548286c84a3a28004f68f05609b4534526871a22053cde", [:mix], [], "hexpm", "1c715055095d3f2705c4e236c18b618420a35490da94149ff8b580a2144f653f"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, "picosat_elixir": {:hex, :picosat_elixir, "0.2.3", "bf326d0f179fbb3b706bb2c15fbc367dacfa2517157d090fdfc32edae004c597", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f76c9db2dec9d2561ffaa9be35f65403d53e984e8cd99c832383b7ab78c16c66"}, "sobelow": {:hex, :sobelow, "0.11.1", "23438964486f8112b41e743bbfd402da3e5b296fdc9eacab29914b79c48916dd", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9897363a7eff96f4809304a90aad819e2ad5e5d24db547af502885146746a53c"}, - "sourceror": {:hex, :sourceror, "0.11.2", "549ce48be666421ac60cfb7f59c8752e0d393baa0b14d06271d3f6a8c1b027ab", [:mix], [], "hexpm", "9ab659118896a36be6eec68ff7b0674cba372fc8e210b1e9dc8cf2b55bb70dfb"}, - "spark": {:hex, :spark, "0.3.4", "0084ce931c0e444194d5198b6f872c74c85607b6e5672436056e9f5b6fa41139", [:mix], [{:nimble_options, "~> 0.5", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "7816d3a43916c5fac2bb2308f9a3442644950e5e269014e4cdc5b2cab0bab5e0"}, + "sourceror": {:hex, :sourceror, "0.12.3", "a2ad3a1a4554b486d8a113ae7adad5646f938cad99bf8bfcef26dc0c88e8fade", [:mix], [], "hexpm", "4d4e78010ca046524e8194ffc4683422f34a96f6b82901abbb45acc79ace0316"}, + "spark": {:hex, :spark, "1.1.18", "349ad7ec69b389294fd3f17a4e49e772cafbbb71d3571add652a80f7b3c44990", [:mix], [{:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "964b46866e01b39810a82f9ee538f7f25d450cb3223af58b0f4717ce69d6f167"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"}, - "telemetry": {:hex, :telemetry, "1.2.0", "a8ce551485a9a3dac8d523542de130eafd12e40bbf76cf0ecd2528f24e812a44", [:rebar3], [], "hexpm", "1427e73667b9a2002cf1f26694c422d5c905df889023903c4518921d53e3e883"}, + "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, + "tesla": {:hex, :tesla, "1.7.0", "a62dda2f80d4f8a925eb7b8c5b78c461e0eb996672719fe1a63b26321a5f8b4e", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.13", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:msgpax, "~> 2.3", [hex: :msgpax, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2e64f01ebfdb026209b47bc651a0e65203fcff4ae79c11efb73c4852b00dc313"}, "timex": {:hex, :timex, "3.7.8", "0e6e8bf7c0aba95f1e13204889b2446e7a5297b1c8e408f15ab58b2c8dc85f81", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 1.1", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "8f3b8edc5faab5205d69e5255a1d64a83b190bab7f16baa78aefcb897cf81435"}, "typable": {:hex, :typable, "0.3.0", "0431e121d124cd26f312123e313d2689b9a5322b15add65d424c07779eaa3ca1", [:mix], [], "hexpm", "880a0797752da1a4c508ac48f94711e04c86156f498065a83d160eef945858f8"}, "tzdata": {:hex, :tzdata, "1.1.1", "20c8043476dfda8504952d00adac41c6eda23912278add38edc140ae0c5bcc46", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a69cec8352eafcd2e198dea28a34113b60fdc6cb57eb5ad65c10292a6ba89787"}, diff --git a/test/hackernews_test.exs b/test/hackernews_test.exs index d396bab..72e00a4 100644 --- a/test/hackernews_test.exs +++ b/test/hackernews_test.exs @@ -9,8 +9,6 @@ defmodule AshJsonApiWrapper.Hackernews.Test do data_layer: AshJsonApiWrapper.DataLayer json_api_wrapper do - finch MyApp.Finch - endpoints do base "https://hacker-news.firebaseio.com/v0/" @@ -88,8 +86,6 @@ defmodule AshJsonApiWrapper.Hackernews.Test do end json_api_wrapper do - finch MyApp.Finch - endpoints do base "https://hacker-news.firebaseio.com/v0/" @@ -124,8 +120,6 @@ defmodule AshJsonApiWrapper.Hackernews.Test do end json_api_wrapper do - finch MyApp.Finch - endpoints do base "https://hacker-news.firebaseio.com/v0/" @@ -156,8 +150,6 @@ defmodule AshJsonApiWrapper.Hackernews.Test do end test "it works" do - Finch.start_link(name: MyApp.Finch) - assert [top_story] = TopStory |> Ash.Query.limit(1)