@openreachtech/hora-skills-ort-renchan 0.3.0 → 0.4.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 (50) hide show
  1. package/dist/skills/hor-backend-testing/SKILL.md +4 -3
  2. package/dist/skills/hor-backend-testing/references/running-tests.md +9 -1
  3. package/dist/skills/hor-build-e2e-test-environment/SKILL.md +17 -8
  4. package/dist/skills/hor-build-e2e-test-environment/references/compose-definition.md +11 -7
  5. package/dist/skills/hor-build-e2e-test-environment/references/runner-and-lifecycle.md +1 -1
  6. package/dist/skills/hor-cookie-authentication/SKILL.md +4 -2
  7. package/dist/skills/hor-cookie-authentication/references/environment.md +4 -2
  8. package/dist/skills/hor-database-design/references/column-types.md +25 -9
  9. package/dist/skills/hor-database-design/references/datetimes.md +7 -3
  10. package/dist/skills/hor-graphql-schema/SKILL.md +10 -8
  11. package/dist/skills/hor-graphql-server-engine/SKILL.md +376 -44
  12. package/dist/skills/hor-light-rag/SKILL.md +6 -1
  13. package/dist/skills/hor-light-rag/references/retrieval-internals.md +3 -1
  14. package/dist/skills/hor-multi-llm-provider/SKILL.md +158 -20
  15. package/dist/skills/hor-multi-llm-provider/references/access-routes.md +230 -0
  16. package/dist/skills/hor-multi-llm-provider/references/provider-internals.md +9 -3
  17. package/dist/skills/hor-mutation-resolver/SKILL.md +6 -2
  18. package/dist/skills/hor-mutation-resolver/references/resolve-flow.md +10 -6
  19. package/dist/skills/hor-oidc-sign-in/SKILL.md +61 -0
  20. package/dist/skills/hor-oidc-sign-in/references/environment.md +94 -0
  21. package/dist/skills/hor-oidc-sign-in/references/id-token-verification.md +98 -0
  22. package/dist/skills/hor-oidc-sign-in/references/resolvers.md +134 -0
  23. package/dist/skills/hor-oidc-sign-in/references/storage.md +118 -0
  24. package/dist/skills/hor-query-resolver/SKILL.md +2 -0
  25. package/dist/skills/hor-query-resolver/references/anatomy.md +7 -7
  26. package/dist/skills/hor-query-resolver/references/data-access.md +17 -0
  27. package/dist/skills/hor-renchan-job-bullmq/SKILL.md +15 -6
  28. package/dist/skills/hor-renchan-job-bullmq/references/daemon-and-scheduler.md +4 -2
  29. package/dist/skills/hor-renchan-job-bullmq/references/engine-and-infra.md +39 -5
  30. package/dist/skills/hor-renchan-job-bullmq/references/job-triple.md +57 -0
  31. package/dist/skills/hor-resolver-validator/SKILL.md +5 -6
  32. package/dist/skills/hor-resolver-validator/references/validator-pattern.md +5 -5
  33. package/dist/skills/hor-restfulapi-architecture/SKILL.md +33 -7
  34. package/dist/skills/hor-restfulapi-architecture/references/behind-iap.md +116 -0
  35. package/dist/skills/hor-restfulapi-architecture/references/credential-routes.md +173 -0
  36. package/dist/skills/hor-restfulapi-architecture/references/engine-and-context.md +11 -5
  37. package/dist/skills/hor-restfulapi-architecture/references/renderers.md +4 -0
  38. package/dist/skills/hor-sequelize-migration/SKILL.md +30 -15
  39. package/dist/skills/hor-sequelize-migration/references/alter-table.md +26 -13
  40. package/dist/skills/hor-sequelize-migration/references/foreign-keys.md +5 -2
  41. package/dist/skills/hor-sequelize-migration/references/indexes.md +41 -2
  42. package/dist/skills/hor-sequelize-migration/references/notation.md +1 -1
  43. package/dist/skills/hor-sequelize-model/references/associations.md +2 -1
  44. package/dist/skills/hor-sequelize-model/references/notation.md +1 -1
  45. package/dist/skills/hor-sequelize-seeder/SKILL.md +9 -4
  46. package/dist/skills/hor-sequelize-seeder/references/notation.md +59 -0
  47. package/dist/skills/hor-type-interface/SKILL.md +48 -32
  48. package/docs/skills.ja.md +5 -4
  49. package/docs/skills.md +5 -4
  50. package/package.json +1 -1
@@ -15,9 +15,11 @@ A skill for writing the `sequelize/migrations/*.cjs` files. It defines the **phy
15
15
  when you add a column in the migration, add the matching attribute in the model (and vice versa).
16
16
  The conventions are split across the detail files below.
17
17
 
18
- This repo does **not** `sync`. The schema is **built entirely by migrations** (dev = SQLite /
19
- staging = MySQL / live = MariaDB — the dialects differ). A model's `unique: true` and the like are
20
- only declarations; **the real object is always created by the migration**.
18
+ This repo does **not** `sync`. The schema is **built entirely by migrations**. The databases these
19
+ skills assume are dev = SQLite / staging = MySQL / live = MariaDB, and the dialects differ; a
20
+ PostgreSQL project substitutes its own databases, and each rule below names PostgreSQL where it
21
+ differs. A model's `unique: true` and the like are only declarations; **the real object is always
22
+ created by the migration**.
21
23
 
22
24
  ## Grand principle: a migration is a filled-in template
23
25
 
@@ -132,8 +134,8 @@ module.exports = {
132
134
  - **Each column** is declared with a camelCase key + `field: COLUMN_NAME.X` (the snake physical
133
135
  name). **Always** declare `allowNull`, and add `defaultValue` when the column has a default. The
134
136
  type is `Sequelize.X` (`BIGINT` / `INTEGER` / `STRING(n)` / `TEXT` (long items: `TEXT('medium')`) /
135
- `DATE(3)` / `BOOLEAN` / `JSON` / `DECIMAL(p,s)` / `BLOB('long')`). Avoid `ENUM`; use a domain
136
- constant + `STRING(n)`.
137
+ `DATE(3)` / `BOOLEAN` / `JSON` (`JSONB` on PostgreSQL) / `DECIMAL(p,s)` / `BLOB('long')`). Avoid
138
+ `ENUM`; use a domain constant + `STRING(n)`.
137
139
  Datetimes default to `DATE(3)`. Keep `allowNull` / `defaultValue` in sync with the same-named
138
140
  column on the model side.
139
141
 
@@ -210,7 +212,8 @@ migrations).
210
212
 
211
213
  - **Why**: dev = SQLite / staging = MySQL / live = MariaDB differ, and there is no `sync`. A DB FK
212
214
  constraint pins insert order and makes cloning into backup (`*_bk`) tables and handling circular
213
- references awkward. Referential integrity is enforced in the **app layer** (associations,
215
+ references awkward. Those costs come from the constraint, not from a dialect, so the rule holds on
216
+ PostgreSQL unchanged. Referential integrity is enforced in the **app layer** (associations,
214
217
  transactions, existence checks). See [foreign-keys.md](./references/foreign-keys.md); for the
215
218
  column notation see [notation.md](./references/notation.md).
216
219
 
@@ -246,9 +249,10 @@ await Promise.all([
246
249
 
247
250
  ### Shortening a long index name (over ~50 chars)
248
251
 
249
- The DB identifier limit is 64 characters. As a safety margin, shorten once a name would run past
250
- **~50 characters**. Shorten in the **following priority order**, taking the **initial of each
251
- word**:
252
+ The identifier limit is 64 characters on MariaDB and MySQL and 63 bytes on PostgreSQL (SQLite sets
253
+ none). As a safety margin, shorten once a name would run past **~50 characters**; the names are
254
+ ASCII snake_case, so a byte is a character. Shorten in the **following priority order**, taking the
255
+ **initial of each word**:
252
256
 
253
257
  1. **First shorten the column name(s)** (`SHORT_COLUMN_NAME`), keeping the table name in full.
254
258
  e.g. `content_generations` + `cgji` (= content_generation_job_id) + `unique`
@@ -257,6 +261,12 @@ word**:
257
261
  e.g. `cgrf` (= content_generation_requirement_files) + `cgji` + `index`
258
262
  → `cgrf_cgji_index`
259
263
 
264
+ Index names are unique per table on MariaDB and MySQL, but per schema on PostgreSQL and per
265
+ database on SQLite, so the same name on two tables is an error there. PostgreSQL also truncates a
266
+ name past 63 bytes instead of rejecting it, so two long names that differ only at the end collide.
267
+ Keep the `<table>_` part (or a `SHORT_TABLE_NAME` unique across the schema). See
268
+ [indexes.md](./references/indexes.md).
269
+
260
270
  Initialism examples: `content_generation_job_id`→`cgji`, `chat_room_id`→`cri`,
261
271
  `customer_id`→`ci`, `content_generation_requirement_files`→`cgrf`, `content_plan_rates`→`err`.
262
272
  Put the abbreviations in `SHORT_COLUMN_NAME` / `SHORT_TABLE_NAME` constants and reference them from
@@ -268,9 +278,13 @@ the `addIndex` `name`. Details and a table of real abbreviations are in
268
278
  Add a column to an existing table with `addColumn`, and drop the same column symmetrically in
269
279
  `down`. The filename is `{timestamp}-{seq}-alter_table-<table>-<column>.cjs`.
270
280
 
271
- - **Do not use `removeColumn` to drop a column.** Sequelize's `removeColumn` does not work on
272
- MariaDB (live), so run raw SQL `ALTER TABLE ... DROP COLUMN` via `queryInterface.sequelize.query`
273
- (in `up` or `down`; quote identifiers with backticks).
281
+ - **On MariaDB, do not use `removeColumn` to drop a column.** Sequelize's `removeColumn` does not
282
+ work on MariaDB, so when MariaDB is the live database run raw SQL `ALTER TABLE ... DROP COLUMN`
283
+ via `queryInterface.sequelize.query` (in `up` or `down`). Quote each identifier with
284
+ `queryInterface.quoteIdentifier()`, which writes backticks on MariaDB, MySQL and SQLite and
285
+ double quotes on PostgreSQL; a hand-written backtick is a syntax error on PostgreSQL.
286
+ - **On PostgreSQL (and SQLite), `queryInterface.removeColumn` works.** A project whose databases
287
+ are only those two drops a column with `removeColumn` and writes no raw SQL.
274
288
  - `up` / `down` are **symmetric** (drop in `down` what `up` added). Column adds can be grouped with
275
289
  `Promise.all`, but drops are run as one raw statement per column, sequentially.
276
290
  - Put a `/* ... */` block at the top of the file describing the **intent** (ticket number, spec
@@ -305,8 +319,8 @@ module.exports = {
305
319
  ) {
306
320
  // removeColumn does not work on MariaDB, so drop via raw SQL DROP COLUMN.
307
321
  await queryInterface.sequelize.query(`
308
- ALTER TABLE \`${TABLE_NAME}\`
309
- DROP COLUMN \`${COLUMN_NAME}\`
322
+ ALTER TABLE ${queryInterface.quoteIdentifier(TABLE_NAME)}
323
+ DROP COLUMN ${queryInterface.quoteIdentifier(COLUMN_NAME)}
310
324
  `)
311
325
  },
312
326
  }
@@ -333,4 +347,5 @@ scripts:
333
347
  - [indexes.md](./references/indexes.md) — index naming, UNIQUE, `Promise.all`, composite indexes,
334
348
  the shortening algorithm for long names with a table of real examples (§4)
335
349
  - [alter-table.md](./references/alter-table.md) — `addColumn`, dropping a column with raw
336
- `DROP COLUMN` (because `removeColumn` fails on MariaDB), symmetric up/down, intent comment (§5)
350
+ `DROP COLUMN` on MariaDB (because `removeColumn` fails there) and with `removeColumn` on
351
+ PostgreSQL, identifier quoting, symmetric up/down, intent comment (§5)
@@ -4,15 +4,21 @@ How to write migrations that add or remove columns on an existing table. Referen
4
4
  `SKILL.md`. The column type / `field` / `allowNull` notation is shared with
5
5
  [notation.md](./notation.md).
6
6
 
7
- ## Add with addColumn, drop with raw SQL DROP COLUMN (symmetric up/down)
7
+ ## Add with addColumn, drop with raw SQL DROP COLUMN on MariaDB (symmetric up/down)
8
8
 
9
9
  `addColumn` in `up`, and drop the same column in `down` to keep them symmetric. The filename is
10
10
  `{timestamp}-{seq}-alter_table-<table>-<column>.cjs`.
11
11
 
12
- **Do not use `removeColumn` to drop a column.** Sequelize's `removeColumn` does not work correctly
13
- on MariaDB (live), so drop a column — in `up` or `down` — with raw SQL
14
- `ALTER TABLE ... DROP COLUMN` via `queryInterface.sequelize.query`. Quote identifiers with backticks
15
- (valid on both SQLite and MariaDB).
12
+ **On MariaDB, do not use `removeColumn` to drop a column.** Sequelize's `removeColumn` does not work
13
+ correctly on MariaDB, so when MariaDB is the live database, drop a column (in `up` or `down`) with
14
+ raw SQL `ALTER TABLE ... DROP COLUMN` via `queryInterface.sequelize.query`. Quote every identifier
15
+ with `queryInterface.quoteIdentifier()`, never with a hand-written backtick (see
16
+ [Quoting identifiers](#quoting-identifiers-in-raw-sql)).
17
+
18
+ **On PostgreSQL (and SQLite), `queryInterface.removeColumn` works.** A project whose databases are
19
+ only those two drops a column with `removeColumn(TABLE_NAME, COLUMN_NAME)` in `up` or `down` and
20
+ writes no raw SQL. The raw form below stays the one to write whenever MariaDB is among the
21
+ databases, because it runs unchanged on all of them.
16
22
 
17
23
  ```js
18
24
  'use strict'
@@ -43,8 +49,8 @@ module.exports = {
43
49
  ) {
44
50
  // removeColumn does not work on MariaDB, so drop via raw SQL DROP COLUMN.
45
51
  await queryInterface.sequelize.query(`
46
- ALTER TABLE \`${TABLE_NAME}\`
47
- DROP COLUMN \`${COLUMN_NAME}\`
52
+ ALTER TABLE ${queryInterface.quoteIdentifier(TABLE_NAME)}
53
+ DROP COLUMN ${queryInterface.quoteIdentifier(COLUMN_NAME)}
48
54
  `)
49
55
  },
50
56
  }
@@ -57,6 +63,13 @@ module.exports = {
57
63
  dialect-independent, run `ALTER TABLE ... DROP COLUMN` directly. The add side (`addColumn`) is
58
64
  fine, so keep using it.
59
65
 
66
+ ### Quoting identifiers in raw SQL
67
+
68
+ `queryInterface.quoteIdentifier(name)` returns the name quoted the way the connected dialect
69
+ expects: backticks on MariaDB, MySQL and SQLite, double quotes on PostgreSQL. A hand-written
70
+ backtick runs on the first three and is a syntax error on PostgreSQL, so a migration that has a
71
+ backtick in it cannot be moved to PostgreSQL without being rewritten.
72
+
60
73
  ## Write an intent comment (`/* ... */`) at the top
61
74
 
62
75
  A column-adding migration is really about "why is this column being added", so put a `/* ... */`
@@ -111,16 +124,16 @@ module.exports = {
111
124
  ) {
112
125
  // removeColumn does not work on MariaDB, so drop per column with raw SQL DROP COLUMN.
113
126
  await queryInterface.sequelize.query(`
114
- ALTER TABLE \`${TABLE_NAME}\`
115
- DROP COLUMN \`${COLUMN_NAME.WIZARD_ANSWERS_JSON}\`
127
+ ALTER TABLE ${queryInterface.quoteIdentifier(TABLE_NAME)}
128
+ DROP COLUMN ${queryInterface.quoteIdentifier(COLUMN_NAME.WIZARD_ANSWERS_JSON)}
116
129
  `)
117
130
  await queryInterface.sequelize.query(`
118
- ALTER TABLE \`${TABLE_NAME}\`
119
- DROP COLUMN \`${COLUMN_NAME.WIZARD_TEMPLATE_ID}\`
131
+ ALTER TABLE ${queryInterface.quoteIdentifier(TABLE_NAME)}
132
+ DROP COLUMN ${queryInterface.quoteIdentifier(COLUMN_NAME.WIZARD_TEMPLATE_ID)}
120
133
  `)
121
134
  await queryInterface.sequelize.query(`
122
- ALTER TABLE \`${TABLE_NAME}\`
123
- DROP COLUMN \`${COLUMN_NAME.WIZARD_TEMPLATE_VERSION}\`
135
+ ALTER TABLE ${queryInterface.quoteIdentifier(TABLE_NAME)}
136
+ DROP COLUMN ${queryInterface.quoteIdentifier(COLUMN_NAME.WIZARD_TEMPLATE_VERSION)}
124
137
  `)
125
138
 
126
139
  return Promise.resolve()
@@ -42,6 +42,9 @@ CustomerId: {
42
42
  DB FK constraint (1) pins insert / delete order, (2) makes cloning into backup (`*_bk`) tables
43
43
  hard, and (3) cannot express circular references. Referential integrity is enforced in the **app
44
44
  layer** (model associations and domain logic).
45
+ - **PostgreSQL gets the same rule.** The three costs belong to the constraint itself, and PostgreSQL
46
+ enforces a constraint as strictly as MariaDB and MySQL do, so a project on PostgreSQL writes no
47
+ `references` either.
45
48
 
46
49
  ## Create the FK *column*; express the relation on the model side
47
50
 
@@ -88,8 +91,8 @@ ContentGenerationJobId: {
88
91
  ## A set of ids you don't want as FKs → a JSON array
89
92
 
90
93
  When you want to hold a set of ids but not enough to warrant individual FK columns or a join table,
91
- hold them in a `JSON`-typed array column. Same idea as having no FK constraint: check referential
92
- integrity in the app layer.
94
+ hold them in a `JSON`-typed array column (`JSONB` on PostgreSQL). Same idea as having no FK
95
+ constraint: check referential integrity in the app layer.
93
96
 
94
97
  ```js
95
98
  // An array of ids without an FK.
@@ -70,8 +70,10 @@ name: [SHORT_TABLE_NAME, 'job_package', 'unique'].join('_')
70
70
 
71
71
  ## Shortening a long index name (over ~50 chars)
72
72
 
73
- The DB identifier limit is 64 characters. As a **safety margin, shorten once a name would run past
74
- ~50 characters**. Shorten in stages, in the **following priority order**.
73
+ The identifier limit is 64 characters on MariaDB and MySQL and 63 bytes on PostgreSQL, so write
74
+ for the stricter 63. SQLite sets none. As a **safety margin, shorten once a name would run past
75
+ ~50 characters**. Index names are ASCII snake_case, so a byte is a character. Shorten in stages, in
76
+ the **following priority order**.
75
77
 
76
78
  ### Priority 1: shorten the column name(s) first (keep the table name in full)
77
79
 
@@ -134,12 +136,49 @@ character** of each word.
134
136
  from the `addIndex` `name` (do not inline). If abbreviations collide within a table, add a second
135
137
  letter (etc.) to keep them unique while staying meaningful.
136
138
 
139
+ ### What the database does with a name that is too long or taken
140
+
141
+ | Database | Over-long name | Same name on two tables |
142
+ | --- | --- | --- |
143
+ | MariaDB / MySQL | error past 64 characters | allowed, names are unique per table |
144
+ | PostgreSQL | cut to 63 bytes with a NOTICE, no error | error `relation ... already exists`, names are unique per schema |
145
+ | SQLite | no limit | error, names are unique per database |
146
+
147
+ - **PostgreSQL's silent cut is the trap.** Two names that differ only after byte 63 become the same
148
+ name, and the second `addIndex` fails with `already exists` although both names looked distinct in
149
+ the file. Shortening to ~50 characters keeps that from happening.
150
+ - **The `<table>_` part is what keeps names unique across tables** on PostgreSQL and SQLite. Keep
151
+ it in full (Priority 1 above), and when `SHORT_TABLE_NAME` is needed, check that the abbreviation
152
+ is unique across the whole schema, not only within the file. If abbreviations collide, add a
153
+ second letter.
154
+
137
155
  ### Shorten only when needed
138
156
 
139
157
  If it fits within ~50 characters, do not shorten. `.join('_')` the full `TABLE_NAME` / `COLUMN_NAME`
140
158
  as in `customers_registered_at_index`. **Do not mechanically initialize just because you can** (it
141
159
  hurts readability).
142
160
 
161
+ ## A UNIQUE index compares with the column's collation
162
+
163
+ A UNIQUE index rejects what the column's collation calls equal. On MariaDB and MySQL with a `_ci`
164
+ collation, `Taro` and `taro` are duplicates, and the second insert fails. PostgreSQL compares
165
+ case-sensitively by default, so both rows fit and a case-insensitive natural key (an email, a login
166
+ name) is not enforced. On PostgreSQL, normalize the value to lower case before it is saved, or
167
+ index `lower(<column>)`, instead of relying on the collation. `addIndex` may not accept an
168
+ expression, so write the index as raw SQL, guarded for PostgreSQL:
169
+
170
+ ```js
171
+ const INDEX_NAME = 'customers_email_lower_unique'
172
+
173
+ if (queryInterface.sequelize.getDialect() === 'postgres') {
174
+ await queryInterface.sequelize.query(
175
+ `CREATE UNIQUE INDEX ${INDEX_NAME} ON ${queryInterface.quoteIdentifier(TABLE_NAME)} (lower(email))`
176
+ )
177
+ }
178
+ ```
179
+
180
+ `down` runs `DROP INDEX IF EXISTS ${INDEX_NAME}` under the same guard.
181
+
143
182
  ## A UNIQUE named index is "the real constraint"
144
183
 
145
184
  The uniqueness of a 1:1 relation's FK or a natural key is **actually enforced by this UNIQUE named
@@ -177,7 +177,7 @@ role: {
177
177
  | `TEXT` / `TEXT('medium')` | long text (body, message, error). For an item that can grow long, use `TEXT('medium')` |
178
178
  | `DATE(3)` | millisecond-precision datetime (`registeredAt` / `expiresAt`, etc.) |
179
179
  | `BOOLEAN` | truth value (`isActive`, etc.) |
180
- | `JSON` | structured data (`resultJson`; an FK-less id array `optionIdsJson`) |
180
+ | `JSON` | structured data (`resultJson`; an FK-less id array `optionIdsJson`). On PostgreSQL use `JSONB`, because `json` has no equality operator |
181
181
  | `DECIMAL(p, s)` | money / rate (`dailyRate` as `DECIMAL(14, 2)`, etc.) |
182
182
  | `BLOB('long')` | binary (uploaded file body) |
183
183
  | `ENUM(...)` | **avoid by default**; use a domain constant + `STRING(n)` |
@@ -214,5 +214,6 @@ Express relations with Sequelize associations **only**. Do not add DB foreign-ke
214
214
  (`hor-sequelize-migration`).
215
215
 
216
216
  - **Why**: referential integrity is enforced in the app layer (transactions, existence checks).
217
- Not adding constraints keeps migration ordering, record deletion, and sqlite tests simple. A
217
+ Not adding constraints keeps migration ordering, record deletion, and sqlite tests simple. The
218
+ rule is the same on MariaDB, MySQL and PostgreSQL; sqlite is only the test database. A
218
219
  model's `belongsTo` etc. are **declarations for JOIN and include**, independent of DB constraints.
@@ -116,7 +116,7 @@ Use the `DataTypes` in the table below.
116
116
  | `TEXT` | long text (body, message) |
117
117
  | `DATE(3)` | millisecond-precision datetime (`registeredAt` / `savedAt`, etc.) |
118
118
  | `BOOLEAN` | truth value (`isActive`, etc.) |
119
- | `JSON` | structured data (`questionsJson` / `resultJson`) |
119
+ | `JSON` | structured data (`questionsJson` / `resultJson`). On PostgreSQL use `DataTypes.JSONB`, matching the migration |
120
120
  | `DECIMAL(p, s)` | money / rate (`dailyRate`, etc.) |
121
121
  | `BLOB('long')` | binary (uploaded file body) |
122
122
  | `ENUM(...)` | **avoid by default**. Use a domain constant + `STRING(n)` instead |
@@ -122,12 +122,17 @@ example — are in [directory-structure.md](./references/directory-structure.md)
122
122
  always sees its parent row, and deletes don't orphan. (There are no DB FK constraints —
123
123
  `hor-sequelize-migration` — but ordering still keeps the data
124
124
  coherent and mirrors real usage.)
125
+ - **On PostgreSQL, advance the id sequence after `bulkInsert`.** Explicit ids do not move a
126
+ PostgreSQL sequence (MariaDB, MySQL and SQLite do move their counter), so run
127
+ `setval(pg_get_serial_sequence(<table>, 'id'), MAX(id))` right after the insert, guarded by
128
+ `getDialect() === 'postgres'`.
125
129
  - **Async fulfillment**: when a value must be computed (e.g. hashing a password via `Encipher`),
126
130
  build the fulfilled array with `await Promise.all(seeds.map(fulfillX))` inside `up` before
127
131
  `bulkInsert`; keep the plain `seeds` array for `down`'s id list.
128
132
 
129
- The full skeleton, the suite example (parent → child insert / child → parent delete), and the
130
- async-fulfillment example (e.g. password hashing) are in [notation.md](./references/notation.md).
133
+ The full skeleton, the suite example (parent → child insert / child → parent delete), the
134
+ `setval` step for PostgreSQL, and the async-fulfillment example (e.g. password hashing) are in
135
+ [notation.md](./references/notation.md).
131
136
 
132
137
  ## 3. Naming
133
138
 
@@ -264,8 +269,8 @@ the matching script directly (`npm run db:seed:dev-master`, `db:seed:dev`, or `d
264
269
  / development, `.directorykeeper`, the `db:seed:*` scripts and `db:refresh` flow, the re-export
265
270
  DRY pattern (§1)
266
271
  - [notation.md](./references/notation.md) — file skeleton, `TimestampSeedsSupplier`, `TABLE_NAME`
267
- string vs object, `seeds` arrays, `bulkInsert` / `bulkDelete`, suites and insert/delete order,
268
- async fulfillment, timestamps (§2, §5)
272
+ string vs object, `seeds` arrays, `bulkInsert` / `bulkDelete`, the PostgreSQL `setval` step,
273
+ suites and insert/delete order, async fulfillment, timestamps (§2, §5)
269
274
  - [naming.md](./references/naming.md) — `{timestamp}-{6-digit-seq}-{table_name}.cjs`, timestamp /
270
275
  creation-order ordering, `_suite`, release-dir naming (§3)
271
276
  - [id-numbering.md](./references/id-numbering.md) — the 10,000-wide id-block rule, the block tables,
@@ -91,6 +91,65 @@ module.exports = {
91
91
  - `down` deletes exactly the rows `up` inserted, by their explicit id list
92
92
  (`{ id: seeds.map(it => it.id) }`). This is why every row needs a stable, explicit `id`.
93
93
 
94
+ ## PostgreSQL: advance the id sequence after seeding explicit ids
95
+
96
+ MariaDB, MySQL and SQLite move an `AUTO_INCREMENT` counter past an explicit id on insert.
97
+ **PostgreSQL does not**: the sequence behind a `BIGSERIAL` id stays at its start, because
98
+ `bulkInsert` with explicit ids never calls `nextval()`. The first row the app creates then asks the
99
+ sequence for `1`, which seeded row `1` already holds, and the insert fails with
100
+ `duplicate key value violates unique constraint "<table>_pkey"`. Master ids `1`...`7` collide at
101
+ once; a `100001` block collides after 100,000 inserts. Advance the sequence for every seeded table.
102
+
103
+ ```js
104
+ module.exports = {
105
+ up: async (queryInterface, Sequelize) => {
106
+ await queryInterface.bulkInsert(TABLE_NAME, TimestampSeedsSupplier.supplyAll(seeds), {})
107
+
108
+ if (queryInterface.sequelize.getDialect() === 'postgres') {
109
+ await queryInterface.sequelize.query(`
110
+ SELECT setval(
111
+ pg_get_serial_sequence('${queryInterface.quoteIdentifier(TABLE_NAME)}', 'id'),
112
+ (SELECT MAX(id) FROM ${queryInterface.quoteIdentifier(TABLE_NAME)})
113
+ )
114
+ `)
115
+ }
116
+ },
117
+
118
+ down: async (queryInterface, Sequelize) => {
119
+ await queryInterface.bulkDelete(TABLE_NAME, { id: seeds.map(it => it.id) })
120
+ },
121
+ }
122
+ ```
123
+
124
+ - **`MAX(id)` of the whole table, not of `seeds`**, so a table that already holds a larger id is not
125
+ moved backwards. The next generated id is `MAX(id) + 1`.
126
+ - **The sequence name is passed as quoted identifier text** (`'"Table"'`), so a mixed-case table name
127
+ resolves the same way as it does in the `MAX(id)` subquery.
128
+ - **A suite repeats the statement once per table**, right after that table's `bulkInsert`. Its
129
+ `TABLE_NAME` is an object of table names, so each table passes its own entry:
130
+
131
+ ```js
132
+ const TABLE_NAME = {
133
+ customer: 'Customers',
134
+ order: 'Orders',
135
+ }
136
+
137
+ const tableNames = Object.values(TABLE_NAME)
138
+
139
+ await Promise.all(
140
+ tableNames.map(tableName =>
141
+ queryInterface.sequelize.query(`
142
+ SELECT setval(
143
+ pg_get_serial_sequence('${queryInterface.quoteIdentifier(tableName)}', 'id'),
144
+ (SELECT MAX(id) FROM ${queryInterface.quoteIdentifier(tableName)})
145
+ )
146
+ `)),
147
+ )
148
+ ```
149
+ - **`down` does nothing to the sequence.** Deleted ids are simply skipped; no id is reused.
150
+ - **The guard keeps one file valid on every database.** A project that runs only on PostgreSQL may
151
+ drop the `if`; the dialects without sequences must not run the statement.
152
+
94
153
  ## Suites: insert parent → child, delete child → parent
95
154
 
96
155
  When a file fills several related tables, insert **parent before child** in `up` (a child's FK
@@ -3,19 +3,19 @@ name: hor-type-interface
3
3
  description: >
4
4
  Define TypeScript type interfaces in .d.ts declaration files: model interfaces (one file per
5
5
  model/table under types/models/, in the global `model` namespace) and resolver input/output
6
- types (one file per resolver under types/resolvers/<category>/, in the global
7
- `graphql.<category>` namespace, as <Resolver>Input and <Resolver>Result). Use this skill
8
- whenever the user asks to add or change a model interface, a resolver's Input/Result types, or
9
- another shared global type.
6
+ types (all in types/graphql.d.ts, in the global `graphql.<category>` namespace, as
7
+ <Resolver>Input and <Resolver>Result). Use this skill whenever the user asks to add or change a
8
+ model interface, a resolver's Input/Result types, or another shared global type.
10
9
  ---
11
10
 
12
11
  # Type Interface Definition
13
12
 
14
13
  A skill for the **`.d.ts` type declarations** that describe an app's data shapes: the **model
15
- interfaces** (one per table) and the **resolver input/output types** (one per resolver). Both are
16
- declared as **ambient global namespaces**, so any JSDoc can reference them (`model.User`,
17
- `graphql.user.CreateOrderInput`) without an import. The core rule is **one file per entity** — one
18
- model, one resolver — merged into a single namespace by TypeScript's declaration merging.
14
+ interfaces** (one per table) and the **resolver input/output types** (a pair per resolver). Both
15
+ are declared as **ambient global namespaces**, so any JSDoc can reference them (`model.User`,
16
+ `graphql.user.CreateOrderInput`) without an import. Each model gets **its own file**, merged into
17
+ one namespace by TypeScript's declaration merging, and every resolver type lives in the one file
18
+ `types/graphql.d.ts`.
19
19
 
20
20
  > This skill states a **general, project-independent rule** — a refined best practice, not a
21
21
  > description of any one project's code, so it need not match a given repo's existing notation. The
@@ -24,16 +24,20 @@ model, one resolver — merged into a single namespace by TypeScript's declarati
24
24
  > project's own model and resolver names and never bake its domain concepts or file paths into the
25
25
  > rule.
26
26
 
27
- ## Grand principle: one file per entity, merged into one global namespace
27
+ ## Grand principle: one file per model, one file for resolver types, all in global namespaces
28
28
 
29
- Every model and every resolver gets its **own `.d.ts` file**, each declaring types into a **shared
30
- global namespace**. TypeScript's **declaration merging** combines the same-named `namespace` blocks
31
- from every file into one, so the split costs nothing at the access site.
29
+ Every model gets its **own `.d.ts` file**, and every resolver type goes into the single file
30
+ `types/graphql.d.ts`. Each file declares types into a **shared global namespace**. TypeScript's
31
+ **declaration merging** combines the same-named `namespace` blocks into one, so the split costs
32
+ nothing at the access site.
32
33
 
33
- - **Why one file per entity.** A monolithic `model.d.ts` / `graphql.d.ts` is a constant merge-conflict
34
- point — every model or resolver change touches the same file. Splitting to `types/models/<ModelName>.d.ts`
35
- and `types/resolvers/<category>/<resolverName>.d.ts` means two changes collide **only when they
36
- touch the same entity**. Adding a model = adding a file.
34
+ - **Why one file per model.** A monolithic `model.d.ts` is a constant merge-conflict point, because
35
+ every model change touches the same file. Splitting to `types/models/<ModelName>.d.ts` means two
36
+ changes collide **only when they touch the same model**. Adding a model = adding a file.
37
+ - **Why one file for resolver types.** A resolver's `Input` / `Result` pair mirrors the schema
38
+ (SDL) one-to-one, so it is written in the same change as the SDL and read beside the other
39
+ resolver types of its category. One file, `types/graphql.d.ts`, is the place to look, and there is
40
+ no per-resolver path to keep in step with the resolver's own file name.
37
41
  - **Why it still reads as one namespace.** `declare global { namespace model { … } }` in
38
42
  `User.d.ts` and the same block in `Order.d.ts` **merge** into a single `model` namespace. Consumers
39
43
  write `model.User` / `model.Order` regardless of which file declared them — the file split is
@@ -67,7 +71,7 @@ declare global {
67
71
  - **`declare global { … }`** puts the namespace in the ambient global scope — visible everywhere with
68
72
  no import.
69
73
  - The **namespace name is fixed by kind**: `model` for model interfaces ([§2](#2-model-interfaces-one-file-per-table)),
70
- `graphql.<category>` for resolver types ([§3](#3-resolver-inputoutput-types-one-file-per-resolver)).
74
+ `graphql.<category>` for resolver types ([§3](#3-resolver-inputoutput-types-in-typesgraphqldts)).
71
75
 
72
76
  ## 2. Model interfaces (one file per table)
73
77
 
@@ -118,15 +122,15 @@ declare global {
118
122
  - Optionally, a model interface may `extend` a framework base-model interface (if the architecture
119
123
  provides one for the common columns); keep that base generic, not a hard-coded app path.
120
124
 
121
- ## 3. Resolver input/output types (one file per resolver)
125
+ ## 3. Resolver input/output types (in `types/graphql.d.ts`)
122
126
 
123
- A resolver's types map **1:1 to the resolver**. Put them in
124
- `types/resolvers/<category>/<resolverName>.d.ts`, declaring into `namespace graphql.<category>` —
125
- where `<category>` is the API/endpoint group (`user`, `admin`, `portal`, …). Each resolver declares
126
- its **`<Resolver>Input`** and its **`<Resolver>Result`** (the output / response).
127
+ Every resolver's types go into the one file `types/graphql.d.ts`, declared into
128
+ `namespace graphql.<category>`, where `<category>` is the API/endpoint group (`user`, `admin`,
129
+ `portal`, …). Each resolver declares its **`<Resolver>Input`** and its **`<Resolver>Result`** (the
130
+ output / response), written as a pair.
127
131
 
128
132
  ```ts
129
- // types/resolvers/user/createOrder.d.ts
133
+ // types/graphql.d.ts
130
134
  export {}
131
135
 
132
136
  declare global {
@@ -140,18 +144,31 @@ declare global {
140
144
  order: model.Order
141
145
  }
142
146
  }
147
+
148
+ namespace graphql.admin {
149
+ interface OrdersInput {
150
+ limit: number
151
+ offset: number
152
+ }
153
+
154
+ interface OrdersResult {
155
+ orders: model.Order[]
156
+ }
157
+ }
143
158
  }
144
159
  ```
145
160
 
146
161
  - **Input** is the resolver's argument shape; **Result** is what it returns (the response). A
147
162
  query uses the same `Input` / `Result` pairing.
163
+ - **One `namespace graphql.<category>` block per category**, inside the single `declare global`.
164
+ Keep a resolver's `Input` and `Result` next to each other.
148
165
  - **Reuse model interfaces in the output** — a Result field is typed as `model.<ModelName>`
149
166
  (`order: model.Order`). The `model` and `graphql.<category>` namespaces are both global, so one
150
167
  references the other with no import.
151
- - **Resolver-local helper types** (a nested filter input, a row sub-shape) live in the **same file**
152
- as the resolver they belong to — they are part of that resolver's 1:1 slice, not shared globals.
153
- - **Category = the resolver's endpoint group.** The same resolver name under a different endpoint is a
154
- different file and a different namespace (`graphql.user.FooInput` vs `graphql.admin.FooInput`).
168
+ - **Resolver-local helper types** (a nested filter input, a row sub-shape) sit in the same block,
169
+ beside the pair they belong to, named so they cannot collide with another resolver's.
170
+ - **Category = the resolver's endpoint group.** The same resolver name under a different endpoint is
171
+ a different namespace (`graphql.user.FooInput` vs `graphql.admin.FooInput`), in the same file.
155
172
 
156
173
  ## 4. Accessing the types
157
174
 
@@ -184,17 +201,16 @@ async resolve ({
184
201
  | Kind | File | Namespace | Interface names | Access |
185
202
  | --- | --- | --- | --- | --- |
186
203
  | Model | `types/models/<ModelName>.d.ts` | `model` | `<ModelName>` | `model.<ModelName>` |
187
- | Resolver | `types/resolvers/<category>/<resolverName>.d.ts` | `graphql.<category>` | `<Resolver>Input`, `<Resolver>Result` | `graphql.<category>.<Resolver>Input` |
204
+ | Resolver | `types/graphql.d.ts` | `graphql.<category>` | `<Resolver>Input`, `<Resolver>Result` | `graphql.<category>.<Resolver>Input` |
188
205
 
189
- - File base names match the entity: `<ModelName>` (PascalCase) for models, `<resolverName>`
190
- (matching the resolver, camelCase) for resolvers.
206
+ - A model's file base name is `<ModelName>` (PascalCase); resolver types share the one file.
191
207
  - Avoid the denied vague identifiers in field names (`data` / `info` / `list` / …); name a field for
192
208
  what it holds.
193
209
 
194
210
  ## Finishing checklist
195
211
 
196
- - [ ] The type lives in its **own file** — one model → `types/models/<ModelName>.d.ts`; one resolver → `types/resolvers/<category>/<resolverName>.d.ts` ([§1](#1-the-dts-scaffold)).
212
+ - [ ] The type lives in the right file: one model → its own `types/models/<ModelName>.d.ts`; a resolver's types → `types/graphql.d.ts` ([§1](#1-the-dts-scaffold)).
197
213
  - [ ] File envelope is `export {}` → `declare global` → the correct `namespace` (`model` or `graphql.<category>`).
198
214
  - [ ] Model interface is 1:1 with a table; fields mirror columns; nullable is `| null`; a foreign-key field starts uppercase ([§2](#2-model-interfaces-one-file-per-table)).
199
- - [ ] Resolver file declares `<Resolver>Input` + `<Resolver>Result`, reuses `model.<ModelName>` in outputs, and keeps resolver-local helper types in the same file ([§3](#3-resolver-inputoutput-types-one-file-per-resolver)).
215
+ - [ ] `types/graphql.d.ts` declares `<Resolver>Input` + `<Resolver>Result` in the resolver's `graphql.<category>` block, reuses `model.<ModelName>` in outputs, and keeps resolver-local helper types beside the pair ([§3](#3-resolver-inputoutput-types-in-typesgraphqldts)).
200
216
  - [ ] The `types/**` directory is included in the project's TS config so the ambient declarations resolve.
package/docs/skills.ja.md CHANGED
@@ -34,13 +34,14 @@
34
34
 
35
35
  | スキル | 概要 |
36
36
  | :-- | :-- |
37
- | `hor-restfulapi-architecture` | renchan バックエンドの REST 層。`server/restfulapi/` 配下のレンダラーアーキテクチャ、ルートとバージョン、`render()`、レスポンス/エラーハッシュ、認証フィルタ、フラッシャー。 |
37
+ | `hor-restfulapi-architecture` | renchan バックエンドの REST 層。`server/restfulapi/` 配下のレンダラーアーキテクチャ、ルートとバージョン、`render()`、レスポンス/エラーハッシュ、認証フィルタ、フラッシャー、リクエストが運ぶ認証情報の読み取り(Cookie、Bearer、IAP JWT、HMAC)、IAP の背後で動くアプリケーション。 |
38
38
 
39
39
  ### 認証
40
40
 
41
41
  | スキル | 概要 |
42
42
  | :-- | :-- |
43
- | `hor-cookie-authentication` | renchan バックエンドのアクター別 Cookie 認証。認証情報とトークンのモデル、アクセストークンとローテーションするリフレッシュトークン(再利用検知つき)、HttpOnly のリフレッシュ Cookie、signIn / signUp / signOut / renewAccessToken の各リゾルバー。 |
43
+ | `hor-cookie-authentication` | renchan バックエンドのアクター別のパスワードサインインと Cookie ベースのセッション。認証情報とトークンのモデル、アクセストークンとローテーションするリフレッシュトークン(再利用検知つき)、HttpOnly のリフレッシュ Cookie、signIn / signUp / signOut / renewAccessToken の各リゾルバー。 |
44
+ | `hor-oidc-sign-in` | 外部の OpenID Connect プロバイダ経由でアクターをサインインさせます。PKCE つき認可コードフロー、state と nonce、ID トークンの検証、セッションを開く前のプロバイダの subject とアクターの紐付け。 |
44
45
 
45
46
  ### 実行場所
46
47
 
@@ -56,7 +57,7 @@
56
57
  | :-- | :-- |
57
58
  | `hor-ai-agent-structure` | `mentsu-agent-loop-core` 上にアプリ側 AI エージェントを構成します。`app/agents/<name>/` に `ProceduralAgentLoop` サブクラスとステップごとの `BaseAgentAction` サブクラスを置きます。 |
58
59
  | `hor-agent-loop` | `@openreachtech/mentsu-agent-loop` の 3 パッケージで LLM エージェントループを構築します。core(反復エンジン)、BullMQ ジョブ実行、GraphQL の起動 mutation と進捗 subscription。 |
59
- | `hor-multi-llm-provider` | Claude / OpenAI / Gemini を 1 つの抽象の下で扱います。抽象モデルプロセッサ、ベンダーごとの基底、モデルごとの具象クラス、モデル名で選択するローダー。 |
60
+ | `hor-multi-llm-provider` | Claude / OpenAI / Gemini を 1 つの抽象の下で扱います。抽象モデルプロセッサ、ベンダーごとの基底、モデルごとの具象クラス、モデル名で選択するローダー、モデルへの到達方法ごとのアクセスルート(ベンダー API キー、サービスアカウントによる Vertex AI、Amazon Bedrock)。 |
60
61
  | `hor-light-rag` | ベクタ DB なしで AI エージェント向けの軽量 RAG を追加します。ローカル埋め込みによる vector-first / LLM フォールバックのランキングと、MySQL の n-gram 全文検索インデックス。 |
61
62
  | `hor-ai-prompt-document-store` | エージェントの設定・指示文・ドキュメント・ツールスキーマをコードに埋め込まず DB に保持し、リクエスト時にプロンプトへ組み立て、バックアップテーブルでバージョン管理します。 |
62
63
 
@@ -70,7 +71,7 @@
70
71
 
71
72
  | スキル | 概要 |
72
73
  | :-- | :-- |
73
- | `hor-type-interface` | `.d.ts` で型インターフェースを定義します。`types/models/` のモデルインターフェース(global `model`)と、`types/resolvers/<category>/` のリゾルバ Input/Result 型。 |
74
+ | `hor-type-interface` | `.d.ts` で型インターフェースを定義します。`types/models/` のモデルインターフェース(global `model`)と、`types/graphql.d.ts` のリゾルバ Input/Result 型(global `graphql.<category>`)。 |
74
75
  | `hor-constant-definition` | アプリ定数は必ず 2 ファイルで定義します。`constants/` の CommonJS マスター(単一の情報源)と、それを再 export する `app/constants/` の ESM ブリッジ。 |
75
76
 
76
77
  ### 設計パターン
package/docs/skills.md CHANGED
@@ -34,13 +34,14 @@ Each skill lives at `kit/skills/<name>/`, directly under the skills directory, a
34
34
 
35
35
  | Skill | Summary |
36
36
  | :-- | :-- |
37
- | `hor-restfulapi-architecture` | The REST layer of a renchan backend — the renderer architecture under `server/restfulapi/`, routes and versions, `render()`, response/error hashes, the auth filter, and flushers. |
37
+ | `hor-restfulapi-architecture` | The REST layer of a renchan backend: the renderer architecture under `server/restfulapi/`, routes and versions, `render()`, response/error hashes, the auth filter, flushers, the credential a request carries (cookie, Bearer, IAP JWT, HMAC), and an application behind IAP. |
38
38
 
39
39
  ### Authentication
40
40
 
41
41
  | Skill | Summary |
42
42
  | :-- | :-- |
43
- | `hor-cookie-authentication` | Cookie-based authentication for a renchan backend, per actor — the credential and token models, access plus rotating refresh tokens with reuse detection, the HttpOnly refresh cookie, and the signIn / signUp / signOut / renewAccessToken resolvers. |
43
+ | `hor-cookie-authentication` | Password sign-in with cookie-based sessions for a renchan backend, per actor: the credential and token models, access plus rotating refresh tokens with reuse detection, the HttpOnly refresh cookie, and the signIn / signUp / signOut / renewAccessToken resolvers. |
44
+ | `hor-oidc-sign-in` | Sign an actor in through an external OpenID Connect provider: the authorization code flow with PKCE, state and nonce, ID token verification, and linking the provider's subject to an actor before the session opens. |
44
45
 
45
46
  ### Execution placement
46
47
 
@@ -56,7 +57,7 @@ Each skill lives at `kit/skills/<name>/`, directly under the skills directory, a
56
57
  | :-- | :-- |
57
58
  | `hor-ai-agent-structure` | Structure an app-side AI agent on `mentsu-agent-loop-core`: a `ProceduralAgentLoop` subclass plus per-step `BaseAgentAction` subclasses under `app/agents/<name>/`. |
58
59
  | `hor-agent-loop` | Build an LLM agent loop with the three `@openreachtech/mentsu-agent-loop` packages — the core iteration engine, a BullMQ job runner, and a GraphQL mutation plus progress subscription. |
59
- | `hor-multi-llm-provider` | Support Claude / OpenAI / Gemini behind one abstraction — an abstract model processor, a base per vendor, a concrete class per model, and a loader that picks one by model name. |
60
+ | `hor-multi-llm-provider` | Support Claude / OpenAI / Gemini behind one abstraction: an abstract model processor, a base per vendor, a concrete class per model, a loader that picks one by model name, and an access route per way of reaching it (vendor API key, Vertex AI service account, Amazon Bedrock). |
60
61
  | `hor-light-rag` | Add lightweight RAG for agent documents without a vector database — a vector-first / LLM-fallback ranker over stored `Document` rows, plus a MySQL n-gram fulltext keyword index. |
61
62
  | `hor-ai-prompt-document-store` | Hold agent config, instructions, documents and tool schemas in the database rather than in code, assembling the runtime prompt at request time and versioning through backup tables. |
62
63
 
@@ -70,7 +71,7 @@ Each skill lives at `kit/skills/<name>/`, directly under the skills directory, a
70
71
 
71
72
  | Skill | Summary |
72
73
  | :-- | :-- |
73
- | `hor-type-interface` | Define `.d.ts` type interfaces — model interfaces under `types/models/` (global `model`) and resolver Input/Result types under `types/resolvers/<category>/`. |
74
+ | `hor-type-interface` | Define `.d.ts` type interfaces, with model interfaces under `types/models/` (global `model`) and resolver Input/Result types in `types/graphql.d.ts` (global `graphql.<category>`). |
74
75
  | `hor-constant-definition` | Define an application constant as two files: a CommonJS master under `constants/` (the source of truth) plus an ESM bridge under `app/constants/` that re-exports it. |
75
76
 
76
77
  ### Design patterns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openreachtech/hora-skills-ort-renchan",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Distributes the renchan backend skills used to develop with Hora Kit.",
5
5
  "type": "module",
6
6
  "files": [