@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,247 @@
1
+ # Mixins (kinds of MixinModel and how to pass them)
2
+
3
+ Conventions for the MixinModels that compose routine behavior onto `RenchanModel`. Referenced
4
+ from `SKILL.md`. For how a Mixin injects features into the extension points (why `super.xxx?.()`
5
+ is kept) see
6
+ [default-methods.md](./default-methods.md#even-unused-extension-points-call-super-and-keep-a-noop).
7
+
8
+ ## Pass mixins as an array from the Mixins getter
9
+
10
+ To make Mixins take effect on a model, **override `static get Mixins ()` to return an array of
11
+ MixinModels**. Import Mixins from `@openreachtech/renchan-sequelize`. You can pass several.
12
+
13
+ - **Why**: at each of the `associate` / `defineScopes` / `defineSubqueries` / `setupHooks`
14
+ extension points, `RenchanModel` walks `Mixins` and composes the Mixin's same-named handler
15
+ (`mixinsApplier`). That is why **routine behavior is declared as a Mixin rather than
16
+ hand-written in the model** — "clone to a history table on every save", "include the latest
17
+ status on find", and the like. Keeping `super.xxx?.()` first in the six methods is what makes
18
+ this composition work
19
+ ([default-methods.md](./default-methods.md#even-unused-extension-points-call-super-and-keep-a-noop)).
20
+ - The `Mixins` getter, and the abstract getters a Mixin requires (next section), go **after the
21
+ six methods** (at the end). The "extensions added to this model" then sit together after the
22
+ skeleton
23
+ ([SKILL.md](../SKILL.md#grand-principle-a-model-is-a-filled-in-template-not-free-form-code)).
24
+
25
+ ```js
26
+ // Good example (Mixins goes after the six methods)
27
+ import {
28
+ BackupMixinModel,
29
+ ModelAttributeFactory,
30
+ } from '@openreachtech/renchan-sequelize'
31
+
32
+ import BaseAppRenchanModel from '../baseModel/BaseAppRenchanModel.js'
33
+
34
+ export default class CustomerOrder extends BaseAppRenchanModel {
35
+ // ... createAttributes through setupHooks (the six methods)
36
+
37
+ /**
38
+ * get: Mixin models to apply
39
+ *
40
+ * @returns {Array<Function>} Mixin models
41
+ */
42
+ static get Mixins () {
43
+ return [
44
+ BackupMixinModel,
45
+ ]
46
+ }
47
+
48
+ // ↓ the abstract getter the Mixin requires (next section)
49
+ }
50
+ ```
51
+
52
+ ## Implement the abstract getter a mixin requires to pass it
53
+
54
+ Each Mixin declares "which model it relates to" and "which column it orders by" via an **abstract
55
+ getter** that `throw`s on the base. Overriding that getter on the model side to inject the
56
+ concrete value is how you **pass input** to the Mixin.
57
+
58
+ - **Why**: a Mixin is a reusable frame and does not know the model-specific counterpart (backup
59
+ target, status table, etc.). If you do not implement the abstract getter, the moment that
60
+ Mixin's handler runs it fails with `".get:XxxModel" must be inherited`. Which getter to pass
61
+ is fixed per Mixin (table below).
62
+ - Return the related model with **`this._.<ModelName>`**, same as
63
+ [associations.md](./associations.md#reference-the-associated-model-via-this_modelname) (to avoid
64
+ a circular import).
65
+
66
+ ```js
67
+ // Good example (implement BackupModel required by BackupMixinModel = pass the backup target)
68
+ /**
69
+ * get: Backup model for BackupMixinModel
70
+ *
71
+ * @returns {typeof import('./CustomerOrdersBk')} Backup model declaration
72
+ */
73
+ static get BackupModel () {
74
+ return this._.CustomerOrdersBk
75
+ }
76
+ ```
77
+
78
+ ```js
79
+ // Bad example (passed to Mixins but the abstract getter is unimplemented — throws on save)
80
+ static get Mixins () {
81
+ return [
82
+ BackupMixinModel,
83
+ ]
84
+ }
85
+ // no BackupModel getter → afterSave: ".get:BackupModel" must be inherited
86
+ ```
87
+
88
+ ## Mixin catalog (kinds and required abstract getters)
89
+
90
+ `index.js` exports six MixinModels. `BaseMixinModel` is the base of all Mixins and is never passed
91
+ directly; implement the abstract getters below and pass a Mixin to `Mixins` when a use arises.
92
+
93
+ | Mixin | Purpose | Required abstract getter | Optional override (default) |
94
+ | --- | --- | --- | --- |
95
+ | `BackupMixinModel` | clone/append business attributes to another table on every save (history) | `BackupModel` | — |
96
+ | `LatestStatusMixinModel` | keep a status history; auto-include on find and get the latest | `StatusModel` / `StatusPhaseModel` | `orderAttributeOfStatusPhaseModel` (`'savedAt'`) |
97
+ | `SuiteVersionMixinModel` | fetch a versioned "suite" per version | `SuiteModel` | `versionKey` (`'startedAt'`) / `getSuiteSorter` |
98
+ | `PaginationMixinModel` | provide `findAllWithPagination()` and a paging scope | none | — |
99
+ | `ReferralMixinModel` | referral tree via invite codes (Fertile Forest) | `InviteCodeModel` / `ReferralNodeModel` | `inviteCodeAttributeOfInviteCodeModel` and others |
100
+ | `AttributesLinearizerMixinModel` | flatten an included nested structure into each node's `dataValues` | none | — |
101
+
102
+ ## How to pass each mixin
103
+
104
+ ### BackupMixinModel (in use)
105
+
106
+ In the `afterSave` hook it `build`s → `save`s the body's business attributes (all attributes
107
+ except `id` / `createdAt` / `updatedAt` / `deletedAt`; the same exclusion as
108
+ [timestamps.md](./timestamps.md)) into the `BackupModel` table, appending a generation. **Pass it
109
+ to the body table (`CustomerOrder`), and `BackupModel` returns the backup table
110
+ (`CustomerOrdersBk`)**.
111
+
112
+ ```js
113
+ // Good example (body table CustomerOrder; cloned to CustomerOrdersBk on every save)
114
+ export default class CustomerOrder extends BaseAppRenchanModel {
115
+ // ... the six methods (e.g. this.belongsTo(this._.Customer) in associate)
116
+
117
+ /**
118
+ * get: Mixin models to apply
119
+ *
120
+ * @returns {Array<Function>} Mixin models
121
+ */
122
+ static get Mixins () {
123
+ return [
124
+ BackupMixinModel,
125
+ ]
126
+ }
127
+
128
+ /**
129
+ * get: Backup model for BackupMixinModel
130
+ *
131
+ * @returns {typeof import('./CustomerOrdersBk')} Backup model declaration
132
+ */
133
+ static get BackupModel () {
134
+ return this._.CustomerOrdersBk
135
+ }
136
+ }
137
+ ```
138
+
139
+ - The backup table (`CustomerOrdersBk`) side is an ordinary model holding the body's business
140
+ attributes plus a save time (`savedAt`). Because its name clashes with the pluralized inference
141
+ of the class name, it declares `tableName`
142
+ ([default-methods.md](./default-methods.md#when-to-add-tablename)).
143
+
144
+ ### LatestStatusMixinModel
145
+
146
+ Relates a status table via `belongsToMany(StatusModel, { through: StatusPhaseModel })`,
147
+ auto-includes it in `beforeFind`, and returns the latest (head of `savedAt` descending) from the
148
+ instance's `latestStatus`. To change the ordering column, override
149
+ `orderAttributeOfStatusPhaseModel`.
150
+
151
+ ```js
152
+ // How to pass (pass StatusModel / StatusPhaseModel to the body table)
153
+ static get Mixins () {
154
+ return [
155
+ LatestStatusMixinModel,
156
+ ]
157
+ }
158
+
159
+ static get StatusModel () {
160
+ return this._.OrderStatus
161
+ }
162
+
163
+ static get StatusPhaseModel () {
164
+ return this._.OrderStatusPhase
165
+ }
166
+ ```
167
+
168
+ ### SuiteVersionMixinModel
169
+
170
+ Manages the `hasMany(SuiteModel)` "suite" by version and provides `findCurrentSuite()` /
171
+ `findAllSuites()` / `createWithSuite()`. The version basis column is `versionKey` (default
172
+ `'startedAt'`), pulling the latest version at or before that point. Override `getSuiteSorter` to
173
+ change the ordering.
174
+
175
+ ```js
176
+ // How to pass (pass SuiteModel; override versionKey to change it)
177
+ static get Mixins () {
178
+ return [
179
+ SuiteVersionMixinModel,
180
+ ]
181
+ }
182
+
183
+ static get SuiteModel () {
184
+ return this._.PriceTableRow
185
+ }
186
+
187
+ static get versionKey () {
188
+ return 'effectiveAt' // when overriding the default 'startedAt'
189
+ }
190
+ ```
191
+
192
+ ### PaginationMixinModel
193
+
194
+ Adds `findAllWithPagination({ pagination, options })` and a `&pagination` scope. It builds
195
+ `findOptions` from a `RequestPagination` and returns a `ResponsePagination` with the records. **No
196
+ abstract getter needed** (just pass it in the array).
197
+
198
+ ```js
199
+ // How to pass (just pass it; no extra getter needed)
200
+ static get Mixins () {
201
+ return [
202
+ PaginationMixinModel,
203
+ ]
204
+ }
205
+ ```
206
+
207
+ ### ReferralMixinModel
208
+
209
+ Handles a referral tree by invite code. Provides `createByInviteCode()` / `buildByInviteCode()`,
210
+ resolves the parent node from the invite code in `beforeCreate`, and `sprout`s a Fertile Forest
211
+ node in `afterCreate`. Pass `InviteCodeModel` (the invite-code table) and `ReferralNodeModel` (the
212
+ tree node).
213
+
214
+ - The tree-node model returned by `ReferralNodeModel` extends `FertileForestModel` (the exception
215
+ in [notation.md](./notation.md#extend-baseapprenchanmodel-and-default-export)).
216
+
217
+ ```js
218
+ // How to pass (pass the invite-code table and the node table)
219
+ static get Mixins () {
220
+ return [
221
+ ReferralMixinModel,
222
+ ]
223
+ }
224
+
225
+ static get InviteCodeModel () {
226
+ return this._.CustomerInviteCode
227
+ }
228
+
229
+ static get ReferralNodeModel () {
230
+ return this._.CustomerReferralNode // a node table extending FertileForestModel
231
+ }
232
+ ```
233
+
234
+ ### AttributesLinearizerMixinModel
235
+
236
+ An instance mixin that **flattens** the nested structure read via include (the nested `entity`)
237
+ into an array on each node's `dataValues`. Use it when you want to treat a record with relations
238
+ as raw values at each level. **No abstract getter needed**.
239
+
240
+ ```js
241
+ // How to pass (just pass it)
242
+ static get Mixins () {
243
+ return [
244
+ AttributesLinearizerMixinModel,
245
+ ]
246
+ }
247
+ ```
@@ -0,0 +1,225 @@
1
+ # Notation (class skeleton, imports, attribute declarations)
2
+
3
+ How to declare the model class, imports, and the attributes inside `createAttributes()`.
4
+ Referenced from `SKILL.md`. For the method ordering see [default-methods.md](./default-methods.md).
5
+
6
+ ## One model per file, filename matches class name
7
+
8
+ One class per file, placed directly under `sequelize/models/`. The filename is the
9
+ **(singular) PascalCase class name** (`CustomerOrder.js` / `OriginObjectCategory.js`).
10
+
11
+ - **Why**: the `SequelizeActivator` in `sequelize/_.js` scans `modelsPath` and registers each
12
+ model by its class name. Because filename, class name, and registered name all match, other
13
+ models can reference it as `this._.CustomerOrder` ([associations.md](./associations.md)). If the
14
+ names drift apart, association resolution grabs `undefined`.
15
+
16
+ ## Extend BaseAppRenchanModel and default-export
17
+
18
+ A model extends the shared app base **`BaseAppRenchanModel`**
19
+ (`sequelize/baseModel/BaseAppRenchanModel.js`) and is exposed with `export default class`.
20
+ `BaseAppRenchanModel` extends `RenchanModel` from `@openreachtech/renchan-sequelize` and is the
21
+ layer that adds app-specific shared implementation. The class body consists only of the six
22
+ override methods ([default-methods.md](./default-methods.md)).
23
+
24
+ - **Why**: a model must never extend Sequelize's `Model` directly, nor even `RenchanModel`
25
+ directly. When you want to add shared behavior (helpers, default options, etc.), routing every
26
+ model through `BaseAppRenchanModel` lets you extend it in **one place**. Default to the more
27
+ extensible `BaseAppRenchanModel`; when you need to add app-specific implementation on top of
28
+ `RenchanModel`, define and collect it in this `BaseAppRenchanModel`.
29
+
30
+ ```js
31
+ // Good example
32
+ import {
33
+ ModelAttributeFactory,
34
+ } from '@openreachtech/renchan-sequelize'
35
+
36
+ import BaseAppRenchanModel from '../baseModel/BaseAppRenchanModel.js'
37
+
38
+ /**
39
+ * CustomerOrder model
40
+ *
41
+ * @class CustomerOrder
42
+ * @extends {BaseAppRenchanModel}
43
+ */
44
+ export default class CustomerOrder extends BaseAppRenchanModel {
45
+ // createAttributes / createOptions / associate / defineScopes / defineSubqueries / setupHooks
46
+ }
47
+ ```
48
+
49
+ - **Exception**: only models that handle a tree (Fertile Forest) extend `FertileForestModel`
50
+ (exported as `FertileForestModel` from the package; `CustomerReferralNode` is one). This
51
+ delegates the tree's queue/depth operations to the framework. Ordinary master / transaction
52
+ tables always use `BaseAppRenchanModel`.
53
+
54
+ ## Import only the package, the app base, and domain constants
55
+
56
+ Imports are limited to the shared app base `BaseAppRenchanModel` (relative path),
57
+ `@openreachtech/renchan-sequelize` (`ModelAttributeFactory` / Mixins / etc.), and **domain
58
+ constants** that hold the values used in place of `ENUM` (`app/domain/*`).
59
+
60
+ - **Why**: a model is a declaration-only layer. Importing business logic or external I/O gives
61
+ the model side effects and breaks initialization order and tests. When you need a set of
62
+ allowed values, pull it from a domain constant instead of a DB `ENUM` (as in
63
+ [timestamps.md](./timestamps.md), "values are managed in the app layer / constants").
64
+
65
+ ## Spread the PK from the factory
66
+
67
+ Spread `...factory.ID_BIGINT` at the **top** of the object returned by `createAttributes()`. Use
68
+ `...factory.ID_INTEGER` when you need an integer PK. Never hand-write `id`.
69
+
70
+ - Build the factory with `const factory = ModelAttributeFactory.create(DataTypes)`.
71
+ - **Why**: so you never get the `bigint` / `autoIncrement` / `primaryKey` / `allowNull:false`
72
+ four-piece set wrong. The PK declaration reads as a single token across every model and lines
73
+ up with `...factory.ID_BIGINT` on the migration side
74
+ (`hor-sequelize-migration`).
75
+
76
+ ```js
77
+ // Good example
78
+ static createAttributes (DataTypes) {
79
+ const factory = ModelAttributeFactory.create(DataTypes)
80
+
81
+ return {
82
+ ...factory.ID_BIGINT,
83
+
84
+ registeredAt: {
85
+ type: DataTypes.DATE(3),
86
+ allowNull: false,
87
+ },
88
+ }
89
+ }
90
+ ```
91
+
92
+ ```js
93
+ // Bad example (hand-writing id)
94
+ return {
95
+ id: {
96
+ type: DataTypes.BIGINT,
97
+ autoIncrement: true,
98
+ primaryKey: true,
99
+ },
100
+ // ...
101
+ }
102
+ ```
103
+
104
+ ## Attribute keys are camelCase, types come from DataTypes
105
+
106
+ Attribute keys are **camelCase** (`registeredAt` / `questionsJson`). Do not write the physical
107
+ column name (snake_case) on the model side — `underscored: true` maps it automatically
108
+ ([default-methods.md](./default-methods.md#createoptions-spreads-supercreateoptions-and-adds-only-extras)).
109
+ Use the `DataTypes` in the table below.
110
+
111
+ | Type | Use |
112
+ | --- | --- |
113
+ | `BIGINT` | PK / FK-like id |
114
+ | `INTEGER` | small integer PK, quantity, version |
115
+ | `STRING(n)` | variable-length string (`191` is the default length; pick `8`/`16`/`32`/`64` by use) |
116
+ | `TEXT` | long text (body, message) |
117
+ | `DATE(3)` | millisecond-precision datetime (`registeredAt` / `savedAt`, etc.) |
118
+ | `BOOLEAN` | truth value (`isActive`, etc.) |
119
+ | `JSON` | structured data (`questionsJson` / `resultJson`) |
120
+ | `DECIMAL(p, s)` | money / rate (`dailyRate`, etc.) |
121
+ | `BLOB('long')` | binary (uploaded file body) |
122
+ | `ENUM(...)` | **avoid by default**. Use a domain constant + `STRING(n)` instead |
123
+
124
+ - Datetimes default to `DATE(3)`. Make millisecond precision the default rather than plain `DATE`
125
+ (for ordering comparisons and history uniqueness).
126
+ - Do not default string lengths to "255 for now"; choose by use (identifiers `STRING(32)`,
127
+ display names / emails and the like `STRING(191)`). Match the migration's physical column length.
128
+ - **Prefer defining the TypeScript type (interface) in `type.d.ts`** and collecting it into the
129
+ TypeScript global namespace `model`. Do not use a JSDoc `@typedef` at the bottom of the model
130
+ file. Express the DataType-to-TS-type mapping on that `type.d.ts` side.
131
+
132
+ ## Always declare allowNull, and defaultValue when a default exists
133
+
134
+ Declare **`allowNull`** on every attribute. Declare **`defaultValue`** on any column that has a
135
+ default.
136
+
137
+ - **Why**: omitting `allowNull` falls back to Sequelize's default (`true`), so the NOT NULL
138
+ intent is not conveyed to the reader and diverges from the migration (which declares
139
+ `allowNull`). Omitting `defaultValue` means the code cannot tell "what goes in when unspecified".
140
+ - Keep the declared `allowNull` / `defaultValue` in sync with the identically named column in the
141
+ migration.
142
+
143
+ ```js
144
+ // Good example
145
+ category: {
146
+ type: DataTypes.STRING(64),
147
+ allowNull: false,
148
+ defaultValue: 'default',
149
+ },
150
+ isActive: {
151
+ type: DataTypes.BOOLEAN,
152
+ allowNull: false,
153
+ defaultValue: true,
154
+ },
155
+ version: {
156
+ type: DataTypes.INTEGER,
157
+ allowNull: false,
158
+ defaultValue: 1,
159
+ },
160
+ ```
161
+
162
+ ```js
163
+ // Bad example (allowNull omitted, default unclear)
164
+ category: {
165
+ type: DataTypes.STRING(64),
166
+ },
167
+ ```
168
+
169
+ ## FK-like columns start with an uppercase letter and carry a comment
170
+
171
+ For a foreign-key-like column, make the attribute key **start with an uppercase letter**
172
+ (`CustomerOrderId` / `TenantBrandId`) and write **`// ForeignKey must start with upper case.`
173
+ immediately above it**. The type is `BIGINT`.
174
+
175
+ - **Why**: Sequelize associations ([associations.md](./associations.md)) resolve the FK name by
176
+ the convention "`<associated model name>` + `Id`". Aligning on an uppercase start lets
177
+ `belongsTo(this._.CustomerOrder)` bind `CustomerOrderId` automatically; lowerCamel
178
+ (`customerOrderId`) fails to wire the relation. The migration side follows the same convention
179
+ (uppercase key + the same comment) and maps `field:` to snake (`customer_order_id`).
180
+ - Do not drop the leading comment either, so the column reads as an FK at a glance.
181
+
182
+ ```js
183
+ // Good example
184
+ // ForeignKey must start with upper case.
185
+ CustomerOrderId: {
186
+ type: DataTypes.BIGINT,
187
+ allowNull: false,
188
+ },
189
+ // A nullable FK (optional relation) also declares allowNull explicitly.
190
+ // ForeignKey must start with upper case.
191
+ TenantBrandId: {
192
+ type: DataTypes.BIGINT,
193
+ allowNull: true,
194
+ },
195
+ ```
196
+
197
+ ```js
198
+ // Bad example (lowerCamel, no comment; the association cannot resolve the FK)
199
+ customerOrderId: {
200
+ type: DataTypes.BIGINT,
201
+ allowNull: false,
202
+ },
203
+ ```
204
+
205
+ ## Unique constraints are enforced by the migration's named index
206
+
207
+ For a column that is unique (a 1:1 relation FK, a natural key), you **may** add `unique: true`
208
+ to the model attribute to **state intent**. The **actual constraint, however, is enforced by the
209
+ migration's named unique index**
210
+ (`hor-sequelize-migration`).
211
+
212
+ - **Why**: the schema is built by migrations, not by `sync`. `unique: true` on the
213
+ model alone does not create a constraint (it has no effect on the DB). The model side is a
214
+ reader-facing declaration that "this column is meant to be unique"; the DB constraint is the
215
+ migration's job. When you write it on both sides, keep them consistent.
216
+
217
+ ```js
218
+ // Good example (1:1 relation FK; the real constraint is the migration's unique index)
219
+ // ForeignKey must start with upper case.
220
+ CustomerOrderId: {
221
+ type: DataTypes.BIGINT,
222
+ allowNull: false,
223
+ unique: true,
224
+ },
225
+ ```
@@ -0,0 +1,74 @@
1
+ # Timestamps (do not include created_at / updated_at in the model)
2
+
3
+ Conventions for how to treat `created_at` / `updated_at` (and `deleted_at`) in the model
4
+ declaration. Referenced from `SKILL.md`. For the migration side, see
5
+ `hor-sequelize-migration`.
6
+
7
+ ## Do not write timestamp columns in attributes
8
+
9
+ Do **not** put `createdAt` / `updatedAt` / `deletedAt` in the return value of
10
+ `createAttributes()`. Leave column creation to the migration (`...factory.TIMESTAMPS`) and value
11
+ management to `timestamps: true`
12
+ ([default-methods.md](./default-methods.md#createoptions-spreads-supercreateoptions-and-adds-only-extras)).
13
+
14
+ - **Why**: these are operational columns **the application does not use** (for auditing / the
15
+ framework). Putting them in attributes makes them look like values you read and write in
16
+ business logic, and double-manages the assumptions of `practicalAttributeNames` (the list of
17
+ real attributes the base `RenchanModel` returns with `createdAt` / `updatedAt` / `deletedAt`
18
+ excluded) and `BackupMixinModel` (which excludes those same three columns when cloning).
19
+ Centralize column definition in the migration and value supply in the framework, and keep the
20
+ model's attributes to **business attributes only**.
21
+ - `timestamps: true` is already returned by the base `createOptions()`. Do not touch `timestamps`
22
+ on the model side ([default-methods.md](./default-methods.md)).
23
+
24
+ ```js
25
+ // Good example (business attributes only; do not write timestamps)
26
+ static createAttributes (DataTypes) {
27
+ const factory = ModelAttributeFactory.create(DataTypes)
28
+
29
+ return {
30
+ ...factory.ID_BIGINT,
31
+
32
+ registeredAt: {
33
+ type: DataTypes.DATE(3),
34
+ allowNull: false,
35
+ },
36
+ }
37
+ }
38
+ ```
39
+
40
+ ```js
41
+ // Bad example (createdAt / updatedAt placed in attributes)
42
+ return {
43
+ ...factory.ID_BIGINT,
44
+
45
+ registeredAt: {
46
+ type: DataTypes.DATE(3),
47
+ allowNull: false,
48
+ },
49
+ createdAt: {
50
+ type: DataTypes.DATE(3),
51
+ allowNull: false,
52
+ },
53
+ updatedAt: {
54
+ type: DataTypes.DATE(3),
55
+ allowNull: false,
56
+ },
57
+ }
58
+ ```
59
+
60
+ ## If you need a business "saved-at" time, use a dedicated datetime column
61
+
62
+ When you want to treat "when it was saved" as part of the business, do not repurpose `createdAt`;
63
+ define a dedicated column with a clear meaning (`savedAt` / `postedAt` / `registeredAt` /
64
+ `modifiedAt` / `generatedAt` / `effectiveAt`, etc., `DATE(3)`) in the attributes.
65
+
66
+ - **Why**: `createdAt` is the framework's audit column and makes no guarantee about when it
67
+ changes operationally (backfill during migration, etc.). Split any datetime that business logic
68
+ may depend on into a dedicated column whose intent shows in its name. The `savedAt` / `startedAt`
69
+ that `BackupMixinModel` / `LatestStatusMixinModel` / `SuiteVersionMixinModel`
70
+ ([mixins.md](./mixins.md)) use for ordering are also such dedicated datetime columns.
71
+ - Every name above ends with `At` because it carries a **time of day**; an attribute whose meaning
72
+ stops at the **calendar date** ends with `On` instead (`billedOn`). A range is two attributes
73
+ keeping the suffix (`modifiedAtFrom` / `modifiedAtTo`) — `From` / `To` mark the ends of a range,
74
+ so a single instant that means "in effect from this moment" is `effectiveAt`, not `effectiveFrom`.