lumen-framework 3.0.3 → 3.1.1

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 (40) hide show
  1. package/dist/cli.cjs +70 -38
  2. package/dist/cli.cjs.map +4 -4
  3. package/dist/index.js +928 -259
  4. package/dist/index.js.map +4 -4
  5. package/dist/index.mjs +919 -250
  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/interfaces.d.ts +1 -1
  21. package/dist/types/packages/router/route/params/errors/client-generated-id-error.d.ts +13 -0
  22. package/dist/types/packages/router/route/params/errors/forbidden-parameter-error.d.ts +14 -0
  23. package/dist/types/packages/router/route/params/errors/index.d.ts +2 -0
  24. package/dist/types/packages/router/route/params/errors/invalid-parameter-error.d.ts +2 -0
  25. package/dist/types/packages/router/route/params/errors/parameter-not-nullable-error.d.ts +2 -0
  26. package/dist/types/packages/router/route/params/errors/parameter-required-error.d.ts +2 -0
  27. package/dist/types/packages/router/route/params/errors/parameter-type-error.d.ts +2 -0
  28. package/dist/types/packages/router/route/params/errors/parameter-value-error.d.ts +2 -0
  29. package/dist/types/packages/router/route/params/errors/resource-mismatch-error.d.ts +2 -0
  30. package/dist/types/packages/router/route/params/index.d.ts +1 -0
  31. package/dist/types/packages/router/route/params/parameter/forbidden-parameter.d.ts +12 -0
  32. package/dist/types/packages/router/route/params/parameter/index.d.ts +8 -0
  33. package/dist/types/packages/router/route/params/utils/validate-client-id.d.ts +8 -0
  34. package/dist/types/packages/serializer/index.d.ts +111 -36
  35. package/dist/types/packages/serializer/utils/include-tree.d.ts +29 -0
  36. package/dist/types/packages/serializer/utils/load-linkage.d.ts +22 -0
  37. package/dist/types/packages/server/index.d.ts +2 -1
  38. package/dist/types/packages/server/interfaces.d.ts +5 -0
  39. package/dist/types/packages/server/utils/source-for.d.ts +10 -0
  40. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -861,7 +861,7 @@ var seed_default = () => template`
861
861
  `;
862
862
 
863
863
  // package.json
864
- var version = "3.0.3";
864
+ var version = "3.1.1";
865
865
 
866
866
  // src/packages/cli/templates/package-json.ts
867
867
  var LUMEN_VERSION = version;
@@ -1034,7 +1034,7 @@ __export(generate_type_exports, {
1034
1034
  });
1035
1035
  var import_path12 = require("path");
1036
1036
  var import_chalk8 = require("chalk");
1037
- var import_inflection19 = require("inflection");
1037
+ var import_inflection20 = require("inflection");
1038
1038
 
1039
1039
  // src/packages/cli/generator/constants.ts
1040
1040
  var import_chalk = require("chalk");
@@ -1656,7 +1656,7 @@ var import_inflection5 = require("inflection");
1656
1656
  var normalize_model_name_default = compose(import_inflection5.singularize, import_inflection5.dasherize, underscore);
1657
1657
 
1658
1658
  // src/packages/database/model/index.ts
1659
- var import_inflection12 = require("inflection");
1659
+ var import_inflection13 = require("inflection");
1660
1660
 
1661
1661
  // src/packages/database/query/index.ts
1662
1662
  var import_inflection8 = require("inflection");
@@ -1686,6 +1686,38 @@ var import_inflection9 = require("inflection");
1686
1686
  // src/packages/database/model/initialize-class.ts
1687
1687
  var import_inflection11 = require("inflection");
1688
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
+
1689
1721
  // src/packages/database/migration/utils/generate-timestamp.ts
1690
1722
  function formatInt(int) {
1691
1723
  return (int / 10).toString().replace(".", "").substr(0, 2);
@@ -1729,11 +1761,11 @@ var database_default2 = Database;
1729
1761
 
1730
1762
  // src/packages/cli/templates/model.ts
1731
1763
  var import_os2 = require("os");
1732
- var import_inflection13 = require("inflection");
1764
+ var import_inflection14 = require("inflection");
1733
1765
  var VALID_ATTR = /^(\w|-)+:(\w|-)+$/;
1734
1766
  var RELATIONSHIP = /^belongs-to|has-(one|many)$/;
1735
1767
  var model_default2 = (name, attrs) => {
1736
- const normalized = chain(name).pipe(underscore).pipe(import_inflection13.classify).value();
1768
+ const normalized = chain(name).pipe(underscore).pipe(import_inflection14.classify).value();
1737
1769
  return template`
1738
1770
  import { Model } from 'lumen-framework';
1739
1771
 
@@ -1741,11 +1773,11 @@ var model_default2 = (name, attrs) => {
1741
1773
  ${entries(
1742
1774
  (attrs || []).filter((attr) => VALID_ATTR.test(attr)).map((attr) => attr.split(":")).filter(([, type]) => RELATIONSHIP.test(type)).reduce(
1743
1775
  (types, [related, type]) => {
1744
- 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();
1745
1777
  const value = Reflect.get(types, key);
1746
1778
  if (value) {
1747
- const inverse = (0, import_inflection13.camelize)(normalized, true);
1748
- 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();
1749
1781
  return {
1750
1782
  ...types,
1751
1783
  [key]: [
@@ -1780,11 +1812,11 @@ var model_default2 = (name, attrs) => {
1780
1812
  };
1781
1813
 
1782
1814
  // src/packages/cli/templates/serializer.ts
1783
- var import_inflection14 = require("inflection");
1815
+ var import_inflection15 = require("inflection");
1784
1816
  var serializer_default = (name, attrs) => {
1785
- let normalized = chain(name).pipe(underscore).pipe(import_inflection14.classify).value();
1817
+ let normalized = chain(name).pipe(underscore).pipe(import_inflection15.classify).value();
1786
1818
  if (!normalized.endsWith("Application")) {
1787
- normalized = (0, import_inflection14.pluralize)(normalized);
1819
+ normalized = (0, import_inflection15.pluralize)(normalized);
1788
1820
  }
1789
1821
  const body = entries(
1790
1822
  attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")).reduce(
@@ -1792,7 +1824,7 @@ var serializer_default = (name, attrs) => {
1792
1824
  const [, type] = parts;
1793
1825
  let [attr] = parts;
1794
1826
  let { hasOne, hasMany, attributes } = obj;
1795
- attr = `${indent(8)}'${(0, import_inflection14.camelize)(underscore(attr), true)}'`;
1827
+ attr = `${indent(8)}'${(0, import_inflection15.camelize)(underscore(attr), true)}'`;
1796
1828
  switch (type) {
1797
1829
  case "belongs-to":
1798
1830
  case "has-one":
@@ -1845,11 +1877,11 @@ ${indent(6)}];`;
1845
1877
  };
1846
1878
 
1847
1879
  // src/packages/cli/templates/controller.ts
1848
- var import_inflection15 = require("inflection");
1880
+ var import_inflection16 = require("inflection");
1849
1881
  var controller_default = (name, attrs) => {
1850
- let normalized = chain(name).pipe(underscore).pipe(import_inflection15.classify).value();
1882
+ let normalized = chain(name).pipe(underscore).pipe(import_inflection16.classify).value();
1851
1883
  if (!normalized.endsWith("Application")) {
1852
- normalized = (0, import_inflection15.pluralize)(normalized);
1884
+ normalized = (0, import_inflection16.pluralize)(normalized);
1853
1885
  }
1854
1886
  const body = entries(
1855
1887
  attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")[0]).reduce(
@@ -1857,7 +1889,7 @@ var controller_default = (name, attrs) => {
1857
1889
  ...obj,
1858
1890
  params: [
1859
1891
  ...obj.params,
1860
- `${indent(8)}'${(0, import_inflection15.camelize)(underscore(attr), true)}'`
1892
+ `${indent(8)}'${(0, import_inflection16.camelize)(underscore(attr), true)}'`
1861
1893
  ]
1862
1894
  }),
1863
1895
  { params: [] }
@@ -1899,10 +1931,10 @@ var empty_migration_default = () => template`
1899
1931
  `;
1900
1932
 
1901
1933
  // src/packages/cli/templates/model-migration.ts
1902
- var import_inflection16 = require("inflection");
1934
+ var import_inflection17 = require("inflection");
1903
1935
  var model_migration_default = (name, attrs) => {
1904
1936
  const indices = ["id"];
1905
- 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();
1906
1938
  let body = "";
1907
1939
  if (Array.isArray(attrs)) {
1908
1940
  body = attrs.filter((attr) => /^(\w|-)+:(\w|-)+$/g.test(attr)).map((attr) => attr.split(":")).filter(([, type]) => !/^has-(one|many)$/g.test(type)).map((attr) => {
@@ -1943,9 +1975,9 @@ var model_migration_default = (name, attrs) => {
1943
1975
  };
1944
1976
 
1945
1977
  // src/packages/cli/templates/middleware.ts
1946
- var import_inflection17 = require("inflection");
1978
+ var import_inflection18 = require("inflection");
1947
1979
  var middleware_default = (name) => {
1948
- 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();
1949
1981
  return template`
1950
1982
  export default function ${normalized}(/*request, response*/) {
1951
1983
 
@@ -1954,9 +1986,9 @@ var middleware_default = (name) => {
1954
1986
  };
1955
1987
 
1956
1988
  // src/packages/cli/templates/util.ts
1957
- var import_inflection18 = require("inflection");
1989
+ var import_inflection19 = require("inflection");
1958
1990
  var util_default = (name) => {
1959
- 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();
1960
1992
  return template`
1961
1993
  export default function ${normalized}() {
1962
1994
 
@@ -2037,7 +2069,7 @@ async function controller(opts) {
2037
2069
  template: controller_default
2038
2070
  });
2039
2071
  if (!name.endsWith("application")) {
2040
- name = (0, import_inflection19.pluralize)(name);
2072
+ name = (0, import_inflection20.pluralize)(name);
2041
2073
  }
2042
2074
  await generate2({
2043
2075
  ...opts,
@@ -2068,7 +2100,7 @@ async function serializer(opts) {
2068
2100
  template: serializer_default
2069
2101
  });
2070
2102
  if (!name.endsWith("application")) {
2071
- name = (0, import_inflection19.pluralize)(name);
2103
+ name = (0, import_inflection20.pluralize)(name);
2072
2104
  }
2073
2105
  await generate2({
2074
2106
  ...opts,
@@ -2119,7 +2151,7 @@ function modelMigration(opts) {
2119
2151
  template: model_migration_default,
2120
2152
  hasConflict: detectConflict
2121
2153
  });
2122
- 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();
2123
2155
  return generate2({
2124
2156
  ...opts,
2125
2157
  cwd,
@@ -2137,7 +2169,7 @@ async function model(opts) {
2137
2169
  template: model_default2
2138
2170
  });
2139
2171
  await modelMigration({ ...opts, name });
2140
- 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();
2141
2173
  return generate2({
2142
2174
  ...opts,
2143
2175
  name
@@ -2187,7 +2219,7 @@ async function resource(opts) {
2187
2219
  `;
2188
2220
  }
2189
2221
  if (index + 1 === closeIndex) {
2190
- str += ` this.resource('${(0, import_inflection19.pluralize)(opts.name)}');
2222
+ str += ` this.resource('${(0, import_inflection20.pluralize)(opts.name)}');
2191
2223
  `;
2192
2224
  }
2193
2225
  return str;
@@ -2417,7 +2449,7 @@ function merge(dest, source) {
2417
2449
  }
2418
2450
 
2419
2451
  // src/packages/loader/utils/format-key.ts
2420
- var import_inflection20 = require("inflection");
2452
+ var import_inflection21 = require("inflection");
2421
2453
  var NAMESPACE_DELIMITER = /\$-/g;
2422
2454
  function formatKey(key, formatter) {
2423
2455
  return chain(key).pipe((str) => {
@@ -2425,7 +2457,7 @@ function formatKey(key, formatter) {
2425
2457
  return formatter(str);
2426
2458
  }
2427
2459
  return str;
2428
- }).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();
2429
2461
  }
2430
2462
 
2431
2463
  // src/packages/loader/utils/bundle-for.ts
@@ -2651,7 +2683,7 @@ function dbseed() {
2651
2683
  // src/packages/cli/commands/destroy.ts
2652
2684
  var import_os8 = require("os");
2653
2685
  var import_chalk11 = require("chalk");
2654
- var import_inflection21 = require("inflection");
2686
+ var import_inflection22 = require("inflection");
2655
2687
  async function destroyType(type, name) {
2656
2688
  const normalizedType = type.toLowerCase();
2657
2689
  let normalizedName = name;
@@ -2659,8 +2691,8 @@ async function destroyType(type, name) {
2659
2691
  let migrations;
2660
2692
  switch (normalizedType) {
2661
2693
  case "model":
2662
- normalizedName = (0, import_inflection21.singularize)(normalizedName);
2663
- 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`;
2664
2696
  break;
2665
2697
  case "migration":
2666
2698
  migrations = await readdir(`${CWD}/db/migrate`);
@@ -2671,14 +2703,14 @@ async function destroyType(type, name) {
2671
2703
  break;
2672
2704
  case "controller":
2673
2705
  case "serializer":
2674
- normalizedName = (0, import_inflection21.pluralize)(normalizedName);
2675
- 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`;
2676
2708
  break;
2677
2709
  case "middleware":
2678
2710
  path6 = `app/${normalizedType}/${normalizedName}.js`;
2679
2711
  break;
2680
2712
  case "util":
2681
- path6 = `app/${(0, import_inflection21.pluralize)(normalizedType)}/${normalizedName}.js`;
2713
+ path6 = `app/${(0, import_inflection22.pluralize)(normalizedType)}/${normalizedName}.js`;
2682
2714
  break;
2683
2715
  default:
2684
2716
  return;
@@ -2693,13 +2725,13 @@ async function destroy2({ type, name }) {
2693
2725
  if (type === "resource") {
2694
2726
  const routes = (await readFile(`${CWD}/app/routes.js`)).toString("utf8").split("\n").reduce((lines, line2) => {
2695
2727
  const pattern = new RegExp(
2696
- `\\s*this.resource\\(('|"|\`)${(0, import_inflection21.pluralize)(name)}('|"|\`)\\);?`
2728
+ `\\s*this.resource\\(('|"|\`)${(0, import_inflection22.pluralize)(name)}('|"|\`)\\);?`
2697
2729
  );
2698
2730
  return pattern.test(line2) ? lines : [...lines, line2];
2699
2731
  }, []).join("\n");
2700
2732
  await Promise.all([
2701
2733
  destroyType("model", name),
2702
- destroyType("migration", `create-${(0, import_inflection21.pluralize)(name)}`),
2734
+ destroyType("migration", `create-${(0, import_inflection22.pluralize)(name)}`),
2703
2735
  destroyType("serializer", name),
2704
2736
  destroyType("controller", name)
2705
2737
  ]);
@@ -2709,7 +2741,7 @@ async function destroy2({ type, name }) {
2709
2741
  } else if (type === "model") {
2710
2742
  await Promise.all([
2711
2743
  destroyType(type, name),
2712
- destroyType("migration", `create-${(0, import_inflection21.pluralize)(name)}`)
2744
+ destroyType("migration", `create-${(0, import_inflection22.pluralize)(name)}`)
2713
2745
  ]);
2714
2746
  } else {
2715
2747
  await destroyType(type, name);