lumen-framework 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/cli.cjs +71 -38
  2. package/dist/cli.cjs.map +4 -4
  3. package/dist/index.js +978 -272
  4. package/dist/index.js.map +4 -4
  5. package/dist/index.mjs +969 -263
  6. package/dist/index.mjs.map +4 -4
  7. package/dist/types/errors/namespaced-serializer-missing-error.d.ts +15 -0
  8. package/dist/types/packages/application/utils/validate-namespaced-serializers.d.ts +15 -0
  9. package/dist/types/packages/controller/errors/index.d.ts +1 -0
  10. package/dist/types/packages/controller/errors/related-record-not-found-error.d.ts +14 -0
  11. package/dist/types/packages/controller/index.d.ts +65 -0
  12. package/dist/types/packages/controller/utils/find-many.d.ts +2 -1
  13. package/dist/types/packages/controller/utils/find-one.d.ts +2 -1
  14. package/dist/types/packages/controller/utils/params-to-query.d.ts +7 -2
  15. package/dist/types/packages/controller/utils/validate-relationships.d.ts +8 -0
  16. package/dist/types/packages/database/constants.d.ts +1 -0
  17. package/dist/types/packages/database/model/index.d.ts +11 -0
  18. package/dist/types/packages/database/model/utils/process-write-error.d.ts +9 -1
  19. package/dist/types/packages/database/validation/errors/validation-error.d.ts +11 -2
  20. package/dist/types/packages/jsonapi/errors/not-acceptable-error.d.ts +1 -1
  21. package/dist/types/packages/jsonapi/index.d.ts +3 -1
  22. package/dist/types/packages/jsonapi/interfaces.d.ts +1 -1
  23. package/dist/types/packages/jsonapi/utils/has-media-type-params.d.ts +6 -0
  24. package/dist/types/packages/jsonapi/utils/is-jsonapi.d.ts +2 -0
  25. package/dist/types/packages/jsonapi/utils/media-type.d.ts +19 -0
  26. package/dist/types/packages/router/route/params/errors/client-generated-id-error.d.ts +13 -0
  27. package/dist/types/packages/router/route/params/errors/forbidden-parameter-error.d.ts +14 -0
  28. package/dist/types/packages/router/route/params/errors/index.d.ts +2 -0
  29. package/dist/types/packages/router/route/params/errors/invalid-parameter-error.d.ts +2 -0
  30. package/dist/types/packages/router/route/params/errors/parameter-not-nullable-error.d.ts +2 -0
  31. package/dist/types/packages/router/route/params/errors/parameter-required-error.d.ts +2 -0
  32. package/dist/types/packages/router/route/params/errors/parameter-type-error.d.ts +2 -0
  33. package/dist/types/packages/router/route/params/errors/parameter-value-error.d.ts +2 -0
  34. package/dist/types/packages/router/route/params/errors/resource-mismatch-error.d.ts +2 -0
  35. package/dist/types/packages/router/route/params/index.d.ts +1 -0
  36. package/dist/types/packages/router/route/params/parameter/forbidden-parameter.d.ts +12 -0
  37. package/dist/types/packages/router/route/params/parameter/index.d.ts +8 -0
  38. package/dist/types/packages/router/route/params/utils/validate-client-id.d.ts +8 -0
  39. package/dist/types/packages/serializer/index.d.ts +111 -36
  40. package/dist/types/packages/serializer/utils/include-tree.d.ts +29 -0
  41. package/dist/types/packages/serializer/utils/load-linkage.d.ts +22 -0
  42. package/dist/types/packages/server/index.d.ts +2 -1
  43. package/dist/types/packages/server/interfaces.d.ts +5 -0
  44. package/dist/types/packages/server/utils/source-for.d.ts +10 -0
  45. package/dist/types/packages/server/utils/validate-accept.d.ts +5 -1
  46. package/dist/types/packages/server/utils/validate-content-type.d.ts +4 -0
  47. package/package.json +1 -1
  48. package/dist/types/packages/jsonapi/utils/has-media-type.d.ts +0 -4
package/dist/cli.cjs CHANGED
@@ -695,6 +695,7 @@ async function compile(dir, env, opts = {}) {
695
695
  ["serializers", serializers]
696
696
  ]);
697
697
  });
698
+ await tryCatch(() => mkdir(import_path9.default.join(dir, "dist")));
698
699
  await Promise.all([
699
700
  createManifest(dir, assets, { useStrict }),
700
701
  createBootScript(dir, { useStrict })
@@ -860,7 +861,7 @@ var seed_default = () => template`
860
861
  `;
861
862
 
862
863
  // package.json
863
- var version = "3.0.2";
864
+ var version = "3.1.0";
864
865
 
865
866
  // src/packages/cli/templates/package-json.ts
866
867
  var LUMEN_VERSION = version;
@@ -1033,7 +1034,7 @@ __export(generate_type_exports, {
1033
1034
  });
1034
1035
  var import_path12 = require("path");
1035
1036
  var import_chalk8 = require("chalk");
1036
- var import_inflection19 = require("inflection");
1037
+ var import_inflection20 = require("inflection");
1037
1038
 
1038
1039
  // src/packages/cli/generator/constants.ts
1039
1040
  var import_chalk = require("chalk");
@@ -1655,7 +1656,7 @@ var import_inflection5 = require("inflection");
1655
1656
  var normalize_model_name_default = compose(import_inflection5.singularize, import_inflection5.dasherize, underscore);
1656
1657
 
1657
1658
  // src/packages/database/model/index.ts
1658
- var import_inflection12 = require("inflection");
1659
+ var import_inflection13 = require("inflection");
1659
1660
 
1660
1661
  // src/packages/database/query/index.ts
1661
1662
  var import_inflection8 = require("inflection");
@@ -1685,6 +1686,38 @@ var import_inflection9 = require("inflection");
1685
1686
  // src/packages/database/model/initialize-class.ts
1686
1687
  var import_inflection11 = require("inflection");
1687
1688
 
1689
+ // src/packages/server/utils/source-for.ts
1690
+ var import_inflection12 = require("inflection");
1691
+ function memberName(key) {
1692
+ return (0, import_inflection12.dasherize)(underscore(key));
1693
+ }
1694
+ function escapePointer(segment) {
1695
+ return segment.replace(/~/g, "~0").replace(/\//g, "~1");
1696
+ }
1697
+ function sourceFor(path6) {
1698
+ const [root, ...rest] = path6.split(".").filter(Boolean).map(memberName);
1699
+ if (!root) {
1700
+ return {};
1701
+ } else if (root === "data") {
1702
+ return {
1703
+ pointer: `/${[root, ...rest].map(escapePointer).join("/")}`
1704
+ };
1705
+ }
1706
+ return {
1707
+ parameter: `${root}${rest.map((key) => `[${key}]`).join("")}`
1708
+ };
1709
+ }
1710
+
1711
+ // src/packages/database/validation/errors/validation-error.ts
1712
+ var ValidationError = class extends Error {
1713
+ constructor(key) {
1714
+ super(`Validation failed for ${key}.`);
1715
+ this.key = key;
1716
+ this.source = sourceFor(`data.attributes.${key}`);
1717
+ }
1718
+ };
1719
+ var validation_error_default = createServerError(ValidationError, 422);
1720
+
1688
1721
  // src/packages/database/migration/utils/generate-timestamp.ts
1689
1722
  function formatInt(int) {
1690
1723
  return (int / 10).toString().replace(".", "").substr(0, 2);
@@ -1728,11 +1761,11 @@ var database_default2 = Database;
1728
1761
 
1729
1762
  // src/packages/cli/templates/model.ts
1730
1763
  var import_os2 = require("os");
1731
- var import_inflection13 = require("inflection");
1764
+ var import_inflection14 = require("inflection");
1732
1765
  var VALID_ATTR = /^(\w|-)+:(\w|-)+$/;
1733
1766
  var RELATIONSHIP = /^belongs-to|has-(one|many)$/;
1734
1767
  var model_default2 = (name, attrs) => {
1735
- const normalized = chain(name).pipe(underscore).pipe(import_inflection13.classify).value();
1768
+ const normalized = chain(name).pipe(underscore).pipe(import_inflection14.classify).value();
1736
1769
  return template`
1737
1770
  import { Model } from 'lumen-framework';
1738
1771
 
@@ -1740,11 +1773,11 @@ var model_default2 = (name, attrs) => {
1740
1773
  ${entries(
1741
1774
  (attrs || []).filter((attr) => VALID_ATTR.test(attr)).map((attr) => attr.split(":")).filter(([, type]) => RELATIONSHIP.test(type)).reduce(
1742
1775
  (types, [related, type]) => {
1743
- const key = chain(type).pipe(underscore).pipe((str) => (0, import_inflection13.camelize)(str, true)).value();
1776
+ const key = chain(type).pipe(underscore).pipe((str) => (0, import_inflection14.camelize)(str, true)).value();
1744
1777
  const value = Reflect.get(types, key);
1745
1778
  if (value) {
1746
- const inverse = (0, import_inflection13.camelize)(normalized, true);
1747
- const relatedKey = chain(related).pipe(underscore).pipe((str) => (0, import_inflection13.camelize)(str, true)).value();
1779
+ const inverse = (0, import_inflection14.camelize)(normalized, true);
1780
+ const relatedKey = chain(related).pipe(underscore).pipe((str) => (0, import_inflection14.camelize)(str, true)).value();
1748
1781
  return {
1749
1782
  ...types,
1750
1783
  [key]: [
@@ -1779,11 +1812,11 @@ var model_default2 = (name, attrs) => {
1779
1812
  };
1780
1813
 
1781
1814
  // src/packages/cli/templates/serializer.ts
1782
- var import_inflection14 = require("inflection");
1815
+ var import_inflection15 = require("inflection");
1783
1816
  var serializer_default = (name, attrs) => {
1784
- let normalized = chain(name).pipe(underscore).pipe(import_inflection14.classify).value();
1817
+ let normalized = chain(name).pipe(underscore).pipe(import_inflection15.classify).value();
1785
1818
  if (!normalized.endsWith("Application")) {
1786
- normalized = (0, import_inflection14.pluralize)(normalized);
1819
+ normalized = (0, import_inflection15.pluralize)(normalized);
1787
1820
  }
1788
1821
  const body = entries(
1789
1822
  attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")).reduce(
@@ -1791,7 +1824,7 @@ var serializer_default = (name, attrs) => {
1791
1824
  const [, type] = parts;
1792
1825
  let [attr] = parts;
1793
1826
  let { hasOne, hasMany, attributes } = obj;
1794
- attr = `${indent(8)}'${(0, import_inflection14.camelize)(underscore(attr), true)}'`;
1827
+ attr = `${indent(8)}'${(0, import_inflection15.camelize)(underscore(attr), true)}'`;
1795
1828
  switch (type) {
1796
1829
  case "belongs-to":
1797
1830
  case "has-one":
@@ -1844,11 +1877,11 @@ ${indent(6)}];`;
1844
1877
  };
1845
1878
 
1846
1879
  // src/packages/cli/templates/controller.ts
1847
- var import_inflection15 = require("inflection");
1880
+ var import_inflection16 = require("inflection");
1848
1881
  var controller_default = (name, attrs) => {
1849
- let normalized = chain(name).pipe(underscore).pipe(import_inflection15.classify).value();
1882
+ let normalized = chain(name).pipe(underscore).pipe(import_inflection16.classify).value();
1850
1883
  if (!normalized.endsWith("Application")) {
1851
- normalized = (0, import_inflection15.pluralize)(normalized);
1884
+ normalized = (0, import_inflection16.pluralize)(normalized);
1852
1885
  }
1853
1886
  const body = entries(
1854
1887
  attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")[0]).reduce(
@@ -1856,7 +1889,7 @@ var controller_default = (name, attrs) => {
1856
1889
  ...obj,
1857
1890
  params: [
1858
1891
  ...obj.params,
1859
- `${indent(8)}'${(0, import_inflection15.camelize)(underscore(attr), true)}'`
1892
+ `${indent(8)}'${(0, import_inflection16.camelize)(underscore(attr), true)}'`
1860
1893
  ]
1861
1894
  }),
1862
1895
  { params: [] }
@@ -1898,10 +1931,10 @@ var empty_migration_default = () => template`
1898
1931
  `;
1899
1932
 
1900
1933
  // src/packages/cli/templates/model-migration.ts
1901
- var import_inflection16 = require("inflection");
1934
+ var import_inflection17 = require("inflection");
1902
1935
  var model_migration_default = (name, attrs) => {
1903
1936
  const indices = ["id"];
1904
- const table = chain(name).pipe((str) => str.substr(24)).pipe(underscore).pipe(import_inflection16.pluralize).value();
1937
+ const table = chain(name).pipe((str) => str.substr(24)).pipe(underscore).pipe(import_inflection17.pluralize).value();
1905
1938
  let body = "";
1906
1939
  if (Array.isArray(attrs)) {
1907
1940
  body = attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")).filter(([, type]) => !/^has-(one|many)$/g.test(type)).map((attr) => {
@@ -1942,9 +1975,9 @@ var model_migration_default = (name, attrs) => {
1942
1975
  };
1943
1976
 
1944
1977
  // src/packages/cli/templates/middleware.ts
1945
- var import_inflection17 = require("inflection");
1978
+ var import_inflection18 = require("inflection");
1946
1979
  var middleware_default = (name) => {
1947
- const normalized = chain(name).pipe(underscore).pipe((str) => (0, import_inflection17.camelize)(str, true)).value();
1980
+ const normalized = chain(name).pipe(underscore).pipe((str) => (0, import_inflection18.camelize)(str, true)).value();
1948
1981
  return template`
1949
1982
  export default function ${normalized}(/*request, response*/) {
1950
1983
 
@@ -1953,9 +1986,9 @@ var middleware_default = (name) => {
1953
1986
  };
1954
1987
 
1955
1988
  // src/packages/cli/templates/util.ts
1956
- var import_inflection18 = require("inflection");
1989
+ var import_inflection19 = require("inflection");
1957
1990
  var util_default = (name) => {
1958
- const normalized = chain(name).pipe(underscore).pipe((str) => (0, import_inflection18.camelize)(str, true)).value();
1991
+ const normalized = chain(name).pipe(underscore).pipe((str) => (0, import_inflection19.camelize)(str, true)).value();
1959
1992
  return template`
1960
1993
  export default function ${normalized}() {
1961
1994
 
@@ -2036,7 +2069,7 @@ async function controller(opts) {
2036
2069
  template: controller_default
2037
2070
  });
2038
2071
  if (!name.endsWith("application")) {
2039
- name = (0, import_inflection19.pluralize)(name);
2072
+ name = (0, import_inflection20.pluralize)(name);
2040
2073
  }
2041
2074
  await generate2({
2042
2075
  ...opts,
@@ -2067,7 +2100,7 @@ async function serializer(opts) {
2067
2100
  template: serializer_default
2068
2101
  });
2069
2102
  if (!name.endsWith("application")) {
2070
- name = (0, import_inflection19.pluralize)(name);
2103
+ name = (0, import_inflection20.pluralize)(name);
2071
2104
  }
2072
2105
  await generate2({
2073
2106
  ...opts,
@@ -2118,7 +2151,7 @@ function modelMigration(opts) {
2118
2151
  template: model_migration_default,
2119
2152
  hasConflict: detectConflict
2120
2153
  });
2121
- name = chain(name).pipe(import_path12.posix.basename).pipe(import_inflection19.pluralize).pipe((str) => `${generateTimestamp()}-create-${str}`).value();
2154
+ name = chain(name).pipe(import_path12.posix.basename).pipe(import_inflection20.pluralize).pipe((str) => `${generateTimestamp()}-create-${str}`).value();
2122
2155
  return generate2({
2123
2156
  ...opts,
2124
2157
  cwd,
@@ -2136,7 +2169,7 @@ async function model(opts) {
2136
2169
  template: model_default2
2137
2170
  });
2138
2171
  await modelMigration({ ...opts, name });
2139
- name = chain(name).pipe(import_path12.posix.basename).pipe(import_inflection19.singularize).value();
2172
+ name = chain(name).pipe(import_path12.posix.basename).pipe(import_inflection20.singularize).value();
2140
2173
  return generate2({
2141
2174
  ...opts,
2142
2175
  name
@@ -2186,7 +2219,7 @@ async function resource(opts) {
2186
2219
  `;
2187
2220
  }
2188
2221
  if (index + 1 === closeIndex) {
2189
- str += ` this.resource('${(0, import_inflection19.pluralize)(opts.name)}');
2222
+ str += ` this.resource('${(0, import_inflection20.pluralize)(opts.name)}');
2190
2223
  `;
2191
2224
  }
2192
2225
  return str;
@@ -2416,7 +2449,7 @@ function merge(dest, source) {
2416
2449
  }
2417
2450
 
2418
2451
  // src/packages/loader/utils/format-key.ts
2419
- var import_inflection20 = require("inflection");
2452
+ var import_inflection21 = require("inflection");
2420
2453
  var NAMESPACE_DELIMITER = /\$-/g;
2421
2454
  function formatKey(key, formatter) {
2422
2455
  return chain(key).pipe((str) => {
@@ -2424,7 +2457,7 @@ function formatKey(key, formatter) {
2424
2457
  return formatter(str);
2425
2458
  }
2426
2459
  return str;
2427
- }).pipe(underscore).pipe(import_inflection20.dasherize).pipe((str) => str.replace(NAMESPACE_DELIMITER, "/")).value();
2460
+ }).pipe(underscore).pipe(import_inflection21.dasherize).pipe((str) => str.replace(NAMESPACE_DELIMITER, "/")).value();
2428
2461
  }
2429
2462
 
2430
2463
  // src/packages/loader/utils/bundle-for.ts
@@ -2650,7 +2683,7 @@ function dbseed() {
2650
2683
  // src/packages/cli/commands/destroy.ts
2651
2684
  var import_os8 = require("os");
2652
2685
  var import_chalk11 = require("chalk");
2653
- var import_inflection21 = require("inflection");
2686
+ var import_inflection22 = require("inflection");
2654
2687
  async function destroyType(type, name) {
2655
2688
  const normalizedType = type.toLowerCase();
2656
2689
  let normalizedName = name;
@@ -2658,8 +2691,8 @@ async function destroyType(type, name) {
2658
2691
  let migrations;
2659
2692
  switch (normalizedType) {
2660
2693
  case "model":
2661
- normalizedName = (0, import_inflection21.singularize)(normalizedName);
2662
- path6 = `app/${(0, import_inflection21.pluralize)(normalizedType)}/${normalizedName}.js`;
2694
+ normalizedName = (0, import_inflection22.singularize)(normalizedName);
2695
+ path6 = `app/${(0, import_inflection22.pluralize)(normalizedType)}/${normalizedName}.js`;
2663
2696
  break;
2664
2697
  case "migration":
2665
2698
  migrations = await readdir(`${CWD}/db/migrate`);
@@ -2670,14 +2703,14 @@ async function destroyType(type, name) {
2670
2703
  break;
2671
2704
  case "controller":
2672
2705
  case "serializer":
2673
- normalizedName = (0, import_inflection21.pluralize)(normalizedName);
2674
- path6 = `app/${(0, import_inflection21.pluralize)(normalizedType)}/${normalizedName}.js`;
2706
+ normalizedName = (0, import_inflection22.pluralize)(normalizedName);
2707
+ path6 = `app/${(0, import_inflection22.pluralize)(normalizedType)}/${normalizedName}.js`;
2675
2708
  break;
2676
2709
  case "middleware":
2677
2710
  path6 = `app/${normalizedType}/${normalizedName}.js`;
2678
2711
  break;
2679
2712
  case "util":
2680
- path6 = `app/${(0, import_inflection21.pluralize)(normalizedType)}/${normalizedName}.js`;
2713
+ path6 = `app/${(0, import_inflection22.pluralize)(normalizedType)}/${normalizedName}.js`;
2681
2714
  break;
2682
2715
  default:
2683
2716
  return;
@@ -2692,13 +2725,13 @@ async function destroy2({ type, name }) {
2692
2725
  if (type === "resource") {
2693
2726
  const routes = (await readFile(`${CWD}/app/routes.js`)).toString("utf8").split("\n").reduce((lines, line2) => {
2694
2727
  const pattern = new RegExp(
2695
- `\\s*this.resource\\(('|"|\`)${(0, import_inflection21.pluralize)(name)}('|"|\`)\\);?`
2728
+ `\\s*this.resource\\(('|"|\`)${(0, import_inflection22.pluralize)(name)}('|"|\`)\\);?`
2696
2729
  );
2697
2730
  return pattern.test(line2) ? lines : [...lines, line2];
2698
2731
  }, []).join("\n");
2699
2732
  await Promise.all([
2700
2733
  destroyType("model", name),
2701
- destroyType("migration", `create-${(0, import_inflection21.pluralize)(name)}`),
2734
+ destroyType("migration", `create-${(0, import_inflection22.pluralize)(name)}`),
2702
2735
  destroyType("serializer", name),
2703
2736
  destroyType("controller", name)
2704
2737
  ]);
@@ -2708,7 +2741,7 @@ async function destroy2({ type, name }) {
2708
2741
  } else if (type === "model") {
2709
2742
  await Promise.all([
2710
2743
  destroyType(type, name),
2711
- destroyType("migration", `create-${(0, import_inflection21.pluralize)(name)}`)
2744
+ destroyType("migration", `create-${(0, import_inflection22.pluralize)(name)}`)
2712
2745
  ]);
2713
2746
  } else {
2714
2747
  await destroyType(type, name);