From e75022c744041a6ecccaab704b98ab28b13856b2 Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Tue, 8 Oct 2024 15:50:30 +0000 Subject: [PATCH] Remove EDTF.js shim in favor of EDTF hex package --- app/lib/edtf.ex | 89 -------- app/lib/edtf/humanize.ex | 35 --- app/lib/edtf/humanize/date.ex | 85 -------- app/lib/edtf/humanize/list.ex | 86 -------- app/lib/meadow/application.ex | 1 - app/mix.exs | 1 + app/mix.lock | 1 + app/priv/nodejs/edtf/.docker-npm | 1 - app/priv/nodejs/edtf/index.js | 28 --- app/priv/nodejs/edtf/package-lock.json | 201 ------------------ app/priv/nodejs/edtf/package.json | 11 - app/priv/nodejs/edtf/portlog.js | 5 - app/test/edtf_test.exs | 166 --------------- app/test/meadow/batches_test.exs | 2 +- app/test/meadow/config_test.exs | 17 +- .../data/csv/metadata_update_jobs_test.exs | 2 +- 16 files changed, 9 insertions(+), 722 deletions(-) delete mode 100644 app/lib/edtf.ex delete mode 100644 app/lib/edtf/humanize.ex delete mode 100644 app/lib/edtf/humanize/date.ex delete mode 100644 app/lib/edtf/humanize/list.ex delete mode 100644 app/priv/nodejs/edtf/.docker-npm delete mode 100755 app/priv/nodejs/edtf/index.js delete mode 100644 app/priv/nodejs/edtf/package-lock.json delete mode 100644 app/priv/nodejs/edtf/package.json delete mode 100644 app/priv/nodejs/edtf/portlog.js delete mode 100644 app/test/edtf_test.exs diff --git a/app/lib/edtf.ex b/app/lib/edtf.ex deleted file mode 100644 index f423565cb..000000000 --- a/app/lib/edtf.ex +++ /dev/null @@ -1,89 +0,0 @@ -defmodule EDTF do - @moduledoc """ - EDTF Parsing GenServer - """ - - use GenServer - - alias Meadow.Config - alias Meadow.Utils.Lambda - - import Meadow.Utils.Atoms - - require Logger - - @timeout 1000 - - @doc """ - Parse an EDTF date string - - Example: - iex> parse("1999-06-10") - {:ok, %{level: 0, type: "Date", values: [1999, 5, 10]}} - - iex> parse("bad date!") - {:error, "Invalid EDTF input: bad date!"} - """ - def parse(value) do - case GenServer.call(__MODULE__, {:parse, value}) do - {:ok, result} -> {:ok, atomize(result)} - other -> other - end - end - - @doc """ - Validate an EDTF date string - - Example: - iex> validate("1999-06-10") - {:ok, "1999-06-10"} - - iex> validate("bad date!") - {:error, "Invalid EDTF input: bad date!"} - """ - def validate(value), - do: GenServer.call(__MODULE__, {:validate, value}) - - @doc """ - Humanize an EDTF date string - - Example: - iex> humanize("1999-06-10") - "June 10, 1999" - - iex> humanize("bad date!") - {:error, "Invalid EDTF input: bad date!"} - """ - def humanize(value) do - case value |> parse() |> EDTF.Humanize.humanize() do - :original -> value - other -> other - end - end - - def child_spec(opts) do - %{ - id: __MODULE__, - start: {__MODULE__, :start_link, [opts]} - } - end - - def start_link(args \\ []) do - GenServer.start_link(__MODULE__, args, name: __MODULE__) - end - - def init(_args) do - Logger.info("Starting EDTF Parser") - - case script_config() |> Lambda.init() do - {_, port} -> {:ok, port} - other -> other - end - end - - def handle_call({command, data}, _from, port) do - {:reply, script_config() |> Lambda.invoke(%{function: command, value: data}, @timeout), port} - end - - defp script_config, do: {:local, {Config.priv_path("nodejs/edtf/index.js"), "handler"}} -end diff --git a/app/lib/edtf/humanize.ex b/app/lib/edtf/humanize.ex deleted file mode 100644 index 32e0dda45..000000000 --- a/app/lib/edtf/humanize.ex +++ /dev/null @@ -1,35 +0,0 @@ -defmodule EDTF.Humanize do - @moduledoc """ - Convert EDTF dates to human readable form - """ - - alias EDTF.Humanize - - def humanize({:ok, value}), do: humanize(value) - def humanize({:error, _} = arg), do: arg - - def humanize(nil), do: "Unknown" - - def humanize([%{type: _} | [%{type: _}]] = values), - do: humanize(%{type: "Interval", values: values}) - - def humanize(%{type: "Interval", values: values}) do - case values do - [value | [%{type: "Infinity"}]] -> "from #{humanize(value)}" - [%{type: "Infinity"} | [value]] -> "before #{humanize(value)}" - _ -> values |> Enum.map_join(" to ", &humanize/1) - end - end - - def humanize(%{type: "Date"} = input), do: Humanize.Date.humanize(input) - def humanize(%{type: "Season"} = input), do: Humanize.Date.humanize(input) - def humanize(%{type: "Year"} = input), do: Humanize.Date.humanize(input) - def humanize(%{type: "Decade"} = input), do: Humanize.Date.humanize(input) - def humanize(%{type: "Century"} = input), do: Humanize.Date.humanize(input) - def humanize(%{type: "List"} = input), do: Humanize.List.humanize(input) - def humanize(%{type: "Set"} = input), do: Humanize.List.humanize(input) - def humanize(%{type: "Continuation"} = input), do: Humanize.List.humanize(input) - - def humanize(input) when is_map(input) and not is_map_key(input, :type), - do: input |> Map.put(:type, "Date") |> humanize() -end diff --git a/app/lib/edtf/humanize/date.ex b/app/lib/edtf/humanize/date.ex deleted file mode 100644 index 6442caf6e..000000000 --- a/app/lib/edtf/humanize/date.ex +++ /dev/null @@ -1,85 +0,0 @@ -defmodule EDTF.Humanize.Date do - @moduledoc """ - Humanize EDTF Date, Year, Decade, Century, and Season types - """ - - @bce_suffix " BCE" - @months ~w(January February March April May June July August September October November December) - @seasons %{ - 21 => "Spring", - 22 => "Summer", - 23 => "Autumn", - 24 => "Winter", - 25 => "Spring (Northern Hemisphere)", - 26 => "Summer (Northern Hemisphere)", - 27 => "Autumn (Northern Hemisphere)", - 28 => "Winter (Northern Hemisphere)", - 29 => "Spring (Southern Hemisphere)", - 30 => "Summer (Southern Hemisphere)", - 31 => "Autumn (Southern Hemisphere)", - 32 => "Winter (Southern Hemisphere)", - 33 => "Quarter 1", - 34 => "Quarter 2", - 35 => "Quarter 3", - 36 => "Quarter 4", - 37 => "Quadrimester 1", - 38 => "Quadrimester 2", - 39 => "Quadrimester 3", - 40 => "Semestral 1", - 41 => "Semestral 2" - } - - def humanize(%{type: "Date", approximate: _v, values: _values} = input) do - "circa " <> (input |> Map.delete(:approximate) |> humanize()) - end - - def humanize(%{type: "Date", unspecified: 15, values: values}) - when length(values) == 1, - do: "Unknown" - - def humanize(%{type: "Date", unspecified: unspecified, values: values} = input) - when unspecified in [8, 12, 14] and length(values) == 1 do - input - |> Map.delete(:unspecified) - |> humanize() - |> String.replace(~r/(\d+)/, "\\0s") - end - - def humanize(%{type: "Date", unspecified: _unspecified, values: _values}) do - :original - end - - def humanize(%{type: "Date", uncertain: _v, values: _values} = input) do - (input |> Map.delete(:uncertain) |> humanize()) <> "?" - end - - def humanize(%{type: "Date", values: values}) do - case values do - [year | [month | [day]]] -> "#{Enum.at(@months, month)} #{day}, #{set_era(year)}" - [year | [month]] -> "#{Enum.at(@months, month)} #{set_era(year)}" - [year] -> "#{set_era(year)}" - end - end - - def humanize(%{type: "Season", values: [year | [season]]}) when year < 0, - do: Map.get(@seasons, season) <> " #{-year}#{@bce_suffix}" - - def humanize(%{type: "Season", values: [year | [season]]}), - do: Map.get(@seasons, season) <> " #{year}" - - def humanize(%{type: "Year", values: [value]}), do: set_era(value) - - def humanize(%{type: "Decade", values: [value]}) when value < 0, - do: "#{-value * 10}s#{@bce_suffix}" - - def humanize(%{type: "Decade", values: [value]}), do: "#{value * 10}s" - - def humanize(%{type: "Century", values: [value]}) when value < 0, - do: "#{Inflex.ordinalize(-value)} Century#{@bce_suffix}" - - def humanize(%{type: "Century", values: [value]}), do: "#{Inflex.ordinalize(value)} Century" - - defp set_era(year) do - if year < 0, do: "#{-year}#{@bce_suffix}", else: to_string(year) - end -end diff --git a/app/lib/edtf/humanize/list.ex b/app/lib/edtf/humanize/list.ex deleted file mode 100644 index f7563b799..000000000 --- a/app/lib/edtf/humanize/list.ex +++ /dev/null @@ -1,86 +0,0 @@ -defmodule EDTF.Humanize.List do - @moduledoc """ - Humanize EDTF Set and List types - """ - - alias EDTF.Humanize - - @units [nil, "year", "month", "date"] - - def humanize(%{type: "Set"} = input) do - input - |> humanize_list_or_set_values() - |> make_list("or") - end - - def humanize(%{type: "List"} = input) do - input - |> humanize_list_or_set_values() - |> make_list("and") - end - - def humanize(%{type: "Continuation", subtype: "Set", position: :earlier, value: value}) do - with {human, time_unit} <- humanize_with_unit(value) do - "some #{time_unit} before #{human}" - end - end - - def humanize(%{type: "Continuation", subtype: "Set", position: :later, value: value}) do - with {human, time_unit} <- humanize_with_unit(value) do - "some #{time_unit} after #{human}" - end - end - - def humanize(%{type: "Continuation", subtype: "List", position: :earlier, value: value}) do - with {human, time_unit} <- humanize_with_unit(value) do - "all #{Inflex.pluralize(time_unit)} before #{human}" - end - end - - def humanize(%{type: "Continuation", subtype: "List", position: :later, value: value}) do - with {human, time_unit} <- humanize_with_unit(value) do - "all #{Inflex.pluralize(time_unit)} after #{human}" - end - end - - defp continuation(type, position, value), - do: %{type: "Continuation", subtype: type, position: position, value: value} - - defp humanize_list_or_set_values(%{type: type, values: values} = input) do - first_value = List.first(values) - last_value = List.last(values) - - case input do - %{earlier: true, later: true} -> - [continuation(type, :earlier, first_value) | values] ++ - [continuation(type, :later, last_value)] - - %{earlier: true} -> - [continuation(type, :earlier, first_value) | values] - - %{later: true} -> - values ++ [continuation(type, :later, last_value)] - - _ -> - values - end - |> Enum.map(&Humanize.humanize/1) - end - - defp humanize_with_unit(value) do - {Humanize.humanize(value), precision(value)} - end - - defp precision(value), do: Enum.at(@units, length(value.values)) - - defp make_list([item], _trailing_join), do: item - - defp make_list(items, trailing_join) when length(items) == 2 do - Enum.join(items, " #{trailing_join} ") - end - - defp make_list(items, trailing_join) do - [Enum.slice(items, 0..-2) |> Enum.join(", "), List.last(items)] - |> Enum.join(", #{trailing_join} ") - end -end diff --git a/app/lib/meadow/application.ex b/app/lib/meadow/application.ex index 1a1e02214..38f90f2e8 100644 --- a/app/lib/meadow/application.ex +++ b/app/lib/meadow/application.ex @@ -25,7 +25,6 @@ defmodule Meadow.Application do end base_children = [ - EDTF, {Phoenix.PubSub, [name: Meadow.PubSub, adapter: Phoenix.PubSub.PG2]}, Meadow.Telemetry, {Registry, keys: :unique, name: Meadow.TaskRegistry} diff --git a/app/mix.exs b/app/mix.exs index 344164592..03b382d04 100644 --- a/app/mix.exs +++ b/app/mix.exs @@ -64,6 +64,7 @@ defmodule Meadow.MixProject do {:ecto_psql_extras, "~> 0.2"}, {:ecto_ranked, "~> 0.5"}, {:ecto_sql, "~> 3.0 and >= 3.4.4"}, + {:edtf, "~> 1.0"}, {:elastix, "~> 0.10.0"}, {:ets, "~> 0.9.0"}, {:ex_aws, "~> 2.5.0"}, diff --git a/app/mix.lock b/app/mix.lock index aa7c188f6..44d3dcf02 100644 --- a/app/mix.lock +++ b/app/mix.lock @@ -29,6 +29,7 @@ "ecto_psql_extras": {:hex, :ecto_psql_extras, "0.8.2", "79350a53246ac5ec27326d208496aebceb77fa82a91744f66a9154560f0759d3", [:mix], [{:ecto_sql, "~> 3.7", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:postgrex, "> 0.16.0 and < 0.20.0", [hex: :postgrex, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1 or ~> 4.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "6149c1c4a5ba6602a76cb09ee7a269eb60dab9694a1dbbb797f032555212de75"}, "ecto_ranked": {:hex, :ecto_ranked, "0.6.0", "c3bc7925610244d3f0be01befb02991670c00f32890174392f2701f760124b26", [:mix], [{:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "735dd6e02096445f4084e0f76e1d0e100cdcf5386d40d6d4cb7e54f2d437fb27"}, "ecto_sql": {:hex, :ecto_sql, "3.12.1", "c0d0d60e85d9ff4631f12bafa454bc392ce8b9ec83531a412c12a0d415a3a4d0", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.12", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aff5b958a899762c5f09028c847569f7dfb9cc9d63bdb8133bff8a5546de6bf5"}, + "edtf": {:hex, :edtf, "1.2.0", "debb74f77b58b3d922e31b3b574a77a147622c09697636115a6f977eb7301e56", [:mix], [{:inflex, "~> 2.1", [hex: :inflex, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "745e3829b1fb24b78eaf51b5a1106a32eb5a36703475cdc6627c908e766718e8"}, "elastix": {:hex, :elastix, "0.10.0", "7567da885677ba9deffc20063db5f3ca8cd10f23cff1ab3ed9c52b7063b7e340", [:mix], [{:httpoison, "~> 1.4", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0", [hex: :poison, repo: "hexpm", optional: true]}, {:retry, "~> 0.8", [hex: :retry, repo: "hexpm", optional: false]}], "hexpm", "5fb342ce068b20f7845f5dd198c2dc80d967deafaa940a6e51b846db82696d1d"}, "eternal": {:hex, :eternal, "1.2.2", "d1641c86368de99375b98d183042dd6c2b234262b8d08dfd72b9eeaafc2a1abd", [:mix], [], "hexpm", "2c9fe32b9c3726703ba5e1d43a1d255a4f3f2d8f8f9bc19f094c7cb1a7a9e782"}, "ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"}, diff --git a/app/priv/nodejs/edtf/.docker-npm b/app/priv/nodejs/edtf/.docker-npm deleted file mode 100644 index e58f02dce..000000000 --- a/app/priv/nodejs/edtf/.docker-npm +++ /dev/null @@ -1 +0,0 @@ -Build on Docker Release diff --git a/app/priv/nodejs/edtf/index.js b/app/priv/nodejs/edtf/index.js deleted file mode 100755 index 54d72f0bb..000000000 --- a/app/priv/nodejs/edtf/index.js +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env node - -const edtf = require("edtf"); -edtf.defaults.level = 3; - -const functions = { - validate: async (value) => await edtf(value).edtf, - parse: async (value) => { - const replacer = (_key, value) => value === Infinity ? {"type": "Infinity"} : value; - let result = await edtf.parse(value); - return JSON.parse(JSON.stringify(result, replacer)) - } -}; - -const handler = (event, _context, _callback) => { - return new Promise((resolve, reject) => { - let func = functions[event.function]; - if (typeof func == "function") { - func(event.value) - .catch(_err => reject(`Invalid EDTF input: ${event.value}`)) - .then(data => resolve(data)); - } else { - reject(`Unknown function: ${event.function}`); - } - }); -} - -module.exports = {handler}; \ No newline at end of file diff --git a/app/priv/nodejs/edtf/package-lock.json b/app/priv/nodejs/edtf/package-lock.json deleted file mode 100644 index a7fae48a2..000000000 --- a/app/priv/nodejs/edtf/package-lock.json +++ /dev/null @@ -1,201 +0,0 @@ -{ - "name": "edtf", - "version": "0.1.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "edtf", - "version": "0.1.0", - "license": "Apache-2.0", - "dependencies": { - "edtf": "^3.1.0" - } - }, - "node_modules/commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" - }, - "node_modules/discontinuous-range": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", - "integrity": "sha1-44Mx8IRLukm5qctxx3FYWqsbxlo=" - }, - "node_modules/drange": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/drange/-/drange-1.1.1.tgz", - "integrity": "sha512-pYxfDYpued//QpnLIm4Avk7rsNtAtQkUES2cwAYSvD/wd2pKD71gN2Ebj3e7klzXwjocvE8c5vx/1fxwpqmSxA==", - "optional": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/edtf": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/edtf/-/edtf-3.1.0.tgz", - "integrity": "sha512-m9pPUyBb/REAYraG/+l+D7HRHpCwK+8jaZyBrO0BP0elRSRxt0O+4ttbpY5SyctkLL/hF/AMEaco36m74ZxQIw==", - "dependencies": { - "nearley": "^2.19.7" - }, - "optionalDependencies": { - "randexp": "^0.5.3" - } - }, - "node_modules/moo": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.1.tgz", - "integrity": "sha512-I1mnb5xn4fO80BH9BLcF0yLypy2UKl+Cb01Fu0hJRkJjlCRtxZMWkTdAtDd5ZqCOxtCkhmRwyI57vWT+1iZ67w==" - }, - "node_modules/nearley": { - "version": "2.20.1", - "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.20.1.tgz", - "integrity": "sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==", - "dependencies": { - "commander": "^2.19.0", - "moo": "^0.5.0", - "railroad-diagrams": "^1.0.0", - "randexp": "0.4.6" - }, - "bin": { - "nearley-railroad": "bin/nearley-railroad.js", - "nearley-test": "bin/nearley-test.js", - "nearley-unparse": "bin/nearley-unparse.js", - "nearleyc": "bin/nearleyc.js" - }, - "funding": { - "type": "individual", - "url": "https://nearley.js.org/#give-to-nearley" - } - }, - "node_modules/nearley/node_modules/randexp": { - "version": "0.4.6", - "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", - "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", - "dependencies": { - "discontinuous-range": "1.0.0", - "ret": "~0.1.10" - }, - "engines": { - "node": ">=0.12" - } - }, - "node_modules/railroad-diagrams": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", - "integrity": "sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=" - }, - "node_modules/randexp": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.5.3.tgz", - "integrity": "sha512-U+5l2KrcMNOUPYvazA3h5ekF80FHTUG+87SEAmHZmolh1M+i/WyTCxVzmi+tidIa1tM4BSe8g2Y/D3loWDjj+w==", - "optional": true, - "dependencies": { - "drange": "^1.0.2", - "ret": "^0.2.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/randexp/node_modules/ret": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/ret/-/ret-0.2.2.tgz", - "integrity": "sha512-M0b3YWQs7R3Z917WRQy1HHA7Ba7D8hvZg6UE5mLykJxQVE2ju0IXbGlaHPPlkY+WN7wFP+wUMXmBFA0aV6vYGQ==", - "optional": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/ret": { - "version": "0.1.15", - "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", - "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", - "engines": { - "node": ">=0.12" - } - } - }, - "dependencies": { - "commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" - }, - "discontinuous-range": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", - "integrity": "sha1-44Mx8IRLukm5qctxx3FYWqsbxlo=" - }, - "drange": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/drange/-/drange-1.1.1.tgz", - "integrity": "sha512-pYxfDYpued//QpnLIm4Avk7rsNtAtQkUES2cwAYSvD/wd2pKD71gN2Ebj3e7klzXwjocvE8c5vx/1fxwpqmSxA==", - "optional": true - }, - "edtf": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/edtf/-/edtf-3.1.0.tgz", - "integrity": "sha512-m9pPUyBb/REAYraG/+l+D7HRHpCwK+8jaZyBrO0BP0elRSRxt0O+4ttbpY5SyctkLL/hF/AMEaco36m74ZxQIw==", - "requires": { - "nearley": "^2.19.7", - "randexp": "^0.5.3" - } - }, - "moo": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.1.tgz", - "integrity": "sha512-I1mnb5xn4fO80BH9BLcF0yLypy2UKl+Cb01Fu0hJRkJjlCRtxZMWkTdAtDd5ZqCOxtCkhmRwyI57vWT+1iZ67w==" - }, - "nearley": { - "version": "2.20.1", - "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.20.1.tgz", - "integrity": "sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==", - "requires": { - "commander": "^2.19.0", - "moo": "^0.5.0", - "railroad-diagrams": "^1.0.0", - "randexp": "0.4.6" - }, - "dependencies": { - "randexp": { - "version": "0.4.6", - "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", - "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", - "requires": { - "discontinuous-range": "1.0.0", - "ret": "~0.1.10" - } - } - } - }, - "railroad-diagrams": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", - "integrity": "sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=" - }, - "randexp": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.5.3.tgz", - "integrity": "sha512-U+5l2KrcMNOUPYvazA3h5ekF80FHTUG+87SEAmHZmolh1M+i/WyTCxVzmi+tidIa1tM4BSe8g2Y/D3loWDjj+w==", - "optional": true, - "requires": { - "drange": "^1.0.2", - "ret": "^0.2.0" - }, - "dependencies": { - "ret": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/ret/-/ret-0.2.2.tgz", - "integrity": "sha512-M0b3YWQs7R3Z917WRQy1HHA7Ba7D8hvZg6UE5mLykJxQVE2ju0IXbGlaHPPlkY+WN7wFP+wUMXmBFA0aV6vYGQ==", - "optional": true - } - } - }, - "ret": { - "version": "0.1.15", - "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", - "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==" - } - } -} diff --git a/app/priv/nodejs/edtf/package.json b/app/priv/nodejs/edtf/package.json deleted file mode 100644 index aa9833a02..000000000 --- a/app/priv/nodejs/edtf/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "edtf", - "version": "0.1.0", - "description": "Date parsing and validation using EDTF.js", - "main": "cli.js", - "author": "bmquinn", - "license": "Apache-2.0", - "dependencies": { - "edtf": "^3.1.0" - } -} diff --git a/app/priv/nodejs/edtf/portlog.js b/app/priv/nodejs/edtf/portlog.js deleted file mode 100644 index 8f2cf6bbc..000000000 --- a/app/priv/nodejs/edtf/portlog.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = (level, message) => { - const output = [`[${level}]`, message].filter(e => e != null).join(" ") + "\n"; - process.stdout.write(output); -} - diff --git a/app/test/edtf_test.exs b/app/test/edtf_test.exs deleted file mode 100644 index 8931d9582..000000000 --- a/app/test/edtf_test.exs +++ /dev/null @@ -1,166 +0,0 @@ -defmodule EDTFTest do - use ExUnit.Case - - import ExUnit.DocTest - - doctest EDTF, import: true - - test "validate/1" do - assert EDTF.validate("2020") == {:ok, "2020"} - assert EDTF.validate("bad date!") == {:error, "Invalid EDTF input: bad date!"} - end - - test "parse/1" do - assert EDTF.parse("2020") == {:ok, %{level: 0, type: "Date", values: [2020]}} - assert EDTF.parse("bad date!") == {:error, "Invalid EDTF input: bad date!"} - end - - describe "humanize/1" do - test "invalid date" do - assert EDTF.humanize("bad date!") == {:error, "Invalid EDTF input: bad date!"} - end - - test "simple date" do - assert EDTF.humanize("2020-06-10") == "June 10, 2020" - assert EDTF.humanize("2020-06") == "June 2020" - assert EDTF.humanize("2020") == "2020" - assert EDTF.humanize("-2020-06") == "June 2020 BCE" - end - - test "approximate date" do - assert EDTF.humanize("2020-06-10~") == "circa June 10, 2020" - assert EDTF.humanize("2020-06~") == "circa June 2020" - assert EDTF.humanize("2020~") == "circa 2020" - assert EDTF.humanize("-2020-06~") == "circa June 2020 BCE" - end - - test "uncertain date" do - assert EDTF.humanize("2020-06-10?") == "June 10, 2020?" - assert EDTF.humanize("2020-06?") == "June 2020?" - assert EDTF.humanize("2020?") == "2020?" - assert EDTF.humanize("-2020-06?") == "June 2020 BCE?" - end - - test "approximate and uncertain date" do - assert EDTF.humanize("2020-06-10%") == "circa June 10, 2020?" - assert EDTF.humanize("2020-06%") == "circa June 2020?" - assert EDTF.humanize("2020%") == "circa 2020?" - assert EDTF.humanize("-2020-06%") == "circa June 2020 BCE?" - end - - test "dates with unspecified digits from the right" do - assert EDTF.humanize("192X") == "1920s" - assert EDTF.humanize("19XX") == "1900s" - assert EDTF.humanize("1XXX") == "1000s" - - assert EDTF.humanize("-192X") == "1920s BCE" - assert EDTF.humanize("-19XX") == "1900s BCE" - assert EDTF.humanize("-1XXX") == "1000s BCE" - end - - test "intervals with unspecified digits from the right" do - assert EDTF.humanize("192X/193X") == "1920s to 1930s" - assert EDTF.humanize("-192X/192X") == "1920s BCE to 1920s" - end - - test "dates with other unspecified digits" do - assert EDTF.humanize("X9X2") == "X9X2" - assert EDTF.humanize("1999-XX") == "1999-XX" - assert EDTF.humanize("1999-12-XX") == "1999-12-XX" - assert EDTF.humanize("-19X9-12-XX") == "-19X9-12-XX" - end - - test "prefixed and exponential years" do - assert EDTF.humanize("Y20020") == "20020" - assert EDTF.humanize("Y-20020") == "20020 BCE" - assert EDTF.humanize("Y17E7") == "170000000" - assert EDTF.humanize("Y-17E7") == "170000000 BCE" - end - - test "decade" do - assert EDTF.humanize("201") == "2010s" - assert EDTF.humanize("-201") == "2010s BCE" - end - - test "century" do - assert EDTF.humanize("20") == "20th Century" - assert EDTF.humanize("21") == "21st Century" - assert EDTF.humanize("-20") == "20th Century BCE" - assert EDTF.humanize("-21") == "21st Century BCE" - end - - test "date interval" do - assert EDTF.humanize("2019-06~/2020") == "circa June 2019 to 2020" - end - - test "unbounded interval" do - assert EDTF.humanize("2019-06~/..") == "from circa June 2019" - assert EDTF.humanize("../2019-06-10~") == "before circa June 10, 2019" - end - - test "interval with unknown bound" do - assert EDTF.humanize("2019-06~/") == "circa June 2019 to Unknown" - assert EDTF.humanize("/2019-06-10~") == "Unknown to circa June 10, 2019" - end - - test "set" do - assert EDTF.humanize("[2019-06]") == "June 2019" - assert EDTF.humanize("[2019-06, 2020-06]") == "June 2019 or June 2020" - assert EDTF.humanize("[2019-06, 2020-06, 2021-06]") == "June 2019, June 2020, or June 2021" - - assert EDTF.humanize("[2019-06, 2020-06, 2021-06..2021-07]") == - "June 2019, June 2020, or June 2021 to July 2021" - - assert EDTF.humanize("[..2020]") == "some year before 2020 or 2020" - assert EDTF.humanize("[..2020-06]") == "some month before June 2020 or June 2020" - assert EDTF.humanize("[..2020-06-10]") == "some date before June 10, 2020 or June 10, 2020" - assert EDTF.humanize("[2020..]") == "2020 or some year after 2020" - assert EDTF.humanize("[2020-06..]") == "June 2020 or some month after June 2020" - assert EDTF.humanize("[2020-06-10..]") == "June 10, 2020 or some date after June 10, 2020" - - assert EDTF.humanize("[..2018, 2020-06-10..]") == - "some year before 2018, 2018, June 10, 2020, or some date after June 10, 2020" - end - - test "list" do - assert EDTF.humanize("{2019-06}") == "June 2019" - assert EDTF.humanize("{2019-06, 2020-06}") == "June 2019 and June 2020" - assert EDTF.humanize("{2019-06, 2020-06, 2021-06}") == "June 2019, June 2020, and June 2021" - - assert EDTF.humanize("{2019-06, 2020-06, 2021-06..2021-07}") == - "June 2019, June 2020, and June 2021 to July 2021" - - assert EDTF.humanize("{..1984}") == "all years before 1984 and 1984" - assert EDTF.humanize("{1984..}") == "1984 and all years after 1984" - end - - test "season" do - assert EDTF.humanize("2020-21") == "Spring 2020" - assert EDTF.humanize("2020-22") == "Summer 2020" - assert EDTF.humanize("2020-23") == "Autumn 2020" - assert EDTF.humanize("2020-24") == "Winter 2020" - assert EDTF.humanize("2020-25") == "Spring (Northern Hemisphere) 2020" - assert EDTF.humanize("2020-26") == "Summer (Northern Hemisphere) 2020" - assert EDTF.humanize("2020-27") == "Autumn (Northern Hemisphere) 2020" - assert EDTF.humanize("2020-28") == "Winter (Northern Hemisphere) 2020" - assert EDTF.humanize("2020-29") == "Spring (Southern Hemisphere) 2020" - assert EDTF.humanize("2020-30") == "Summer (Southern Hemisphere) 2020" - assert EDTF.humanize("2020-31") == "Autumn (Southern Hemisphere) 2020" - assert EDTF.humanize("2020-32") == "Winter (Southern Hemisphere) 2020" - assert EDTF.humanize("2020-33") == "Quarter 1 2020" - assert EDTF.humanize("2020-34") == "Quarter 2 2020" - assert EDTF.humanize("2020-35") == "Quarter 3 2020" - assert EDTF.humanize("2020-36") == "Quarter 4 2020" - assert EDTF.humanize("2020-37") == "Quadrimester 1 2020" - assert EDTF.humanize("2020-38") == "Quadrimester 2 2020" - assert EDTF.humanize("2020-39") == "Quadrimester 3 2020" - assert EDTF.humanize("2020-40") == "Semestral 1 2020" - assert EDTF.humanize("2020-41") == "Semestral 2 2020" - end - - test "intervals with seasons" do - assert EDTF.humanize("1995-24/1996-22") == "Winter 1995 to Summer 1996" - assert EDTF.humanize("-1995-24/1996-22") == "Winter 1995 BCE to Summer 1996" - end - end -end diff --git a/app/test/meadow/batches_test.exs b/app/test/meadow/batches_test.exs index 804d845cf..46d497b6d 100644 --- a/app/test/meadow/batches_test.exs +++ b/app/test/meadow/batches_test.exs @@ -177,7 +177,7 @@ defmodule Meadow.BatchesTest do add = %{ descriptive_metadata: %{ box_name: ["His Airness"], - date_created: [%{edtf: "1009"}, %{edtf: "100X"}, %{edtf: "~1968"}] + date_created: [%{edtf: "1009"}, %{edtf: "100X"}, %{edtf: "~1968?"}] } } diff --git a/app/test/meadow/config_test.exs b/app/test/meadow/config_test.exs index c1df81aed..f1286f28e 100644 --- a/app/test/meadow/config_test.exs +++ b/app/test/meadow/config_test.exs @@ -61,13 +61,13 @@ defmodule Meadow.ConfigTest do test "aws_environment/0" do with env <- Config.aws_environment() |> Enum.into(%{}) do - assert env |> Map.has_key?('TMPDIR') + assert env |> Map.has_key?(~c"TMPDIR") if Application.get_env(:ex_aws, :s3) do - assert env |> Map.get('AWS_REGION') == 'us-east-1' - assert env |> Map.get('AWS_SECRET_ACCESS_KEY') == 'fake' - assert env |> Map.get('AWS_ACCESS_KEY_ID') == 'fake' - assert env |> Map.get('AWS_S3_ENDPOINT') |> Enum.slice(0..15) == 'http://localhost' + assert env |> Map.get(~c"AWS_REGION") == ~c"us-east-1" + assert env |> Map.get(~c"AWS_SECRET_ACCESS_KEY") == ~c"fake" + assert env |> Map.get(~c"AWS_ACCESS_KEY_ID") == ~c"fake" + assert env |> Map.get(~c"AWS_S3_ENDPOINT") |> Enum.slice(0..15) == ~c"http://localhost" end end end @@ -103,12 +103,5 @@ defmodule Meadow.ConfigTest do assert Config.iiif_manifest_url_deprecated() == "http://no-slash-test/minio/test-pyramids/public/" end - - test "validate release config" do - System.put_env("__COMPILE_CHECK__", "TRUE") - assert ConfigReader.read!("config/releases.exs") |> is_list() - after - System.delete_env("__COMPILE_CHECK__") - end end end diff --git a/app/test/meadow/data/csv/metadata_update_jobs_test.exs b/app/test/meadow/data/csv/metadata_update_jobs_test.exs index fdc0839ae..fb533107d 100644 --- a/app/test/meadow/data/csv/metadata_update_jobs_test.exs +++ b/app/test/meadow/data/csv/metadata_update_jobs_test.exs @@ -66,7 +66,7 @@ defmodule Meadow.Data.CSV.MetadataUpdateJobsTest do assert work.visibility.id == "AUTHENTICATED" assert work.descriptive_metadata.date_created == [ - %{edtf: "~1899", humanized: "circa 1899?"} + %{edtf: "~1899", humanized: "circa 1899"} ] assert work.administrative_metadata.project_proposer == [