@openreachtech/hora-skills-ort-renchan 0.0.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 (126) hide show
  1. package/LICENSE +201 -0
  2. package/README.ja.md +135 -0
  3. package/README.md +135 -0
  4. package/dist/skills/hor-agent-loop/SKILL.md +123 -0
  5. package/dist/skills/hor-agent-loop/references/core.md +485 -0
  6. package/dist/skills/hor-agent-loop/references/graphql-integration.md +178 -0
  7. package/dist/skills/hor-agent-loop/references/renchan-job-integration.md +368 -0
  8. package/dist/skills/hor-agent-loop/references/testing.md +492 -0
  9. package/dist/skills/hor-ai-agent-structure/SKILL.md +403 -0
  10. package/dist/skills/hor-ai-agent-structure/references/loop-and-actions.md +100 -0
  11. package/dist/skills/hor-ai-prompt-document-store/SKILL.md +220 -0
  12. package/dist/skills/hor-ai-prompt-document-store/references/models-and-composition.md +156 -0
  13. package/dist/skills/hor-backend-testing/SKILL.md +118 -0
  14. package/dist/skills/hor-backend-testing/references/placement-and-ordering.md +89 -0
  15. package/dist/skills/hor-backend-testing/references/purity-and-mocks.md +82 -0
  16. package/dist/skills/hor-backend-testing/references/running-tests.md +186 -0
  17. package/dist/skills/hor-bank-id/SKILL.md +91 -0
  18. package/dist/skills/hor-build-e2e-test-environment/SKILL.md +609 -0
  19. package/dist/skills/hor-build-e2e-test-environment/references/compose-definition.md +368 -0
  20. package/dist/skills/hor-build-e2e-test-environment/references/edge-and-proxy.md +287 -0
  21. package/dist/skills/hor-build-e2e-test-environment/references/environment-and-ports.md +201 -0
  22. package/dist/skills/hor-build-e2e-test-environment/references/runner-and-lifecycle.md +330 -0
  23. package/dist/skills/hor-build-e2e-test-environment/references/seed-data.md +145 -0
  24. package/dist/skills/hor-build-e2e-test-environment/references/windows-runner.md +146 -0
  25. package/dist/skills/hor-constant-definition/SKILL.md +139 -0
  26. package/dist/skills/hor-cookie-authentication/SKILL.md +33 -0
  27. package/dist/skills/hor-cookie-authentication/references/auth-filter.md +55 -0
  28. package/dist/skills/hor-cookie-authentication/references/cookie-context.md +53 -0
  29. package/dist/skills/hor-cookie-authentication/references/dev-login-seeder.md +22 -0
  30. package/dist/skills/hor-cookie-authentication/references/environment.md +64 -0
  31. package/dist/skills/hor-cookie-authentication/references/error-codes.md +24 -0
  32. package/dist/skills/hor-cookie-authentication/references/migrations.md +18 -0
  33. package/dist/skills/hor-cookie-authentication/references/resolvers.md +97 -0
  34. package/dist/skills/hor-cookie-authentication/references/session-clerk.md +41 -0
  35. package/dist/skills/hor-cookie-authentication/references/token-models.md +125 -0
  36. package/dist/skills/hor-database-design/SKILL.md +54 -0
  37. package/dist/skills/hor-database-design/references/column-types.md +92 -0
  38. package/dist/skills/hor-database-design/references/datetimes.md +88 -0
  39. package/dist/skills/hor-database-design/references/master-tables.md +117 -0
  40. package/dist/skills/hor-database-design/references/normalization.md +40 -0
  41. package/dist/skills/hor-database-design/references/update-history.md +35 -0
  42. package/dist/skills/hor-execution-placement-pattern/SKILL.md +216 -0
  43. package/dist/skills/hor-external-api-client/SKILL.md +99 -0
  44. package/dist/skills/hor-external-api-client/references/architecture.md +127 -0
  45. package/dist/skills/hor-external-api-client/references/authorization.md +105 -0
  46. package/dist/skills/hor-external-api-client/references/capsule.md +130 -0
  47. package/dist/skills/hor-external-api-client/references/conventions.md +68 -0
  48. package/dist/skills/hor-external-api-client/references/launcher.md +138 -0
  49. package/dist/skills/hor-external-api-client/references/payload.md +176 -0
  50. package/dist/skills/hor-external-api-client/references/sdk-wrapper.md +291 -0
  51. package/dist/skills/hor-external-api-client/references/testing.md +130 -0
  52. package/dist/skills/hor-external-api-client/references/usage.md +152 -0
  53. package/dist/skills/hor-graphql-schema/SKILL.md +360 -0
  54. package/dist/skills/hor-graphql-server-engine/SKILL.md +356 -0
  55. package/dist/skills/hor-light-rag/SKILL.md +242 -0
  56. package/dist/skills/hor-light-rag/references/retrieval-internals.md +143 -0
  57. package/dist/skills/hor-multi-llm-provider/SKILL.md +288 -0
  58. package/dist/skills/hor-multi-llm-provider/references/provider-internals.md +153 -0
  59. package/dist/skills/hor-mutation-resolver/SKILL.md +360 -0
  60. package/dist/skills/hor-mutation-resolver/references/dependency-injection.md +148 -0
  61. package/dist/skills/hor-mutation-resolver/references/errors.md +120 -0
  62. package/dist/skills/hor-mutation-resolver/references/resolve-flow.md +275 -0
  63. package/dist/skills/hor-mutation-resolver/references/testing.md +125 -0
  64. package/dist/skills/hor-mutation-resolver/references/transaction.md +197 -0
  65. package/dist/skills/hor-post-worker/SKILL.md +320 -0
  66. package/dist/skills/hor-query-resolver/SKILL.md +246 -0
  67. package/dist/skills/hor-query-resolver/references/anatomy.md +384 -0
  68. package/dist/skills/hor-query-resolver/references/data-access.md +248 -0
  69. package/dist/skills/hor-query-resolver/references/errors-and-context.md +172 -0
  70. package/dist/skills/hor-query-resolver/references/testing.md +241 -0
  71. package/dist/skills/hor-renchan-job-bullmq/SKILL.md +178 -0
  72. package/dist/skills/hor-renchan-job-bullmq/references/daemon-and-scheduler.md +182 -0
  73. package/dist/skills/hor-renchan-job-bullmq/references/engine-and-infra.md +106 -0
  74. package/dist/skills/hor-renchan-job-bullmq/references/job-triple.md +189 -0
  75. package/dist/skills/hor-renchan-job-bullmq/references/queues.md +74 -0
  76. package/dist/skills/hor-renchan-job-bullmq/references/subscriptions.md +113 -0
  77. package/dist/skills/hor-resolver-share/SKILL.md +262 -0
  78. package/dist/skills/hor-resolver-validator/SKILL.md +194 -0
  79. package/dist/skills/hor-resolver-validator/references/inspector-api.md +115 -0
  80. package/dist/skills/hor-resolver-validator/references/validator-pattern.md +281 -0
  81. package/dist/skills/hor-restfulapi-architecture/SKILL.md +275 -0
  82. package/dist/skills/hor-restfulapi-architecture/references/engine-and-context.md +192 -0
  83. package/dist/skills/hor-restfulapi-architecture/references/renderers.md +204 -0
  84. package/dist/skills/hor-restfulapi-architecture/references/response-and-flusher.md +118 -0
  85. package/dist/skills/hor-restfulapi-architecture/references/validation.md +229 -0
  86. package/dist/skills/hor-security-audit/SKILL.md +110 -0
  87. package/dist/skills/hor-security-audit/references/application-surface.md +90 -0
  88. package/dist/skills/hor-security-audit/references/auth-and-transport.md +147 -0
  89. package/dist/skills/hor-security-audit/references/code-safety.md +74 -0
  90. package/dist/skills/hor-security-audit/references/dependencies.md +72 -0
  91. package/dist/skills/hor-security-audit/references/network-and-logging.md +56 -0
  92. package/dist/skills/hor-security-audit/references/secrets.md +95 -0
  93. package/dist/skills/hor-sequelize-migration/SKILL.md +336 -0
  94. package/dist/skills/hor-sequelize-migration/references/alter-table.md +147 -0
  95. package/dist/skills/hor-sequelize-migration/references/foreign-keys.md +107 -0
  96. package/dist/skills/hor-sequelize-migration/references/indexes.md +149 -0
  97. package/dist/skills/hor-sequelize-migration/references/notation.md +215 -0
  98. package/dist/skills/hor-sequelize-model/SKILL.md +69 -0
  99. package/dist/skills/hor-sequelize-model/references/associations.md +218 -0
  100. package/dist/skills/hor-sequelize-model/references/default-methods.md +244 -0
  101. package/dist/skills/hor-sequelize-model/references/mixins.md +247 -0
  102. package/dist/skills/hor-sequelize-model/references/notation.md +225 -0
  103. package/dist/skills/hor-sequelize-model/references/timestamps.md +74 -0
  104. package/dist/skills/hor-sequelize-seeder/SKILL.md +275 -0
  105. package/dist/skills/hor-sequelize-seeder/references/development-coverage.md +74 -0
  106. package/dist/skills/hor-sequelize-seeder/references/directory-structure.md +113 -0
  107. package/dist/skills/hor-sequelize-seeder/references/id-numbering.md +133 -0
  108. package/dist/skills/hor-sequelize-seeder/references/naming.md +59 -0
  109. package/dist/skills/hor-sequelize-seeder/references/notation.md +170 -0
  110. package/dist/skills/hor-sequelize-subquery/SKILL.md +369 -0
  111. package/dist/skills/hor-strategy-pattern/SKILL.md +371 -0
  112. package/dist/skills/hor-stub-api/SKILL.md +330 -0
  113. package/dist/skills/hor-subscription-resolver/SKILL.md +105 -0
  114. package/dist/skills/hor-subscription-resolver/references/authentication.md +99 -0
  115. package/dist/skills/hor-subscription-resolver/references/basic-notation.md +116 -0
  116. package/dist/skills/hor-subscription-resolver/references/design-philosophy.md +68 -0
  117. package/dist/skills/hor-type-interface/SKILL.md +200 -0
  118. package/docs/skills.ja.md +40 -0
  119. package/docs/skills.md +40 -0
  120. package/lib/equip/CommandLineArguments.js +178 -0
  121. package/lib/equip/HoraSkillsCli.js +590 -0
  122. package/lib/equip/SkillsInstaller.js +443 -0
  123. package/lib/equip/SkillsManifestFile.js +260 -0
  124. package/lib/equip/constants/CLI_COMMAND.js +8 -0
  125. package/lib/equip/hora-skills-ort-renchan.js +8 -0
  126. package/package.json +51 -0
@@ -0,0 +1,371 @@
1
+ ---
2
+ name: hor-strategy-pattern
3
+ description: >
4
+ Implement the strategy pattern as a trio of a base processor class, one concrete subclass per
5
+ variant, and a bulk loader that auto-discovers the subclasses from a directory and picks one by
6
+ a dispatch getter. Use this skill whenever the user asks to replace an else-if / switch chain
7
+ that dispatches on a "type" string with pluggable processor classes, or to add a new event /
8
+ webhook / message handler that must be auto-discovered.
9
+ ---
10
+
11
+ # Strategy Pattern (processor classes + a bulk loader)
12
+
13
+ A skill for dispatching on a string "type" value to one of several behaviors **without an
14
+ `else if` / `switch` chain**. Each branch becomes a class; a loader auto-discovers the classes
15
+ from a directory and picks one by a dispatch **getter**. The class skeleton each piece follows
16
+ (one file / one class, `static create()` factory, JSDoc typedefs) comes from `class-design` —
17
+ this skill covers how the three pieces fit together.
18
+
19
+ Reach for it when:
20
+
21
+ - You would otherwise write `if (type === 'a') ... else if (type === 'b') ...`.
22
+ - New variants get added over time and you want to drop a file in a folder, not edit a switch.
23
+ - Each branch has non-trivial logic worth testing in isolation.
24
+
25
+ Do **not** reach for it for a 2-branch boolean or a value map with no behavior — a plain
26
+ lookup hash is enough there.
27
+
28
+ ## Grand principle: adding a variant means adding a file, never editing a dispatch chain
29
+
30
+ Every rule in this skill serves one point: **the set of variants is discovered from the
31
+ filesystem, not listed in code**. A new variant is one new subclass file dropped into the
32
+ processor directory; no existing file changes.
33
+
34
+ - **Why not a switch**: an `else if` / `switch` chain concentrates every variant's wiring in one
35
+ function, so every new variant edits (and risks breaking) shared code, and each branch's logic
36
+ can't be tested in isolation. One-class-per-variant keeps each branch independently testable
37
+ and reviewable.
38
+ - **Why auto-discovery**: if the loader imported each subclass by name, the "chain" would just
39
+ move into the import list. Loading every class in the directory
40
+ ([4](#4-bulk-loader-auto-discover-and-pick-by-getter)) makes the directory itself the
41
+ registry.
42
+ - **Why dispatch by getter**: the key a processor handles is part of that processor's contract,
43
+ so it lives **on the subclass** as an overridden getter — not in a name field passed from
44
+ outside, and not in a mapping table kept next to the loader.
45
+
46
+ ```js
47
+ // Good: the caller asks the loader; variants stay out of the call site
48
+ const processor = loader.resolveProcessor(eventCategory)
49
+
50
+ if (!processor) {
51
+ return null
52
+ }
53
+
54
+ return processor.process({
55
+ event,
56
+ })
57
+ ```
58
+
59
+ ```js
60
+ // Avoid: an else-if chain enumerating every variant at the call site
61
+ // → every new variant edits this shared function; branches can't be tested in isolation
62
+ if (eventCategory === 'created') {
63
+ return handleCreated(event)
64
+ } else if (eventCategory === 'updated') {
65
+ return handleUpdated(event)
66
+ } else if (eventCategory === 'deleted') {
67
+ return handleDeleted(event)
68
+ }
69
+ ```
70
+
71
+ ## Comment language in the sample code
72
+
73
+ Comments in the `js` examples in this SKILL.md follow the prose language (here, **English**),
74
+ because the examples are *explanation* of the skill. Comments inside the **artifact this skill
75
+ produces** (the real processor / loader code) follow the **codebase** language — English — to
76
+ match the surrounding source.
77
+
78
+ ## 1. The three pieces
79
+
80
+ | Piece | Role | Count |
81
+ | --- | --- | --- |
82
+ | Base class | Declares the `static create()` factory, the abstract dispatch **getter** (throws until overridden), and the abstract work method (throws until overridden) | 1 |
83
+ | Concrete subclasses | One file per variant; each overrides the dispatch getter to return its key and overrides the work method | 1 per variant |
84
+ | Bulk loader | `static async createAsync()` loads every class in the processor directory via `DeepBulkClassLoader`, instantiates each; `resolveProcessor(key)` finds the one whose dispatch getter matches, `?? null` | 1 |
85
+
86
+ Typical layout (a payment-gateway webhook example):
87
+
88
+ ```
89
+ app/tools/eventProcessors/
90
+ ├── BaseEventProcessor.js
91
+ ├── concretes/
92
+ │ ├── CreateEventProcessor.js
93
+ │ ├── UpdateEventProcessor.js
94
+ │ └── DeleteEventProcessor.js
95
+ app/tools/bulkLoaders/
96
+ └── BulkEventProcessorsLoader.js
97
+ ```
98
+
99
+ ## 2. Base class: an abstract getter + an abstract work method
100
+
101
+ Dispatch is **by getter**, not by a `processorName` field or a `static getName()`. The getter
102
+ throws until a subclass overrides it. `static create()` is the factory; the work method is
103
+ abstract and also throws. Throwing abstract members are the whole "interface" — there is no
104
+ TypeScript interface to implement.
105
+
106
+ ```js
107
+ /**
108
+ * Base class for event processors.
109
+ */
110
+ export default class BaseEventProcessor {
111
+ /**
112
+ * Factory method.
113
+ *
114
+ * @template {X extends typeof BaseEventProcessor ? X : never} T, X
115
+ * @param {BaseEventProcessorFactoryParams} params - Parameters for the factory.
116
+ * @returns {InstanceType<T>} An instance of the class.
117
+ * @this {T}
118
+ */
119
+ static create (params) {
120
+ return /** @type {InstanceType<T>} */ (
121
+ new this(params)
122
+ )
123
+ }
124
+
125
+ /**
126
+ * get: Dispatch key this processor handles.
127
+ *
128
+ * @abstract
129
+ * @returns {string}
130
+ * @throws {Error} - When not overridden in a subclass.
131
+ */
132
+ get eventCategory () {
133
+ throw new Error('eventCategory must be implemented in subclass')
134
+ }
135
+
136
+ /**
137
+ * Process the event.
138
+ *
139
+ * @abstract
140
+ * @param {EventProcessorParams} params - Parameters for processing.
141
+ * @returns {Promise<*>}
142
+ * @throws {Error} - When not overridden in a subclass.
143
+ */
144
+ async process ({
145
+ event,
146
+ }) {
147
+ throw new Error('process must be implemented in subclass')
148
+ }
149
+ }
150
+
151
+ /**
152
+ * @typedef {object} EventProcessorParams
153
+ * @property {*} event - The event to process.
154
+ */
155
+
156
+ /**
157
+ * @typedef {{
158
+ * [key: string]: *
159
+ * }} BaseEventProcessorFactoryParams
160
+ */
161
+ ```
162
+
163
+ - When a processor needs collaborators, take them as constructor deps and default them in
164
+ `create()` (e.g. `static create ({ randomTextGenerator = this.createRandomTextGenerator() } = {})`),
165
+ following `class-design`. Keep that shape rather than `new`-ing collaborators inside the work
166
+ method.
167
+
168
+ ## 3. Concrete subclass: one file per variant
169
+
170
+ Override the dispatch getter (mark it `@override`) to return the key **from a shared constant
171
+ hash, not a bare string literal**, and override the work method. `static create()` is inherited
172
+ from the base — subclasses only redefine it when they need extra defaults.
173
+
174
+ ```js
175
+ import BaseEventProcessor from '../BaseEventProcessor.js'
176
+
177
+ import CONSTANT from '../../../globals/constants.js'
178
+
179
+ const {
180
+ EVENT_TYPE,
181
+ } = CONSTANT
182
+
183
+ /**
184
+ * Event processor: handle "create" events.
185
+ */
186
+ export default class CreateEventProcessor extends BaseEventProcessor {
187
+ /**
188
+ * get: Dispatch key this processor handles.
189
+ *
190
+ * @override
191
+ * @returns {string}
192
+ */
193
+ get eventCategory () {
194
+ return EVENT_TYPE.CREATE_RECORD
195
+ }
196
+
197
+ /**
198
+ * Process the event.
199
+ *
200
+ * @override
201
+ * @param {{
202
+ * event: *
203
+ * }} params - Parameters for processing.
204
+ * @returns {Promise<*>}
205
+ */
206
+ async process ({
207
+ event,
208
+ }) {
209
+ return this.buildResult({
210
+ event,
211
+ })
212
+ }
213
+ }
214
+ ```
215
+
216
+ - **Why a constant hash for the key**: the same key string appears on the producer side (the
217
+ webhook / message payload) and the consumer side (the getter). A shared constant makes a typo
218
+ a reference error instead of a silent dispatch miss.
219
+ - Suffix concrete classes by role (`~Processor`, `~Handler`, `~Converter`), aligned with the
220
+ base class name.
221
+
222
+ ## 4. Bulk loader: auto-discover and pick by getter
223
+
224
+ The loader resolves the processor directory with `rootPath.to(...)`, loads every class in it via
225
+ `DeepBulkClassLoader.create({ poolPath }).loadClasses()`, and instantiates each with
226
+ `.create()`. `resolveProcessor(key)` matches on the dispatch getter and returns **`?? null`** on a
227
+ miss — there is no default / fallback processor and no throw inside the loader.
228
+
229
+ ```js
230
+ import {
231
+ DeepBulkClassLoader,
232
+ } from '@openreachtech/renchan'
233
+
234
+ import {
235
+ rootPath,
236
+ } from '../../globals/_.js'
237
+
238
+ const eventProcessorPath = rootPath.to('app/tools/eventProcessors/concretes')
239
+
240
+ /**
241
+ * Bulk loader for event processors.
242
+ */
243
+ export default class BulkEventProcessorsLoader {
244
+ /**
245
+ * Constructor.
246
+ *
247
+ * @constructor
248
+ * @param {BulkEventProcessorsLoaderConstructorParams} params - Parameters of this constructor.
249
+ */
250
+ constructor ({
251
+ processors,
252
+ }) {
253
+ this.processors = processors
254
+ }
255
+
256
+ /**
257
+ * Factory method as async.
258
+ *
259
+ * @param {string} [path] - The path to load processors from.
260
+ * @returns {Promise<BulkEventProcessorsLoader>}
261
+ */
262
+ static async createAsync (path = eventProcessorPath) {
263
+ const processorClasses = await this.loadProcessorClasses(path)
264
+
265
+ const processors = processorClasses.map(ProcessorClass =>
266
+ ProcessorClass.create()
267
+ )
268
+
269
+ return new this({
270
+ processors,
271
+ })
272
+ }
273
+
274
+ /**
275
+ * Factory method.
276
+ *
277
+ * @template {X extends typeof BulkEventProcessorsLoader ? X : never} T, X
278
+ * @param {BulkEventProcessorsLoaderFactoryParams} params - Parameters for the factory.
279
+ * @returns {InstanceType<T>} An instance of the class.
280
+ * @this {T}
281
+ */
282
+ static create (params) {
283
+ return /** @type {InstanceType<T>} */ (
284
+ new this(params)
285
+ )
286
+ }
287
+
288
+ /**
289
+ * Load processor classes from the specified path.
290
+ *
291
+ * @param {string} path - The path to load processor classes from.
292
+ * @returns {Promise<Array<typeof import('../eventProcessors/BaseEventProcessor.js').default>>}
293
+ */
294
+ static async loadProcessorClasses (path) {
295
+ return /** @type {*} */ (
296
+ DeepBulkClassLoader.create({
297
+ poolPath: path,
298
+ })
299
+ .loadClasses()
300
+ )
301
+ }
302
+
303
+ /**
304
+ * Resolve a processor by dispatch key.
305
+ *
306
+ * @param {string} eventCategory - The dispatch key.
307
+ * @returns {import('../eventProcessors/BaseEventProcessor.js').default | null}
308
+ */
309
+ resolveProcessor (eventCategory) {
310
+ return this.processors.find(processor => processor.eventCategory === eventCategory)
311
+ ?? null
312
+ }
313
+ }
314
+
315
+ /**
316
+ * @typedef {object} BulkEventProcessorsLoaderConstructorParams
317
+ * @property {Array<import('../eventProcessors/BaseEventProcessor.js').default>} processors - The event processors.
318
+ */
319
+
320
+ /**
321
+ * @typedef {{
322
+ * processors: Array<import('../eventProcessors/BaseEventProcessor.js').default>
323
+ * }} BulkEventProcessorsLoaderFactoryParams
324
+ */
325
+ ```
326
+
327
+ - **Why `?? null` and no fallback processor**: what a miss means (skip? log? error response?)
328
+ is the caller's decision, and it differs per call site. A `'default_processor'` chain inside
329
+ the loader hides unknown keys from the caller.
330
+ - Build the loader once (at startup / in a shared instance) and reuse it — `createAsync()` reads
331
+ the filesystem, so don't re-run it per event.
332
+
333
+ ## 5. Caller side
334
+
335
+ The caller asks the loader for a processor and decides what a `null` means:
336
+
337
+ ```js
338
+ const loader = await BulkEventProcessorsLoader.createAsync()
339
+
340
+ const processor = loader.resolveProcessor(eventCategory)
341
+
342
+ if (!processor) {
343
+ return null
344
+ }
345
+
346
+ return processor.process({
347
+ event,
348
+ })
349
+ ```
350
+
351
+ ## 6. Testing
352
+
353
+ Following the `hoc-jest` skill, split files per class.
354
+
355
+ - **Base class**: each abstract member throws (`eventCategory`, the work method); `static create()`
356
+ returns an instance of the called class.
357
+ - **Each concrete subclass**: inheritance (extends the base); the dispatch getter returns the
358
+ expected constant; the work method's behavior with `test.each()` over its variable inputs.
359
+ - **Bulk loader**: `resolveProcessor()` returns the matching processor for each known key
360
+ (`test.each()` over the keys), and **`null` for an unknown key** — don't skip the miss case.
361
+
362
+ ## Finishing checklist
363
+
364
+ - [ ] Did the change add a variant as **one new subclass file**, without editing a dispatch chain or an import list?
365
+ - [ ] Is dispatch a **getter** overridden per subclass (no `processorName` field, no `static getName()`)?
366
+ - [ ] Do the abstract base members throw `new Error('... must be implemented in subclass')`?
367
+ - [ ] Does the dispatch getter return its key from a **shared constant hash**, not a bare string literal?
368
+ - [ ] Does the loader auto-discover via `DeepBulkClassLoader` from a `rootPath.to(...)` directory, and does `resolveProcessor()` return `?? null` on a miss (no fallback processor, no throw)?
369
+ - [ ] Is `static create()` the factory everywhere, with constructor deps defaulted in `create()` when needed (per `class-design`)?
370
+ - [ ] One class per file, suffixed by role (`~Processor`, `~Handler`, `~Converter`)?
371
+ - [ ] Do tests cover the abstract throws, each subclass's getter + behavior, and the loader's known-key / unknown-key cases?
@@ -0,0 +1,330 @@
1
+ ---
2
+ name: hor-stub-api
3
+ description: >
4
+ Implement a stub GraphQL resolver: a query/mutation resolver that returns hardcoded,
5
+ schema-accurate data with no DB access and no business logic, so the frontend can
6
+ develop against the API contract before the real backend exists. Use this skill
7
+ whenever the user asks to add or edit a stub resolver (a class under
8
+ server/graphql/resolvers/<audience>/stub/), wants "a fake API the frontend can call
9
+ now", or needs to migrate a finished stub into a real resolver under actual/.
10
+ ---
11
+
12
+ # Stub API (schema-accurate stub resolvers)
13
+
14
+ A skill for implementing **stub resolvers**: query/mutation resolver classes that return hardcoded,
15
+ schema-accurate data. They exist so the frontend can build against the API contract while the real
16
+ backend logic is still unwritten. A stub lives under
17
+ `server/graphql/resolvers/<audience>/stub/{queries,mutations}/` (where `<audience>` is one of the
18
+ app's audience folders, e.g. `customer` / `admin`); the matching real resolver later lives under
19
+ `server/graphql/resolvers/<audience>/actual/…` with the **same class name and interface**.
20
+
21
+ The schema the stub must mirror is authored per `hor-graphql-schema`. The real implementation the stub
22
+ is eventually replaced by is authored per `hor-query-resolver` / `hor-mutation-resolver`; this skill covers
23
+ only the stub itself and the hand-off to the real resolver.
24
+
25
+ ## Grand principle: a stub returns hardcoded literals only — no logic of any kind
26
+
27
+ Everything a stub's `resolve()` returns is a **hardcoded literal**. No DB access, no service calls,
28
+ no validation, no computation, no conditionals, no `map`/`filter`/`reduce` over input. The single
29
+ exception is the pagination slice ([2](#2-paginated-query-stub)).
30
+
31
+ - **Why literals only**: a stub's job is to pin down the **contract** (the response shape), not to
32
+ approximate the behavior. Any logic you write in a stub is unverified pseudo-implementation — it
33
+ can drift from the real rules, the frontend starts depending on it, and the divergence shows up
34
+ as breakage at migration time. A literal cannot lie about anything except the shape, and the
35
+ shape is exactly what a stub exists to guarantee.
36
+ - **Why schema-accurate**: the returned shape must match the GraphQL schema exactly (every required
37
+ field present, correct types). A stub that omits fields forces the frontend to discover the gap
38
+ against the real API later — the one failure mode a stub is supposed to prevent.
39
+ - **Echo input back only where the schema result mirrors it** (e.g. a mutation that returns the id
40
+ it was given); otherwise return plausible hardcoded ids/values. Echoing is reading a field, not
41
+ computing — transforming input is already logic and belongs to the real resolver.
42
+
43
+ ```js
44
+ // Good: every field is a hardcoded literal — the stub pins the shape and nothing else
45
+ /** @override */
46
+ async resolve ({
47
+ variables: {
48
+ input,
49
+ },
50
+ context,
51
+ }) {
52
+ return {
53
+ shippingAddressId: 1003,
54
+ }
55
+ }
56
+ ```
57
+
58
+ ```js
59
+ // Avoid: computing values from input in a stub
60
+ // → unverified pseudo-logic the frontend starts depending on; it drifts from the real rules and breaks at migration time
61
+ async resolve ({
62
+ variables: {
63
+ input,
64
+ },
65
+ }) {
66
+ const normalizedCode = input.postalCode.replace('-', '') // computation — belongs to the real resolver
67
+ return {
68
+ shippingAddressId: normalizedCode.length > 0
69
+ ? 1003
70
+ : null, // conditional — a stub never branches
71
+ }
72
+ }
73
+ ```
74
+
75
+ ## 1. Query stub
76
+
77
+ Extend `BaseQueryResolver`. `schema` is a **`static get`** returning the camelCase GraphQL
78
+ operation name. `resolve()` destructures `{ variables: { input }, context }` and returns literals.
79
+
80
+ ```js
81
+ import {
82
+ BaseQueryResolver,
83
+ } from '@openreachtech/renchan'
84
+
85
+ /**
86
+ * Stub resolver: shippingCarriers query.
87
+ *
88
+ * @extends {BaseQueryResolver}
89
+ */
90
+ export default class ShippingCarriersQueryResolver extends BaseQueryResolver {
91
+ /**
92
+ * get: Operation name.
93
+ *
94
+ * @override
95
+ * @returns {string}
96
+ */
97
+ static get schema () {
98
+ return 'shippingCarriers'
99
+ }
100
+
101
+ /**
102
+ * Resolve. Returns hardcoded, schema-accurate data.
103
+ *
104
+ * @override
105
+ */
106
+ async resolve ({
107
+ variables: {
108
+ input: {
109
+ searchParameters,
110
+ },
111
+ },
112
+ context,
113
+ }) {
114
+ const allCarriers = [
115
+ {
116
+ shippingCarrierId: 1,
117
+ shippingCarrierName: 'Alpha Express',
118
+ shippingCarrierCode: 'ALPHA',
119
+ },
120
+ {
121
+ shippingCarrierId: 2,
122
+ shippingCarrierName: 'Beta Logistics',
123
+ shippingCarrierCode: 'BETA',
124
+ },
125
+ ]
126
+
127
+ return {
128
+ shippingCarriers: allCarriers,
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ - If the query takes no input, drop the `input` destructuring and keep just `resolve ()` or
135
+ `resolve ({ context })`.
136
+ - The file name is `<Operation>QueryResolver.js`, matching the class name.
137
+
138
+ ## 2. Paginated query stub
139
+
140
+ When the query is paginated (`input.pagination` with `limit` / `offset` / `sort`), hardcode a full
141
+ `const all<Things>` array of **at least 10 records** (every value unique), then return the correct
142
+ page. The slice below is the **only** operation the whole stub is allowed to do.
143
+
144
+ ```js
145
+ import {
146
+ BaseQueryResolver,
147
+ } from '@openreachtech/renchan'
148
+
149
+ /**
150
+ * Stub resolver: customerBillingHistories query (paginated).
151
+ *
152
+ * @extends {BaseQueryResolver}
153
+ */
154
+ export default class CustomerBillingHistoriesQueryResolver extends BaseQueryResolver {
155
+ /**
156
+ * get: Operation name.
157
+ *
158
+ * @override
159
+ * @returns {string}
160
+ */
161
+ static get schema () {
162
+ return 'customerBillingHistories'
163
+ }
164
+
165
+ /**
166
+ * Resolve. Returns the requested page of hardcoded records.
167
+ *
168
+ * @override
169
+ */
170
+ async resolve ({
171
+ variables: {
172
+ input: {
173
+ pagination: {
174
+ limit,
175
+ offset,
176
+ sort,
177
+ },
178
+ },
179
+ },
180
+ }) {
181
+ const allBillingHistories = [
182
+ {
183
+ orderPaymentId: 50001,
184
+ totalPrice: '5450.00',
185
+ paidAt: new Date('2024-01-18T14:00:00.000Z'),
186
+ // ... the rest of the schema-required fields, all hardcoded
187
+ },
188
+ // ... at least 10 hardcoded records total, every value unique
189
+ ]
190
+
191
+ const totalRecords = allBillingHistories.length
192
+ const billingHistories = allBillingHistories.slice(offset, offset + limit)
193
+
194
+ return {
195
+ billingHistories,
196
+ pagination: {
197
+ limit,
198
+ offset,
199
+ sort,
200
+ totalRecords,
201
+ },
202
+ }
203
+ }
204
+ }
205
+ ```
206
+
207
+ - **Use `slice(offset, offset + limit)`** — it returns a copy of the requested page. Do **not** use
208
+ `splice`, which mutates the source array.
209
+ - `totalRecords` is the array's `.length` (never a hardcoded number), so the page math stays
210
+ correct as records are added.
211
+ - Hardcode **at least 10 records with every value unique**, so the frontend can see paging actually
212
+ advance and distinguish the records on screen.
213
+ - This slice + `.length` is the only computation permitted; every field inside the records is a
214
+ hardcoded literal.
215
+
216
+ ## 3. Mutation stub
217
+
218
+ Extend `BaseMutationResolver`. Same **`static get schema ()`**, plus a
219
+ **`static get errorCodeHash ()`** that spreads `super.errorCodeHash`. Stubs keep the hash empty —
220
+ real error codes are added during migration ([4](#4-migrating-a-stub-to-a-real-resolver)).
221
+
222
+ ```js
223
+ import {
224
+ BaseMutationResolver,
225
+ } from '@openreachtech/renchan'
226
+
227
+ /**
228
+ * Stub resolver: addShippingAddress mutation.
229
+ *
230
+ * @extends {BaseMutationResolver}
231
+ */
232
+ export default class AddShippingAddressMutationResolver extends BaseMutationResolver {
233
+ /**
234
+ * get: Operation name.
235
+ *
236
+ * @override
237
+ * @returns {string}
238
+ */
239
+ static get schema () {
240
+ return 'addShippingAddress'
241
+ }
242
+
243
+ /**
244
+ * get: Error code hash. Kept empty in a stub.
245
+ *
246
+ * @override
247
+ * @returns {Record<string, string>}
248
+ */
249
+ static get errorCodeHash () {
250
+ return {
251
+ ...super.errorCodeHash,
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Resolve. Returns hardcoded, schema-accurate data.
257
+ *
258
+ * @override
259
+ */
260
+ async resolve ({
261
+ variables: {
262
+ input,
263
+ },
264
+ context,
265
+ }) {
266
+ return {
267
+ shippingAddressId: 1003,
268
+ }
269
+ }
270
+ }
271
+ ```
272
+
273
+ Echo input back when the result mirrors it — destructure exactly the fields you return:
274
+
275
+ ```js
276
+ /** @override */
277
+ async resolve ({
278
+ variables: {
279
+ input: {
280
+ originObjectCategoryId,
281
+ originObjectUniqueKey,
282
+ },
283
+ },
284
+ context,
285
+ }) {
286
+ return {
287
+ originObjectCategoryId,
288
+ originObjectUniqueKey,
289
+ updatedColumnsWithValues: [],
290
+ }
291
+ }
292
+ ```
293
+
294
+ ## 4. Migrating a stub to a real resolver
295
+
296
+ Preserve the interface, swap only the body. The frontend must not notice the switch except that
297
+ the data becomes real.
298
+
299
+ 1. **Keep the class name, `static get schema ()`, and `static get errorCodeHash ()`.** Move the
300
+ file from `…/stub/…` to `…/actual/…`.
301
+ 2. **Fill `errorCodeHash` with real codes** (spread `super.errorCodeHash` first):
302
+
303
+ ```js
304
+ /** @override */
305
+ static get errorCodeHash () {
306
+ return {
307
+ ...super.errorCodeHash,
308
+
309
+ InvalidPostalCode: '203.M004.001',
310
+ InvalidPrefecture: '203.M004.002',
311
+ }
312
+ }
313
+ ```
314
+ 3. **Replace the literal return with real work** — validate input, run DB/transaction logic through
315
+ Sequelize models, and format the response with **the same shape the stub returned**. Structure
316
+ the real resolver per `hor-query-resolver` / `hor-mutation-resolver` (extracted `validateInput` /
317
+ transaction callback / `formatResponse` — not everything inlined in `resolve()`).
318
+ 4. Throwing an error-code key surfaces it via `errorCodeHash` — this is where the codes added in
319
+ step 2 come into play.
320
+
321
+ ## Finishing checklist
322
+
323
+ - [ ] Is every returned field a **hardcoded literal** (no DB, no service calls, no validation, no conditionals, no `map`/`filter`/`reduce`)?
324
+ - [ ] Does the returned shape match the GraphQL schema **exactly** (all required fields, correct types)?
325
+ - [ ] Is the file under `server/graphql/resolvers/<audience>/stub/{queries,mutations}/`, with class name `<Operation>QueryResolver` / `<Operation>MutationResolver` and a matching file name?
326
+ - [ ] Does `static get schema ()` return the camelCase operation name?
327
+ - [ ] Does a mutation stub define `static get errorCodeHash ()` spreading `super.errorCodeHash`, kept empty?
328
+ - [ ] Paginated stub: ≥ 10 hardcoded records with unique values, page via `slice(offset, offset + limit)` (never `splice`), `totalRecords` = array `.length`?
329
+ - [ ] Is input echoed back only where the schema result mirrors it (no transformation of input)?
330
+ - [ ] When migrating: same class name / `schema` / `errorCodeHash` interface, file moved to `actual/`, real codes filled in, response shape unchanged?