@burnsred/entity-sync 0.0.0-stage → 3.0.0-rc.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.
- package/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +11 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +240 -2
- package/agents/entity-editor.md +16 -0
- package/bin/entity-sync.mjs +36 -0
- package/dist/cli.d.mts +20 -0
- package/dist/commands/asserts.d.mts +4 -0
- package/dist/commands/check.d.mts +6 -0
- package/dist/commands/inspect.d.mts +30 -0
- package/dist/commands/plan.d.mts +28 -0
- package/dist/commands/schema.d.mts +39 -0
- package/dist/config.d.mts +175 -0
- package/dist/index.d.mts +5 -0
- package/dist/lib/cache.d.mts +120 -0
- package/dist/lib/diff.d.mts +228 -0
- package/dist/lib/field-map.d.mts +93 -0
- package/dist/lib/gen-asserts.d.mts +70 -0
- package/dist/lib/graph.d.mts +90 -0
- package/dist/lib/parse-entities.d.mts +257 -0
- package/dist/lib/parse-schema.d.mts +98 -0
- package/dist/lib/resolve.d.mts +135 -0
- package/dist/project.d.mts +60 -0
- package/hooks/editor-guard.mjs +86 -0
- package/hooks/hooks.json +15 -0
- package/package.json +54 -4
- package/skills/entity/SKILL.md +105 -0
- package/skills/entity/reference/create.md +74 -0
- package/skills/entity/reference/editor.md +80 -0
- package/skills/entity/reference/enums.md +89 -0
- package/skills/entity/reference/fields.md +101 -0
- package/skills/entity/reference/sync.md +191 -0
- package/src/cli.mjs +110 -0
- package/src/commands/asserts.mjs +52 -0
- package/src/commands/check.mjs +88 -0
- package/src/commands/inspect.mjs +290 -0
- package/src/commands/plan.mjs +542 -0
- package/src/commands/schema.mjs +206 -0
- package/src/config.mjs +205 -0
- package/src/index.mjs +19 -0
- package/src/lib/cache.mjs +323 -0
- package/src/lib/diff.mjs +706 -0
- package/src/lib/field-map.mjs +438 -0
- package/src/lib/gen-asserts.mjs +478 -0
- package/src/lib/graph.mjs +284 -0
- package/src/lib/parse-entities.mjs +935 -0
- package/src/lib/parse-schema.mjs +667 -0
- package/src/lib/resolve.mjs +455 -0
- package/src/project.mjs +115 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "burnsred-entity-sync",
|
|
3
|
+
"owner": { "name": "BurnsRED" },
|
|
4
|
+
"metadata": {
|
|
5
|
+
"description": "The entity-sync plugin, served from an installed @burnsred/entity-sync npm package"
|
|
6
|
+
},
|
|
7
|
+
"plugins": [
|
|
8
|
+
{
|
|
9
|
+
"name": "entity-sync",
|
|
10
|
+
"source": "./",
|
|
11
|
+
"description": "/entity skill, entity-editor subagent and guard hook for keeping @burnsred/entity definitions in sync with a DRF OpenAPI schema."
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "entity-sync",
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
|
+
"description": "/entity skill, entity-editor subagent and guard hook for keeping @burnsred/entity definitions in sync with a DRF OpenAPI schema. Pair with the @burnsred/entity-sync npm package.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "BurnsRED"
|
|
7
|
+
},
|
|
8
|
+
"repository": "https://bitbucket.org/burnsred/burnsred-entity-library",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"keywords": ["burnsred", "entity", "drf", "openapi", "drf-spectacular"]
|
|
11
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [3.0.0-rc.0](https://bitbucket.org-burnsred/burnsred/burnsred-entity-library/compare/v2.1.0...v3.0.0-rc.0) (2026-12-03)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **BRE-113:** burnsred plugin marketplace, docs and verification ([46eecc1](https://bitbucket.org-burnsred/burnsred/burnsred-entity-library/commits/46eecc1f2f78c6e2322d66e4dbfee6d04e95a92d))
|
|
11
|
+
* **entity-sync:** config file and entity-sync CLI ([d7ae60c](https://bitbucket.org-burnsred/burnsred/burnsred-entity-library/commits/d7ae60c6414b411f7afd1ae6ad52735716fb7999))
|
|
12
|
+
* **entity-sync:** install the plugin from the npm package as a local marketplace ([d7b14f9](https://bitbucket.org-burnsred/burnsred/burnsred-entity-library/commits/d7b14f9ddb79753f37e02de4c85cf75781d2b10a))
|
|
13
|
+
* **entity-sync:** port AMSv2 entity-sync tooling verbatim ([256179f](https://bitbucket.org-burnsred/burnsred/burnsred-entity-library/commits/256179f054faf36b19853161af20ad24d5056726))
|
|
14
|
+
* **entity-sync:** ship the /entity skill as a Claude Code plugin ([069f153](https://bitbucket.org-burnsred/burnsred/burnsred-entity-library/commits/069f1537a2fedb691522aa12c30d4230da7c3ebb))
|
|
15
|
+
* **entity-sync:** ship type declarations so defineConfig is typed in TS config files ([62b4197](https://bitbucket.org-burnsred/burnsred/burnsred-entity-library/commits/62b41973520574546b0a4e7423cef66b9ac0d529))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-present Thierry Wong and Burnsred
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,241 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @burnsred/entity-sync
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Keep `@burnsred/entity` definitions in sync with a Django REST Framework
|
|
4
|
+
broker's OpenAPI schema (drf-spectacular), and let Claude Code do the edits.
|
|
5
|
+
|
|
6
|
+
Two things ship from this directory:
|
|
7
|
+
|
|
8
|
+
- **the `entity-sync` CLI** (npm package): fetches the schema, generates its
|
|
9
|
+
TypeScript types, writes a drift report a few KB long, and generates
|
|
10
|
+
compile-time assertions so `tsc` - not the report - decides whether an entity
|
|
11
|
+
is correct.
|
|
12
|
+
- **the `entity-sync` Claude Code plugin**: the `/entity-sync:entity` skill
|
|
13
|
+
(`sync` and `create`), the `entity-editor` subagent it delegates per-entity
|
|
14
|
+
edits to, and a hook that keeps that subagent to a short list of commands.
|
|
15
|
+
|
|
16
|
+
The broker side lives in the sibling [`entity-broker`](../../plugins/entity-broker)
|
|
17
|
+
plugin.
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
### 1. Install
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install -D @burnsred/entity-sync
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`typescript` and `prettier` are peer dependencies: your project's versions
|
|
28
|
+
parse the entities, format the generated files and run the check.
|
|
29
|
+
|
|
30
|
+
### 2. Configure
|
|
31
|
+
|
|
32
|
+
`entity-sync.config.mjs` at the project root. Paths are relative to it.
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
import { defineConfig } from '@burnsred/entity-sync';
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
schema: {
|
|
39
|
+
url: 'http://localhost:8000/api/schema/',
|
|
40
|
+
// Must match the broker's SPECTACULAR_SETTINGS.TITLE: refuses a schema
|
|
41
|
+
// from a different service answering on the same port.
|
|
42
|
+
expectedTitle: 'Example API',
|
|
43
|
+
},
|
|
44
|
+
// Mirror src/settings: each settings.X_URL used in an entity's apiBase,
|
|
45
|
+
// mapped to the path prefix it has in the schema.
|
|
46
|
+
settingsPrefixes: {
|
|
47
|
+
BASE_API_URL: '/api/example/v1',
|
|
48
|
+
AUTH_URL: '/api/auth/v1/',
|
|
49
|
+
},
|
|
50
|
+
// What a bare relative apiBase ('/order/') is resolved against: the
|
|
51
|
+
// axios baseURL. A settingsPrefixes key or a literal path.
|
|
52
|
+
apiBasePrefix: 'BASE_API_URL',
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
| option | default | notes |
|
|
57
|
+
| ------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------- |
|
|
58
|
+
| `schema.url` | - | fetch from the broker; requires `expectedTitle` |
|
|
59
|
+
| `schema.file` | - | or read an exported yaml/json (CI, offline) |
|
|
60
|
+
| `schema.expectedTitle` | - | checked against `info.title` |
|
|
61
|
+
| `schema.auth` | basic, `API_SUPERUSER_USERNAME` / `_PASSWORD` | `{ type: 'basic', usernameEnv, passwordEnv }`, or `false` |
|
|
62
|
+
| `schema.envFiles` | `['env/.env', 'env/.env.local']` | later files win; the shell wins over all |
|
|
63
|
+
| `schema.yaml` | `src/api/schema.yaml` | verbatim copy of what the broker served (`url` only) |
|
|
64
|
+
| `schema.dts` | `src/api/schema.d.ts` | generated types |
|
|
65
|
+
| `schema.importSpecifier` | relative path from the asserts file to `dts` | e.g. `'@/api/schema'` if you prefer an alias |
|
|
66
|
+
| `entitiesDir` | `src/entities` | |
|
|
67
|
+
| `assertsFile` | `<entitiesDir>/__generated__/schema-asserts.ts` | |
|
|
68
|
+
| `stateDir` | `.entity-sync` | per-developer report/plan/lock; gitignore it |
|
|
69
|
+
| `settingsPrefixes` | `{}` | never guessed |
|
|
70
|
+
| `apiBasePrefix` | `''` | |
|
|
71
|
+
| `equivalentFieldClasses` | `{ CharField: ['TextField'] }` | merged over the default |
|
|
72
|
+
| `knownNoise` | - | a doc listing report ops that are not real drift; printed with the plan |
|
|
73
|
+
|
|
74
|
+
### 3. Scripts
|
|
75
|
+
|
|
76
|
+
The skill runs these by name, so add all of them:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
"entity:sync": "entity-sync sync",
|
|
80
|
+
"entity:schema": "entity-sync schema",
|
|
81
|
+
"entity:plan": "entity-sync plan",
|
|
82
|
+
"entity:asserts": "entity-sync asserts",
|
|
83
|
+
"entity:check": "entity-sync check",
|
|
84
|
+
"entity:check:errors": "entity-sync check --grouped",
|
|
85
|
+
"entity:inspect": "entity-sync inspect",
|
|
86
|
+
"entity:version": "entity-sync --version"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 4. Files
|
|
90
|
+
|
|
91
|
+
Commit:
|
|
92
|
+
- `src/api/schema.yaml`
|
|
93
|
+
- `src/api/schema.d.ts`
|
|
94
|
+
- `src/entities/__generated__/schema-asserts.ts`
|
|
95
|
+
|
|
96
|
+
.gitignore
|
|
97
|
+
|
|
98
|
+
```gitignore
|
|
99
|
+
# entity-sync per-developer state (report, plan, lock)
|
|
100
|
+
.entity-sync/
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
.prettierignore
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
# kept verbatim as fetched from the broker by entity-sync
|
|
107
|
+
src/api/schema.*
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 5. Claude Code plugin
|
|
111
|
+
|
|
112
|
+
Commit this to the project's `.claude/settings.json` so everyone gets the
|
|
113
|
+
plugin once they trust the workspace:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"extraKnownMarketplaces": {
|
|
118
|
+
"burnsred": {
|
|
119
|
+
"source": {
|
|
120
|
+
"source": "git",
|
|
121
|
+
"url": "git@bitbucket.org:burnsred/burnsred-entity-library.git",
|
|
122
|
+
"ref": "master"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"enabledPlugins": { "entity-sync@burnsred": true },
|
|
127
|
+
"permissions": {
|
|
128
|
+
"allow": ["Bash(npm run *)", "Bash(npx eslint *)"]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Plugins cannot ship permissions, hence the `allow` rules. Use
|
|
134
|
+
`Bash(npm run *)`: `Bash(npm run entity:*)` does **not** match `npm run
|
|
135
|
+
entity:check` (a trailing `:*` is the legacy prefix form, which wants a space
|
|
136
|
+
after `npm run entity`).
|
|
137
|
+
|
|
138
|
+
Then run `/entity-sync:entity sync`.
|
|
139
|
+
|
|
140
|
+
#### From the installed npm package
|
|
141
|
+
|
|
142
|
+
The package is also a single-plugin marketplace (`burnsred-entity-sync`), so
|
|
143
|
+
the copy in `node_modules` can be installed as the full plugin, with no git
|
|
144
|
+
access - useful before publishing, or to pin the plugin to the package version:
|
|
145
|
+
|
|
146
|
+
```sh
|
|
147
|
+
claude plugin marketplace add ./node_modules/@burnsred/entity-sync --scope project
|
|
148
|
+
claude plugin install entity-sync@burnsred-entity-sync --scope project
|
|
149
|
+
# after each npm update of @burnsred/entity-sync:
|
|
150
|
+
claude plugin update entity-sync@burnsred-entity-sync --scope project
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Behaviour, as tested:
|
|
154
|
+
|
|
155
|
+
- Claude Code **copies** the plugin into its cache, keyed by version. It does
|
|
156
|
+
not read `node_modules` live, and a new session does not pick up a newer
|
|
157
|
+
package on its own: run `plugin update` (a `postinstall` script can do it).
|
|
158
|
+
Because the cache is keyed by version, bump the version when re-packing for
|
|
159
|
+
a test, or the update may find nothing new.
|
|
160
|
+
- `marketplace add` writes an **absolute** path into `.claude/settings.json`;
|
|
161
|
+
make that path relative (`./node_modules/@burnsred/entity-sync`) before
|
|
162
|
+
committing. Whether teammates are then offered the plugin on trusting the
|
|
163
|
+
workspace is not yet verified; CLI commands alone do not register a
|
|
164
|
+
marketplace declared only in project settings.
|
|
165
|
+
- Use this or the `burnsred` marketplace, not both: each offers `entity-sync`.
|
|
166
|
+
|
|
167
|
+
For a single session, `claude --plugin-dir node_modules/@burnsred/entity-sync`
|
|
168
|
+
loads the same plugin without installing anything.
|
|
169
|
+
|
|
170
|
+
#### Without the plugin
|
|
171
|
+
|
|
172
|
+
The skill also installs on its own, for other agents or without a marketplace:
|
|
173
|
+
|
|
174
|
+
```sh
|
|
175
|
+
npx skills add git@bitbucket.org:burnsred/burnsred-entity-library.git --skill entity
|
|
176
|
+
# or, from the installed package (stays on the same version as the CLI):
|
|
177
|
+
npx skills experimental_sync -a claude-code -y
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
That gets the skill only: no subagent and no hook. The skill then dispatches a
|
|
181
|
+
general-purpose subagent with `reference/editor.md` as its brief, and the
|
|
182
|
+
command limits become instructions rather than enforcement.
|
|
183
|
+
|
|
184
|
+
## How the guard works
|
|
185
|
+
|
|
186
|
+
`hooks/editor-guard.mjs` runs before every Bash call. Claude Code passes
|
|
187
|
+
`agent_type: "entity-sync:entity-editor"` when the call comes from the editor,
|
|
188
|
+
and no `agent_type` from the main session. For the editor it allows only
|
|
189
|
+
single, unchained `npm run entity:inspect`, `npx entity-sync inspect`,
|
|
190
|
+
`npx eslint` and `npx prettier` commands; everything else is denied with a
|
|
191
|
+
reason, including `entity:check`, which belongs to the orchestrator because it
|
|
192
|
+
is a project-wide `tsc`. Everything else passes straight through. It matches
|
|
193
|
+
command text, so it is a guardrail rather than a security boundary.
|
|
194
|
+
|
|
195
|
+
Set `ENTITY_SYNC_HOOK_LOG=<file>` to log every hook input.
|
|
196
|
+
|
|
197
|
+
## Commands
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
entity-sync sync schema, then plan
|
|
201
|
+
entity-sync schema fetch/read the schema, regenerate the types
|
|
202
|
+
entity-sync plan [--all] write the drift report (--all: include drift seen before)
|
|
203
|
+
entity-sync asserts regenerate the compile-time assertions
|
|
204
|
+
entity-sync check [--grouped] [-- <tsc args>]
|
|
205
|
+
asserts, then the project's tsc (default --noEmit)
|
|
206
|
+
entity-sync inspect <cmd> component <Name> | components | path <substr> |
|
|
207
|
+
entity <Name> | entities | enums | errors
|
|
208
|
+
entity-sync errors group tsc output on stdin by entity
|
|
209
|
+
entity-sync --version
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
All take `--config <path>`.
|
|
213
|
+
|
|
214
|
+
## Annotations
|
|
215
|
+
|
|
216
|
+
Decisions are recorded on the entity in JSDoc, once, instead of being
|
|
217
|
+
re-derived every sync: `@schema <Component>`, `@schemaAlso <Component>`,
|
|
218
|
+
`@noSchema <reason>`, `@schemaSubset <reason>`, `@schemaIgnore <field>
|
|
219
|
+
<reason>`, and `@schemaEnum <Component>` on a choices dict. See
|
|
220
|
+
`skills/entity/reference/sync.md`.
|
|
221
|
+
|
|
222
|
+
## Origin
|
|
223
|
+
|
|
224
|
+
Extracted from perpetual-ams-frontend (AMSv2), where it was built in PR #68
|
|
225
|
+
(AMS-215) alongside the broker's drf-spectacular adoption (perpetual-ams-broker
|
|
226
|
+
PR #51) and refined in PR #136 (AMS-380). Ported from
|
|
227
|
+
`origin/release/sprint-13 @ 8bff8f747`; with an AMS config it produces
|
|
228
|
+
byte-identical reports and assertions to the original scripts. See
|
|
229
|
+
`docs/BRE-113-entity-sync-skill.md` at the repo root for the full history.
|
|
230
|
+
|
|
231
|
+
## Development
|
|
232
|
+
|
|
233
|
+
```sh
|
|
234
|
+
npx vitest run packages/entity-sync # unit + end-to-end fixture tests
|
|
235
|
+
claude plugin validate packages/entity-sync
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
`test/fixture` is a small consumer project; the end-to-end test copies it under
|
|
239
|
+
`.test-tmp/` and drives the bin against it. `npm version` (via `lerna version`)
|
|
240
|
+
copies the package version into `.claude-plugin/plugin.json` and the skill's
|
|
241
|
+
version marker; a test fails if they drift.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: entity-editor
|
|
3
|
+
description: Applies entity-sync ops to a single entity file. Use when the /entity sync procedure has a report section for one entity (or one dependency cycle) and its field declarations and Fields/Record types need to be brought into line with the schema. Dispatch one per entity, in parallel across a wave. Returns a one-line-per-field summary, not the file contents.
|
|
4
|
+
model: sonnet
|
|
5
|
+
color: green
|
|
6
|
+
tools: Read, Edit, Grep, Glob, Bash, mcp__ide__getDiagnostics
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
Read `${CLAUDE_PLUGIN_ROOT}/skills/entity/reference/editor.md` and follow it
|
|
10
|
+
exactly. It is your complete brief; the rule files it names (`fields.md`,
|
|
11
|
+
`enums.md`) are in the same directory.
|
|
12
|
+
|
|
13
|
+
Your Bash access is limited by the plugin's hook to `npm run entity:inspect`,
|
|
14
|
+
`npx entity-sync inspect`, `npx eslint` and `npx prettier`. Anything else,
|
|
15
|
+
including `entity:check`, is refused - report what you needed instead of
|
|
16
|
+
working around it.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
/**
|
|
4
|
+
* entity-sync - keep @burnsred/entity definitions in sync with a DRF schema.
|
|
5
|
+
*
|
|
6
|
+
* entity-sync sync schema, then plan
|
|
7
|
+
* entity-sync schema fetch/read the OpenAPI schema, regenerate types
|
|
8
|
+
* entity-sync plan [--all] write the drift report
|
|
9
|
+
* entity-sync asserts regenerate the compile-time assertions
|
|
10
|
+
* entity-sync check [--grouped] [-- <tsc args>]
|
|
11
|
+
* asserts, then the project's tsc
|
|
12
|
+
* entity-sync inspect <cmd> debug views of the parsed data
|
|
13
|
+
* entity-sync errors group tsc output (stdin) by entity
|
|
14
|
+
* entity-sync --version
|
|
15
|
+
*
|
|
16
|
+
* Global option: --config <path> (default: entity-sync.config.{mjs,js,json} in
|
|
17
|
+
* the current directory).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { readFileSync } from 'node:fs';
|
|
21
|
+
|
|
22
|
+
import { main } from '../src/cli.mjs';
|
|
23
|
+
|
|
24
|
+
const { version } = JSON.parse(
|
|
25
|
+
readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
main(process.argv.slice(2), { version }).then(
|
|
29
|
+
(code) => {
|
|
30
|
+
process.exitCode = code;
|
|
31
|
+
},
|
|
32
|
+
(error) => {
|
|
33
|
+
console.error(`\nentity-sync failed - ${error.message}`);
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
},
|
|
36
|
+
);
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split out `--config <path>` from the rest.
|
|
3
|
+
*
|
|
4
|
+
* @param {string[]} argv
|
|
5
|
+
*/
|
|
6
|
+
export function parseArgs(argv: string[]): {
|
|
7
|
+
command: string;
|
|
8
|
+
args: string[];
|
|
9
|
+
configPath: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @param {string[]} argv
|
|
13
|
+
* @param {{ version: string, cwd?: string }} options
|
|
14
|
+
* @returns {Promise<number>} exit code
|
|
15
|
+
*/
|
|
16
|
+
export function main(argv: string[], { version, cwd }: {
|
|
17
|
+
version: string;
|
|
18
|
+
cwd?: string;
|
|
19
|
+
}): Promise<number>;
|
|
20
|
+
export const HELP: "entity-sync <command> [--config <path>]\n\n sync schema, then plan\n schema fetch/read the OpenAPI schema, regenerate types\n plan [--all] write the drift report to the state dir\n asserts regenerate the compile-time assertions\n check [--grouped] [-- <tsc args>]\n asserts, then the project's tsc\n inspect <cmd> component <Name> | components | path <substr> |\n entity <Name> | entities | enums | errors\n errors group tsc output (stdin) by entity\n --version print the version";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Group tsc's assertion failures by entity, resolving each error's line number
|
|
3
|
+
* back to the entity block it sits in.
|
|
4
|
+
*
|
|
5
|
+
* Exists so this analysis is a command rather than a throwaway one-liner: it
|
|
6
|
+
* was re-typed by hand several times while calibrating the assertions, which is
|
|
7
|
+
* exactly the work that belongs in a script.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} tscOutput
|
|
10
|
+
* @param {string} assertsSource contents of the assertions file
|
|
11
|
+
* @param {string} assertsName its basename, as tsc prints it
|
|
12
|
+
* @returns {{ grouped: Map<string, string[]>, total: number }}
|
|
13
|
+
*/
|
|
14
|
+
export function groupAssertionErrors(tscOutput: string, assertsSource: string, assertsName: string): {
|
|
15
|
+
grouped: Map<string, string[]>;
|
|
16
|
+
total: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @param {{ grouped: Map<string, string[]>, total: number }} result
|
|
20
|
+
*/
|
|
21
|
+
export function printGroupedErrors({ grouped, total }: {
|
|
22
|
+
grouped: Map<string, string[]>;
|
|
23
|
+
total: number;
|
|
24
|
+
}): void;
|
|
25
|
+
/**
|
|
26
|
+
* @param {import('../config.mjs').ResolvedConfig} config
|
|
27
|
+
* @param {string[]} [args]
|
|
28
|
+
*/
|
|
29
|
+
export function run(config: import("../config.mjs").ResolvedConfig, args?: string[]): void;
|
|
30
|
+
export const USAGE: "usage: entity-sync inspect component <Name> | components | path <substring> | entity <Name> | entities | enums | errors";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {object} input
|
|
3
|
+
* @param {import('../lib/resolve.mjs').Resolution[]} input.resolutions
|
|
4
|
+
* @param {import('../lib/diff.mjs').EntityDiff[]} input.diffs
|
|
5
|
+
* @param {string[][]} input.waves
|
|
6
|
+
* @param {string[]} input.unordered
|
|
7
|
+
* @param {string[][]} input.cycles
|
|
8
|
+
* @param {Map<string, import('../lib/cache.mjs').Staleness>} input.staleness
|
|
9
|
+
* @param {import('../lib/resolve.mjs').EnumResolution[]} [input.enumResolutions]
|
|
10
|
+
* @param {Record<string, import('../lib/parse-schema.mjs').SchemaComponent>} [input.components]
|
|
11
|
+
* @param {boolean} [input.showAll] include drift already seen on a previous run
|
|
12
|
+
*/
|
|
13
|
+
export function renderReport({ resolutions, diffs, waves, unordered, cycles, staleness, enumResolutions, components, showAll, }: {
|
|
14
|
+
resolutions: import("../lib/resolve.mjs").Resolution[];
|
|
15
|
+
diffs: import("../lib/diff.mjs").EntityDiff[];
|
|
16
|
+
waves: string[][];
|
|
17
|
+
unordered: string[];
|
|
18
|
+
cycles: string[][];
|
|
19
|
+
staleness: Map<string, import("../lib/cache.mjs").Staleness>;
|
|
20
|
+
enumResolutions?: import("../lib/resolve.mjs").EnumResolution[] | undefined;
|
|
21
|
+
components?: Record<string, import("../lib/parse-schema.mjs").SchemaComponent> | undefined;
|
|
22
|
+
showAll?: boolean | undefined;
|
|
23
|
+
}): string;
|
|
24
|
+
/**
|
|
25
|
+
* @param {import('../config.mjs').ResolvedConfig} config
|
|
26
|
+
* @param {string[]} [args]
|
|
27
|
+
*/
|
|
28
|
+
export function run(config: import("../config.mjs").ResolvedConfig, args?: string[]): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../config.mjs').ResolvedConfig} ResolvedConfig
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Load the configured env files. Later files win over earlier ones, and the
|
|
6
|
+
* shell wins over all of them: `process.loadEnvFile` never overrides a variable
|
|
7
|
+
* that is already set, so the files are loaded last-first.
|
|
8
|
+
*
|
|
9
|
+
* @param {string[]} files absolute
|
|
10
|
+
*/
|
|
11
|
+
export function loadEnvFiles(files: string[]): void;
|
|
12
|
+
/**
|
|
13
|
+
* Confirm the document describes the application we expect.
|
|
14
|
+
*
|
|
15
|
+
* @param {unknown} doc parsed OpenAPI document
|
|
16
|
+
* @param {string | null} expectedTitle
|
|
17
|
+
* @param {string} source where the document came from, for the error
|
|
18
|
+
* @returns {{ title: string, version: string }}
|
|
19
|
+
*/
|
|
20
|
+
export function assertExpectedApi(doc: unknown, expectedTitle: string | null, source: string): {
|
|
21
|
+
title: string;
|
|
22
|
+
version: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Generate the `.d.ts` text from a parsed document.
|
|
26
|
+
*
|
|
27
|
+
* The parsed document is passed rather than the raw text, so generation cannot
|
|
28
|
+
* disagree with the document the guards just validated. `astToString` emits
|
|
29
|
+
* only the types; the "do not edit" banner is added by openapi-typescript's
|
|
30
|
+
* CLI, so prepend it explicitly or it is lost.
|
|
31
|
+
*
|
|
32
|
+
* @param {unknown} doc
|
|
33
|
+
*/
|
|
34
|
+
export function generateDts(doc: unknown): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* @param {ResolvedConfig} config
|
|
37
|
+
*/
|
|
38
|
+
export function run(config: ResolvedConfig): Promise<void>;
|
|
39
|
+
export type ResolvedConfig = import("../config.mjs").ResolvedConfig;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} BasicAuthConfig
|
|
3
|
+
* @property {'basic'} type
|
|
4
|
+
* @property {string} [usernameEnv] default `API_SUPERUSER_USERNAME`
|
|
5
|
+
* @property {string} [passwordEnv] default `API_SUPERUSER_PASSWORD`
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} SchemaConfig
|
|
9
|
+
* @property {string} [url] fetch the OpenAPI document from the broker
|
|
10
|
+
* @property {string} [file] or read it from a file (yaml or json)
|
|
11
|
+
* @property {string} [expectedTitle] required with `url`: guards against the wrong service answering
|
|
12
|
+
* @property {BasicAuthConfig | false} [auth] default basic auth from env
|
|
13
|
+
* @property {string[]} [envFiles] loaded before reading credentials; later files win, the shell wins over all
|
|
14
|
+
* @property {string} [yaml] where the verbatim document is written (`url` only)
|
|
15
|
+
* @property {string} [dts] generated types, the artifact everything parses
|
|
16
|
+
* @property {string} [importSpecifier] how `schema-asserts.ts` imports `components`; default: relative path to `dts`
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {object} Config
|
|
20
|
+
* @property {SchemaConfig} [schema]
|
|
21
|
+
* @property {string} [entitiesDir]
|
|
22
|
+
* @property {string} [assertsFile]
|
|
23
|
+
* @property {string} [stateDir] per-developer state (report, plan, lock); gitignore it
|
|
24
|
+
* @property {Record<string, string>} [settingsPrefixes] `settings.X` constant -> schema path prefix
|
|
25
|
+
* @property {string} [apiBasePrefix] prefix for a bare relative `apiBase`; a `settingsPrefixes` key or a literal path
|
|
26
|
+
* @property {Record<string, string[]>} [equivalentFieldClasses] merged over the defaults
|
|
27
|
+
* @property {string} [knownNoise] optional doc listing report ops that are not real drift
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {object} ResolvedConfig
|
|
31
|
+
* @property {string} root
|
|
32
|
+
* @property {string | null} configFile
|
|
33
|
+
* @property {{ url: string | null, file: string | null, expectedTitle: string | null, auth: Required<BasicAuthConfig> | false, envFiles: string[], yaml: string, dts: string, importSpecifier: string }} schema
|
|
34
|
+
* @property {string} entitiesDir
|
|
35
|
+
* @property {string} assertsFile
|
|
36
|
+
* @property {string} stateDir
|
|
37
|
+
* @property {Record<string, string>} settingsPrefixes
|
|
38
|
+
* @property {string} apiBasePrefix
|
|
39
|
+
* @property {Readonly<Record<string, readonly string[]>>} equivalentFieldClasses
|
|
40
|
+
* @property {string | null} knownNoise
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Identity helper so a config file gets editor completion.
|
|
44
|
+
*
|
|
45
|
+
* @param {Config} config
|
|
46
|
+
* @returns {Config}
|
|
47
|
+
*/
|
|
48
|
+
export function defineConfig(config: Config): Config;
|
|
49
|
+
/**
|
|
50
|
+
* Module specifier from one file's directory to another file, posix-style and
|
|
51
|
+
* always explicitly relative, with TypeScript extensions dropped.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} fromDir absolute
|
|
54
|
+
* @param {string} toFile absolute
|
|
55
|
+
*/
|
|
56
|
+
export function relativeSpecifier(fromDir: string, toFile: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Apply defaults and resolve paths. Exported separately from `loadConfig` so
|
|
59
|
+
* tests can resolve an in-memory config.
|
|
60
|
+
*
|
|
61
|
+
* @param {Config} config
|
|
62
|
+
* @param {string} root absolute directory the config's paths are relative to
|
|
63
|
+
* @param {string | null} [configFile]
|
|
64
|
+
* @returns {ResolvedConfig}
|
|
65
|
+
*/
|
|
66
|
+
export function resolveConfig(config: Config, root: string, configFile?: string | null): ResolvedConfig;
|
|
67
|
+
/**
|
|
68
|
+
* Find, import and resolve the project config.
|
|
69
|
+
*
|
|
70
|
+
* @param {{ cwd?: string, configPath?: string }} [options]
|
|
71
|
+
* @returns {Promise<ResolvedConfig>}
|
|
72
|
+
*/
|
|
73
|
+
export function loadConfig({ cwd, configPath }?: {
|
|
74
|
+
cwd?: string;
|
|
75
|
+
configPath?: string;
|
|
76
|
+
}): Promise<ResolvedConfig>;
|
|
77
|
+
/**
|
|
78
|
+
* A path relative to the project root, for log lines and report text.
|
|
79
|
+
*
|
|
80
|
+
* @param {ResolvedConfig} config
|
|
81
|
+
* @param {string} path absolute
|
|
82
|
+
*/
|
|
83
|
+
export function display(config: ResolvedConfig, path: string): string;
|
|
84
|
+
export const CONFIG_FILENAMES: string[];
|
|
85
|
+
export type BasicAuthConfig = {
|
|
86
|
+
type: "basic";
|
|
87
|
+
/**
|
|
88
|
+
* default `API_SUPERUSER_USERNAME`
|
|
89
|
+
*/
|
|
90
|
+
usernameEnv?: string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* default `API_SUPERUSER_PASSWORD`
|
|
93
|
+
*/
|
|
94
|
+
passwordEnv?: string | undefined;
|
|
95
|
+
};
|
|
96
|
+
export type SchemaConfig = {
|
|
97
|
+
/**
|
|
98
|
+
* fetch the OpenAPI document from the broker
|
|
99
|
+
*/
|
|
100
|
+
url?: string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* or read it from a file (yaml or json)
|
|
103
|
+
*/
|
|
104
|
+
file?: string | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* required with `url`: guards against the wrong service answering
|
|
107
|
+
*/
|
|
108
|
+
expectedTitle?: string | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* default basic auth from env
|
|
111
|
+
*/
|
|
112
|
+
auth?: false | BasicAuthConfig | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* loaded before reading credentials; later files win, the shell wins over all
|
|
115
|
+
*/
|
|
116
|
+
envFiles?: string[] | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* where the verbatim document is written (`url` only)
|
|
119
|
+
*/
|
|
120
|
+
yaml?: string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* generated types, the artifact everything parses
|
|
123
|
+
*/
|
|
124
|
+
dts?: string | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* how `schema-asserts.ts` imports `components`; default: relative path to `dts`
|
|
127
|
+
*/
|
|
128
|
+
importSpecifier?: string | undefined;
|
|
129
|
+
};
|
|
130
|
+
export type Config = {
|
|
131
|
+
schema?: SchemaConfig | undefined;
|
|
132
|
+
entitiesDir?: string | undefined;
|
|
133
|
+
assertsFile?: string | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* per-developer state (report, plan, lock); gitignore it
|
|
136
|
+
*/
|
|
137
|
+
stateDir?: string | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* `settings.X` constant -> schema path prefix
|
|
140
|
+
*/
|
|
141
|
+
settingsPrefixes?: Record<string, string> | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* prefix for a bare relative `apiBase`; a `settingsPrefixes` key or a literal path
|
|
144
|
+
*/
|
|
145
|
+
apiBasePrefix?: string | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* merged over the defaults
|
|
148
|
+
*/
|
|
149
|
+
equivalentFieldClasses?: Record<string, string[]> | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* optional doc listing report ops that are not real drift
|
|
152
|
+
*/
|
|
153
|
+
knownNoise?: string | undefined;
|
|
154
|
+
};
|
|
155
|
+
export type ResolvedConfig = {
|
|
156
|
+
root: string;
|
|
157
|
+
configFile: string | null;
|
|
158
|
+
schema: {
|
|
159
|
+
url: string | null;
|
|
160
|
+
file: string | null;
|
|
161
|
+
expectedTitle: string | null;
|
|
162
|
+
auth: Required<BasicAuthConfig> | false;
|
|
163
|
+
envFiles: string[];
|
|
164
|
+
yaml: string;
|
|
165
|
+
dts: string;
|
|
166
|
+
importSpecifier: string;
|
|
167
|
+
};
|
|
168
|
+
entitiesDir: string;
|
|
169
|
+
assertsFile: string;
|
|
170
|
+
stateDir: string;
|
|
171
|
+
settingsPrefixes: Record<string, string>;
|
|
172
|
+
apiBasePrefix: string;
|
|
173
|
+
equivalentFieldClasses: Readonly<Record<string, readonly string[]>>;
|
|
174
|
+
knownNoise: string | null;
|
|
175
|
+
};
|