meocord 4.1.2 → 4.2.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 (140) hide show
  1. package/CHANGELOG.md +362 -0
  2. package/THIRD_PARTY_NOTICES.md +14 -13
  3. package/dist/cjs/_shared/{controller.decorator-BywwkU9O.cjs → controller.decorator-XKMlcUZz.cjs} +669 -185
  4. package/dist/cjs/_shared/{providers-BMMLp2SN.cjs → providers-BZgJyfZS.cjs} +218 -75
  5. package/dist/cjs/_shared/{sharded-cooldown-store-B65iaiAy.cjs → sharded-cooldown-store-CsJJyCZd.cjs} +10 -7
  6. package/dist/cjs/_shared/{startup-roots-lFc69AxC.cjs → startup-roots-CgfPQrNl.cjs} +374 -132
  7. package/dist/cjs/_shared/{translate-error-BnM8FbSH.cjs → translate-error-BUAR1WYG.cjs} +21 -7
  8. package/dist/cjs/common/index.cjs +4 -4
  9. package/dist/cjs/core/index.cjs +365 -310
  10. package/dist/cjs/decorator/index.cjs +85 -61
  11. package/dist/cjs/testing/index.cjs +2236 -496
  12. package/dist/cli.json +1 -1
  13. package/dist/esm/bin/app-template/README.md.template +3 -1
  14. package/dist/esm/bin/app-template/src/controllers/button/sample.button.controller.spec.ts.template +8 -4
  15. package/dist/esm/bin/app-template/src/controllers/button/sample.button.controller.ts.template +2 -2
  16. package/dist/esm/bin/app-template/src/guards/owner.guard.spec.ts.template +8 -4
  17. package/dist/esm/bin/app-template/src/guards/owner.guard.ts.template +1 -1
  18. package/dist/esm/bin/app-template/vitest.config.ts.template +1 -1
  19. package/dist/esm/bin/app-template/vitest.setup.ts.template +7 -3
  20. package/dist/esm/bin/generator.js +4 -5
  21. package/dist/esm/bin/helper/filter-generator.helper.js +4 -5
  22. package/dist/esm/bin/helper/guard-generator.helper.js +4 -5
  23. package/dist/esm/bin/helper/interceptor-generator.helper.js +4 -5
  24. package/dist/esm/bin/helper/observer-generator.helper.js +4 -5
  25. package/dist/esm/bin/helper/pipe-generator.helper.js +4 -5
  26. package/dist/esm/bin/helper/service-generator.helper.js +4 -5
  27. package/dist/esm/bin/meocord.js +84 -25
  28. package/dist/esm/build/load-config.pre-entry.js +17 -4
  29. package/dist/esm/build/rsbuild-config.js +16 -12
  30. package/dist/esm/build/typed-externals.js +36 -0
  31. package/dist/esm/common/cooldown-store.js +10 -2
  32. package/dist/esm/common/decorator.js +6 -6
  33. package/dist/esm/common/deprecation.js +2 -2
  34. package/dist/esm/common/errors.js +27 -2
  35. package/dist/esm/common/execution-context.js +1 -1
  36. package/dist/esm/common/meocord-text.js +11 -8
  37. package/dist/esm/common/metadata.js +1 -1
  38. package/dist/esm/common/response/call-order.js +9 -4
  39. package/dist/esm/common/response/presenter.js +33 -6
  40. package/dist/esm/common/response/response-state.js +84 -10
  41. package/dist/esm/common/route.js +21 -5
  42. package/dist/esm/common/sharded-cooldown-store.js +1 -1
  43. package/dist/esm/common/translate-error.js +1 -1
  44. package/dist/esm/common/translator.js +37 -6
  45. package/dist/esm/core/command-conflicts.js +34 -34
  46. package/dist/esm/core/command-registration.js +93 -24
  47. package/dist/esm/core/command-routes.js +2 -2
  48. package/dist/esm/core/component-routes.js +74 -31
  49. package/dist/esm/core/cooldown-runner.js +29 -8
  50. package/dist/esm/core/dispatcher.js +51 -7
  51. package/dist/esm/core/fallback.js +20 -11
  52. package/dist/esm/core/filter-runner.js +2 -2
  53. package/dist/esm/core/guard-runner.js +16 -3
  54. package/dist/esm/core/handler-input.js +4 -3
  55. package/dist/esm/core/handler-pipeline.js +27 -14
  56. package/dist/esm/core/handler-registry.js +1 -1
  57. package/dist/esm/core/interceptor-runner.js +2 -2
  58. package/dist/esm/core/lifecycle-hooks.js +134 -47
  59. package/dist/esm/core/meocord-factory.js +241 -179
  60. package/dist/esm/core/meocord.app.js +116 -75
  61. package/dist/esm/core/message-routes.js +4 -3
  62. package/dist/esm/core/observer-runner.js +4 -3
  63. package/dist/esm/core/providers.js +45 -23
  64. package/dist/esm/core/route-specificity.js +4 -4
  65. package/dist/esm/core/running-calls.js +43 -0
  66. package/dist/esm/core/scalar-types.js +15 -3
  67. package/dist/esm/core/shard-context.js +6 -7
  68. package/dist/esm/core/shard-manager.js +16 -10
  69. package/dist/esm/core/startup-roots.js +23 -4
  70. package/dist/esm/core/theme-resolvers.js +4 -1
  71. package/dist/esm/core/theme-runtime.js +2 -2
  72. package/dist/esm/core/theme-scope.js +3 -1
  73. package/dist/esm/core/theme-validation.js +17 -10
  74. package/dist/esm/decorator/app.decorator.js +12 -7
  75. package/dist/esm/decorator/command-builder.decorator.js +4 -4
  76. package/dist/esm/decorator/controller-class.decorator.js +9 -4
  77. package/dist/esm/decorator/controller.decorator.js +162 -83
  78. package/dist/esm/decorator/cooldown.decorator.js +20 -3
  79. package/dist/esm/decorator/defer.decorator.js +4 -4
  80. package/dist/esm/decorator/event.decorator.js +5 -5
  81. package/dist/esm/decorator/filter.decorator.js +7 -7
  82. package/dist/esm/decorator/guard.decorator.js +11 -10
  83. package/dist/esm/decorator/inject.decorator.js +4 -4
  84. package/dist/esm/decorator/interceptor.decorator.js +7 -7
  85. package/dist/esm/decorator/observer.decorator.js +4 -4
  86. package/dist/esm/decorator/service.decorator.js +4 -4
  87. package/dist/esm/decorator/theme.decorator.js +3 -3
  88. package/dist/esm/decorator/validation.decorator.js +10 -10
  89. package/dist/esm/package.json.js +1 -1
  90. package/dist/esm/testing/catalog.js +27 -11
  91. package/dist/esm/testing/cooldown-store-suite.js +85 -15
  92. package/dist/esm/testing/discord-defaults.js +249 -21
  93. package/dist/esm/testing/index.js +4 -2
  94. package/dist/esm/testing/inspect-handler.js +20 -3
  95. package/dist/esm/testing/meocord-testing-module.js +352 -205
  96. package/dist/esm/testing/mock-fn.js +173 -22
  97. package/dist/esm/testing/mock-interaction.js +1214 -209
  98. package/dist/esm/testing/response.js +1 -1
  99. package/dist/esm/testing/routing.js +39 -14
  100. package/dist/esm/testing/snowflake.js +9 -2
  101. package/dist/esm/testing/startup-errors.js +26 -0
  102. package/dist/esm/testing/strict-mocks.js +65 -0
  103. package/dist/esm/testing/theme.js +1 -1
  104. package/dist/esm/util/bundle-entry.util.js +2 -1
  105. package/dist/esm/util/common.util.js +47 -19
  106. package/dist/esm/util/dev-runner.util.js +8 -8
  107. package/dist/esm/util/generator-cli.util.js +4 -5
  108. package/dist/esm/util/interaction.util.js +3 -3
  109. package/dist/esm/util/meocord-config-loader.util.js +10 -2
  110. package/dist/esm/util/meocord-config-validation.util.js +4 -5
  111. package/dist/esm/util/meocord-source-config.util.js +65 -20
  112. package/dist/esm/util/metadata-keys.js +1 -0
  113. package/dist/esm/util/method-wrapper.util.js +16 -0
  114. package/dist/esm/util/platform.util.js +10 -10
  115. package/dist/esm/util/refusal.util.js +148 -8
  116. package/dist/esm/util/shard-process.util.js +4 -1
  117. package/dist/esm/util/sharding-mode.util.js +5 -7
  118. package/dist/esm/util/shared-state.util.js +21 -0
  119. package/dist/esm/util/tsconfig-paths.util.js +29 -0
  120. package/dist/esm/util/tsconfig.util.js +10 -10
  121. package/dist/esm/util/value.util.js +12 -1
  122. package/dist/types/common/index.d.cts +8 -8
  123. package/dist/types/common/index.d.ts +8 -8
  124. package/dist/types/core/index.d.cts +10 -7
  125. package/dist/types/core/index.d.ts +10 -7
  126. package/dist/types/decorator/index.d.cts +31 -29
  127. package/dist/types/decorator/index.d.ts +31 -29
  128. package/dist/types/{index-D7n0FBMm.d.ts → index-DKJclIi-.d.ts} +107 -36
  129. package/dist/types/{index-DEP0NYrU.d.cts → index-Dlf0ZZtS.d.cts} +107 -36
  130. package/dist/types/interface/index.d.cts +1 -1
  131. package/dist/types/interface/index.d.ts +1 -1
  132. package/dist/types/{route-C-aMI7Sl.d.cts → route-Bh1U13yy.d.cts} +8 -4
  133. package/dist/types/{route-C-aMI7Sl.d.ts → route-Bh1U13yy.d.ts} +8 -4
  134. package/dist/types/testing/index.d.cts +406 -70
  135. package/dist/types/testing/index.d.ts +406 -70
  136. package/dist/types/{theme-resolvers-COHdX5g6.d.cts → theme-resolvers-CyEz9pnv.d.cts} +1 -1
  137. package/dist/types/{theme-resolvers-DedxyscT.d.ts → theme-resolvers-DA204O-q.d.ts} +1 -1
  138. package/dist/types/{translator-J6tIUfdp.d.ts → translator-Bg7hwxDF.d.cts} +21 -8
  139. package/dist/types/{translator-B4mc1lzJ.d.cts → translator-CeP4bCzp.d.ts} +21 -8
  140. package/package.json +4 -3
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var controller_decorator = require('./controller.decorator-BywwkU9O.cjs');
3
+ var controller_decorator = require('./controller.decorator-XKMlcUZz.cjs');
4
4
  var discord_js = require('discord.js');
5
5
 
6
- /** The longest customId Discord accepts. */ const MAX_CUSTOM_ID_LENGTH = 100;
6
+ const logger = new controller_decorator.Logger('Route');
7
7
  const PLACEHOLDER = /\{(\w+)(?::([^}/]*))?}/g;
8
8
  /** Encodes the characters that would end a param's segment, or read as an encoding, in a customId. */ const encodeSegment = (value)=>value.replace(/%/g, '%25').replace(/\//g, '%2F');
9
9
  /**
@@ -16,6 +16,10 @@ const PLACEHOLDER = /\{(\w+)(?::([^}/]*))?}/g;
16
16
  decodeSegment(value)
17
17
  ]));
18
18
  }
19
+ /** The segment types whose value is text, which `build` takes only as a string. */ const TEXT_TYPES = new Set([
20
+ 'snowflake',
21
+ 'uuid'
22
+ ]);
19
23
  /**
20
24
  * Makes a typed route from a customId pattern, so one declaration serves the handler and the ids that reach it.
21
25
  *
@@ -28,7 +32,8 @@ const PLACEHOLDER = /\{(\w+)(?::([^}/]*))?}/g;
28
32
  * fails to compile, and a typed param takes a value of its type.
29
33
  *
30
34
  * @param pattern - The customId pattern, where `{name}` captures one `/`-separated segment and `{name:int}` a
31
- * typed one.
35
+ * typed one. A param's name is ASCII letters, digits and _: a brace pair such as `{café}` is literal text, and is
36
+ * warned about.
32
37
  * @returns A route whose `build` takes a value for each param.
33
38
  * @throws Error when the pattern cannot be read, as `@Command` would throw for it.
34
39
  *
@@ -50,9 +55,12 @@ const PLACEHOLDER = /\{(\w+)(?::([^}/]*))?}/g;
50
55
  *
51
56
  * @group Utilities
52
57
  * @see {@link Route}
53
- * @see {@link https://meocord.dev/docs/4.1/components | Buttons, selects and modals}
58
+ * @see {@link https://meocord.dev/docs/4.2/components | Buttons, selects and modals}
54
59
  */ function route(pattern) {
55
60
  const { params, types } = controller_decorator.createRegexFromPattern(pattern);
61
+ const braces = controller_decorator.literalBraces(pattern);
62
+ // Once per pattern, as a route made inside a handler is made on every call
63
+ if (braces) controller_decorator.warnOnce(logger, `Pattern "${pattern}": ${braces}`);
56
64
  const names = new Set(params);
57
65
  const build = (values = {})=>{
58
66
  const unknown = Object.keys(values).filter((name)=>!names.has(name));
@@ -62,6 +70,11 @@ const PLACEHOLDER = /\{(\w+)(?::([^}/]*))?}/g;
62
70
  const value = Object.hasOwn(values, name) ? values[name] : undefined;
63
71
  const type = Object.hasOwn(types, name) ? types[name] : undefined;
64
72
  if (value === undefined || value === null) throw new TypeError(`route('${pattern}').build() needs a value for ${placeholder}.`);
73
+ // A snowflake's or uuid's value is its text: a number for a snowflake may have lost digits before it got here
74
+ if (type && TEXT_TYPES.has(type) && typeof value !== 'string') {
75
+ const lost = type === 'snowflake' ? ' A number may have lost digits already: pass the ID as text, such as user.id.' : '';
76
+ throw new TypeError(`route('${pattern}').build() got the ${typeof value} ${String(value)} for ${placeholder}, which takes its value as a string.${lost}`);
77
+ }
65
78
  const text = String(value);
66
79
  if (text === '') throw new TypeError(`route('${pattern}').build() got an empty {${name}}, which no customId segment can hold.`);
67
80
  // A typed segment must read back as the value it was built from, or the route could never match it
@@ -71,8 +84,9 @@ const PLACEHOLDER = /\{(\w+)(?::([^}/]*))?}/g;
71
84
  }
72
85
  return encodeSegment(text);
73
86
  });
74
- if (id.length > MAX_CUSTOM_ID_LENGTH) {
75
- throw new RangeError(`route('${pattern}').build() made a customId of ${id.length} characters, over Discord's ${MAX_CUSTOM_ID_LENGTH}: "${id}".`);
87
+ if (id === '') throw new RangeError(`route('${pattern}').build() made an empty customId; Discord's customIds are 1 to ${controller_decorator.MAX_CUSTOM_ID_LENGTH} characters.`);
88
+ if (id.length > controller_decorator.MAX_CUSTOM_ID_LENGTH) {
89
+ throw new RangeError(`route('${pattern}').build() made a customId of ${id.length} characters, over Discord's ${controller_decorator.MAX_CUSTOM_ID_LENGTH}: "${id}".`);
76
90
  }
77
91
  return id;
78
92
  };
@@ -139,7 +153,7 @@ const PLACEHOLDER = /\{(\w+)(?::([^}/]*))?}/g;
139
153
  * @group Utilities
140
154
  * @category Localisation
141
155
  * @see {@link createTranslator}
142
- * @see {@link https://meocord.dev/docs/4.1/localisation | Localisation}
156
+ * @see {@link https://meocord.dev/docs/4.2/localisation | Localisation}
143
157
  */ function translateError(error, t, target) {
144
158
  const locale = target instanceof discord_js.BaseInteraction ? controller_decorator.interactionLocale(target) : target instanceof discord_js.Message ? controller_decorator.messageLocale(target) : target;
145
159
  return errorText(error, t, locale);
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var controller_decorator = require('../_shared/controller.decorator-BywwkU9O.cjs');
3
+ var controller_decorator = require('../_shared/controller.decorator-XKMlcUZz.cjs');
4
4
  require('reflect-metadata');
5
- var translateError = require('../_shared/translate-error-BnM8FbSH.cjs');
6
- var shardedCooldownStore = require('../_shared/sharded-cooldown-store-B65iaiAy.cjs');
5
+ var translateError = require('../_shared/translate-error-BUAR1WYG.cjs');
6
+ var shardedCooldownStore = require('../_shared/sharded-cooldown-store-CsJJyCZd.cjs');
7
7
  require('../enum/index.cjs');
8
8
  require('discord.js');
9
9
  require('path');
@@ -150,7 +150,7 @@ const assigned = {};
150
150
  *
151
151
  * @group Utilities
152
152
  * @see {@link ExecutionContext}
153
- * @see {@link https://meocord.dev/docs/4.1/guards | Guards}
153
+ * @see {@link https://meocord.dev/docs/4.2/guards | Guards}
154
154
  */ function createMetadata(description) {
155
155
  const key = Symbol(description);
156
156
  const decorator = (value)=>function(target, propertyKey) {