diff --git a/.changeset/dynamic-key-registry.md b/.changeset/dynamic-key-registry.md new file mode 100644 index 0000000..4c2093f --- /dev/null +++ b/.changeset/dynamic-key-registry.md @@ -0,0 +1,5 @@ +--- +"@astrologyengine/cms-contract": minor +--- + +Add typed manifests, shared field validation, definition checks, and a manifest sync client and CLI. The CMS now serves a database-backed key registry with active, unused, and deleted key states; the legacy catalog and seed remain for transitional tooling. diff --git a/README.md b/README.md index 20a8b23..7643f15 100644 --- a/README.md +++ b/README.md @@ -63,30 +63,38 @@ curl localhost:8787/v1/content/en/body/SUN Admin (`Authorization: Bearer $CMS_ADMIN_TOKEN`; optional `X-CMS-Actor: `): -| Method & path | Purpose | -| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | -| `GET /v1/admin/locales` · `POST /v1/admin/locales` · `PATCH`/`DELETE /v1/admin/locales/:code` | Manage locales (new ones start disabled) | -| `GET /v1/admin/entries/:collection/:key` | All stored translations of an entry | -| `PUT`/`DELETE /v1/admin/entries/:collection/:key/translations/:locale` | Edit text (`If-Match: "r"` or `If-None-Match: *` for concurrency) | -| `GET /v1/admin/coverage` | Missing, fallback-served and placeholder-mismatched entries per locale; orphans | -| `GET /v1/admin/revisions` | History, newest first (`collection`, `key`, `locale`, `before`, `limit`) | -| `GET /v1/admin/catalog` | The catalog | +| Method & path | Purpose | +| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | +| `GET /v1/admin/locales` · `POST /v1/admin/locales` · `PATCH`/`DELETE /v1/admin/locales/:code` | Manage locales (new ones start disabled) | +| `GET /v1/admin/entries/:collection/:key` | All stored translations of an entry | +| `PUT`/`DELETE /v1/admin/entries/:collection/:key/translations/:locale` | Edit text (`If-Match: "r"` or `If-None-Match: *` for concurrency) | +| `GET /v1/admin/coverage` | Missing, fallback-served and placeholder-mismatched entries per locale; unused keys | +| `GET /v1/admin/revisions` | History, newest first (`collection`, `key`, `locale`, `before`, `limit`) | +| `GET /v1/definitions` (public) | Registered collections and key definitions | Field shapes: `body`, `angle`, `sign` and `aspect` take `{ name, insight, keywords }`; `house` takes `{ insight, keywords }`; `ui` takes -`{ text }`, where `text` must contain exactly the catalog's `{placeholders}`. +`{ text }`, where `text` must contain exactly the registered key's `{placeholders}`. ## Adding copy -Keys are defined in code: - -1. Add the key to `packages/contract/src/catalog.ts`, declaring any placeholders. -2. Add its English text to `packages/contract/seed/en.json`. `bun run test` fails until the two - match. -3. Use it in the website with `t("your.key")`; type checks reject unknown keys. - -Deploying runs the seed, which inserts the new English text without touching -existing edits. See the runbook for the order of deploy steps. +The running CMS reads collections and keys from D1. A website can define a typed +manifest with `defineManifest` from `@astrologyengine/cms-contract/manifest`, then +register it through `POST /v1/admin/sync`. The contract CLI provides +`cms-contract check --manifest --against ` and +`cms-contract sync --manifest --origin `; sync reads +`CMS_ADMIN_TOKEN` and uses the checkout's HEAD and full git history. + +Sync registers new keys, preserves editor changes, and marks omitted keys unused. +Unused keys remain served for older web builds. Admins can soft-delete unused keys +and restore them; collection shapes and placeholder definitions cannot change. +`GET /v1/definitions` exposes definitions without translation text. + +The legacy catalog, English seed, and seed commands remain for transitional local +and release tooling. Website manifest ownership and deploy integration are a +separate handoff; see [the plan](docs/plans/web-owned-catalog.md). The rewritten +initial schema requires a fresh database; it is not an upgrade migration for an +existing CMS database. ## Develop with web diff --git a/bun.lock b/bun.lock index ffc12e5..6aacb77 100644 --- a/bun.lock +++ b/bun.lock @@ -14,6 +14,7 @@ "@cloudflare/vitest-plugin": "1.1.13", "@cloudflare/workers-types": "5.20261029.1", "@types/bun": "1.3.14", + "@types/node": "26.6.6", "oxfmt": "0.76.0", "oxlint": "1.91.0", "typescript": "6.0.3", diff --git a/docs/plans/web-owned-catalog.md b/docs/plans/web-owned-catalog.md new file mode 100644 index 0000000..7ebc849 --- /dev/null +++ b/docs/plans/web-owned-catalog.md @@ -0,0 +1,559 @@ +# Plan: web-owned catalog (manifest sync) + +| | | +| -------------- | ------------------------------------------------------------------------ | +| **Status** | Draft, for review | +| **Date** | 2026-11-13 | +| **Design** | `docs/designs/cms.md` (rev. 2); this plan adds rev. 3 in its final phase | +| **Runbook** | `docs/runbooks/cms.md` | +| **Supersedes** | Design decision #9 ("code-defined keys"), §5.1 catalog, §8 seeding | + +## 1. Goal + +Adding a key to the website must not require a CMS change or release. Today +every collection and key is hardcoded in `packages/contract/src/catalog.ts`, +with English text in `packages/contract/seed/en.json`, so each new `t("…")` +in web needs a CMS PR, a contract release and a CMS deploy first. + +After this plan: + +- **Web owns collections, keys and their approved English text** in a typed + manifest in the web repo. +- **Web's main and release deploys sync the manifest to the CMS.** Sync only + creates collections and keys, fills in missing English, and refreshes English + that no editor has touched. It never overwrites an editor's work. +- **The CMS owns shapes, validation, storage, editing, history and serving.** + It contains no astrology-specific code. +- **Type safety is kept.** Web derives `t()` keys and parameter types from its + manifest, and the placeholders come from the English text itself. +- **Editors keep every copy-editing ability** they have today. Only creating + keys moves from CMS code to web code. + +## 2. Decisions + +Agreed in review, 2026-11-13. + +| # | Question | Decision | +| --- | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | How does web use dynamic keys? | By code reference, typed. The point is to stop needing CMS changes for new keys. Prefix listing is not needed. | +| 2 | Who defines keys? | Web, in a manifest with the approved English text. Deploy registers keys and never overwrites edits. | +| 3 | How far does decoupling go? | Web owns **all** collections and keys, astrology collections included. The CMS owns the field shapes. | +| 4 | Changing a key's definition | Not allowed. Placeholders and collection shapes can't change; a different definition needs a new key name (e.g. `…V2`). | +| 5 | Keep shapes? | Yes: `named`, `reference`, `text`, fixed in the CMS. The upcoming admin UI picks its editing component by shape. | +| 6 | Do PR previews sync? | No. Only main (staging) and releases (alpha) sync. Web falls back to its manifest English for keys the CMS doesn't have yet. | +| 7 | How does CI authenticate? | `CMS_ADMIN_TOKEN` for now, and only in web's main and release deploy jobs. Revisit (e.g. GitHub OIDC) during admin UI planning. | +| 8 | Switching over | Start fresh: nothing has been deployed (D1 IDs are still `REPLACE_WITH_…`, deploys are gated). `0001_init.sql` is rewritten; no backfill and no seed. | +| 9 | Placeholders | Derived from the English text (`"Showing {shown}"` gives `{shown}`). Fixed at first sync. | +| 10 | Contract package | Kept, made generic: shapes, placeholder and manifest types, `checkManifest`, sync client, locale helpers, wire types. No catalog and no seed. | +| 11 | Pre-merge conflict detection | A public, read-only `GET /v1/definitions` endpoint, plus `checkManifest()` from the contract (the same function the sync endpoint uses). No secret needed in PR CI. | +| 12 | Which environment each check uses | Feature PRs check against **staging**; release PRs check against **alpha**. | +| — | Deleting keys | **Soft delete.** Only unused keys can be deleted. Admins can restore them. Key names are **never reused**. | +| 13 | A manifest contains a deleted key | Rejected (`key_retired`). To bring it back, an admin restores it first. The friction is intentional: it forces admins and developers to coordinate. | +| 14 | Plan scope | CMS only, plus a web handoff (§11). The web repo isn't available here. | +| 15 | Method | Red/green TDD with `[red]` commit pairs (org convention). | +| 16 | Where does the contract live? | Here, in `packages/contract`. | +| 17 | Manifest English changes after sync | Sync replaces English **only if no editor has changed it** since the last sync. This is tracked by a server-set `origin` on each translation, not by the spoofable `X-CMS-Actor` header. | +| 18 | Stale or out-of-order syncs | The client checks git ancestry (`merge-base --is-ancestor HEAD`), and the server does a compare-and-swap on the last synced commit. Coverage counts only **active** keys. | + +## 3. Findings that shape this plan + +Checked in this checkout before planning: + +1. **"The catalog" is the in-code object everywhere.** `isCatalogEntry`, + `validateFields`, `buildEntries`, `coverageReport`, orphan detection and the + "default text can't be deleted" rule all read it, and `createApp(catalog)` + passes it in. Tests pass a small `testCatalog`. All of these move to a + registry stored in D1. +2. **Shapes do one job:** per-collection field validation in + `src/fields.ts`, plus placeholder checks for `text`. Nothing public uses + them. The contract bundle type is `Record`. +3. **Nothing is deployed.** `wrangler.jsonc` still has + `REPLACE_WITH_STAGING_DATABASE_ID` / `REPLACE_WITH_ALPHA_DATABASE_ID`, and + `deploy.yml` is gated by `CMS_DEPLOY_ENABLED`. Rewriting `0001_init.sql` is + therefore safe. The additive-only rule applies again from the first remote + deploy. +4. **`revisions.subject` has a CHECK constraint** (`'translation','locale'`). + It can't be altered in place; the rewrite of `0001` fixes it. +5. **D1 limits the number of queries per Worker invocation** (50 on Free, 1,000 + on Paid; confirm against current Cloudflare docs during Phase 3). Today's + content is 6 collections, 204 keys and a 25 KB seed. A sync that uses one + statement per key, plus a revision row each, would exceed the limit. **Sync + must use set-based statements** over a JSON parameter (`INSERT … SELECT … + FROM json_each(?)`), so the statement count is fixed: about **18 per sync** + (5 reads + 13 writes, §8), whether the manifest has 3 keys or 20,000. That + is under the Free limit of 50 even if every statement in a batch counts + separately. At that point the practical limits are request CPU time (10 ms + on Workers Free) and D1 statement duration, not query count (see Risks). + _Verified in local D1:_ a single `json_each` statement inserts any number of + rows. +6. **A compare-and-swap that aborts the whole batch is possible in D1** with a + single-row table and a `BEFORE UPDATE` trigger that calls + `RAISE(ABORT, 'sync_conflict')`. + _Verified in local D1:_ the stale update fails with + `SQLITE_CONSTRAINT_TRIGGER`, and the row is unchanged. +7. **Request bodies are capped at 64 KB** (`src/write.ts`). A manifest will + outgrow that, so the sync route gets its own 1 MB cap. +8. **GitHub's default checkout is shallow** (`fetch-depth: 1`), so the + ancestry check needs full history in web's deploy jobs (§11). + +## 4. Target model + +**Shape** (CMS-owned, fixed): `named` `{name, insight, keywords}`, +`reference` `{insight, keywords}`, `text` `{text}`. Validation rules are +unchanged from design §5.2. + +**Collection:** a name plus a shape. It is created by sync, and its shape can +never change. + +**Key:** `(collection, key)`. A `text` key also has its placeholder set, +derived from the English text at creation and never changed afterwards. Each +key has a status: + +| Status | Meaning | Served publicly | Counted in coverage | Set by | +| --------- | ---------------------------------------- | --------------- | ------------------- | --------------------------------- | +| `active` | In the last synced manifest | yes | yes | sync (create, or reappears) | +| `unused` | No longer in the last synced manifest | yes (rollbacks) | listed separately | sync (absent); admin restore | +| `deleted` | Retired by an admin; name never reusable | no | no | admin delete (only from `unused`) | + +``` + sync: absent admin: delete + active ─────────────────► unused ─────────────────► deleted + ◄───────────────── ◄───────────────── + sync: present admin: restore + (same definition) +``` + +**Translation:** unchanged, apart from a new server-set +`origin ∈ {sync, editor}`. Sync may replace default-locale text only while its +`origin` is `sync`. Any admin `PUT` sets `editor`. + +**Sync head (per environment):** the web commit of the last successful sync. +It is used for ordering (the client's ancestry check) and for concurrency (the +server's compare-and-swap). + +## 5. Schema (`migrations/0001_init.sql`, rewritten) + +`locales` and `meta` are unchanged. The new or changed parts: + +```sql +CREATE TABLE collections ( + name TEXT PRIMARY KEY, + shape TEXT NOT NULL CHECK (shape IN ('named', 'reference', 'text')), + created_at TEXT NOT NULL +); + +CREATE TABLE keys ( + collection TEXT NOT NULL REFERENCES collections (name), + key TEXT NOT NULL, + placeholders TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(placeholders)), + status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'unused', 'deleted')), + created_at TEXT NOT NULL, + updated_at TEXT NOT NULL, + PRIMARY KEY (collection, key) +); + +CREATE TABLE translations ( + collection TEXT NOT NULL, + key TEXT NOT NULL, + locale TEXT NOT NULL REFERENCES locales (code) ON DELETE CASCADE, + fields TEXT NOT NULL CHECK (json_valid(fields)), + revision INTEGER NOT NULL DEFAULT 1, + origin TEXT NOT NULL CHECK (origin IN ('sync', 'editor')), + updated_at TEXT NOT NULL, + PRIMARY KEY (collection, key, locale), + FOREIGN KEY (collection, key) REFERENCES keys (collection, key) +); + +CREATE TABLE syncs ( + id INTEGER PRIMARY KEY, + commit_sha TEXT NOT NULL, + actor TEXT NOT NULL, + summary TEXT NOT NULL CHECK (json_valid(summary)), + created_at TEXT NOT NULL +); + +-- Single row; the trigger turns a stale `expected` into a batch abort. +CREATE TABLE sync_head ( + id INTEGER PRIMARY KEY CHECK (id = 1), + commit_sha TEXT, + expected TEXT, + updated_at TEXT +); +CREATE TRIGGER sync_head_cas BEFORE UPDATE ON sync_head +WHEN NEW.expected IS NOT OLD.commit_sha +BEGIN SELECT RAISE(ABORT, 'sync_conflict'); END; + +-- revisions: subject adds 'collection' and 'key'; action adds 'restore'; +-- new nullable sync_id REFERENCES syncs (id). +``` + +Seed rows: `meta.content_version = 1`, locale `en` (as today) and +`sync_head (1, NULL, NULL, NULL)`. + +## 6. Contract `@astrologyengine/cms-contract` 0.2.0 + +This is a breaking change; the version stays below 1.0, so it's a minor bump. +The package stays dependency-free. + +| Export | Contents | +| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `./shapes` | `Shape`, field types per shape, `validateFields(shape, fields)` → `{ ok } \| { ok: false, issues }`. This replaces the zod schemas in `src/fields.ts`, so CMS and web share one set of rules. | +| `./placeholders` | `placeholdersIn(text)`, `samePlaceholders(a, b)`, and type `PlaceholdersOf` (template literal inference: `"Hi {name}"` → `"name"`). | +| `./manifest` | `defineManifest()`, the `Manifest` types, and type helpers `TextKeys`, `ParamsOf`, `EntryOf`. Also `checkManifest(manifest, definitions)` → `{ ok, conflicts[], issues[], created[], reactivated[], unused[] }`. | +| `./definitions` | Wire type for `GET /v1/definitions`. | +| `./sync` | `SyncRequest`/`SyncResult` types, `fetchDefinitions(origin)`, `syncManifest({ origin, token, manifest, commit, expected })`. | +| `./locales`, `./types` | Unchanged. | +| `bin: cms-contract` | `check --manifest --against ` and `sync --manifest --origin [--force]`. Runs on Node ≥ 22 and needs `git` for `sync`. | +| **Removed** | `./catalog`, `./catalog-schema`, `./seed/en.json`. | + +Manifest as web will write it: + +```ts +import { defineManifest } from "@astrologyengine/cms-contract/manifest"; + +export const manifest = defineManifest({ + locale: "en", + collections: { + body: { + shape: "named", + entries: { + SUN: { name: "Sun", insight: "…", keywords: ["identity", "purpose"] }, + }, + }, + house: { + shape: "reference", + entries: { "1": { insight: "…", keywords: ["self"] } }, + }, + ui: { + shape: "text", + entries: { + "app.status.updating": "Showing {shown}; you asked for {requested}.", + }, + }, + }, +}); +// Web: t("app.status.updating", { shown, requested }) is type-checked. +// Missing or extra params are compile errors. +``` + +In `text` collections, each entry is a plain string, so TypeScript keeps the +literal type for placeholder inference. On the wire it becomes `{ text }`. + +`checkManifest` conflict codes: `shape_changed`, `placeholders_changed`, +`key_retired`, `locale_mismatch`, plus field or name `issues`. It compares +definitions only; it can't see `origin`, so text refresh is decided on the +server. + +**Sync client CLI** (`cms-contract sync`): + +1. `GET /v1/admin/sync` → head commit `H` (`null` on a fresh environment). +2. If `H` is set and differs from `HEAD`: if `H` isn't in local history, fail + with "fetch full history (`fetch-depth: 0`)". Otherwise, run + `git merge-base --is-ancestor H HEAD`, and refuse if it isn't an ancestor + (stale or out-of-order sync). `--force` skips this step only. +3. `POST /v1/admin/sync` with `{ commit: HEAD, expected: H, manifest }`. +4. Print the summary. Exit non-zero on `409`, `412` or `422`. + +The manifest file can be `.json`, or an ES module exporting `manifest` +(Node 24 strips TypeScript types). + +## 7. API changes + +**New** + +| Method & path | Auth | Description | +| ------------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `GET /v1/definitions` | public | Collections with shape; every key with `placeholders` and `status`, **deleted keys included** (needed for `key_retired`). No text. Cacheable, with `ETag: "v"` like other public routes. | +| `POST /v1/admin/sync` | admin | `{ commit, expected, manifest }`. Body limit 1 MB. Results: `200` with a summary (`created`, `reactivated`, `unused`, `refreshed`, `drift`). `409 definition_conflict` with `conflicts[]`. `412 precondition_failed` (stale `expected`). `422 validation_failed`. | +| `GET /v1/admin/sync` | admin | Current head `{ commit, syncedAt, actor } \| null` and the last 20 syncs. | +| `DELETE /v1/admin/entries/:collection/:key` | admin | Soft-delete. `409` unless the key is `unused`. Writes a `key/delete` revision. | +| `POST /v1/admin/entries/:collection/:key/restore` | admin | `deleted` → `unused`. Translations come back unchanged. Writes a `key/restore` revision. | + +**Changed** + +- `GET /v1/content/:locale` (and the single-entry route): serves `active` and + `unused` keys from the registry. `deleted` keys are omitted, or return `404` + (`unknown_entry`). The response shape is unchanged. +- `PUT …/translations/:locale`: validated against the registry (shape and + stored placeholders). Sets `origin = 'editor'`. `409` for `deleted` keys. +- `DELETE …/translations/:locale`: still refuses the default locale. There are + no orphans any more; deleted keys keep their rows for restore. +- `GET /v1/admin/entries/:collection/:key`: adds `status`. `inCatalog` is + removed. +- `GET /v1/admin/coverage`: `total`, `missing`, `fallbacks` and + `placeholderMismatches` count **active keys only**. `orphans` is replaced by + `unused: ["collection:key", …]`. + +**Removed:** `GET /v1/admin/catalog` (replaced by `GET /v1/definitions`). + +## 8. Sync algorithm (server) + +1. Authenticate, apply the 1 MB body limit, and parse the request. Validate the + manifest with the contract's `validateFields` and name rules (`422`). Check + that the manifest locale is the default locale. +2. Read the default locale, collections, keys, default-locale translations + (`origin`, `revision`, `fields`) and `sync_head`: **5 reads**. Run `checkManifest` against them, and answer `409` + on any conflict. +3. Build the change set: new collections; new keys (`active`, placeholders from + the text); English inserts (`origin = 'sync'`); English refreshes (where the + text differs and `origin = 'sync'`); `unused → active`; `active → unused` + for absent keys. `drift` lists keys whose English differs but has + `origin = 'editor'`; these are reported, never written. +4. Run **one batch of 13 statements**, each set-based over `json_each(?)` + where it touches many rows. The count doesn't depend on manifest size: + 1. `UPDATE sync_head SET commit_sha = ?, expected = ?` (the trigger aborts + on a stale `expected`, giving `412`). _(1)_ + 2. Insert collections; insert keys; reactivate keys (`unused → active`); + mark absent keys `active → unused`. _(4)_ + 3. Insert translations; refresh translations with a guard + `WHERE origin = 'sync' AND revision = ?`. An editor who saves during a + sync wins: that key isn't refreshed, and it's reported as drift. _(2)_ + 4. Insert the `syncs` row, then revisions for created collections, created + keys, created translations and refreshed translations (`actor` from + `X-CMS-Actor`, default `sync`; `sync_id` set). Revisions are written + only for rows that actually changed. _(5)_ + 5. Bump `content_version` once, and only if something changed. _(1)_ +5. A re-run with the same commit and the same manifest changes nothing and + doesn't bump the version. + +## 9. CI and release matrix (consumer behaviour) + +Feature PRs check against staging, release PRs check against alpha, and +deploys sync. Soft delete plus name retirement means that **alpha's definitions +are always a subset of staging's**, so the release PR check is a safety net +that should never fail. + +| Scenario | Feature PR (vs staging) | Main deploy (sync staging) | Release PR (vs alpha) | Release (sync alpha) | +| -------------------------------------------- | ---------------------------------- | --------------------------------- | --------------------- | ------------------------------------------------- | +| New key | ✅ | creates | ✅ | creates | +| Changed placeholders on an existing key | ❌ `placeholders_changed` | n/a | n/a | n/a | +| Two PRs add the same key differently | git conflict or duplicate property | n/a | n/a | n/a | +| Key removed from the manifest | ✅ | marks `unused` | ✅ | marks `unused` | +| Unused key re-added with the same definition | ✅ | reactivates | ✅ | reactivates | +| Deleted key re-added | ❌ `key_retired` | n/a | n/a | n/a | +| English typo fix, no editor change | ✅ | refreshes | ✅ | refreshes | +| English typo fix, editor already edited | ✅ | reported as `drift` | ✅ | reported as `drift` | +| Re-run of an old deploy | n/a | client refuses (not a descendant) | n/a | client refuses | +| Two syncs racing | n/a | second gets `412` | n/a | second gets `412` | +| Alpha rolled back to an older release | n/a | n/a | n/a | no sync needed: keys are never removed by deploys | + +## 10. Method + +Red/green TDD, as in `docs/plans/cms.md`: + +1. **Red:** the smallest test for the next behaviour. Confirm it fails for the + expected reason. Commit `test(scope): … [red]`. +2. **Green:** the least code that passes, with the whole suite green. Commit + `feat(scope): …`. +3. **Refactor** with the suite green. + +Refactors that don't change behaviour (Phase 2) rely on the existing suite and +must keep it green at every commit. Each phase is done when `bun run test`, +`check`, `lint`, `format:check` and `contract:test` are green. + +## Phase 1: Contract primitives (additive) + +Nothing in the Worker changes yet. + +1. `placeholders`: move `placeholdersIn`/`samePlaceholders` into the contract + and add `PlaceholdersOf`. Type tests use `expectTypeOf` and run under + `check`. They cover: none, one, repeated, adjacent, an invalid identifier + (ignored), and a 2,000-character string. +2. `shapes`: dependency-free `validateFields(shape, fields)` with exactly the + rules from design §5.2, ported from the zod schemas. Existing + `fields.test.ts` cases become its tests. The issue format stays + `{ path, message }`. +3. `manifest`: `defineManifest`, and the type helpers `TextKeys`, `ParamsOf`, + `EntryOf`. Type tests: an unknown key is an error, a missing or extra param + is an error, and non-text collections have no params. +4. `checkManifest`: one test per conflict code and per `created` / + `reactivated` / `unused` outcome, plus a `locale_mismatch` case. Name + rules: collections `^[a-z]+$`, and keys `^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$` + (same as today). + +**Done when** the contract builds with no runtime dependencies and its tests +and type tests pass. + +## Phase 2: Registry-backed Worker (refactor) + +1. Rewrite `0001_init.sql` as in §5. Reset local state + (`rm -rf .wrangler/state`). +2. Add `src/registry.ts` to load collections and keys. `createApp()` no longer + takes a catalog. `fields.ts` validates with the contract's `validateFields` + and the stored placeholders. +3. Test helpers: `defineTestRegistry({ … })` inserts collections and keys + matching today's `testCatalog`. `resetDb` also clears `keys`, + `collections`, `syncs` and `sync_head`. `addTranslation` takes an `origin`. +4. Existing behaviour tests stay green without changing their assertions. + +**Done when** the suite is green and `src/catalog.ts` / `src/catalog-schema.ts` +have no remaining Worker imports. + +## Phase 3: Sync endpoint (TDD) + +One red/green pair for each of these behaviours: + +1. `401` without a token; `413` above 1 MB; `422` for an invalid manifest or a + non-default locale. +2. A fresh sync creates collections, keys (`active`), English translations + (`origin = sync`), revisions (`sync_id` set), a `syncs` row and the head. It + bumps the version once. +3. Re-running the same commit and manifest is a no-op, with no version bump. +4. `409 definition_conflict` for `shape_changed`, `placeholders_changed` and + `key_retired`, with nothing written. +5. Absent keys become `unused`; a re-added unused key becomes `active`. +6. English refresh happens only while `origin = sync`; editor-changed keys are + reported in `drift` and left untouched. +7. A stale `expected` gives `412`, with **no partial writes** (every table is + unchanged). +8. An editor `PUT` landing between the read and the batch wins. This uses a + test seam in the sync service that runs a callback between steps 2 and 4. +9. **Scale:** a 2,000-key manifest syncs in one batch. Count every D1 + statement the request issues (reads and batch statements, through a + counting wrapper around the `DB` binding). Assert the count is identical + for 3 keys and for 2,000, and is **≤ 20**. +10. `GET /v1/admin/sync` returns the head and recent syncs. + +**Done when** all of the above are green. + +## Phase 4: Key lifecycle and editor writes (TDD) + +1. Admin `PUT` sets `origin = editor`, and validates against the stored shape + and placeholders. +2. `DELETE /v1/admin/entries/:c/:k`: `409` for `active` keys; `unused` → + `deleted`, with a revision. +3. `POST …/restore`: `deleted` → `unused`, with translations intact and a + revision. `409` for any other status. +4. Public bundle and single-entry routes: `active` and `unused` are served, + `deleted` is not. +5. `PUT` on a deleted key gives `409`. Deleting the default-locale translation + is still refused. +6. Coverage counts active keys only; `unused[]` replaces `orphans`. +7. Admin entry view returns `status`. `GET /v1/admin/catalog` is removed + (`404`). + +## Phase 5: Definitions endpoint and sync client (TDD) + +1. `GET /v1/definitions`: returns its shape, includes deleted keys, contains no + text, sends an `ETag` and answers `304`, and has CORS like the other public + routes. +2. Contract `fetchDefinitions`/`syncManifest`, tested with a stub `fetch`. +3. CLI `cms-contract check` and `cms-contract sync`, tested with + `node --test` against a temporary git repo and a local stub server. Cases: + first sync; a descendant; a non-descendant refused; `--force`; the head + missing from a shallow clone (clear error); `412` is reported; the exit + codes. +4. A `.json` manifest and a `.ts` module manifest both load. + +## Phase 6: Tooling cleanup + +1. Delete `packages/contract/src/catalog.ts`, `catalog-schema.ts`, + `seed/en.json`, `src/catalog*.ts`, `src/seed.ts`, `scripts/seed.ts`, and the + `seed:*` scripts. Replace `test/catalog.test.ts` and `test/seed.test.ts` + with the contract tests from Phase 1. +2. Add `examples/manifest.ts`: a few keys for each shape, for standalone + development. Add a `sync:local` script: + `cms-contract sync --manifest examples/manifest.ts --origin http://127.0.0.1:8787 --force` + (`--manifest` can be overridden). +3. `dev:e2e`: takes `--manifest ` (required). It resets state, applies + migrations, starts the Worker, waits for `/health`, syncs with `--force`, + then applies `--fixture` through the admin API. The fixture format is + unchanged. +4. `pack-contract.mjs`: ship `dist`, `bin` and `LICENSE`, with no `seed`. + Update `pack-contract.test.mjs`. +5. `deploy.yml`: drop the seed step. `smoke.mjs` still checks English + coverage, which is active keys only; it passes on a fresh environment with + no keys. Extend `contract:test` to the contract's CLI tests. +6. `wrangler deploy --dry-run --env staging` and `--env alpha` pass. + +## Phase 7: Docs and release + +1. Design doc: add a **rev. 3** section that summarises §2 and §4 of this + plan, and mark decision #9, §5.1 and §8 as superseded. +2. Runbook: + - First-time setup: no seed. After the CMS deploy, the first web sync (or a + manual `cms-contract sync`) fills the environment, and must run before the + web deploy. + - Routine deploys: migrate → deploy → smoke. + - Content operations: deleting and restoring keys; `drift` in sync output. + - Developer workflow for keys now lives in web; link the web docs. + - **Don't reset the staging database casually.** PR checks rely on it + keeping every definition. If it is lost or corrupted: + 1. **Time Travel first** (within 30 days on Paid, 7 on Free). It restores + staging's own history, so nothing is lost. + 2. **Otherwise, clone alpha:** + `wrangler d1 export DB --remote --env alpha`, then import it into an + empty staging database. Afterwards, **raise `content_version`** above + both databases' previous values. Otherwise web isolates holding a + staging `ETag "vN"` could get a `304` for different content. Then + **re-sync main** by re-running the latest main deploy. Alpha's sync + head is a release commit on main, so the ancestry check passes, and + the sync recreates every unreleased key from main's manifest. + 3. What a clone loses: staging-only edits and translations, staging-only + locales, staging revision history, and the definitions of keys that + were added and removed on main **between releases**. Those names could + then be reused without a conflict. That's harmless, because they never + reached alpha; the only thing affected is rolling staging back to one + of those intermediate commits. + - Recovery if main's history is rewritten: a one-off `--force` sync by an + admin, recorded in the incident notes. +3. README: setup becomes `migrate:local` → `dev` → `sync:local`. Update the + layout table and the API quick reference; "Adding copy" points to web. +4. A changeset for the contract (0.2.0, breaking), with a summary of the + migration for web. +5. Update the plan's status and add an "As built" section. + +## 11. Web handoff + +To be planned in the web repo. Order matters. + +1. **CMS first.** Merge this plan's work and publish contract **0.2.0**. Web + pinned to 0.1.x keeps working only against a CMS that hasn't been + redeployed; with deploys gated and nothing live, no compatibility window is + needed. +2. **Manifest.** Generate web's initial manifest once from the pinned 0.1.x + package (`catalog.ts` keys + `seed/en.json` text). After that it's edited by + hand. The `ui` naming convention test (`area.element[.variant]`, lower + camel case) moves into web's manifest tests. +3. **Copy helpers.** Type `t()` and the entry helpers from the manifest + (`TextKeys`, `ParamsOf`, `EntryOf`). A key missing from the CMS bundle falls + back to the **manifest English**, not the raw key. The snapshot fallback + (design §9.5) is unchanged. +4. **Main deploy** (staging): checkout with `fetch-depth: 0`; run + `cms-contract sync --origin https://cms-staging.astrologyengine.dev` with + `CMS_ADMIN_TOKEN` from the `staging` environment secret; then build the + snapshot and deploy. Syncing before deploy means new keys exist when the + new code goes live. +5. **Release deploy** (alpha): the same, against + `https://cms-alpha.astrologyengine.dev`. +6. **PR previews:** no sync and no admin token. New keys render from the + manifest English. +7. **Feature PR CI:** `cms-contract check --against `. **Release PR + CI** (the changesets release branch): `--against `. Gate both on + `CMS_DEPLOY_ENABLED` until the environments exist. +8. **Local:** `dev:stack` and Playwright call `dev:e2e --manifest `. +9. Remove the `$cms` catalog type import and the use of the `seed/en.json` + snapshot. + +## Risks + +| Risk | Mitigation | +| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| D1 per-invocation query limits | About 18 statements per sync whatever the size; the Phase 3 scale test asserts the count is identical for 3 and 2,000 keys and ≤ 20. | +| Request CPU time on large syncs (10 ms on Workers Free) | Today's 25 KB manifest is far below this. Measure sync CPU on staging with the real manifest during first provisioning; Workers Paid (30 s default) removes the concern. | +| The ancestry check runs in the client and can be bypassed | Only admin-token holders can sync. The server-side compare-and-swap still orders concurrent syncs. Revisit with OIDC during UI planning. | +| Admin token stored in web CI | Only in environment-scoped secrets for the main and release deploy jobs; never in PR workflows (the check uses the public endpoint). | +| Shallow CI clones break the ancestry check | The client fails with an explicit message; the handoff requires `fetch-depth: 0`. | +| Staging database lost or reset | Runbook: Time Travel first; otherwise clone alpha, raise `content_version`, re-sync main (Phase 7). The clone only forgets keys that were never released. | +| TypeScript performance with many template-literal placeholder types | Type test with a 2,000-character string and a 1,000-key manifest in Phase 1. Fallback: an explicit params annotation on individual keys. | +| Public definitions reveal unreleased key names | They're already public through the staging bundle. Definitions contain no text. | +| Key names get uglier over time (`…V2`) | Accepted in review; preferred over key versioning. | + +## Out of scope (follow-ups) + +- Admin UI, OAuth, and scoped roles (e.g. per-language translators, English + source editors). +- Replacing `CMS_ADMIN_TOKEN` in CI (e.g. GitHub OIDC). +- Flagging translations as outdated when their English changes. +- The web implementation (§11). +- Spanish content, and anything else already out of scope in the design. diff --git a/migrations/0001_init.sql b/migrations/0001_init.sql index 87d6fa8..b2c254a 100644 --- a/migrations/0001_init.sql +++ b/migrations/0001_init.sql @@ -1,4 +1,5 @@ --- CMS schema. See docs/designs/cms.md §6.1. Migrations are additive-only. +-- CMS schema. See docs/designs/cms.md §6.1 and docs/plans/web-owned-catalog.md §5. +-- Migrations are additive-only once an environment has been deployed. CREATE TABLE locales ( code TEXT PRIMARY KEY, @@ -11,27 +12,70 @@ CREATE TABLE locales ( ); CREATE UNIQUE INDEX locales_single_default ON locales (is_default) WHERE is_default = 1; +-- Key registry: web's manifest defines it; sync creates entries, never reshapes them. +CREATE TABLE collections ( + name TEXT PRIMARY KEY, + shape TEXT NOT NULL CHECK (shape IN ('named', 'reference', 'text')), + created_at TEXT NOT NULL +); + +CREATE TABLE keys ( + collection TEXT NOT NULL REFERENCES collections (name), + key TEXT NOT NULL, + placeholders TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(placeholders)), + status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'unused', 'deleted')), + created_at TEXT NOT NULL, + updated_at TEXT NOT NULL, + PRIMARY KEY (collection, key) +); + CREATE TABLE translations ( collection TEXT NOT NULL, key TEXT NOT NULL, locale TEXT NOT NULL REFERENCES locales (code) ON DELETE CASCADE, fields TEXT NOT NULL CHECK (json_valid(fields)), revision INTEGER NOT NULL DEFAULT 1, + -- Who last wrote the text: sync may refresh default-locale text only while 'sync'. + origin TEXT NOT NULL CHECK (origin IN ('sync', 'editor')), updated_at TEXT NOT NULL, - PRIMARY KEY (collection, key, locale) + PRIMARY KEY (collection, key, locale), + FOREIGN KEY (collection, key) REFERENCES keys (collection, key) ); CREATE INDEX translations_locale ON translations (locale); +CREATE TABLE syncs ( + id INTEGER PRIMARY KEY, + commit_sha TEXT NOT NULL, + actor TEXT NOT NULL, + summary TEXT NOT NULL CHECK (json_valid(summary)), + created_at TEXT NOT NULL +); + +-- Single row: the last synced web commit. An update must name the current +-- commit in `expected`; otherwise the trigger aborts the whole batch. +CREATE TABLE sync_head ( + id INTEGER PRIMARY KEY CHECK (id = 1), + commit_sha TEXT, + expected TEXT, + updated_at TEXT +); +CREATE TRIGGER sync_head_cas BEFORE UPDATE ON sync_head +WHEN NEW.expected IS NOT OLD.commit_sha +BEGIN + SELECT RAISE(ABORT, 'sync_conflict'); +END; + CREATE TABLE revisions ( id INTEGER PRIMARY KEY, - subject TEXT NOT NULL CHECK (subject IN ('translation', 'locale')), - action TEXT NOT NULL CHECK (action IN ('create', 'update', 'delete')), + subject TEXT NOT NULL CHECK (subject IN ('translation', 'locale', 'collection', 'key')), + action TEXT NOT NULL CHECK (action IN ('create', 'update', 'delete', 'restore')), collection TEXT, key TEXT, locale TEXT, before TEXT, after TEXT, actor TEXT NOT NULL, + sync_id INTEGER REFERENCES syncs (id), created_at TEXT NOT NULL ); CREATE INDEX revisions_lookup ON revisions (collection, key, locale, id); @@ -42,5 +86,6 @@ CREATE TABLE meta ( ); INSERT INTO meta (key, value) VALUES ('content_version', 1); +INSERT INTO sync_head (id, commit_sha, expected, updated_at) VALUES (1, NULL, NULL, NULL); INSERT INTO locales (code, name, enabled, is_default, fallback, created_at, updated_at) VALUES ('en', 'English', 1, 1, NULL, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), strftime('%Y-%m-%dT%H:%M:%fZ', 'now')); diff --git a/package.json b/package.json index 3ed77b4..10625b1 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ "seed:alpha": "bun run contract:build && bun scripts/seed.ts --env alpha", "deploy:staging": "bun run contract:build && wrangler deploy --env staging", "deploy:alpha": "bun run contract:build && wrangler deploy --env alpha", - "contract:build": "tsc -p packages/contract", + "contract:build": "tsc -p packages/contract && tsc -p packages/contract/tsconfig.cli.json", "contract:watch": "tsc -p packages/contract --watch --preserveWatchOutput", "contract:pack": "bun run contract:build && node scripts/pack-contract.mjs", - "contract:test": "node --test scripts/*.test.mjs", + "contract:test": "bun run contract:build && node --test scripts/*.test.mjs packages/contract/test/*.test.mjs", "validate": "bun run contract:build && bun run check && bun run lint && bun run format:check && bun run test && bun run contract:test", "version:release": "changeset version && node scripts/sync-version.mjs && bun install --lockfile-only && bun run format", "release:publish": "node scripts/publish-release.mjs", @@ -43,6 +43,7 @@ "@cloudflare/vitest-plugin": "1.1.13", "@cloudflare/workers-types": "5.20261029.1", "@types/bun": "1.3.14", + "@types/node": "26.6.6", "oxfmt": "0.76.0", "oxlint": "1.91.0", "typescript": "6.0.3", diff --git a/packages/contract/package.json b/packages/contract/package.json index 96b3286..bed0d9d 100644 --- a/packages/contract/package.json +++ b/packages/contract/package.json @@ -7,6 +7,9 @@ "url": "https://github.com/AstrologyEngine/cms.git", "directory": "packages/contract" }, + "bin": { + "cms-contract": "./dist/cli/main.js" + }, "files": [ "dist", "seed", @@ -26,6 +29,26 @@ "types": "./dist/locales.d.ts", "import": "./dist/locales.js" }, + "./placeholders": { + "types": "./dist/placeholders.d.ts", + "import": "./dist/placeholders.js" + }, + "./shapes": { + "types": "./dist/shapes.d.ts", + "import": "./dist/shapes.js" + }, + "./manifest": { + "types": "./dist/manifest.d.ts", + "import": "./dist/manifest.js" + }, + "./definitions": { + "types": "./dist/definitions.d.ts", + "import": "./dist/definitions.js" + }, + "./sync": { + "types": "./dist/sync.d.ts", + "import": "./dist/sync.js" + }, "./types": { "types": "./dist/types.d.ts", "import": "./dist/types.js" diff --git a/packages/contract/src/cli/errors.ts b/packages/contract/src/cli/errors.ts new file mode 100644 index 0000000..a03acac --- /dev/null +++ b/packages/contract/src/cli/errors.ts @@ -0,0 +1,11 @@ +/** A CLI failure with its exit code: 1 refused, 2 could not run. */ +export type CliError = Error & { name: "CliError"; exitCode: 1 | 2 }; + +export const cliError = (exitCode: 1 | 2, message: string): CliError => + Object.assign(new Error(message), { name: "CliError" as const, exitCode }); + +export const isCliError = (error: unknown): error is CliError => + error instanceof Error && + error.name === "CliError" && + "exitCode" in error && + (error.exitCode === 1 || error.exitCode === 2); diff --git a/packages/contract/src/cli/format.ts b/packages/contract/src/cli/format.ts new file mode 100644 index 0000000..15f938f --- /dev/null +++ b/packages/contract/src/cli/format.ts @@ -0,0 +1,24 @@ +import type { ManifestConflict, ManifestIssue } from "../manifest.js"; + +const set = (names: readonly string[]) => `{${names.join(", ")}}`; + +/** One line per conflict, with what to do about it. */ +export const describeConflict = (conflict: ManifestConflict) => { + switch (conflict.code) { + case "placeholders_changed": + return `${conflict.collection}:${conflict.key}: placeholders changed (CMS ${set(conflict.expected)}, manifest ${set(conflict.actual)}); use a new key name.`; + case "key_retired": + return `${conflict.collection}:${conflict.key}: retired by an admin; ask them to restore it, or use a new key name.`; + case "shape_changed": + return `${conflict.collection}: shape changed (${conflict.expected} → ${conflict.actual}); use a new collection name.`; + case "locale_mismatch": + return `manifest locale '${conflict.actual}' must be the CMS default '${conflict.expected}'.`; + } +}; + +export const describeIssue = ({ path, message }: ManifestIssue) => + `${path || "(manifest)"}: ${message}`; + +/** Indented bullet list under a heading. */ +export const section = (heading: string, lines: string[]) => + [heading, ...lines.map((line) => ` - ${line}`)].join("\n"); diff --git a/packages/contract/src/cli/git.ts b/packages/contract/src/cli/git.ts new file mode 100644 index 0000000..3944586 --- /dev/null +++ b/packages/contract/src/cli/git.ts @@ -0,0 +1,32 @@ +import { spawnSync } from "node:child_process"; +import { cliError } from "./errors.js"; + +const git = (cwd: string, ...args: string[]) => + spawnSync("git", args, { cwd, encoding: "utf8" }); + +/** Full SHA of HEAD in `cwd`. */ +export const headCommit = (cwd: string) => { + const result = git(cwd, "rev-parse", "--verify", "HEAD"); + if (result.status !== 0) + throw cliError( + 2, + `Not a git checkout with commits (${cwd}); run sync inside the checkout the manifest belongs to.`, + ); + return result.stdout.trim(); +}; + +/** Whether the commit is present in the local history. */ +export const hasCommit = (cwd: string, sha: string) => + git(cwd, "cat-file", "-e", `${sha}^{commit}`).status === 0; + +/** Whether `ancestor` is an ancestor of (or equal to) `descendant`. */ +export const isAncestor = ( + cwd: string, + ancestor: string, + descendant: string, +) => { + const result = git(cwd, "merge-base", "--is-ancestor", ancestor, descendant); + if (result.status === 0) return true; + if (result.status === 1) return false; + throw cliError(2, `git merge-base failed: ${result.stderr.trim()}`); +}; diff --git a/packages/contract/src/cli/load.ts b/packages/contract/src/cli/load.ts new file mode 100644 index 0000000..60908da --- /dev/null +++ b/packages/contract/src/cli/load.ts @@ -0,0 +1,46 @@ +import { readFile } from "node:fs/promises"; +import { extname, resolve } from "node:path"; +import { pathToFileURL } from "node:url"; +import { cliError } from "./errors.js"; + +const MODULES = new Set([".ts", ".mts", ".js", ".mjs"]); + +/** + * Read a manifest: `.json`, or an ES module (`.ts`/`.mts` need Node's type + * stripping, on by default from Node 22.18) exporting `manifest` or a default. + */ +export const loadManifest = async (file: string): Promise => { + const path = resolve(file); + if (MODULES.has(extname(path))) { + let module: Record; + try { + module = (await import(pathToFileURL(path).href)) as Record< + string, + unknown + >; + } catch (error) { + throw cliError( + 2, + `Cannot load manifest module ${path}: ${(error as Error).message}`, + ); + } + const manifest = module.manifest ?? module.default; + if (manifest === undefined) + throw cliError( + 2, + `Manifest module ${path} exports neither \`manifest\` nor a default.`, + ); + return manifest; + } + let text: string; + try { + text = await readFile(path, "utf8"); + } catch { + throw cliError(2, `Cannot read manifest ${path}.`); + } + try { + return JSON.parse(text); + } catch { + throw cliError(2, `Manifest ${path} is not valid JSON.`); + } +}; diff --git a/packages/contract/src/cli/main.ts b/packages/contract/src/cli/main.ts new file mode 100644 index 0000000..8471e3e --- /dev/null +++ b/packages/contract/src/cli/main.ts @@ -0,0 +1,181 @@ +#!/usr/bin/env node +/** + * cms-contract: check a manifest against a CMS, or sync it. + * + * cms-contract check --manifest --against + * cms-contract sync --manifest --origin [--actor ] [--force] + * + * `sync` reads the admin token from CMS_ADMIN_TOKEN and must run inside the + * git checkout whose HEAD the manifest belongs to. + * + * Exit codes: 0 success; 1 refused (conflicts, invalid manifest, stale or + * concurrent sync); 2 could not run (usage, token, file, git, network, auth). + */ +import { parseArgs } from "node:util"; +import { checkManifest } from "../manifest.js"; +import { + isCmsError, + type CmsError, + fetchDefinitions, + fetchSyncState, + syncManifest, +} from "../sync.js"; +import type { SyncResult } from "../sync.js"; +import type { ManifestConflict, ManifestIssue } from "../manifest.js"; +import { cliError, isCliError } from "./errors.js"; +import { describeConflict, describeIssue, section } from "./format.js"; +import { headCommit, hasCommit, isAncestor } from "./git.js"; +import { loadManifest } from "./load.js"; + +type Options = { + manifest?: string; + origin?: string; + against?: string; + actor?: string; + force: boolean; +}; + +const USAGE = `Usage: + cms-contract check --manifest --against + cms-contract sync --manifest --origin [--actor ] [--force]`; + +const required = (value: string | undefined, flag: string) => { + if (!value) throw cliError(2, `Missing ${flag}.\n${USAGE}`); + return value; +}; + +const short = (sha: string) => sha.slice(0, 12); + +const describeResult = (origin: string, result: SyncResult) => { + const lines = [ + `Synced ${short(result.commit)} to ${origin}: version ${result.version}${result.changed ? "" : " (no content changes)"}.`, + ]; + const lists: [string, string[]][] = [ + ["created collections", result.createdCollections], + ["created", result.created], + ["reactivated", result.reactivated], + ["now unused", result.unused], + ["refreshed", result.refreshed], + [ + "drift (editors changed the text; manifest text not applied)", + result.drift, + ], + ]; + for (const [label, ids] of lists) + if (ids.length) lines.push(` ${label}: ${ids.join(", ")}`); + return lines.join("\n"); +}; + +const sync = async (options: Options) => { + const origin = required(options.origin, "--origin"); + const file = required(options.manifest, "--manifest"); + const token = process.env.CMS_ADMIN_TOKEN ?? ""; + if (!token) throw cliError(2, "CMS_ADMIN_TOKEN is not set."); + const manifest = await loadManifest(file); + const cwd = process.cwd(); + const commit = headCommit(cwd); + const client = { origin, token, actor: options.actor }; + const { head } = await fetchSyncState(client); + const expected = head?.commit ?? null; + if (expected && expected !== commit && !options.force) { + if (!hasCommit(cwd, expected)) + throw cliError( + 2, + `The last synced commit ${short(expected)} is not in this checkout's history; fetch full history (e.g. actions/checkout with fetch-depth: 0).`, + ); + if (!isAncestor(cwd, expected, commit)) + throw cliError( + 1, + `HEAD ${short(commit)} does not descend from the last synced commit ${short(expected)}: this manifest is older than, or diverged from, what ${origin} has. Refusing to sync (use --force only to recover, e.g. after history was rewritten).`, + ); + } + const result = await syncManifest({ ...client, commit, expected, manifest }); + console.log(describeResult(origin, result)); + return 0; +}; + +/** CMS answers that mean "refused" (exit 1) rather than "could not run". */ +const REFUSALS = new Set([ + "definition_conflict", + "validation_failed", + "precondition_failed", +]); + +const describeCmsError = (error: CmsError) => { + const heading = `cms-contract: ${error.message} (${error.status} ${error.code})`; + const conflicts = (error.details.conflicts ?? []) as ManifestConflict[]; + const issues = (error.details.issues ?? []) as ManifestIssue[]; + if (conflicts.length) + return section(heading, conflicts.map(describeConflict)); + if (issues.length) return section(heading, issues.map(describeIssue)); + return heading; +}; + +const check = async (options: Options) => { + const origin = required(options.against, "--against"); + const manifest = await loadManifest(required(options.manifest, "--manifest")); + const definitions = await fetchDefinitions({ origin }); + const result = checkManifest(manifest, definitions); + if (!result.ok) { + const parts = [`cms-contract: manifest is not compatible with ${origin}.`]; + if (result.conflicts.length) + parts.push(section("Conflicts:", result.conflicts.map(describeConflict))); + if (result.issues.length) + parts.push(section("Issues:", result.issues.map(describeIssue))); + console.error(parts.join("\n")); + return 1; + } + const lines = [ + `Manifest is compatible with ${origin} (version ${definitions.version}).`, + ]; + const lists: [string, string[]][] = [ + ["would create collections", result.createdCollections], + ["would create", result.created], + ["would reactivate", result.reactivated], + ["would mark unused", result.unused], + ]; + for (const [label, ids] of lists) + if (ids.length) lines.push(` ${label}: ${ids.join(", ")}`); + console.log(lines.join("\n")); + return 0; +}; + +const commands: Record Promise> = { + check, + sync, +}; + +const main = async () => { + let parsed; + try { + parsed = parseArgs({ + allowPositionals: true, + options: { + manifest: { type: "string" }, + origin: { type: "string" }, + against: { type: "string" }, + actor: { type: "string" }, + force: { type: "boolean", default: false }, + }, + }); + } catch (error) { + throw cliError(2, `${(error as Error).message}\n${USAGE}`); + } + const [name] = parsed.positionals; + const command = + name && Object.hasOwn(commands, name) ? commands[name] : undefined; + if (!command) throw cliError(2, USAGE); + return command(parsed.values); +}; + +try { + process.exitCode = await main(); +} catch (error) { + if (isCliError(error)) { + console.error(`cms-contract: ${error.message}`); + process.exitCode = error.exitCode; + } else if (isCmsError(error)) { + console.error(describeCmsError(error)); + process.exitCode = REFUSALS.has(error.code) ? 1 : 2; + } else throw error; +} diff --git a/packages/contract/src/definitions.ts b/packages/contract/src/definitions.ts new file mode 100644 index 0000000..1edbd7a --- /dev/null +++ b/packages/contract/src/definitions.ts @@ -0,0 +1,15 @@ +/** Wire types for `GET /v1/definitions`: every collection and key, no text. */ +import type { Shape } from "./shapes.js"; + +export type KeyStatus = "active" | "unused" | "deleted"; +export type KeyDefinition = { placeholders: string[]; status: KeyStatus }; +export type CollectionDefinition = { + shape: Shape; + keys: Record; +}; +export type Definitions = { + /** The CMS default locale; a manifest must be written in it. */ + default: string; + version: number; + collections: Record; +}; diff --git a/packages/contract/src/manifest.ts b/packages/contract/src/manifest.ts new file mode 100644 index 0000000..c531d59 --- /dev/null +++ b/packages/contract/src/manifest.ts @@ -0,0 +1,268 @@ +/** + * The website's content manifest: collections, keys and approved default-locale + * text. Web owns it; deploys sync it to the CMS (docs/plans/web-owned-catalog.md). + */ +import type { Definitions } from "./definitions.js"; +import { canonicalLocale } from "./locales.js"; +import { + placeholdersIn, + samePlaceholders, + type PlaceholdersOf, +} from "./placeholders.js"; +import { + isShape, + validateFields, + type FieldsOf, + type Shape, +} from "./shapes.js"; + +type ManifestFields = { + readonly [F in keyof FieldsOf]: FieldsOf[F] extends string[] + ? readonly string[] + : FieldsOf[F]; +}; + +export type ManifestCollection = + | { + readonly shape: "named"; + readonly entries: { readonly [key: string]: ManifestFields<"named"> }; + } + | { + readonly shape: "reference"; + readonly entries: { readonly [key: string]: ManifestFields<"reference"> }; + } + | { + readonly shape: "text"; + /** Text entries are plain strings so their placeholders can be typed. */ + readonly entries: { readonly [key: string]: string }; + }; + +export type Manifest = { + readonly locale: string; + readonly collections: { readonly [name: string]: ManifestCollection }; +}; + +/** Identity helper that keeps literal types for key and placeholder inference. */ +export const defineManifest = (manifest: M): M => + manifest; + +type CollectionsMap = M["collections"]; + +/** Names of the manifest's collections. */ +export type CollectionsOf = keyof CollectionsMap & + string; + +/** Names of the manifest's `text` collections. */ +export type TextCollectionsOf = { + [C in CollectionsOf]: CollectionsMap[C]["shape"] extends "text" + ? C + : never; +}[CollectionsOf]; + +/** Keys of one collection. */ +export type KeysOf< + M extends Manifest, + C extends CollectionsOf, +> = keyof CollectionsMap[C]["entries"] & string; + +/** Keys of one `text` collection. */ +export type TextKeys< + M extends Manifest, + C extends TextCollectionsOf, +> = KeysOf; + +/** Parameters a text key's placeholders require, e.g. `{ name: string | number }`. */ +export type ParamsOf< + M extends Manifest, + C extends TextCollectionsOf, + K extends TextKeys, +> = { + [P in PlaceholdersOf[C]["entries"][K] & string>]: + | string + | number; +}; + +/** Fields the CMS serves for an entry (its collection shape's fields). */ +export type EntryOf< + M extends Manifest, + C extends CollectionsOf, + // Constrains K to the collection's keys; the fields depend on the shape only. + _K extends KeysOf, +> = FieldsOf[C]["shape"]>; + +export type ManifestConflict = + | { code: "locale_mismatch"; expected: string; actual: string } + | { + code: "shape_changed"; + collection: string; + expected: Shape; + actual: Shape; + } + | { + code: "placeholders_changed"; + collection: string; + key: string; + expected: string[]; + actual: string[]; + } + | { code: "key_retired"; collection: string; key: string }; + +export type ManifestIssue = { path: string; message: string }; + +export type ManifestCheck = { + ok: boolean; + conflicts: ManifestConflict[]; + issues: ManifestIssue[]; + /** New collections. */ + createdCollections: string[]; + /** New keys, as `collection:key`. */ + created: string[]; + /** Unused keys the manifest brings back, as `collection:key`. */ + reactivated: string[]; + /** Active keys the manifest no longer has, as `collection:key`. */ + unused: string[]; +}; + +const COLLECTION_NAME = /^[a-z]+$/; +const KEY_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/; + +const isRecord = (value: unknown): value is Record => + typeof value === "object" && value !== null && !Array.isArray(value); + +const own = (record: Record, name: string): T | undefined => + Object.hasOwn(record, name) ? record[name] : undefined; + +/** + * Compare a manifest with the CMS's definitions. Validates the manifest (it may + * be untrusted JSON) and reports definition conflicts. Pure; shared by the + * CMS sync endpoint and web's PR checks. Lists are sorted by collection, then key. + */ +export const checkManifest = ( + manifest: unknown, + definitions: Definitions, +): ManifestCheck => { + const result: ManifestCheck = { + ok: false, + conflicts: [], + issues: [], + createdCollections: [], + created: [], + reactivated: [], + unused: [], + }; + const issue = (path: string, message: string) => + result.issues.push({ path, message }); + const finish = () => { + result.ok = !result.conflicts.length && !result.issues.length; + return result; + }; + + if (!isRecord(manifest)) { + issue("", "Manifest must be an object."); + return finish(); + } + if (typeof manifest.locale !== "string") + issue("locale", "Required: the default locale's language tag."); + else { + const locale = canonicalLocale(manifest.locale); + if (!locale) issue("locale", "Not a valid language tag."); + else if (locale !== canonicalLocale(definitions.default)) + result.conflicts.push({ + code: "locale_mismatch", + expected: definitions.default, + actual: locale, + }); + } + if (!isRecord(manifest.collections)) { + issue("collections", "Must be an object of collections."); + return finish(); + } + + const present = new Set(); + for (const name of Object.keys(manifest.collections).sort()) { + const path = `collections.${name}`; + const collection = manifest.collections[name]; + if (!COLLECTION_NAME.test(name)) { + issue(path, "Collection names are lowercase letters only."); + continue; + } + if (!isRecord(collection)) { + issue(path, "Must be an object with shape and entries."); + continue; + } + const { shape, entries } = collection; + if (!isShape(shape)) { + issue(`${path}.shape`, "Must be one of: named, reference, text."); + continue; + } + if (!isRecord(entries)) { + issue(`${path}.entries`, "Must be an object of entries."); + continue; + } + const existing = own(definitions.collections, name); + const keys = Object.keys(entries).sort(); + for (const key of keys) present.add(`${name}:${key}`); + if (existing && existing.shape !== shape) { + result.conflicts.push({ + code: "shape_changed", + collection: name, + expected: existing.shape, + actual: shape, + }); + continue; + } + if (!existing) result.createdCollections.push(name); + + for (const key of keys) { + const keyPath = `${path}.entries.${key}`; + if (!KEY_NAME.test(key)) { + issue(keyPath, "Keys are 1–128 letters, digits, '.', '_' or '-'."); + continue; + } + const value = entries[key]; + let placeholders: string[] = []; + if (shape === "text") { + if (typeof value !== "string") { + issue(keyPath, "Text entries must be strings."); + continue; + } + const checked = validateFields("text", { text: value }); + if (!checked.ok) { + for (const { message } of checked.issues) issue(keyPath, message); + continue; + } + placeholders = placeholdersIn(value); + } else { + const checked = validateFields(shape, value); + if (!checked.ok) { + for (const { path: field, message } of checked.issues) + issue(field ? `${keyPath}.${field}` : keyPath, message); + continue; + } + } + + const id = `${name}:${key}`; + const definition = existing && own(existing.keys, key); + if (!definition) result.created.push(id); + else if (definition.status === "deleted") + result.conflicts.push({ code: "key_retired", collection: name, key }); + else if (!samePlaceholders(definition.placeholders, placeholders)) + result.conflicts.push({ + code: "placeholders_changed", + collection: name, + key, + expected: [...definition.placeholders], + actual: placeholders, + }); + else if (definition.status === "unused") result.reactivated.push(id); + } + } + + for (const name of Object.keys(definitions.collections).sort()) { + const keys = definitions.collections[name]!.keys; + for (const key of Object.keys(keys).sort()) + if (keys[key]!.status === "active" && !present.has(`${name}:${key}`)) + result.unused.push(`${name}:${key}`); + } + return finish(); +}; diff --git a/packages/contract/src/placeholders.ts b/packages/contract/src/placeholders.ts new file mode 100644 index 0000000..e860354 --- /dev/null +++ b/packages/contract/src/placeholders.ts @@ -0,0 +1,83 @@ +/** + * `{name}` placeholders in text copy (docs/designs/cms.md §5.4). Dependency-free: + * the CMS validates with these functions and the website derives types from them. + */ +const PLACEHOLDER = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g; + +/** Unique `{name}` placeholders in order of first appearance. */ +export const placeholdersIn = (text: string) => [ + ...new Set(Array.from(text.matchAll(PLACEHOLDER), (match) => match[1]!)), +]; + +export const samePlaceholders = ( + a: readonly string[], + b: readonly string[], +) => { + const left = new Set(a); + const right = new Set(b); + return left.size === right.size && [...left].every((name) => right.has(name)); +}; + +type Lower = + | "a" + | "b" + | "c" + | "d" + | "e" + | "f" + | "g" + | "h" + | "i" + | "j" + | "k" + | "l" + | "m" + | "n" + | "o" + | "p" + | "q" + | "r" + | "s" + | "t" + | "u" + | "v" + | "w" + | "x" + | "y" + | "z"; +type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; +type IdentifierStart = Lower | Uppercase | "_"; +type IdentifierPart = IdentifierStart | Digit; + +type IsIdentifierRest = S extends "" + ? true + : S extends `${infer C}${infer Rest}` + ? C extends IdentifierPart + ? IsIdentifierRest + : false + : false; + +type IsIdentifier = S extends `${infer C}${infer Rest}` + ? C extends IdentifierStart + ? IsIdentifierRest + : false + : false; + +/** Tail-recursive scan: first `{`, then up to the next `}`; innermost `{` wins. */ +type Scan< + S extends string, + Found extends string = never, +> = S extends `${string}{${infer Body}}${infer Rest}` + ? Body extends `${string}{${infer Inner}` + ? Scan<`{${Inner}}${Rest}`, Found> + : Scan extends true ? Found | Body : Found> + : Found; + +/** + * Placeholder names in a text literal, as a union: + * `PlaceholdersOf<"Hi {name}">` is `"name"`. Mirrors `placeholdersIn`; + * non-literal `string` gives `string`. + */ +export type PlaceholdersOf = string extends S + ? string + : Scan; diff --git a/packages/contract/src/shapes.ts b/packages/contract/src/shapes.ts new file mode 100644 index 0000000..32bec47 --- /dev/null +++ b/packages/contract/src/shapes.ts @@ -0,0 +1,83 @@ +/** + * Field shapes (docs/designs/cms.md §5.2). The CMS owns this fixed set; a + * collection names one. Dependency-free so the website can share the rules. + */ +export const shapes = ["named", "reference", "text"] as const; +export type Shape = (typeof shapes)[number]; + +export type NamedFields = { name: string; insight: string; keywords: string[] }; +export type ReferenceFields = { insight: string; keywords: string[] }; +export type TextFields = { text: string }; +export type FieldsOf = { + named: NamedFields; + reference: ReferenceFields; + text: TextFields; +}[S]; + +export type FieldIssue = { path: string; message: string }; +export type FieldsResult = + | { ok: true; fields: FieldsOf } + | { ok: false; issues: FieldIssue[] }; + +export const isShape = (value: unknown): value is Shape => + (shapes as readonly unknown[]).includes(value); + +type Rule = (value: unknown, path: string, issues: FieldIssue[]) => void; + +/** Plain text: 1–`max` characters, not blank, no leading/trailing whitespace. */ +const text = + (max: number): Rule => + (value, path, issues) => { + const fail = (message: string) => issues.push({ path, message }); + if (typeof value !== "string") return fail("Must be a string."); + if (!value.trim()) return fail("Must not be blank."); + if (value.length > max) return fail(`Must be at most ${max} characters.`); + if (value.trim() !== value) + return fail("Must not have leading or trailing whitespace."); + }; + +const keywords: Rule = (value, path, issues) => { + if (!Array.isArray(value)) + return issues.push({ path, message: "Must be a list of keywords." }); + if (value.length < 1 || value.length > 8) + issues.push({ path, message: "Must have 1–8 keywords." }); + value.forEach((keyword, index) => + text(50)(keyword, `${path}.${index}`, issues), + ); +}; + +const rules: Record> = { + named: { name: text(100), insight: text(2000), keywords }, + reference: { insight: text(2000), keywords }, + text: { text: text(2000) }, +}; + +const isRecord = (value: unknown): value is Record => + typeof value === "object" && value !== null && !Array.isArray(value); + +/** + * Validate fields for a shape (docs/designs/cms.md §5.2). Unknown fields are + * rejected. Reports every failing field, one issue per path; `path` is dotted + * (`keywords.1`) and empty for the whole value. + */ +export const validateFields = ( + shape: S, + fields: unknown, +): FieldsResult => { + if (!isRecord(fields)) + return { ok: false, issues: [{ path: "", message: "Must be an object." }] }; + const spec = rules[shape]; + const issues: FieldIssue[] = []; + for (const [name, rule] of Object.entries(spec)) { + if (Object.hasOwn(fields, name)) rule(fields[name], name, issues); + else issues.push({ path: name, message: "Required." }); + } + for (const name of Object.keys(fields)) + if (!Object.hasOwn(spec, name)) + issues.push({ path: name, message: "Unknown field." }); + if (issues.length) return { ok: false, issues }; + const clean = Object.fromEntries( + Object.keys(spec).map((name) => [name, fields[name]]), + ); + return { ok: true, fields: clean as FieldsOf }; +}; diff --git a/packages/contract/src/sync.ts b/packages/contract/src/sync.ts new file mode 100644 index 0000000..b7c2226 --- /dev/null +++ b/packages/contract/src/sync.ts @@ -0,0 +1,164 @@ +/** + * HTTP client for manifest sync (docs/plans/web-owned-catalog.md §6–8). + * Runtime-neutral (fetch only): used by the `cms-contract` CLI and usable from + * any script or Worker. + */ +import type { Definitions } from "./definitions.js"; + +export type SyncRequest = { + /** Full SHA of the web commit whose manifest is synced. */ + commit: string; + /** The last synced commit the client checked ancestry against, or null. */ + expected: string | null; + manifest: unknown; +}; + +export type SyncSummary = { + createdCollections: string[]; + created: string[]; + reactivated: string[]; + unused: string[]; + refreshed: string[]; + /** Keys whose manifest text differs from editor-changed CMS text. */ + drift: string[]; +}; + +export type SyncResult = SyncSummary & { + commit: string; + /** Whether content changed (and the content version was bumped). */ + changed: boolean; + version: number; +}; + +export type SyncState = { + head: { commit: string; syncedAt: string; actor: string } | null; + recent: { + id: number; + commit: string; + actor: string; + createdAt: string; + summary: SyncSummary; + }[]; +}; + +/** A failed CMS call: HTTP status (0 for network errors), CMS error code, details. */ +export type CmsError = Error & { + name: "CmsError"; + status: number; + code: string; + details: Record; +}; + +export const cmsError = ( + status: number, + code: string, + message: string, + details: Record = {}, +): CmsError => + Object.assign(new Error(message), { + name: "CmsError" as const, + status, + code, + details, + }); + +export const isCmsError = (error: unknown): error is CmsError => + error instanceof Error && + error.name === "CmsError" && + "status" in error && + typeof error.status === "number" && + "code" in error && + typeof error.code === "string" && + "details" in error && + typeof error.details === "object" && + error.details !== null; + +export type ClientOptions = { + /** CMS origin, e.g. https://cms-staging.astrologyengine.dev */ + origin: string; + fetch?: typeof fetch; + /** Per-request timeout; default 30 s. */ + timeoutMs?: number; +}; + +export type AdminOptions = ClientOptions & { + token: string; + /** Recorded as the revision actor (X-CMS-Actor); default "sync". */ + actor?: string; +}; + +/** `origin` + path, tolerating a trailing slash on the origin. */ +const urlOf = (origin: string, path: string) => + `${origin.replace(/\/+$/, "")}${path}`; + +const request = async ( + { origin, fetch: fetcher = fetch, timeoutMs = 30_000 }: ClientOptions, + path: string, + init: RequestInit = {}, +): Promise => { + let response: Response; + try { + response = await fetcher(urlOf(origin, path), { + ...init, + signal: AbortSignal.timeout(timeoutMs), + }); + } catch (error) { + throw cmsError( + 0, + "network_error", + `Could not reach ${origin}: ${error instanceof Error ? error.message : String(error)}`, + ); + } + const text = await response.text(); + let body: unknown; + try { + body = JSON.parse(text); + } catch { + body = undefined; + } + if (!response.ok) { + const error = (body as { error?: Record } | undefined) + ?.error; + if (error && typeof error.code === "string") { + const { code, message, ...details } = error; + throw cmsError(response.status, code, String(message), details); + } + throw cmsError( + response.status, + "http_error", + `${response.status} ${response.statusText || "error"} from ${path}: ${text.slice(0, 200)}`, + ); + } + return body as T; +}; + +const adminHeaders = ({ token, actor }: AdminOptions) => ({ + authorization: `Bearer ${token}`, + ...(actor ? { "x-cms-actor": actor } : {}), +}); + +/** Public definitions: every collection and key, no text. */ +export const fetchDefinitions = (options: ClientOptions) => + request(options, "/v1/definitions"); + +/** The last synced commit and recent syncs (admin). */ +export const fetchSyncState = (options: AdminOptions) => + request(options, "/v1/admin/sync", { + headers: adminHeaders(options), + }); + +/** Sync a manifest (admin). Throws CmsError on 409, 412, 422 and others. */ +export const syncManifest = ({ + commit, + expected, + manifest, + ...options +}: AdminOptions & SyncRequest) => + request(options, "/v1/admin/sync", { + method: "POST", + headers: { + ...adminHeaders(options), + "content-type": "application/json", + }, + body: JSON.stringify({ commit, expected, manifest }), + }); diff --git a/packages/contract/test/cli-check.test.mjs b/packages/contract/test/cli-check.test.mjs new file mode 100644 index 0000000..0396462 --- /dev/null +++ b/packages/contract/test/cli-check.test.mjs @@ -0,0 +1,119 @@ +import assert from "node:assert/strict"; +import { mkdtemp, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; +import { after, before, beforeEach, describe, test } from "node:test"; +import { manifest, run, startCms } from "./helpers.mjs"; + +let cms; +let dir; +before(async () => { + cms = await startCms(); + // Not a git checkout: check needs neither git nor a token. + dir = await mkdtemp(resolve(tmpdir(), "cms-cli-check-")); + await writeFile(resolve(dir, "manifest.json"), JSON.stringify(manifest)); +}); +after(async () => { + await cms.close(); + await rm(dir, { recursive: true, force: true }); +}); +beforeEach(() => { + cms.state.definitions = { default: "en", version: 4, collections: {} }; + cms.state.requests = []; +}); + +const check = (...extra) => + run( + ["check", "--manifest", "manifest.json", "--against", cms.origin, ...extra], + { + cwd: dir, + }, + ); + +describe("cms-contract check", () => { + test("rejects inherited object property names as commands", async () => { + const { status, stderr } = await run(["constructor"], { cwd: dir }); + assert.equal(status, 2); + assert.match(stderr, /Usage:/); + }); + + test("passes and lists what a sync would change", async () => { + cms.state.definitions.collections = { + ui: { + shape: "text", + keys: { + "app.title": { placeholders: [], status: "unused" }, + "app.gone": { placeholders: [], status: "active" }, + }, + }, + }; + const { status, stdout, stderr } = await check(); + assert.equal(status, 0, stderr); + assert.match(stdout, /Manifest is compatible with .* \(version 4\)/); + assert.match(stdout, /would create: ui:app\.count/); + assert.match(stdout, /would reactivate: ui:app\.title/); + assert.match(stdout, /would mark unused: ui:app\.gone/); + assert.deepEqual( + cms.state.requests.map((r) => `${r.method} ${r.url}`), + ["GET /v1/definitions"], + ); + assert.equal(cms.state.requests[0].headers.authorization, undefined); + }); + + test("fails with readable conflicts", async () => { + cms.state.definitions = { + default: "fr", + version: 4, + collections: { + ui: { + shape: "text", + keys: { + "app.count": { placeholders: ["count"], status: "active" }, + "app.title": { placeholders: [], status: "deleted" }, + }, + }, + }, + }; + const { status, stderr } = await check(); + assert.equal(status, 1); + assert.match(stderr, /manifest locale 'en' must be the CMS default 'fr'/); + assert.match( + stderr, + /ui:app\.count: placeholders changed \(CMS \{count\}, manifest \{n\}\)/, + ); + assert.match(stderr, /ui:app\.title: retired/); + }); + + test("fails for an invalid manifest", async () => { + const invalid = resolve(dir, "invalid.json"); + await writeFile( + invalid, + JSON.stringify({ + locale: "en", + collections: { ui: { shape: "text", entries: { x: " " } } }, + }), + ); + const { status, stderr } = await run( + ["check", "--manifest", invalid, "--against", cms.origin], + { cwd: dir }, + ); + assert.equal(status, 1); + assert.match(stderr, /collections\.ui\.entries\.x: Must not be blank\./); + }); + + test("exits 2 without --against or when the CMS is unreachable", async () => { + for (const args of [ + ["check", "--manifest", "manifest.json"], + [ + "check", + "--manifest", + "manifest.json", + "--against", + "http://127.0.0.1:9", + ], + ]) { + const { status, stderr } = await run(args, { cwd: dir }); + assert.equal(status, 2, stderr); + } + }); +}); diff --git a/packages/contract/test/cli-load.test.mjs b/packages/contract/test/cli-load.test.mjs new file mode 100644 index 0000000..077e631 --- /dev/null +++ b/packages/contract/test/cli-load.test.mjs @@ -0,0 +1,72 @@ +import assert from "node:assert/strict"; +import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; +import { after, before, describe, test } from "node:test"; +import { run, startCms } from "./helpers.mjs"; + +let cms; +let dir; +before(async () => { + cms = await startCms(); + dir = await mkdtemp(resolve(tmpdir(), "cms-cli-load-")); + // Like web: the manifest imports defineManifest from the installed contract. + await mkdir(resolve(dir, "node_modules/@astrologyengine"), { + recursive: true, + }); + await symlink( + resolve(import.meta.dirname, ".."), + resolve(dir, "node_modules/@astrologyengine/cms-contract"), + ); + await writeFile(resolve(dir, "package.json"), '{ "type": "module" }'); + await writeFile( + resolve(dir, "manifest.ts"), + `import { defineManifest } from "@astrologyengine/cms-contract/manifest"; +type Shape = "text"; +const shape: Shape = "text"; +export const manifest = defineManifest({ + locale: "en", + collections: { ui: { shape, entries: { "app.hello": "Hi {name}" } } }, +}); +`, + ); + await writeFile( + resolve(dir, "default.mjs"), + `export default { locale: "en", collections: { ui: { shape: "text", entries: { "app.bye": "Bye" } } } };`, + ); + await writeFile(resolve(dir, "neither.mjs"), "export const other = 1;"); + await writeFile(resolve(dir, "broken.json"), "{ not json"); +}); +after(async () => { + await cms.close(); + await rm(dir, { recursive: true, force: true }); +}); + +const check = (file) => + run(["check", "--manifest", file, "--against", cms.origin], { cwd: dir }); + +describe("manifest files", () => { + test("loads a TypeScript module exporting `manifest`", async () => { + const { status, stdout, stderr } = await check("manifest.ts"); + assert.equal(status, 0, stderr); + assert.match(stdout, /would create: ui:app\.hello/); + }); + + test("loads a module's default export", async () => { + const { status, stdout, stderr } = await check("default.mjs"); + assert.equal(status, 0, stderr); + assert.match(stdout, /would create: ui:app\.bye/); + }); + + test("exits 2 for modules without a manifest, bad JSON and missing files", async () => { + for (const [file, message] of [ + ["neither.mjs", /exports neither `manifest` nor a default/], + ["broken.json", /not valid JSON/], + ["missing.json", /Cannot read manifest/], + ]) { + const { status, stderr } = await check(file); + assert.equal(status, 2, stderr); + assert.match(stderr, message); + } + }); +}); diff --git a/packages/contract/test/cli-sync.test.mjs b/packages/contract/test/cli-sync.test.mjs new file mode 100644 index 0000000..9247000 --- /dev/null +++ b/packages/contract/test/cli-sync.test.mjs @@ -0,0 +1,261 @@ +import assert from "node:assert/strict"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; +import { after, before, beforeEach, describe, test } from "node:test"; +import { git, makeRepo, manifest, run, startCms, TOKEN } from "./helpers.mjs"; + +let repo; +let cms; +/** Extra temporary directories (worktrees, clones) removed after the run. */ +const temporary = []; +before(async () => { + repo = await makeRepo(); + cms = await startCms(); +}); +after(async () => { + await cms.close(); + await repo.cleanup(); + for (const dir of temporary) await rm(dir, { recursive: true, force: true }); +}); +beforeEach(() => { + cms.state.head = null; + cms.state.post = null; + cms.state.requests = []; +}); + +const sync = (...extra) => + run( + ["sync", "--manifest", "manifest.json", "--origin", cms.origin, ...extra], + { + cwd: repo.dir, + env: { CMS_ADMIN_TOKEN: TOKEN }, + }, + ); + +describe("cms-contract sync", () => { + test("first sync sends HEAD with expected null", async () => { + const { status, stdout, stderr } = await sync(); + assert.equal(status, 0, stderr); + const [post] = cms.posts(); + assert.deepEqual(post.body, { commit: repo.b, expected: null, manifest }); + assert.equal(post.headers.authorization, `Bearer ${TOKEN}`); + assert.match(stdout, new RegExp(`Synced ${repo.b.slice(0, 12)}`)); + assert.match(stdout, /version 5/); + assert.match(stdout, /created: ui:app\.count/); + }); + + test("a descendant of the last synced commit sends it as expected", async () => { + cms.state.head = repo.a; + const { status, stderr } = await sync(); + assert.equal(status, 0, stderr); + assert.deepEqual(cms.posts()[0].body.expected, repo.a); + assert.equal(cms.posts()[0].body.commit, repo.b); + }); + + test("re-syncing the last synced commit needs no ancestry check", async () => { + cms.state.head = repo.b; + const { status, stderr } = await sync(); + assert.equal(status, 0, stderr); + assert.equal(cms.posts()[0].body.expected, repo.b); + }); + + test("forwards --actor as X-CMS-Actor", async () => { + const { status, stderr } = await sync("--actor", "web-ci"); + assert.equal(status, 0, stderr); + assert.equal(cms.posts()[0].headers["x-cms-actor"], "web-ci"); + }); +}); + +describe("cms-contract sync refusals", () => { + test("refuses a HEAD that doesn't descend from the last synced commit", async () => { + cms.state.head = repo.b; + const { status, stderr } = await run( + ["sync", "--manifest", "manifest.json", "--origin", cms.origin], + { cwd: await checkout(repo.c), env: { CMS_ADMIN_TOKEN: TOKEN } }, + ); + assert.equal(status, 1); + assert.match(stderr, /does not descend from the last synced commit/); + assert.equal(cms.posts().length, 0); + }); + + test("asks for full history when the last synced commit isn't local", async () => { + cms.state.head = repo.a; + const { status, stderr } = await run( + ["sync", "--manifest", "manifest.json", "--origin", cms.origin], + { cwd: await shallowClone(), env: { CMS_ADMIN_TOKEN: TOKEN } }, + ); + assert.equal(status, 2); + assert.match(stderr, /fetch-depth: 0/); + assert.equal(cms.posts().length, 0); + }); + + test("--force skips the ancestry check but still sends the current head", async () => { + cms.state.head = repo.b; + const { status, stderr } = await run( + [ + "sync", + "--manifest", + "manifest.json", + "--origin", + cms.origin, + "--force", + ], + { cwd: await checkout(repo.c), env: { CMS_ADMIN_TOKEN: TOKEN } }, + ); + assert.equal(status, 0, stderr); + assert.deepEqual( + { + commit: cms.posts()[0].body.commit, + expected: cms.posts()[0].body.expected, + }, + { commit: repo.c, expected: repo.b }, + ); + }); +}); + +/** A worktree of the repo at `commit` (detached). */ +const checkout = async (commit) => { + const dir = await mkdtemp(resolve(tmpdir(), "cms-cli-worktree-")); + temporary.push(dir); + await rm(dir, { recursive: true }); + git(repo.dir, "worktree", "add", "-q", "--detach", dir, commit); + return dir; +}; + +/** A depth-1 clone of main (HEAD = B, without A in its history). */ +const shallowClone = async () => { + const dir = await mkdtemp(resolve(tmpdir(), "cms-cli-shallow-")); + temporary.push(dir); + git(dir, "clone", "-q", "--depth", "1", `file://${repo.dir}`, "clone"); + return resolve(dir, "clone"); +}; + +describe("cms-contract sync errors", () => { + test("prints definition conflicts and exits 1", async () => { + cms.state.post = { + status: 409, + body: { + error: { + code: "definition_conflict", + message: "The manifest changes existing definitions.", + conflicts: [ + { + code: "placeholders_changed", + collection: "ui", + key: "app.count", + expected: ["n"], + actual: ["count"], + }, + { code: "key_retired", collection: "ui", key: "app.old" }, + { + code: "shape_changed", + collection: "body", + expected: "named", + actual: "reference", + }, + ], + }, + }, + }; + const { status, stderr } = await sync(); + assert.equal(status, 1); + assert.match( + stderr, + /ui:app\.count: placeholders changed \(CMS \{n\}, manifest \{count\}\)/, + ); + assert.match(stderr, /ui:app\.old: retired/); + assert.match(stderr, /body: shape changed \(named → reference\)/); + }); + + test("prints manifest issues and exits 1", async () => { + cms.state.post = { + status: 422, + body: { + error: { + code: "validation_failed", + message: "Manifest is invalid.", + issues: [ + { + path: "manifest.collections.ui.entries.x", + message: "Must not be blank.", + }, + ], + }, + }, + }; + const { status, stderr } = await sync(); + assert.equal(status, 1); + assert.match( + stderr, + /manifest\.collections\.ui\.entries\.x: Must not be blank\./, + ); + }); + + test("reports a concurrent sync (412) and exits 1", async () => { + cms.state.post = { + status: 412, + body: { + error: { + code: "precondition_failed", + message: "Another sync happened first.", + }, + }, + }; + const { status, stderr } = await sync(); + assert.equal(status, 1); + assert.match(stderr, /Another sync happened first/); + }); + + test("exits 2 when it can't run", async () => { + const cases = [ + // wrong token + run(["sync", "--manifest", "manifest.json", "--origin", cms.origin], { + cwd: repo.dir, + env: { CMS_ADMIN_TOKEN: "wrong".repeat(10) }, + }), + // unreachable CMS + run( + [ + "sync", + "--manifest", + "manifest.json", + "--origin", + "http://127.0.0.1:9", + ], + { + cwd: repo.dir, + env: { CMS_ADMIN_TOKEN: TOKEN }, + }, + ), + // missing token + run(["sync", "--manifest", "manifest.json", "--origin", cms.origin], { + cwd: repo.dir, + }), + // not a git checkout + run( + [ + "sync", + "--manifest", + `${repo.dir}/manifest.json`, + "--origin", + cms.origin, + ], + { + cwd: tmpdir(), + env: { CMS_ADMIN_TOKEN: TOKEN }, + }, + ), + // missing flag + run(["sync", "--manifest", "manifest.json"], { + cwd: repo.dir, + env: { CMS_ADMIN_TOKEN: TOKEN }, + }), + ]; + for (const { status, stderr } of await Promise.all(cases)) { + assert.equal(status, 2, stderr); + assert.match(stderr, /^cms-contract: /); + } + assert.equal(cms.posts().length, 0); + }); +}); diff --git a/packages/contract/test/helpers.mjs b/packages/contract/test/helpers.mjs new file mode 100644 index 0000000..f82e8f5 --- /dev/null +++ b/packages/contract/test/helpers.mjs @@ -0,0 +1,144 @@ +/** Test helpers for the cms-contract CLI (run with `node --test`). */ +import { execFileSync, spawn } from "node:child_process"; +import { mkdtemp, rm, writeFile } from "node:fs/promises"; +import { createServer } from "node:http"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; + +export const CLI = resolve(import.meta.dirname, "../dist/cli/main.js"); +export const TOKEN = "t".repeat(40); + +export const manifest = { + locale: "en", + collections: { + ui: { + shape: "text", + entries: { "app.title": "Explorer", "app.count": "{n} left" }, + }, + }, +}; + +export const git = (cwd, ...args) => + execFileSync("git", args, { cwd, encoding: "utf8" }).trim(); + +/** + * A repository with main: A → B and a side branch C off A (not a descendant + * of B). HEAD is B. `manifest.json` is committed in each. + */ +export const makeRepo = async () => { + const dir = await mkdtemp(resolve(tmpdir(), "cms-cli-repo-")); + git(dir, "init", "-q", "-b", "main"); + git(dir, "config", "user.name", "Test"); + git(dir, "config", "user.email", "test@example.test"); + git(dir, "config", "commit.gpgsign", "false"); + const commit = async (message) => { + await writeFile(resolve(dir, "manifest.json"), JSON.stringify(manifest)); + await writeFile(resolve(dir, "log.txt"), message); + git(dir, "add", "."); + git(dir, "commit", "-q", "-m", message); + return git(dir, "rev-parse", "HEAD"); + }; + const a = await commit("A"); + git(dir, "checkout", "-q", "-b", "side"); + const c = await commit("C"); + git(dir, "checkout", "-q", "main"); + const b = await commit("B"); + return { + dir, + a, + b, + c, + cleanup: () => rm(dir, { recursive: true, force: true }), + }; +}; + +export const syncResult = (commit, overrides = {}) => ({ + commit, + changed: true, + version: 5, + createdCollections: [], + created: ["ui:app.count"], + reactivated: [], + unused: [], + refreshed: [], + drift: [], + ...overrides, +}); + +/** + * A stub CMS. `state.head` is the last synced commit; `state.post` overrides + * the POST /v1/admin/sync response ({ status, body }); `state.definitions` + * answers GET /v1/definitions. Every request is recorded. + */ +export const startCms = async () => { + const state = { + head: null, + post: null, + definitions: { default: "en", version: 4, collections: {} }, + requests: [], + }; + const server = createServer(async (request, response) => { + let raw = ""; + for await (const chunk of request) raw += chunk; + const record = { + method: request.method, + url: request.url, + headers: request.headers, + body: raw ? JSON.parse(raw) : undefined, + }; + state.requests.push(record); + const send = (status, body) => { + response.writeHead(status, { "content-type": "application/json" }); + response.end(JSON.stringify(body)); + }; + const admin = request.url.startsWith("/v1/admin/"); + if (admin && request.headers.authorization !== `Bearer ${TOKEN}`) + return send(401, { + error: { + code: "unauthorized", + message: "A valid admin token is required.", + }, + }); + if (request.method === "GET" && request.url === "/v1/definitions") + return send(200, state.definitions); + if (request.method === "GET" && request.url === "/v1/admin/sync") + return send(200, { + head: state.head + ? { + commit: state.head, + syncedAt: "2026-11-01T00:00:00.000Z", + actor: "sync", + } + : null, + recent: [], + }); + if (request.method === "POST" && request.url === "/v1/admin/sync") { + if (state.post) return send(state.post.status, state.post.body); + state.head = record.body.commit; + return send(200, syncResult(record.body.commit)); + } + send(404, { error: { code: "not_found", message: "Not found." } }); + }); + await new Promise((ready) => server.listen(0, "127.0.0.1", ready)); + const origin = `http://127.0.0.1:${server.address().port}`; + return { + origin, + state, + posts: () => state.requests.filter((r) => r.method === "POST"), + close: () => new Promise((done) => server.close(done)), + }; +}; + +/** Run the built CLI; resolves with { status, stdout, stderr }. */ +export const run = (args, { cwd, env = {} } = {}) => + new Promise((done) => { + const child = spawn(process.execPath, [CLI, ...args], { + cwd, + env: { PATH: process.env.PATH, HOME: process.env.HOME, ...env }, + }); + let stdout = ""; + let stderr = ""; + child.stdout.on("data", (chunk) => (stdout += chunk)); + child.stderr.on("data", (chunk) => (stderr += chunk)); + child.on("close", (status) => done({ status, stdout, stderr })); + }); diff --git a/packages/contract/tsconfig.cli.json b/packages/contract/tsconfig.cli.json new file mode 100644 index 0000000..f8ed663 --- /dev/null +++ b/packages/contract/tsconfig.cli.json @@ -0,0 +1,8 @@ +{ + // The CLI runs on Node; the rest of the contract stays runtime-neutral + // (tsconfig.json has no Node types and excludes src/cli). + "extends": "./tsconfig.json", + "compilerOptions": { "types": ["node"] }, + "include": ["src/cli"], + "exclude": [] +} diff --git a/packages/contract/tsconfig.json b/packages/contract/tsconfig.json index 597449c..fa55027 100644 --- a/packages/contract/tsconfig.json +++ b/packages/contract/tsconfig.json @@ -10,5 +10,6 @@ "types": [], "skipLibCheck": true }, - "include": ["src"] + "include": ["src"], + "exclude": ["src/cli"] } diff --git a/scripts/dev-e2e.ts b/scripts/dev-e2e.ts index 6c3c56e..efe882f 100644 --- a/scripts/dev-e2e.ts +++ b/scripts/dev-e2e.ts @@ -9,7 +9,8 @@ import { fileURLToPath } from "node:url"; */ import { readFileSync, rmSync, writeFileSync } from "node:fs"; import { parseArgs } from "node:util"; -import { seedSql, type SeedFile } from "../src/seed"; +import { catalog } from "@astrologyengine/cms-contract/catalog"; +import { registrySql, seedSql, type SeedFile } from "../src/seed"; const { values } = parseArgs({ options: { @@ -46,18 +47,20 @@ const literal = (value: string | null) => rmSync(persistTo, { recursive: true, force: true }); run(["d1", "migrations", "apply", "DB", "--local", "--persist-to", persistTo]); +const seededAt = new Date().toISOString(); execute( - seedSql( - JSON.parse( - readFileSync( - fileURLToPath( - import.meta.resolve("@astrologyengine/cms-contract/seed/en.json"), + registrySql(catalog, seededAt) + + seedSql( + JSON.parse( + readFileSync( + fileURLToPath( + import.meta.resolve("@astrologyengine/cms-contract/seed/en.json"), + ), + "utf8", ), - "utf8", - ), - ) as SeedFile, - new Date().toISOString(), - ), + ) as SeedFile, + seededAt, + ), ); if (values.fixture) { const fixture = JSON.parse(readFileSync(values.fixture, "utf8")) as { diff --git a/scripts/seed.ts b/scripts/seed.ts index 7581693..0f2546c 100644 --- a/scripts/seed.ts +++ b/scripts/seed.ts @@ -10,7 +10,8 @@ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { parseArgs } from "node:util"; -import { seedSql, type SeedFile } from "../src/seed"; +import { catalog } from "@astrologyengine/cms-contract/catalog"; +import { registrySql, seedSql, type SeedFile } from "../src/seed"; const { values } = parseArgs({ options: { @@ -64,7 +65,8 @@ export const applySql = ( if (import.meta.main) { const seed = JSON.parse(readFileSync(values.file!, "utf8")) as SeedFile; - applySql(seedSql(seed, new Date().toISOString()), { + const timestamp = new Date().toISOString(); + applySql(registrySql(catalog, timestamp) + seedSql(seed, timestamp), { local: values.local!, env: values.env, persistTo: values["persist-to"], diff --git a/src/app.ts b/src/app.ts index 75dedef..ec37378 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,18 +1,19 @@ import { Hono } from "hono"; import { requireAdmin } from "./auth"; -import type { Catalog } from "./catalog-schema"; import { cors } from "./cors"; import { contentVersion } from "./db"; import type { Bindings } from "./env"; import { apiError, isApiError, errorResponse } from "./http"; import { adminRoutes } from "./routes/admin"; +import { keyRoutes } from "./routes/keys"; import { publicRoutes } from "./routes/public"; +import { syncRoutes } from "./routes/sync"; export type AppEnv = { Bindings: Bindings }; const READ_METHODS = new Set(["GET", "HEAD", "OPTIONS"]); -export const createApp = (catalog: Catalog) => { +export const createApp = () => { const app = new Hono(); app.use(cors); @@ -39,8 +40,10 @@ export const createApp = (catalog: Catalog) => { }); app.use("/v1/admin/*", requireAdmin); - app.route("/", publicRoutes(catalog)); - app.route("/", adminRoutes(catalog)); + app.route("/", publicRoutes()); + app.route("/", adminRoutes()); + app.route("/", syncRoutes()); + app.route("/", keyRoutes()); app.notFound((c) => errorResponse(c, apiError(404, "not_found", "Not found.")), diff --git a/src/catalog-schema.ts b/src/catalog-schema.ts deleted file mode 100644 index 97b3083..0000000 --- a/src/catalog-schema.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "@astrologyengine/cms-contract/catalog-schema"; diff --git a/src/catalog.ts b/src/catalog.ts deleted file mode 100644 index 1b1b1d0..0000000 --- a/src/catalog.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "@astrologyengine/cms-contract/catalog"; diff --git a/src/content.ts b/src/content.ts index dfb791c..f78b532 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,5 +1,5 @@ -import type { Catalog } from "./catalog-schema"; import type { TranslationRecord } from "./db"; +import { servedCollections, type Registry } from "./registry"; type Fields = Record; @@ -15,9 +15,9 @@ export const resolveEntry = ( return null; }; -/** Bundle of all catalog entries resolved along `chain`. */ +/** Bundle of all served (active and unused) entries resolved along `chain`. */ export const buildEntries = ( - catalog: Catalog, + registry: Registry, chain: string[], rows: TranslationRecord[], ) => { @@ -28,9 +28,9 @@ export const buildEntries = ( } const entries: Record> = {}; const fallbacks: Record = {}; - for (const [collection, definition] of Object.entries(catalog)) { + for (const [collection, , keys] of servedCollections(registry)) { entries[collection] = {}; - for (const key of Object.keys(definition.keys)) { + for (const key of keys) { const id = `${collection}:${key}`; const resolved = resolveEntry(chain, byEntry.get(id) ?? []); if (!resolved) continue; diff --git a/src/coverage.ts b/src/coverage.ts index d993563..164de9a 100644 --- a/src/coverage.ts +++ b/src/coverage.ts @@ -1,19 +1,21 @@ -import type { Catalog } from "./catalog-schema"; import { resolveEntry } from "./content"; import type { Locale, TranslationRecord } from "./db"; -import { isCatalogEntry } from "./fields"; import { effectiveChain } from "./locales"; import { placeholdersIn, samePlaceholders } from "./placeholders"; +import { activeCollections, activeKey, type Registry } from "./registry"; -/** Coverage of the catalog per locale, plus orphaned translations. */ +/** + * Coverage of active keys per locale (what translators work on), plus the + * unused keys (no longer in the website's manifest, still served). + */ export const coverageReport = ( - catalog: Catalog, + registry: Registry, locales: Locale[], rows: TranslationRecord[], ) => { - const ids = Object.entries(catalog) - .flatMap(([collection, definition]) => - Object.keys(definition.keys).map((key) => `${collection}:${key}`), + const ids = activeCollections(registry) + .flatMap(([collection, , keys]) => + keys.map((key) => `${collection}:${key}`), ) .sort(); const byEntry = new Map(); @@ -22,10 +24,10 @@ export const coverageReport = ( byEntry.set(id, [...(byEntry.get(id) ?? []), row]); } const mismatched = (row: TranslationRecord) => { - const definition = catalog[row.collection]; - if (definition?.shape !== "text") return false; + if (registry[row.collection]?.shape !== "text") return false; + const definition = activeKey(registry, row.collection, row.key)!; const { text } = JSON.parse(row.fields) as { text: string }; - return !samePlaceholders(definition.keys[row.key]!, placeholdersIn(text)); + return !samePlaceholders(definition.placeholders, placeholdersIn(text)); }; return { @@ -57,13 +59,12 @@ export const coverageReport = ( complete: !missing.length && !placeholderMismatches.length, }; }), - orphans: rows - .filter((row) => !isCatalogEntry(catalog, row.collection, row.key)) - .map(({ collection, key, locale }) => ({ collection, key, locale })) - .sort((a, b) => - `${a.collection}:${a.key}:${a.locale}`.localeCompare( - `${b.collection}:${b.key}:${b.locale}`, - ), - ), + unused: Object.entries(registry) + .flatMap(([collection, { keys }]) => + Object.keys(keys) + .filter((key) => keys[key]!.status === "unused") + .map((key) => `${collection}:${key}`), + ) + .sort(), }; }; diff --git a/src/fields.ts b/src/fields.ts index b6430c2..fc73ded 100644 --- a/src/fields.ts +++ b/src/fields.ts @@ -1,27 +1,6 @@ -import { z } from "zod"; -import type { Catalog, Shape } from "./catalog-schema"; +import { validateFields as validateShape } from "@astrologyengine/cms-contract/shapes"; import { placeholdersIn, samePlaceholders } from "./placeholders"; - -const trimmed = (max: number) => - z - .string() - .min(1) - .max(max) - .refine((value) => value.trim() === value && value.trim().length > 0, { - message: "Must not be blank or have leading/trailing whitespace", - }); - -const keywords = z.array(trimmed(50)).min(1).max(8); - -export const shapeSchemas = { - named: z.strictObject({ - name: trimmed(100), - insight: trimmed(2000), - keywords, - }), - reference: z.strictObject({ insight: trimmed(2000), keywords }), - text: z.strictObject({ text: trimmed(2000) }), -} satisfies Record; +import { servedKey, type Registry } from "./registry"; export type FieldsResult = | { ok: true; fields: Record } @@ -32,42 +11,31 @@ export type FieldsResult = [detail: string]: unknown; }; -export const isCatalogEntry = ( - catalog: Catalog, - collection: string, - key: string, -) => - Object.hasOwn(catalog, collection) && - Object.hasOwn(catalog[collection]!.keys, key); - -/** Validate translation fields for a catalog entry. */ +/** Validate translation fields for a served (active or unused) key. */ export const validateFields = ( - catalog: Catalog, + registry: Registry, collection: string, key: string, fields: unknown, ): FieldsResult => { - if (!isCatalogEntry(catalog, collection, key)) + const definition = servedKey(registry, collection, key); + if (!definition) return { ok: false, code: "unknown_entry", - message: `'${collection}:${key}' is not in the catalog.`, + message: `'${collection}:${key}' is not registered.`, }; - const definition = catalog[collection]!; - const parsed = shapeSchemas[definition.shape].safeParse(fields); - if (!parsed.success) + const checked = validateShape(registry[collection]!.shape, fields); + if (!checked.ok) return { ok: false, code: "validation_failed", message: "Fields are invalid.", - issues: parsed.error.issues.map(({ path, message }) => ({ - path: path.join("."), - message, - })), + issues: checked.issues, }; - if ("text" in parsed.data) { - const expected = definition.keys[key]!; - const actual = placeholdersIn(parsed.data.text); + if ("text" in checked.fields) { + const expected = definition.placeholders; + const actual = placeholdersIn(checked.fields.text); if (!samePlaceholders(expected, actual)) return { ok: false, @@ -77,5 +45,5 @@ export const validateFields = ( actual, }; } - return { ok: true, fields: parsed.data }; + return { ok: true, fields: checked.fields }; }; diff --git a/src/http.ts b/src/http.ts index 9d34f34..b22ad24 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1,5 +1,6 @@ import type { Context } from "hono"; import type { ContentfulStatusCode } from "hono/utils/http-status"; +import type { z } from "zod"; export type ErrorCode = | "bad_request" @@ -11,6 +12,7 @@ export type ErrorCode = | "conflict" | "precondition_failed" | "placeholder_mismatch" + | "definition_conflict" | "fallback_cycle" | "method_not_allowed" | "unsupported_media_type" @@ -77,3 +79,16 @@ export const publicVersioned = async ( return c.body(null, 304); return c.json(await body()); }; + +/** Parse with a zod schema, or throw 422 validation_failed with its issues. */ +export const parse = (schema: z.ZodType, value: unknown): T => { + const parsed = schema.safeParse(value); + if (!parsed.success) + throw apiError(422, "validation_failed", "Request is invalid.", { + issues: parsed.error.issues.map(({ path, message }) => ({ + path: path.join("."), + message, + })), + }); + return parsed.data; +}; diff --git a/src/index.ts b/src/index.ts index 63aa405..08d8633 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ import { createApp } from "./app"; -import { catalog } from "./catalog"; -export default createApp(catalog); +export default createApp(); diff --git a/src/placeholders.ts b/src/placeholders.ts index 2c7d63a..f96a187 100644 --- a/src/placeholders.ts +++ b/src/placeholders.ts @@ -1,15 +1 @@ -const PLACEHOLDER = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g; - -/** Unique `{name}` placeholders in order of first appearance. */ -export const placeholdersIn = (text: string) => [ - ...new Set(Array.from(text.matchAll(PLACEHOLDER), (match) => match[1]!)), -]; - -export const samePlaceholders = ( - a: readonly string[], - b: readonly string[], -) => { - const left = new Set(a); - const right = new Set(b); - return left.size === right.size && [...left].every((name) => right.has(name)); -}; +export * from "@astrologyengine/cms-contract/placeholders"; diff --git a/src/registry.ts b/src/registry.ts new file mode 100644 index 0000000..b92eceb --- /dev/null +++ b/src/registry.ts @@ -0,0 +1,89 @@ +/** + * The key registry stored in D1 (docs/plans/web-owned-catalog.md §4): every + * collection with its shape and every key with its placeholders and status. + * It replaces the code-defined catalog. + */ +import type { + CollectionDefinition, + KeyDefinition, +} from "@astrologyengine/cms-contract/definitions"; +import type { Shape } from "@astrologyengine/cms-contract/shapes"; + +export type Registry = Record; + +type RegistryRow = { + name: string; + shape: Shape; + key: string | null; + placeholders: string | null; + status: KeyDefinition["status"] | null; +}; + +/** The whole registry, in one query. */ +export const loadRegistry = async (db: D1Database): Promise => { + const { results } = await db + .prepare( + `SELECT c.name, c.shape, k.key, k.placeholders, k.status + FROM collections c LEFT JOIN keys k ON k.collection = c.name + ORDER BY c.name, k.key`, + ) + .all(); + const registry: Registry = Object.create(null); + for (const row of results) { + const collection = (registry[row.name] ??= { shape: row.shape, keys: {} }); + if (row.key !== null) + collection.keys[row.key] = { + placeholders: JSON.parse(row.placeholders!) as string[], + status: row.status!, + }; + } + return registry; +}; + +type Statuses = readonly KeyDefinition["status"][]; +const ACTIVE: Statuses = ["active"]; +/** Served publicly and editable: unused keys stay live for older web builds. */ +const SERVED: Statuses = ["active", "unused"]; + +/** The key's definition, if it is registered. */ +export const findKey = ( + registry: Registry, + collection: string, + key: string, +): KeyDefinition | undefined => { + const keys = Object.hasOwn(registry, collection) + ? registry[collection]!.keys + : undefined; + return keys && Object.hasOwn(keys, key) ? keys[key] : undefined; +}; + +const keyWith = + (statuses: Statuses) => + (registry: Registry, collection: string, key: string) => { + const found = findKey(registry, collection, key); + return found && statuses.includes(found.status) ? found : undefined; + }; + +/** The key's definition if it is registered and active. */ +export const activeKey = keyWith(ACTIVE); +/** The key's definition if it is active or unused. */ +export const servedKey = keyWith(SERVED); + +const collectionsWith = (statuses: Statuses) => (registry: Registry) => + Object.entries(registry) + .map( + ([name, { shape, keys }]) => + [ + name, + shape, + Object.keys(keys).filter((key) => + statuses.includes(keys[key]!.status), + ), + ] as const, + ) + .filter(([, , keys]) => keys.length > 0); + +/** Active keys per collection (collections without any are omitted). */ +export const activeCollections = collectionsWith(ACTIVE); +/** Active and unused keys per collection (collections without any are omitted). */ +export const servedCollections = collectionsWith(SERVED); diff --git a/src/routes/admin.ts b/src/routes/admin.ts index 9eb9165..34bef19 100644 --- a/src/routes/admin.ts +++ b/src/routes/admin.ts @@ -1,7 +1,6 @@ import { Hono } from "hono"; import { z } from "zod"; import type { AppEnv } from "../app"; -import type { Catalog } from "../catalog-schema"; import { allTranslations, entryTranslations, @@ -10,14 +9,15 @@ import { type TranslationRecord, } from "../db"; import { coverageReport } from "../coverage"; -import { isCatalogEntry, validateFields } from "../fields"; -import { apiError } from "../http"; +import { validateFields } from "../fields"; +import { apiError, parse } from "../http"; import { canonicalLocale, defaultFallbackFor, effectiveChain, wouldCycle, } from "../locales"; +import { findKey, loadRegistry, type Registry } from "../registry"; import { actorOf, commitWrite, now, readJson } from "../write"; const localeCode = z.string().transform((value, ctx) => { @@ -52,18 +52,6 @@ const updateLocale = z message: "Provide at least one field", }); -const parse = (schema: z.ZodType, value: unknown): T => { - const parsed = schema.safeParse(value); - if (!parsed.success) - throw apiError(422, "validation_failed", "Request is invalid.", { - issues: parsed.error.issues.map(({ path, message }) => ({ - path: path.join("."), - message, - })), - }); - return parsed.data; -}; - const invalid = (message: string): never => { throw apiError(422, "validation_failed", message); }; @@ -143,7 +131,17 @@ const presentTranslation = (row: TranslationRecord) => ({ updatedAt: row.updated_at, }); -export const adminRoutes = (catalog: Catalog) => { +/** Translations of deleted keys are frozen until the key is restored. */ +const refuseDeleted = (registry: Registry, collection: string, key: string) => { + if (findKey(registry, collection, key)?.status === "deleted") + throw apiError( + 409, + "conflict", + `'${collection}:${key}' is deleted; restore it before editing.`, + ); +}; + +export const adminRoutes = () => { const routes = new Hono(); routes.get("/v1/admin/locales", async (c) => { @@ -298,14 +296,13 @@ export const adminRoutes = (catalog: Catalog) => { return c.body(null, 204); }); - routes.get("/v1/admin/catalog", (c) => c.json({ collections: catalog })); - routes.get("/v1/admin/coverage", async (c) => { - const [locales, rows] = await Promise.all([ + const [registry, locales, rows] = await Promise.all([ + loadRegistry(c.env.DB), listLocales(c.env.DB), allTranslations(c.env.DB), ]); - return c.json(coverageReport(catalog, locales, rows)); + return c.json(coverageReport(registry, locales, rows)); }); routes.get("/v1/admin/revisions", async (c) => { @@ -347,21 +344,23 @@ export const adminRoutes = (catalog: Catalog) => { routes.get("/v1/admin/entries/:collection/:key", async (c) => { const { collection, key } = c.req.param(); - const inCatalog = isCatalogEntry(catalog, collection, key); - const rows = await entryTranslations(c.env.DB, collection, key); - if (!inCatalog && !rows.length) + const [registry, rows] = await Promise.all([ + loadRegistry(c.env.DB), + entryTranslations(c.env.DB, collection, key), + ]); + const definition = findKey(registry, collection, key); + if (!definition) throw apiError( 404, "unknown_entry", - `'${collection}:${key}' is not in the catalog.`, + `'${collection}:${key}' is not registered.`, ); - const definition = inCatalog ? catalog[collection]! : null; return c.json({ collection, key, - inCatalog, - shape: definition?.shape ?? null, - placeholders: definition ? [...definition.keys[key]!] : [], + status: definition.status, + shape: registry[collection]!.shape, + placeholders: [...definition.placeholders], translations: rows.map(presentTranslation), }); }); @@ -375,8 +374,10 @@ export const adminRoutes = (catalog: Catalog) => { await listLocales(c.env.DB), c.req.param("locale"), ); + const registry = await loadRegistry(c.env.DB); + refuseDeleted(registry, collection, key); const validated = validateFields( - catalog, + registry, collection, key, await readJson(c), @@ -404,7 +405,7 @@ export const adminRoutes = (catalog: Catalog) => { match !== null ? db .prepare( - `UPDATE translations SET fields = ?, revision = revision + 1, updated_at = ? + `UPDATE translations SET fields = ?, revision = revision + 1, origin = 'editor', updated_at = ? ${where}${match === "any" ? "" : " AND revision = ?"} RETURNING revision`, ) .bind( @@ -417,12 +418,12 @@ export const adminRoutes = (catalog: Catalog) => { ) : db .prepare( - `INSERT INTO translations (collection, key, locale, fields, revision, updated_at) - VALUES (?, ?, ?, ?, 1, ?) + `INSERT INTO translations (collection, key, locale, fields, revision, origin, updated_at) + VALUES (?, ?, ?, ?, 1, 'editor', ?) ON CONFLICT (collection, key, locale) DO ${ createOnly ? "NOTHING" - : "UPDATE SET fields = excluded.fields, revision = translations.revision + 1, updated_at = excluded.updated_at" + : "UPDATE SET fields = excluded.fields, revision = translations.revision + 1, origin = 'editor', updated_at = excluded.updated_at" } RETURNING revision`, ) @@ -474,11 +475,12 @@ export const adminRoutes = (catalog: Catalog) => { : []; if (!locale || !existing) throw apiError(404, "not_found", "Translation does not exist."); - if (locale.isDefault && isCatalogEntry(catalog, collection, key)) + refuseDeleted(await loadRegistry(c.env.DB), collection, key); + if (locale.isDefault) throw apiError( 409, "conflict", - "Catalog entries keep their default-locale text; edit it instead.", + "Keys keep their default-locale text; edit it instead.", ); const match = ifMatch(c.req.header("if-match")); if (match === "never") preconditionFailed(); diff --git a/src/routes/keys.ts b/src/routes/keys.ts new file mode 100644 index 0000000..a305777 --- /dev/null +++ b/src/routes/keys.ts @@ -0,0 +1,99 @@ +/** + * Key lifecycle (docs/plans/web-owned-catalog.md §4): admins soft-delete + * unused keys and restore deleted ones. Sync owns active ↔ unused. + */ +import type { KeyStatus } from "@astrologyengine/cms-contract/definitions"; +import { Hono } from "hono"; +import type { AppEnv } from "../app"; +import { apiError } from "../http"; +import { actorOf, commitWrite, now } from "../write"; + +type KeyRow = { status: KeyStatus; placeholders: string }; + +const findKey = async (db: D1Database, collection: string, key: string) => { + const row = await db + .prepare( + "SELECT status, placeholders FROM keys WHERE collection = ? AND key = ?", + ) + .bind(collection, key) + .first(); + if (!row) + throw apiError( + 404, + "unknown_entry", + `'${collection}:${key}' is not registered.`, + ); + return { status: row.status, placeholders: JSON.parse(row.placeholders) }; +}; + +const changedMeanwhile = (): never => { + throw apiError(409, "conflict", "The key's status changed; re-read it."); +}; + +export const keyRoutes = () => { + const routes = new Hono(); + + routes.delete("/v1/admin/entries/:collection/:key", async (c) => { + const { collection, key } = c.req.param(); + const actor = actorOf(c); + const current = await findKey(c.env.DB, collection, key); + if (current.status !== "unused") + throw apiError( + 409, + "conflict", + current.status === "active" + ? "Active keys are in use by the website; only unused keys can be deleted." + : "The key is already deleted.", + ); + const { version } = await commitWrite( + c.env.DB, + [ + c.env.DB.prepare( + "UPDATE keys SET status = 'deleted', updated_at = ? WHERE collection = ? AND key = ? AND status = 'unused'", + ).bind(now(), collection, key), + ], + { + subject: "key", + action: "delete", + collection, + key, + before: current, + after: { ...current, status: "deleted" }, + actor, + }, + { guard: true }, + ); + if (version === null) changedMeanwhile(); + return c.body(null, 204); + }); + + routes.post("/v1/admin/entries/:collection/:key/restore", async (c) => { + const { collection, key } = c.req.param(); + const actor = actorOf(c); + const current = await findKey(c.env.DB, collection, key); + if (current.status !== "deleted") + throw apiError(409, "conflict", "Only deleted keys can be restored."); + const { version } = await commitWrite( + c.env.DB, + [ + c.env.DB.prepare( + "UPDATE keys SET status = 'unused', updated_at = ? WHERE collection = ? AND key = ? AND status = 'deleted'", + ).bind(now(), collection, key), + ], + { + subject: "key", + action: "restore", + collection, + key, + before: current, + after: { ...current, status: "unused" }, + actor, + }, + { guard: true }, + ); + if (version === null) changedMeanwhile(); + return c.json({ collection, key, status: "unused" }); + }); + + return routes; +}; diff --git a/src/routes/public.ts b/src/routes/public.ts index cda8467..e9e768a 100644 --- a/src/routes/public.ts +++ b/src/routes/public.ts @@ -1,6 +1,6 @@ import { Hono, type Context } from "hono"; +import type { Definitions } from "@astrologyengine/cms-contract/definitions"; import type { AppEnv } from "../app"; -import type { Catalog } from "../catalog-schema"; import { buildEntries, resolveEntry } from "../content"; import { contentVersion, @@ -8,9 +8,9 @@ import { listLocales, translationsIn, } from "../db"; -import { isCatalogEntry } from "../fields"; import { apiError, publicVersioned } from "../http"; import { canonicalLocale, effectiveChain } from "../locales"; +import { loadRegistry, servedKey } from "../registry"; /** The enabled locale named in the path, with its chain; 404 otherwise. */ const availableLocale = async (c: Context, requested: string) => { @@ -33,7 +33,7 @@ const availableLocale = async (c: Context, requested: string) => { }; }; -export const publicRoutes = (catalog: Catalog) => { +export const publicRoutes = () => { const routes = new Hono(); routes.get("/v1/locales", async (c) => @@ -53,17 +53,37 @@ export const publicRoutes = (catalog: Catalog) => { }), ); + // Every collection and key (deleted ones too, so web's PR checks can spot + // retired names), without text. Key names are public through bundles anyway. + routes.get("/v1/definitions", async (c) => { + const version = await contentVersion(c.env.DB); + return publicVersioned(c, version, async () => { + const [registry, locales] = await Promise.all([ + loadRegistry(c.env.DB), + listLocales(c.env.DB), + ]); + return { + default: locales.find((locale) => locale.isDefault)!.code, + version, + collections: registry, + } satisfies Definitions; + }); + }); + routes.get("/v1/content/:locale", async (c) => { const locale = await availableLocale(c, c.req.param("locale")); const version = await contentVersion(c.env.DB); return publicVersioned(c, version, async () => { - const rows = await translationsIn(c.env.DB, locale.chain); + const [registry, rows] = await Promise.all([ + loadRegistry(c.env.DB), + translationsIn(c.env.DB, locale.chain), + ]); return { locale: locale.code, default: locale.defaultCode, chain: locale.chain, version, - ...buildEntries(catalog, locale.chain, rows), + ...buildEntries(registry, locale.chain, rows), }; }); }); @@ -71,11 +91,11 @@ export const publicRoutes = (catalog: Catalog) => { routes.get("/v1/content/:locale/:collection/:key", async (c) => { const { collection, key } = c.req.param(); const locale = await availableLocale(c, c.req.param("locale")); - if (!isCatalogEntry(catalog, collection, key)) + if (!servedKey(await loadRegistry(c.env.DB), collection, key)) throw apiError( 404, "unknown_entry", - `'${collection}:${key}' is not in the catalog.`, + `'${collection}:${key}' is not registered.`, ); return publicVersioned(c, await contentVersion(c.env.DB), async () => { const rows = await entryTranslations( diff --git a/src/routes/sync.ts b/src/routes/sync.ts new file mode 100644 index 0000000..08d6781 --- /dev/null +++ b/src/routes/sync.ts @@ -0,0 +1,21 @@ +import { Hono } from "hono"; +import type { AppEnv } from "../app"; +import { parse } from "../http"; +import { runSync, SYNC_MAX_BYTES, syncRequest, syncState } from "../sync"; +import { actorOf, readJson } from "../write"; + +export const syncRoutes = () => { + const routes = new Hono(); + + routes.post("/v1/admin/sync", async (c) => { + // Sync is recorded as 'sync' unless the caller names itself. + const actor = + c.req.header("x-cms-actor") === undefined ? "sync" : actorOf(c); + const request = parse(syncRequest, await readJson(c, SYNC_MAX_BYTES)); + return c.json(await runSync(c.env.DB, request, actor)); + }); + + routes.get("/v1/admin/sync", async (c) => c.json(await syncState(c.env.DB))); + + return routes; +}; diff --git a/src/seed.ts b/src/seed.ts index 46173e9..db99418 100644 --- a/src/seed.ts +++ b/src/seed.ts @@ -10,13 +10,46 @@ export type SeedFile = { const literal = (value: string) => `'${value.replaceAll("'", "''")}'`; +/** Catalog-shaped key definitions: collection → shape and key → placeholders. */ +export type CatalogLike = Record< + string, + { shape: string; keys: Record } +>; + +/** + * Registry rows for a code-defined catalog, inserted only when missing. + * Transitional: replaced by manifest sync (docs/plans/web-owned-catalog.md). + */ +export const registrySql = (catalog: CatalogLike, timestamp: string) => { + const lines: string[] = []; + for (const [collection, { shape, keys }] of Object.entries(catalog)) { + lines.push( + `INSERT INTO collections (name, shape, created_at) VALUES (${[collection, shape, timestamp].map(literal).join(", ")}) ON CONFLICT (name) DO NOTHING;`, + ); + for (const [key, placeholders] of Object.entries(keys)) + lines.push( + `INSERT INTO keys (collection, key, placeholders, status, created_at, updated_at) VALUES (${[ + collection, + key, + JSON.stringify(placeholders), + "active", + timestamp, + timestamp, + ] + .map(literal) + .join(", ")}) ON CONFLICT (collection, key) DO NOTHING;`, + ); + } + return `${lines.join("\n")}\n`; +}; + /** One statement per line (JSON escapes newlines inside values). */ export const seedSql = (seed: SeedFile, timestamp: string) => { const lines: string[] = []; for (const [collection, entries] of Object.entries(seed.entries)) for (const [key, fields] of Object.entries(entries)) lines.push( - `INSERT INTO translations (collection, key, locale, fields, revision, updated_at) VALUES (${[ + `INSERT INTO translations (collection, key, locale, fields, revision, origin, updated_at) VALUES (${[ collection, key, seed.locale, @@ -25,7 +58,7 @@ export const seedSql = (seed: SeedFile, timestamp: string) => { .map(literal) .join( ", ", - )}, 1, ${literal(timestamp)}) ON CONFLICT (collection, key, locale) DO NOTHING;`, + )}, 1, 'sync', ${literal(timestamp)}) ON CONFLICT (collection, key, locale) DO NOTHING;`, ); lines.push( `UPDATE meta SET value = value + 1 WHERE key = 'content_version' AND EXISTS (SELECT 1 FROM translations WHERE updated_at = ${literal(timestamp)});`, diff --git a/src/sync.ts b/src/sync.ts new file mode 100644 index 0000000..70b0ba6 --- /dev/null +++ b/src/sync.ts @@ -0,0 +1,413 @@ +/** + * Manifest sync (docs/plans/web-owned-catalog.md §8): web's deploys register + * collections and keys and fill in default-locale text. Never overwrites text + * an editor changed. + */ +import { + checkManifest, + type Manifest, +} from "@astrologyengine/cms-contract/manifest"; +import type { + SyncResult, + SyncState, + SyncSummary, +} from "@astrologyengine/cms-contract/sync"; +import { z } from "zod"; +import { listLocales } from "./db"; +import { apiError } from "./http"; +import { placeholdersIn } from "./placeholders"; +import { loadRegistry } from "./registry"; +import { now } from "./write"; + +export const SYNC_MAX_BYTES = 1024 * 1024; + +const commitSha = z + .string() + .regex(/^[0-9a-f]{40}$/, "Must be a full, lowercase commit SHA."); + +export const syncRequest = z.strictObject({ + commit: commitSha, + /** The commit of the last sync the client checked ancestry against. */ + expected: commitSha.nullable(), + manifest: z.unknown().refine((value) => value !== undefined, "Required."), +}); +export type SyncRequest = z.infer; + +export type SyncHooks = { + /** Test seam: runs after reading state and before the write batch. */ + beforeWrite?: () => Promise; +}; + +const invalid = (issues: { path: string; message: string }[]): never => { + throw apiError(422, "validation_failed", "Manifest is invalid.", { issues }); +}; + +type Entry = { + collection: string; + key: string; + fields: Record; + placeholders: string[]; +}; + +/** Wire entries of a validated manifest, sorted by collection, then key. */ +const entriesOf = (manifest: Manifest): Entry[] => + Object.keys(manifest.collections) + .sort() + .flatMap((collection) => { + const { shape, entries } = manifest.collections[collection]!; + return Object.keys(entries) + .sort() + .map((key) => { + const value = (entries as Record)[key]; + return shape === "text" + ? { + collection, + key, + fields: { text: value as string }, + placeholders: placeholdersIn(value as string), + } + : { + collection, + key, + fields: value as Record, + placeholders: [], + }; + }); + }); + +/** JSON with object keys sorted, so field order doesn't count as a change. */ +const canonical = (value: unknown): string => + JSON.stringify(value, (_key, inner: unknown) => + inner && typeof inner === "object" && !Array.isArray(inner) + ? Object.fromEntries( + Object.entries(inner).sort(([a], [b]) => (a < b ? -1 : 1)), + ) + : inner, + ); + +type StoredText = { + collection: string; + key: string; + fields: string; + origin: "sync" | "editor"; + revision: number; +}; + +/** A property of the current `json_each(?) j` element. */ +const field = (name: string) => `json_extract(j.value, '$.${name}')`; + +/** `collection:key` → parts; collection names never contain ':'. */ +const splitId = (id: string) => { + const at = id.indexOf(":"); + return { collection: id.slice(0, at), key: id.slice(at + 1) }; +}; + +/** + * Run the sync batch. The first statement updates sync_head; its trigger + * aborts the whole (atomic) batch when `expected` isn't the current head. + */ +const writeBatch = async ( + db: D1Database, + statements: D1PreparedStatement[], +) => { + try { + return await db.batch(statements); + } catch (error) { + if (String(error).includes("sync_conflict")) + throw apiError( + 412, + "precondition_failed", + "Another sync happened first; re-check ancestry against the new head and retry.", + ); + throw error; + } +}; + +/** Move the listed keys from one status to another, in one statement. */ +const setStatus = ( + db: D1Database, + ids: string[], + from: "active" | "unused", + to: "active" | "unused", + timestamp: string, +) => + db + .prepare( + `UPDATE keys SET status = ?2, updated_at = ?3 + WHERE status = ?4 AND (collection, key) IN ( + SELECT ${field("collection")}, ${field("key")} FROM json_each(?1) j)`, + ) + .bind(JSON.stringify(ids.map(splitId)), to, timestamp, from); + +/** Columns of a revision row written by sync; the sync row is the newest one. */ +const REVISION = `INSERT INTO revisions (subject, action, collection, key, locale, before, after, actor, sync_id, created_at)`; +const SYNC_ID = "(SELECT max(id) FROM syncs)"; + +export const runSync = async ( + db: D1Database, + request: SyncRequest, + actor: string, + hooks: SyncHooks = {}, +): Promise => { + const [locales, registry, state] = await Promise.all([ + listLocales(db), + loadRegistry(db), + db + .prepare( + `SELECT (SELECT commit_sha FROM sync_head WHERE id = 1) AS head, + (SELECT value FROM meta WHERE key = 'content_version') AS version`, + ) + .first<{ head: string | null; version: number }>(), + ]); + if (request.expected !== state!.head) + throw apiError( + 412, + "precondition_failed", + "Another sync happened first; re-check ancestry against the new head and retry.", + ); + const defaultLocale = locales.find((locale) => locale.isDefault)!.code; + const check = checkManifest(request.manifest, { + default: defaultLocale, + version: 0, + collections: registry, + }); + const issues = check.issues.map(({ path, message }) => ({ + path: path ? `manifest.${path}` : "manifest", + message, + })); + for (const conflict of check.conflicts) + if (conflict.code === "locale_mismatch") + issues.push({ + path: "manifest.locale", + message: `Must be the default locale '${conflict.expected}'.`, + }); + if (issues.length) invalid(issues); + if (check.conflicts.length) + throw apiError( + 409, + "definition_conflict", + "The manifest changes existing definitions; use new key names instead.", + { conflicts: check.conflicts }, + ); + + const manifest = request.manifest as Manifest; + const entries = entriesOf(manifest); + const { results: stored } = await db + .prepare( + "SELECT collection, key, fields, origin, revision FROM translations WHERE locale = ?", + ) + .bind(defaultLocale) + .all(); + const storedById = new Map( + stored.map((row) => [`${row.collection}:${row.key}`, row]), + ); + const refresh: (Entry & { revision: number; before: unknown })[] = []; + const drift: string[] = []; + for (const entry of entries) { + const id = `${entry.collection}:${entry.key}`; + const row = storedById.get(id); + if (!row || canonical(JSON.parse(row.fields)) === canonical(entry.fields)) + continue; + if (row.origin === "sync") + refresh.push({ + ...entry, + revision: row.revision, + before: JSON.parse(row.fields), + }); + else drift.push(id); + } + const created = new Set(check.created); + const newCollections = check.createdCollections.map((name) => ({ + name, + shape: manifest.collections[name]!.shape, + })); + const newKeys = entries.filter((entry) => + created.has(`${entry.collection}:${entry.key}`), + ); + const summary = { + createdCollections: check.createdCollections, + created: check.created, + reactivated: check.reactivated, + unused: check.unused, + refreshed: refresh.map(({ collection, key }) => `${collection}:${key}`), + drift, + }; + const changed = Object.entries(summary).some( + ([name, list]) => name !== "drift" && list.length > 0, + ); + if (!changed && request.commit === state!.head) + return { + commit: request.commit, + changed, + version: state!.version, + ...summary, + }; + + await hooks.beforeWrite?.(); + const timestamp = now(); + const json = (value: unknown) => JSON.stringify(value); + // Order matters: the head update must come first (its trigger guards the + // batch), the sync row before revisions (they reference it), and writes + // before the revisions that select the rows they changed. + const statements = { + head: db + .prepare( + "UPDATE sync_head SET commit_sha = ?, expected = ?, updated_at = ? WHERE id = 1", + ) + .bind(request.commit, request.expected, timestamp), + sync: db + .prepare( + "INSERT INTO syncs (commit_sha, actor, summary, created_at) VALUES (?, ?, ?, ?)", + ) + .bind(request.commit, actor, json(summary), timestamp), + collections: db + .prepare( + `INSERT INTO collections (name, shape, created_at) + SELECT ${field("name")}, ${field("shape")}, ?2 FROM json_each(?1) j`, + ) + .bind(json(newCollections), timestamp), + keys: db + .prepare( + `INSERT INTO keys (collection, key, placeholders, status, created_at, updated_at) + SELECT ${field("collection")}, ${field("key")}, ${field("placeholders")}, 'active', ?2, ?2 + FROM json_each(?1) j`, + ) + .bind(json(newKeys), timestamp), + reactivate: setStatus(db, check.reactivated, "unused", "active", timestamp), + unuse: setStatus(db, check.unused, "active", "unused", timestamp), + insertText: db + .prepare( + `INSERT INTO translations (collection, key, locale, fields, revision, origin, updated_at) + SELECT ${field("collection")}, ${field("key")}, ?2, ${field("fields")}, 1, 'sync', ?3 + FROM json_each(?1) j WHERE true + ON CONFLICT (collection, key, locale) DO NOTHING`, + ) + .bind(json(entries), defaultLocale, timestamp), + refreshText: db + .prepare( + // MATERIALIZED keeps the JSON as the outer loop: each element then + // finds its row by primary key instead of scanning the array per row. + `WITH j AS MATERIALIZED ( + SELECT ${field("collection")} AS collection, ${field("key")} AS key, + ${field("fields")} AS fields, ${field("revision")} AS revision + FROM json_each(?1) j + ) + UPDATE translations + SET fields = j.fields, revision = translations.revision + 1, updated_at = ?3 + FROM j + WHERE translations.collection = j.collection AND translations.key = j.key + AND translations.locale = ?2 AND translations.origin = 'sync' + AND translations.revision = j.revision + RETURNING translations.collection AS collection, translations.key AS key`, + ) + .bind(json(refresh), defaultLocale, timestamp), + collectionRevisions: db + .prepare( + `${REVISION} + SELECT 'collection', 'create', ${field("name")}, NULL, NULL, NULL, + json_object('shape', ${field("shape")}), ?2, ${SYNC_ID}, ?3 + FROM json_each(?1) j`, + ) + .bind(json(newCollections), actor, timestamp), + keyRevisions: db + .prepare( + `${REVISION} + SELECT 'key', 'create', ${field("collection")}, ${field("key")}, NULL, NULL, + json_object('placeholders', json(${field("placeholders")})), ?2, ${SYNC_ID}, ?3 + FROM json_each(?1) j`, + ) + .bind(json(newKeys), actor, timestamp), + createRevisions: db + .prepare( + `${REVISION} + SELECT 'translation', 'create', t.collection, t.key, t.locale, NULL, t.fields, ?3, ${SYNC_ID}, ?4 + FROM json_each(?1) j CROSS JOIN translations t + ON t.collection = ${field("collection")} AND t.key = ${field("key")} + WHERE t.locale = ?2 AND t.origin = 'sync' AND t.revision = 1 AND t.updated_at = ?4 + ORDER BY t.collection, t.key`, + ) + .bind(json(entries), defaultLocale, actor, timestamp), + refreshRevisions: db + .prepare( + `${REVISION} + SELECT 'translation', 'update', t.collection, t.key, t.locale, json(${field("before")}), t.fields, ?3, ${SYNC_ID}, ?4 + FROM json_each(?1) j CROSS JOIN translations t + ON t.collection = ${field("collection")} AND t.key = ${field("key")} + WHERE t.locale = ?2 AND t.origin = 'sync' AND t.updated_at = ?4 + AND t.revision = ${field("revision")} + 1 + ORDER BY t.collection, t.key`, + ) + .bind(json(refresh), defaultLocale, actor, timestamp), + version: db + .prepare( + "UPDATE meta SET value = value + ? WHERE key = 'content_version' RETURNING value", + ) + .bind(changed ? 1 : 0), + }; + const names = Object.keys(statements) as (keyof typeof statements)[]; + const batch = await writeBatch(db, Object.values(statements)); + const result = (name: keyof typeof statements) => + batch[names.indexOf(name)]!.results as T[]; + + // An editor who saved between our read and the batch wins: the guarded + // update skipped their row, so report it as drift instead. + const refreshed = new Set( + result<{ collection: string; key: string }>("refreshText").map( + ({ collection, key }) => `${collection}:${key}`, + ), + ); + const lost = summary.refreshed.filter((id) => !refreshed.has(id)); + if (lost.length) { + summary.refreshed = summary.refreshed.filter((id) => refreshed.has(id)); + summary.drift = [...summary.drift, ...lost].sort(); + await db + .prepare( + "UPDATE syncs SET summary = ? WHERE id = (SELECT max(id) FROM syncs WHERE commit_sha = ?)", + ) + .bind(json(summary), request.commit) + .run(); + } + const version = result<{ value: number }>("version")[0]!.value; + return { commit: request.commit, changed, version, ...summary }; +}; + +type SyncRecord = { + id: number; + commit_sha: string; + actor: string; + summary: string; + created_at: string; +}; + +/** The last synced commit and the 20 most recent syncs, newest first. */ +export const syncState = async (db: D1Database): Promise => { + const [head, { results }] = await Promise.all([ + db + .prepare("SELECT commit_sha FROM sync_head WHERE id = 1") + .first<{ commit_sha: string | null }>(), + db + .prepare( + "SELECT id, commit_sha, actor, summary, created_at FROM syncs ORDER BY id DESC LIMIT 20", + ) + .all(), + ]); + // Every head change writes its syncs row in the same batch. + const current = results.find((row) => row.commit_sha === head?.commit_sha); + return { + head: + head?.commit_sha && current + ? { + commit: current.commit_sha, + syncedAt: current.created_at, + actor: current.actor, + } + : null, + recent: results.map((row) => ({ + id: row.id, + commit: row.commit_sha, + actor: row.actor, + createdAt: row.created_at, + summary: JSON.parse(row.summary) as SyncSummary, + })), + }; +}; diff --git a/src/write.ts b/src/write.ts index 855aba3..bf83f8e 100644 --- a/src/write.ts +++ b/src/write.ts @@ -5,7 +5,10 @@ import { apiError } from "./http"; export const MAX_BODY_BYTES = 64 * 1024; /** Parse a JSON request body, enforcing content type and size. */ -export const readJson = async (c: Context): Promise => { +export const readJson = async ( + c: Context, + maxBytes = MAX_BODY_BYTES, +): Promise => { const type = c.req.header("content-type")?.split(";")[0]?.trim(); if (type !== "application/json") throw apiError( @@ -14,9 +17,9 @@ export const readJson = async (c: Context): Promise => { "Content-Type must be application/json.", ); const declared = Number(c.req.header("content-length") ?? 0); - if (declared > MAX_BODY_BYTES) tooLarge(); + if (declared > maxBytes) tooLarge(maxBytes); const bytes = await c.req.arrayBuffer(); - if (bytes.byteLength > MAX_BODY_BYTES) tooLarge(); + if (bytes.byteLength > maxBytes) tooLarge(maxBytes); try { return JSON.parse(new TextDecoder().decode(bytes)); } catch { @@ -24,8 +27,12 @@ export const readJson = async (c: Context): Promise => { } }; -const tooLarge = (): never => { - throw apiError(413, "payload_too_large", "Body exceeds 64 KB."); +const tooLarge = (maxBytes: number): never => { + throw apiError( + 413, + "payload_too_large", + `Body exceeds ${maxBytes / 1024} KB.`, + ); }; /** The informational actor from X-CMS-Actor (1–64 printable chars). */ @@ -45,8 +52,8 @@ export const actorOf = (c: Context) => { export const now = () => new Date().toISOString(); export type Revision = { - subject: "translation" | "locale"; - action: "create" | "update" | "delete"; + subject: "translation" | "locale" | "collection" | "key"; + action: "create" | "update" | "delete" | "restore"; collection?: string | null; key?: string | null; locale?: string | null; diff --git a/test/admin-keys.test.ts b/test/admin-keys.test.ts new file mode 100644 index 0000000..1346392 --- /dev/null +++ b/test/admin-keys.test.ts @@ -0,0 +1,147 @@ +import { env } from "cloudflare:workers"; +import { beforeEach, describe, expect, it } from "vitest"; +import { + addTranslation, + admin, + registerKeys, + resetDb, + revisions, + version, +} from "./helpers"; +import { sun } from "./fixtures"; + +beforeEach(async () => { + await resetDb(); + // PLUTO: unused with English text; VULCAN: already deleted. + await addTranslation("body", "PLUTO", "en", { ...sun, name: "Pluto" }); + await registerKeys({ + body: { + shape: "named", + keys: { VULCAN: { placeholders: [], status: "deleted" } }, + }, + }); +}); + +const entry = (collection: string, key: string) => + `/v1/admin/entries/${collection}/${key}`; +const status = async (collection: string, key: string) => + ( + await env.DB.prepare( + "SELECT status FROM keys WHERE collection = ? AND key = ?", + ) + .bind(collection, key) + .first<{ status: string }>() + )?.status; + +describe("DELETE /v1/admin/entries/:collection/:key", () => { + const remove = (collection: string, key: string) => + admin(entry(collection, key), { + method: "DELETE", + headers: { "x-cms-actor": "amy" }, + }); + + it("soft-deletes an unused key, keeping its text for restore", async () => { + const before = await version(); + const response = await remove("body", "PLUTO"); + expect(response.status).toBe(204); + expect(await status("body", "PLUTO")).toBe("deleted"); + expect( + await env.DB.prepare( + "SELECT locale FROM translations WHERE key = 'PLUTO'", + ).all(), + ).toMatchObject({ results: [{ locale: "en" }] }); + expect(await version()).toBe(before + 1); + const [last] = (await revisions()).slice(-1); + expect(last).toMatchObject({ + subject: "key", + action: "delete", + collection: "body", + key: "PLUTO", + locale: null, + actor: "amy", + }); + expect(JSON.parse(last!.before!)).toEqual({ + status: "unused", + placeholders: [], + }); + expect(JSON.parse(last!.after!)).toEqual({ + status: "deleted", + placeholders: [], + }); + }); + + it.each([ + ["an active key", "SUN"], + ["an already deleted key", "VULCAN"], + ])("refuses %s with 409", async (_label, key) => { + const before = await status("body", key); + const response = await remove("body", key); + expect(response.status).toBe(409); + expect(await response.json()).toMatchObject({ + error: { code: "conflict" }, + }); + expect(await status("body", key)).toBe(before); + }); + + it("answers 404 unknown_entry for unregistered keys", async () => { + const response = await remove("body", "NIBIRU"); + expect(response.status).toBe(404); + expect(await response.json()).toMatchObject({ + error: { code: "unknown_entry" }, + }); + }); +}); + +describe("POST /v1/admin/entries/:collection/:key/restore", () => { + const restore = (collection: string, key: string) => + admin(`${entry(collection, key)}/restore`, { + method: "POST", + headers: { "x-cms-actor": "amy" }, + }); + + it("restores a deleted key as unused, with its text intact", async () => { + await admin(entry("body", "PLUTO"), { method: "DELETE" }); + const before = await version(); + const response = await restore("body", "PLUTO"); + expect(response.status).toBe(200); + expect(await response.json()).toEqual({ + collection: "body", + key: "PLUTO", + status: "unused", + }); + expect(await status("body", "PLUTO")).toBe("unused"); + expect( + await env.DB.prepare( + "SELECT fields FROM translations WHERE key = 'PLUTO' AND locale = 'en'", + ).first<{ fields: string }>(), + ).toEqual({ fields: JSON.stringify({ ...sun, name: "Pluto" }) }); + expect(await version()).toBe(before + 1); + const [last] = (await revisions()).slice(-1); + expect(last).toMatchObject({ + subject: "key", + action: "restore", + collection: "body", + key: "PLUTO", + actor: "amy", + }); + expect(JSON.parse(last!.after!)).toEqual({ + status: "unused", + placeholders: [], + }); + }); + + it.each([ + ["an active key", "SUN"], + ["an unused key", "PLUTO"], + ])("refuses %s with 409", async (_label, key) => { + const response = await restore("body", key); + expect(response.status).toBe(409); + expect(await response.json()).toMatchObject({ + error: { code: "conflict" }, + }); + }); + + it("answers 404 unknown_entry for unregistered keys", async () => { + expect((await restore("body", "NIBIRU")).status).toBe(404); + }); +}); diff --git a/test/admin-reports.test.ts b/test/admin-reports.test.ts index 12e45ba..a295b25 100644 --- a/test/admin-reports.test.ts +++ b/test/admin-reports.test.ts @@ -1,14 +1,18 @@ import { beforeEach, describe, expect, it } from "vitest"; -import { addLocale, addTranslation, admin, resetDb } from "./helpers"; -import { sun, testCatalog } from "./fixtures"; +import { + addLocale, + addTranslation, + admin, + registerKeys, + resetDb, +} from "./helpers"; +import { sun } from "./fixtures"; beforeEach(resetDb); describe("GET /v1/admin/catalog", () => { - it("returns the catalog", async () => { - expect(await (await admin("/v1/admin/catalog")).json()).toEqual({ - collections: testCatalog, - }); + it("is gone; GET /v1/definitions replaces it", async () => { + expect((await admin("/v1/admin/catalog")).status).toBe(404); }); }); @@ -31,16 +35,24 @@ describe("GET /v1/admin/coverage", () => { await addTranslation("body", "SUN", "es-419", sun); await addTranslation("body", "MOON", "es-ES", sun); await addTranslation("ui", "app.previous", "es-ES", { text: "{date}" }); + // Unused (registered by addTranslation) and deleted keys aren't counted. await addTranslation("body", "PLUTO", "es-ES", sun); + await registerKeys({ + body: { + shape: "named", + keys: { VULCAN: { placeholders: [], status: "deleted" } }, + }, + }); + await addTranslation("body", "VULCAN", "en", sun); }); - it("reports per-locale completeness, fallbacks, mismatches and orphans", async () => { + it("reports per-locale completeness, fallbacks, mismatches and unused keys", async () => { const response = await admin("/v1/admin/coverage"); expect(response.status).toBe(200); const report = await response.json<{ total: number; locales: Record[]; - orphans: unknown[]; + unused: string[]; }>(); expect(report.total).toBe(7); expect(report.locales).toEqual([ @@ -102,9 +114,8 @@ describe("GET /v1/admin/coverage", () => { complete: false, }, ]); - expect(report.orphans).toEqual([ - { collection: "body", key: "PLUTO", locale: "es-ES" }, - ]); + expect(report.unused).toEqual(["body:PLUTO"]); + expect(report).not.toHaveProperty("orphans"); }); }); diff --git a/test/admin-sync.test.ts b/test/admin-sync.test.ts new file mode 100644 index 0000000..03974ea --- /dev/null +++ b/test/admin-sync.test.ts @@ -0,0 +1,801 @@ +import { env } from "cloudflare:workers"; +import { beforeEach, describe, expect, it } from "vitest"; +import { + admin, + call, + registerKeys, + resetDbWith, + revisions, + sha, + version, +} from "./helpers"; +import { runSync } from "../src/sync"; +import { sun } from "./fixtures"; + +beforeEach(() => resetDbWith({})); + +const manifest = { + locale: "en", + collections: { + body: { shape: "named", entries: { SUN: sun } }, + ui: { + shape: "text", + entries: { + "app.title": "Explorer", + "app.previous": "From {place} on {date}.", + }, + }, + }, +}; + +const sync = (json: unknown, headers: Record = {}) => + admin("/v1/admin/sync", { method: "POST", json, headers }); + +const body = (overrides: Record = {}) => ({ + commit: sha(1), + expected: null, + manifest, + ...overrides, +}); + +describe("POST /v1/admin/sync: requests", () => { + it("requires the admin token", async () => { + const response = await call("/v1/admin/sync", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify(body()), + }); + expect(response.status).toBe(401); + }); + + it("rejects bodies over 1 MB and accepts larger ones than other routes", async () => { + const huge = JSON.stringify(body({ padding: "x".repeat(1024 * 1024) })); + const tooLarge = await admin("/v1/admin/sync", { + method: "POST", + headers: { "content-type": "application/json" }, + body: huge, + }); + expect(tooLarge.status).toBe(413); + // 200 KB is over the 64 KB default but within the sync limit: the request + // is read and then rejected for its content instead. + const large = await sync(body({ padding: "x".repeat(200 * 1024) })); + expect(large.status).toBe(422); + }); + + it.each([ + ["a missing commit", { commit: undefined }], + ["a short commit", { commit: "abc123" }], + [ + "an uppercase commit", + { commit: sha(1).toUpperCase().replace(/0/g, "A") }, + ], + ["a missing expected", { expected: undefined }], + ["a bad expected", { expected: "HEAD" }], + ["a missing manifest", { manifest: undefined }], + ])("rejects %s with 422", async (_label, overrides) => { + const response = await sync(body(overrides)); + expect(response.status).toBe(422); + expect(await response.json()).toMatchObject({ + error: { code: "validation_failed", issues: expect.any(Array) }, + }); + }); + + it("rejects an invalid manifest with its issues", async () => { + const response = await sync( + body({ + manifest: { + locale: "en", + collections: { body: { shape: "named", entries: { SUN: {} } } }, + }, + }), + ); + expect(response.status).toBe(422); + const { error } = await response.json<{ + error: { code: string; issues: { path: string }[] }; + }>(); + expect(error.code).toBe("validation_failed"); + expect(error.issues.map((issue) => issue.path)).toEqual([ + "manifest.collections.body.entries.SUN.name", + "manifest.collections.body.entries.SUN.insight", + "manifest.collections.body.entries.SUN.keywords", + ]); + }); + + it("requires the manifest to be in the default locale", async () => { + const response = await sync( + body({ manifest: { ...manifest, locale: "fr" } }), + ); + expect(response.status).toBe(422); + expect(await response.json()).toMatchObject({ + error: { + code: "validation_failed", + issues: [{ path: "manifest.locale" }], + }, + }); + }); +}); + +const rows = async (sql: string) => + (await env.DB.prepare(sql).all()).results; + +const emptySummary = { + createdCollections: [], + created: [], + reactivated: [], + unused: [], + refreshed: [], + drift: [], +}; + +describe("POST /v1/admin/sync: first sync", () => { + it("creates collections, keys and English text and records the sync", async () => { + const response = await sync(body(), { "x-cms-actor": "web-ci" }); + expect(response.status).toBe(200); + expect(await response.json()).toEqual({ + ...emptySummary, + commit: sha(1), + changed: true, + version: 2, + createdCollections: ["body", "ui"], + created: ["body:SUN", "ui:app.previous", "ui:app.title"], + }); + + expect( + await rows("SELECT name, shape FROM collections ORDER BY name"), + ).toEqual([ + { name: "body", shape: "named" }, + { name: "ui", shape: "text" }, + ]); + expect( + await rows( + "SELECT collection, key, placeholders, status FROM keys ORDER BY collection, key", + ), + ).toEqual([ + { collection: "body", key: "SUN", placeholders: "[]", status: "active" }, + { + collection: "ui", + key: "app.previous", + placeholders: '["place","date"]', + status: "active", + }, + { + collection: "ui", + key: "app.title", + placeholders: "[]", + status: "active", + }, + ]); + expect( + await rows( + "SELECT collection, key, locale, fields, revision, origin FROM translations ORDER BY collection, key", + ), + ).toEqual([ + { + collection: "body", + key: "SUN", + locale: "en", + fields: JSON.stringify(sun), + revision: 1, + origin: "sync", + }, + { + collection: "ui", + key: "app.previous", + locale: "en", + fields: JSON.stringify({ text: "From {place} on {date}." }), + revision: 1, + origin: "sync", + }, + { + collection: "ui", + key: "app.title", + locale: "en", + fields: JSON.stringify({ text: "Explorer" }), + revision: 1, + origin: "sync", + }, + ]); + + const [record] = await rows<{ + id: number; + commit_sha: string; + actor: string; + }>("SELECT id, commit_sha, actor FROM syncs"); + expect(record).toMatchObject({ commit_sha: sha(1), actor: "web-ci" }); + expect(await rows("SELECT commit_sha FROM sync_head")).toEqual([ + { commit_sha: sha(1) }, + ]); + + const history = await revisions(); + expect( + history.map(({ subject, action, collection, key, locale, after }) => [ + subject, + action, + collection, + key, + locale, + JSON.parse(after!), + ]), + ).toEqual([ + ["collection", "create", "body", null, null, { shape: "named" }], + ["collection", "create", "ui", null, null, { shape: "text" }], + ["key", "create", "body", "SUN", null, { placeholders: [] }], + [ + "key", + "create", + "ui", + "app.previous", + null, + { placeholders: ["place", "date"] }, + ], + ["key", "create", "ui", "app.title", null, { placeholders: [] }], + ["translation", "create", "body", "SUN", "en", sun], + [ + "translation", + "create", + "ui", + "app.previous", + "en", + { text: "From {place} on {date}." }, + ], + ["translation", "create", "ui", "app.title", "en", { text: "Explorer" }], + ]); + for (const revision of history) { + expect(revision.actor).toBe("web-ci"); + expect(revision.before).toBeNull(); + expect((revision as { sync_id?: number }).sync_id).toBe(record!.id); + } + expect(await version()).toBe(2); + }); + + it("serves the synced text and defaults the actor to 'sync'", async () => { + await sync(body()); + const bundle = await ( + await call("/v1/content/en") + ).json<{ + entries: Record>; + }>(); + expect(bundle.entries).toEqual({ + body: { SUN: sun }, + ui: { + "app.previous": { text: "From {place} on {date}." }, + "app.title": { text: "Explorer" }, + }, + }); + expect(await rows("SELECT actor FROM syncs")).toEqual([{ actor: "sync" }]); + }); +}); + +describe("POST /v1/admin/sync: repeated syncs", () => { + beforeEach(async () => { + await sync(body()); + }); + + it("is a no-op for the same commit and manifest", async () => { + const before = await revisions(); + const response = await sync(body({ expected: sha(1) })); + expect(response.status).toBe(200); + expect(await response.json()).toEqual({ + ...emptySummary, + commit: sha(1), + changed: false, + version: 2, + }); + expect(await rows("SELECT id FROM syncs")).toHaveLength(1); + expect(await revisions()).toEqual(before); + expect(await version()).toBe(2); + }); + + it("rejects a stale expected head even for an unchanged commit", async () => { + const before = await snapshot(); + const response = await sync(body()); + expect(response.status).toBe(412); + expect(await snapshot()).toEqual(before); + }); + + it("moves the head for a new commit without bumping the version", async () => { + const response = await sync(body({ commit: sha(2), expected: sha(1) })); + expect(await response.json()).toMatchObject({ + commit: sha(2), + changed: false, + version: 2, + }); + expect(await rows("SELECT commit_sha FROM sync_head")).toEqual([ + { commit_sha: sha(2) }, + ]); + expect(await rows("SELECT commit_sha FROM syncs ORDER BY id")).toEqual([ + { commit_sha: sha(1) }, + { commit_sha: sha(2) }, + ]); + expect(await version()).toBe(2); + }); +}); + +/** Every table sync may write, for "nothing changed" assertions. */ +const snapshot = async () => ({ + collections: await rows("SELECT * FROM collections ORDER BY name"), + keys: await rows("SELECT * FROM keys ORDER BY collection, key"), + translations: await rows( + "SELECT * FROM translations ORDER BY collection, key, locale", + ), + revisions: await rows("SELECT * FROM revisions ORDER BY id"), + syncs: await rows("SELECT * FROM syncs ORDER BY id"), + head: await rows("SELECT * FROM sync_head"), + version: await version(), +}); + +/** `manifest` with some ui entries replaced or added. */ +const withUi = (entries: Record) => ({ + ...manifest, + collections: { + ...manifest.collections, + ui: { + shape: "text", + entries: { ...manifest.collections.ui.entries, ...entries }, + }, + }, +}); + +describe("POST /v1/admin/sync: definition conflicts", () => { + beforeEach(async () => { + await sync(body()); + await registerKeys({ + ui: { + shape: "text", + keys: { "app.gone": { placeholders: [], status: "deleted" } }, + }, + }); + }); + + it.each([ + [ + "a changed shape", + { + ...manifest, + collections: { + ...manifest.collections, + body: { + shape: "reference", + entries: { SUN: { insight: "x", keywords: ["a"] } }, + }, + }, + }, + { + code: "shape_changed", + collection: "body", + expected: "named", + actual: "reference", + }, + ], + [ + "changed placeholders", + withUi({ "app.previous": "From {date}." }), + { + code: "placeholders_changed", + collection: "ui", + key: "app.previous", + expected: ["place", "date"], + actual: ["date"], + }, + ], + [ + "a retired key", + withUi({ "app.gone": "Back again." }), + { code: "key_retired", collection: "ui", key: "app.gone" }, + ], + ])( + "rejects %s with 409 and writes nothing", + async (_label, changed, conflict) => { + const before = await snapshot(); + const response = await sync( + body({ commit: sha(2), expected: sha(1), manifest: changed }), + ); + expect(response.status).toBe(409); + expect(await response.json()).toMatchObject({ + error: { code: "definition_conflict", conflicts: [conflict] }, + }); + expect(await snapshot()).toEqual(before); + }, + ); +}); + +describe("POST /v1/admin/sync: unused and reactivated keys", () => { + const status = async (collection: string, key: string) => + ( + await env.DB.prepare( + "SELECT status FROM keys WHERE collection = ? AND key = ?", + ) + .bind(collection, key) + .first<{ status: string }>() + )?.status; + + beforeEach(async () => { + await sync(body()); + }); + + it("marks keys the manifest dropped as unused and keeps their text", async () => { + const { "app.title": _dropped, ...rest } = manifest.collections.ui.entries; + const response = await sync( + body({ + commit: sha(2), + expected: sha(1), + manifest: { + locale: "en", + // body is dropped entirely; ui loses app.title. + collections: { ui: { shape: "text", entries: rest } }, + }, + }), + ); + expect(await response.json()).toMatchObject({ + changed: true, + version: 3, + unused: ["body:SUN", "ui:app.title"], + }); + expect(await status("body", "SUN")).toBe("unused"); + expect(await status("ui", "app.title")).toBe("unused"); + expect(await status("ui", "app.previous")).toBe("active"); + expect( + await rows("SELECT key FROM translations ORDER BY collection, key"), + ).toHaveLength(3); + }); + + it("reactivates unused keys the manifest brings back", async () => { + const { "app.title": _dropped, ...rest } = manifest.collections.ui.entries; + const withoutTitle = { + ...manifest, + collections: { + ...manifest.collections, + ui: { shape: "text", entries: rest }, + }, + }; + await sync( + body({ commit: sha(2), expected: sha(1), manifest: withoutTitle }), + ); + const response = await sync(body({ commit: sha(3), expected: sha(2) })); + expect(await response.json()).toMatchObject({ + changed: true, + version: 4, + reactivated: ["ui:app.title"], + unused: [], + }); + expect(await status("ui", "app.title")).toBe("active"); + }); +}); + +describe("POST /v1/admin/sync: English refresh and drift", () => { + const english = async (collection: string, key: string) => + env.DB.prepare( + "SELECT fields, revision, origin FROM translations WHERE collection = ? AND key = ? AND locale = 'en'", + ) + .bind(collection, key) + .first<{ fields: string; revision: number; origin: string }>(); + const next = (entries: Record, extra = {}) => + sync( + body({ + commit: sha(2), + expected: sha(1), + manifest: withUi(entries), + ...extra, + }), + ); + + beforeEach(async () => { + await sync(body()); + }); + + it("refreshes text no editor has changed, with a revision", async () => { + const response = await next({ "app.title": "Chart Explorer" }); + expect(await response.json()).toMatchObject({ + changed: true, + version: 3, + refreshed: ["ui:app.title"], + drift: [], + }); + expect(await english("ui", "app.title")).toEqual({ + fields: JSON.stringify({ text: "Chart Explorer" }), + revision: 2, + origin: "sync", + }); + const [last] = (await revisions()).slice(-1); + expect(last).toMatchObject({ + subject: "translation", + action: "update", + collection: "ui", + key: "app.title", + locale: "en", + actor: "sync", + }); + expect(JSON.parse(last!.before!)).toEqual({ text: "Explorer" }); + expect(JSON.parse(last!.after!)).toEqual({ text: "Chart Explorer" }); + }); + + it("refreshes named entries too", async () => { + const manifestWithSun = { + ...manifest, + collections: { + ...manifest.collections, + body: { + shape: "named", + entries: { SUN: { ...sun, insight: "Purpose." } }, + }, + }, + }; + const response = await sync( + body({ commit: sha(2), expected: sha(1), manifest: manifestWithSun }), + ); + expect(await response.json()).toMatchObject({ refreshed: ["body:SUN"] }); + expect(JSON.parse((await english("body", "SUN"))!.fields)).toEqual({ + ...sun, + insight: "Purpose.", + }); + }); + + it("reports editor-changed text as drift and leaves it alone", async () => { + await admin("/v1/admin/entries/ui/app.title/translations/en", { + method: "PUT", + json: { text: "Edited Explorer" }, + }); + const versionAfterEdit = await version(); + const response = await next({ "app.title": "Chart Explorer" }); + expect(await response.json()).toMatchObject({ + changed: false, + version: versionAfterEdit, + refreshed: [], + drift: ["ui:app.title"], + }); + expect(await english("ui", "app.title")).toMatchObject({ + fields: JSON.stringify({ text: "Edited Explorer" }), + origin: "editor", + }); + }); + + it("ignores field order when comparing text", async () => { + const { name, insight, keywords } = sun; + await env.DB.prepare( + "UPDATE translations SET fields = ? WHERE collection = 'body' AND key = 'SUN'", + ) + .bind(JSON.stringify({ keywords, insight, name })) + .run(); + const response = await next({}); + expect(await response.json()).toMatchObject({ refreshed: [], drift: [] }); + }); +}); + +describe("POST /v1/admin/sync: compare-and-swap on the head", () => { + beforeEach(async () => { + await sync(body()); + }); + + it.each([ + ["a different commit", sha(2)], + ["no previous sync", null], + ])( + "answers 412 for an expected of %s and writes nothing", + async (_label, expected) => { + const before = await snapshot(); + const response = await sync( + body({ + commit: sha(3), + expected, + manifest: withUi({ "app.new": "New." }), + }), + ); + expect(response.status).toBe(412); + expect(await response.json()).toMatchObject({ + error: { code: "precondition_failed" }, + }); + expect(await snapshot()).toEqual(before); + }, + ); +}); + +describe("runSync: writes racing the sync (test seam)", () => { + beforeEach(async () => { + await sync(body()); + }); + + const edit = () => + admin("/v1/admin/entries/ui/app.title/translations/en", { + method: "PUT", + json: { text: "Edited during sync" }, + headers: { "x-cms-actor": "amy" }, + }); + + it("lets an editor who saves mid-sync win; the key is reported as drift", async () => { + const result = await runSync( + env.DB, + { + commit: sha(2), + expected: sha(1), + manifest: withUi({ "app.title": "Chart Explorer" }), + }, + "sync", + { beforeWrite: async () => void (await edit()) }, + ); + expect(result).toMatchObject({ refreshed: [], drift: ["ui:app.title"] }); + const row = await env.DB.prepare( + "SELECT fields, origin FROM translations WHERE key = 'app.title'", + ).first<{ fields: string; origin: string }>(); + expect(row).toEqual({ + fields: JSON.stringify({ text: "Edited during sync" }), + origin: "editor", + }); + const updates = (await revisions()).filter( + (revision) => revision.action === "update", + ); + expect(updates.map((revision) => revision.actor)).toEqual(["amy"]); + const [record] = await rows<{ summary: string }>( + "SELECT summary FROM syncs ORDER BY id DESC LIMIT 1", + ); + expect(JSON.parse(record!.summary)).toMatchObject({ + refreshed: [], + drift: ["ui:app.title"], + }); + }); + + it("rejects a sync when another sync lands first", async () => { + const before = await snapshot(); + await expect( + runSync( + env.DB, + { + commit: sha(3), + expected: sha(1), + manifest: withUi({ "app.x": "X." }), + }, + "sync", + { + beforeWrite: async () => + void (await sync(body({ commit: sha(2), expected: sha(1) }))), + }, + ), + ).rejects.toMatchObject({ status: 412, code: "precondition_failed" }); + const after = await snapshot(); + // Only the competing sync's effects: head moved to sha(2), one more syncs row. + expect(after.head).toMatchObject([{ commit_sha: sha(2) }]); + expect(after.syncs).toHaveLength(before.syncs.length + 1); + expect(after.keys).toEqual(before.keys); + }); +}); + +describe("runSync at scale", () => { + /** D1 binding that counts prepared statements and batches. */ + const counting = (db: D1Database) => { + const stats = { statements: 0, batches: 0 }; + const wrapped = new Proxy(db, { + get(target, property) { + if (property === "prepare") + return (sql: string) => { + stats.statements += 1; + return target.prepare(sql); + }; + if (property === "batch") + return (statements: D1PreparedStatement[]) => { + stats.batches += 1; + return target.batch(statements); + }; + const value: unknown = Reflect.get(target, property); + return typeof value === "function" ? value.bind(target) : value; + }, + }); + return { db: wrapped, stats }; + }; + + const manifestOf = (count: number, suffix = "") => ({ + locale: "en", + collections: { + ui: { + shape: "text", + entries: Object.fromEntries( + Array.from({ length: count }, (_, index) => [ + `area${index % 40}.element${index}`, + `Text number ${index} for {name} and {count}${suffix}.`, + ]), + ), + }, + }, + }); + + const run = async ( + count: number, + commit: string, + expected: string | null, + suffix = "", + ) => { + const { db, stats } = counting(env.DB); + const result = await runSync( + db, + { commit, expected, manifest: manifestOf(count, suffix) }, + "sync", + ); + return { result, stats }; + }; + + it("uses the same, small number of statements for 3 and 2,000 keys", async () => { + const small = await run(3, sha(1), null); + await resetDbWith({}); + const large = await run(2000, sha(1), null); + expect(large.result.created).toHaveLength(2000); + expect(large.stats).toEqual(small.stats); + expect(large.stats.batches).toBe(1); + expect(large.stats.statements).toBeLessThanOrEqual(20); + expect( + await rows("SELECT key FROM translations WHERE origin = 'sync'"), + ).toHaveLength(2000); + + // Refreshing all 2,000 texts costs the same as creating them. + const refresh = await run(2000, sha(2), sha(1), " again"); + expect(refresh.result.refreshed).toHaveLength(2000); + expect(refresh.stats).toEqual(large.stats); + expect( + (await revisions()).filter((revision) => revision.action === "update"), + ).toHaveLength(2000); + + // Dropping almost all of them: 1,997 keys become unused. + const shrink = await run(3, sha(3), sha(2), " again"); + expect(shrink.result.unused).toHaveLength(1997); + expect(shrink.stats).toEqual(large.stats); + }); +}); + +describe("GET /v1/admin/sync", () => { + type SyncState = { + head: { commit: string; syncedAt: string; actor: string } | null; + recent: { + id: number; + commit: string; + actor: string; + createdAt: string; + summary: Record; + }[]; + }; + const state = async () => (await admin("/v1/admin/sync")).json(); + + it("has no head before the first sync", async () => { + expect(await state()).toEqual({ head: null, recent: [] }); + }); + + it("returns the head and the 20 most recent syncs, newest first", async () => { + await sync(body(), { "x-cms-actor": "web-ci" }); + for (let n = 2; n <= 22; n += 1) + await sync(body({ commit: sha(n), expected: sha(n - 1) })); + const { head, recent } = await state(); + expect(head).toEqual({ + commit: sha(22), + syncedAt: expect.stringMatching(/^\d{4}-\d\d-\d\dT/), + actor: "sync", + }); + expect(recent).toHaveLength(20); + expect(recent.map((entry) => entry.commit)).toEqual( + Array.from({ length: 20 }, (_, index) => sha(22 - index)), + ); + expect(recent[0]).toMatchObject({ + actor: "sync", + summary: { ...emptySummary }, + }); + }); + + it("requires the admin token", async () => { + expect((await call("/v1/admin/sync")).status).toBe(401); + }); +}); + +describe("registry names", () => { + it("syncs and serves collections and keys named like object properties", async () => { + const manifest = { + locale: "en", + collections: { + constructor: { shape: "text", entries: { toString: "Works" } }, + }, + }; + expect((await sync(body({ manifest }))).status).toBe(200); + expect(await (await call("/v1/definitions")).json()).toMatchObject({ + collections: { + constructor: { keys: { toString: { status: "active" } } }, + }, + }); + expect( + await (await call("/v1/content/en/constructor/toString")).json(), + ).toMatchObject({ fields: { text: "Works" } }); + }); +}); diff --git a/test/admin-translations.test.ts b/test/admin-translations.test.ts index 5829eda..758b06e 100644 --- a/test/admin-translations.test.ts +++ b/test/admin-translations.test.ts @@ -4,6 +4,7 @@ import { addLocale, addTranslation, admin, + registerKeys, resetDb, revisions, version, @@ -44,7 +45,7 @@ describe("GET /v1/admin/entries/:collection/:key", () => { expect(await response.json()).toEqual({ collection: "body", key: "SUN", - inCatalog: true, + status: "active", shape: "named", placeholders: [], translations: [ @@ -64,20 +65,31 @@ describe("GET /v1/admin/entries/:collection/:key", () => { }); }); - it("shows orphans and declared placeholders", async () => { + it("shows each key's status, shape and placeholders", async () => { await addTranslation("body", "PLUTO", "en", sun); + await registerKeys({ + body: { + shape: "named", + keys: { VULCAN: { placeholders: [], status: "deleted" } }, + }, + }); expect(await (await admin(path("body", "PLUTO"))).json()).toMatchObject({ - inCatalog: false, + status: "unused", + shape: "named", translations: [{ locale: "en" }], }); - expect( - await (await admin(path("ui", "app.previous"))).json(), - ).toMatchObject({ - inCatalog: true, + expect(await (await admin(path("body", "VULCAN"))).json()).toMatchObject({ + status: "deleted", + translations: [], + }); + const text = await (await admin(path("ui", "app.previous"))).json(); + expect(text).toMatchObject({ + status: "active", shape: "text", placeholders: ["date", "place"], translations: [], }); + expect(text).not.toHaveProperty("inCatalog"); }); it("answers 404 unknown_entry for unknown, unstored entries", async () => { @@ -189,6 +201,42 @@ describe("PUT …/translations/:locale", () => { }); }); + it("marks admin writes as editor-originated, on create and update", async () => { + await addTranslation("body", "SUN", "en", sun, "sync"); + await put("body", "SUN", "en", { ...sun, insight: "Edited." }); + await addLocale("fr"); + await addTranslation("body", "SUN", "fr", sun, "sync"); + // The If-Match path is a separate UPDATE statement. + await put("body", "SUN", "fr", sun, { "if-match": '"r1"' }); + await addLocale("de"); + await put("body", "SUN", "de", { ...sun, name: "Sonne" }); + const origins = await env.DB.prepare( + "SELECT locale, origin FROM translations WHERE key = 'SUN' ORDER BY locale", + ).all<{ locale: string; origin: string }>(); + expect(origins.results).toEqual([ + { locale: "de", origin: "editor" }, + { locale: "en", origin: "editor" }, + { locale: "fr", origin: "editor" }, + ]); + }); + + it("validates text against the key's stored placeholders", async () => { + await registerKeys({ + ui: { + shape: "text", + keys: { "app.count": { placeholders: ["n"], status: "active" } }, + }, + }); + expect( + (await put("ui", "app.count", "en", { text: "{n} left" })).status, + ).toBe(201); + expect( + await (await put("ui", "app.count", "en", { text: "{m} left" })).json(), + ).toMatchObject({ + error: { code: "placeholder_mismatch", expected: ["n"], actual: ["m"] }, + }); + }); + it("answers 422 for invalid fields and placeholder mismatches", async () => { const invalid = await put("body", "SUN", "en", { name: "Sun" }); expect(invalid.status).toBe(422); @@ -249,9 +297,15 @@ describe("DELETE …/translations/:locale", () => { }); }); - it("deletes orphans in any locale", async () => { + it("deletes other locales of unused keys but keeps their default text", async () => { await addTranslation("body", "PLUTO", "en", sun); - expect((await del("body", "PLUTO", "en")).status).toBe(204); + await addTranslation("body", "PLUTO", "fr", sun); + expect((await del("body", "PLUTO", "fr")).status).toBe(204); + const response = await del("body", "PLUTO", "en"); + expect(response.status).toBe(409); + expect(await response.json()).toMatchObject({ + error: { code: "conflict" }, + }); }); it("answers 404 for missing translations", async () => { @@ -259,3 +313,41 @@ describe("DELETE …/translations/:locale", () => { expect((await del("body", "SUN", "de")).status).toBe(404); }); }); + +describe("translation writes by key status", () => { + beforeEach(async () => { + await addLocale("fr"); + await registerKeys({ + body: { + shape: "named", + keys: { VULCAN: { placeholders: [], status: "deleted" } }, + }, + }); + await addTranslation("body", "PLUTO", "en", sun); // unused + await addTranslation("body", "VULCAN", "en", sun); + await addTranslation("body", "VULCAN", "fr", sun); + }); + + it("lets editors fix the text of unused keys", async () => { + const response = await put("body", "PLUTO", "en", { + ...sun, + insight: "Fixed.", + }); + expect(response.status).toBe(200); + expect((await put("body", "PLUTO", "fr", sun)).status).toBe(201); + }); + + it("refuses writes to deleted keys until they are restored", async () => { + for (const response of [ + await put("body", "VULCAN", "en", sun), + await put("body", "VULCAN", "fr", sun), + await del("body", "VULCAN", "fr"), + ]) { + expect(response.status).toBe(409); + expect(await response.json()).toMatchObject({ + error: { code: "conflict" }, + }); + } + expect(await stored("body", "VULCAN", "fr")).not.toBeNull(); + }); +}); diff --git a/test/catalog.test.ts b/test/catalog.test.ts index 2fad2c9..898f470 100644 --- a/test/catalog.test.ts +++ b/test/catalog.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from "vitest"; -import { catalog } from "../src/catalog"; +import { catalog } from "@astrologyengine/cms-contract/catalog"; import { validateFields } from "../src/fields"; +import { registryFrom } from "./fixtures"; import type { SeedFile } from "../src/seed"; import seedJson from "@astrologyengine/cms-contract/seed/en.json"; @@ -48,7 +49,12 @@ describe("seed/en.json", () => { it("passes field and placeholder validation", () => { for (const [collection, entries] of Object.entries(seed.entries)) for (const [key, fields] of Object.entries(entries)) { - const result = validateFields(catalog, collection, key, fields); + const result = validateFields( + registryFrom(catalog), + collection, + key, + fields, + ); expect(result, `${collection}:${key}`).toMatchObject({ ok: true }); } }); diff --git a/test/contract/check-manifest.test.ts b/test/contract/check-manifest.test.ts new file mode 100644 index 0000000..5bda9e2 --- /dev/null +++ b/test/contract/check-manifest.test.ts @@ -0,0 +1,266 @@ +import type { Definitions } from "@astrologyengine/cms-contract/definitions"; +import { + checkManifest, + type Manifest, +} from "@astrologyengine/cms-contract/manifest"; +import { describe, expect, it } from "vitest"; + +const sun = { name: "Sun", insight: "Identity.", keywords: ["identity"] }; +const moon = { name: "Moon", insight: "Feeling.", keywords: ["feeling"] }; + +const definitions: Definitions = { + default: "en", + version: 7, + collections: { + body: { + shape: "named", + keys: { + SUN: { placeholders: [], status: "active" }, + MOON: { placeholders: [], status: "unused" }, + VULCAN: { placeholders: [], status: "deleted" }, + }, + }, + ui: { + shape: "text", + keys: { + "app.title": { placeholders: [], status: "active" }, + "app.previous": { placeholders: ["date", "place"], status: "active" }, + "app.old": { placeholders: [], status: "active" }, + "app.legacy": { placeholders: ["n"], status: "unused" }, + }, + }, + }, +}; + +const base = { + locale: "en", + collections: { + body: { shape: "named", entries: { SUN: sun } }, + ui: { + shape: "text", + entries: { + "app.title": "Explorer", + "app.previous": "From {place} on {date}.", + "app.old": "Old.", + }, + }, + }, +} satisfies Manifest; + +/** `base` with one collection's entries replaced. */ +const withEntries = (collection: "body" | "ui", entries: object) => ({ + ...base, + collections: { + ...base.collections, + [collection]: { ...base.collections[collection], entries }, + }, +}); + +const empty: Definitions = { default: "en", version: 1, collections: {} }; + +describe("checkManifest", () => { + it("creates everything in a fresh environment", () => { + expect(checkManifest(base, empty)).toEqual({ + ok: true, + conflicts: [], + issues: [], + createdCollections: ["body", "ui"], + created: ["body:SUN", "ui:app.old", "ui:app.previous", "ui:app.title"], + reactivated: [], + unused: [], + }); + }); + + it("reports nothing for a manifest that matches", () => { + expect(checkManifest(base, definitions)).toEqual({ + ok: true, + conflicts: [], + issues: [], + createdCollections: [], + created: [], + reactivated: [], + unused: [], + }); + }); + + it("treats placeholders as a set", () => { + const manifest = withEntries("ui", { + ...base.collections.ui.entries, + "app.previous": "{date}: from {place}, again {date}.", + }); + expect(checkManifest(manifest, definitions).ok).toBe(true); + }); + + it("marks active keys the manifest dropped as unused", () => { + const { "app.old": _dropped, ...rest } = base.collections.ui.entries; + expect(checkManifest(withEntries("ui", rest), definitions)).toMatchObject({ + ok: true, + unused: ["ui:app.old"], + }); + }); + + it("marks every active key of a dropped collection as unused", () => { + const manifest = { locale: "en", collections: { ui: base.collections.ui } }; + expect(checkManifest(manifest, definitions)).toMatchObject({ + ok: true, + unused: ["body:SUN"], + }); + }); + + it("creates new keys and reactivates unused ones", () => { + const manifest = withEntries("body", { + SUN: sun, + MOON: moon, + MARS: { ...sun, name: "Mars" }, + }); + expect(checkManifest(manifest, definitions)).toMatchObject({ + ok: true, + created: ["body:MARS"], + reactivated: ["body:MOON"], + }); + }); + + it("rejects changed placeholders, including on unused keys", () => { + const manifest = withEntries("ui", { + ...base.collections.ui.entries, + "app.previous": "From {date}.", + "app.legacy": "No count.", + }); + expect(checkManifest(manifest, definitions)).toMatchObject({ + ok: false, + conflicts: [ + { + code: "placeholders_changed", + collection: "ui", + key: "app.legacy", + expected: ["n"], + actual: [], + }, + { + code: "placeholders_changed", + collection: "ui", + key: "app.previous", + expected: ["date", "place"], + actual: ["date"], + }, + ], + reactivated: [], + }); + }); + + it("rejects a changed collection shape without checking its keys", () => { + const manifest = { + ...base, + collections: { + ...base.collections, + body: { + shape: "reference", + entries: { NEW: { insight: "x", keywords: ["a"] } }, + }, + }, + }; + expect(checkManifest(manifest, definitions)).toMatchObject({ + ok: false, + conflicts: [ + { + code: "shape_changed", + collection: "body", + expected: "named", + actual: "reference", + }, + ], + created: [], + }); + }); + + it("rejects retired keys, even with the same definition", () => { + const manifest = withEntries("body", { + SUN: sun, + VULCAN: { ...sun, name: "Vulcan" }, + }); + expect(checkManifest(manifest, definitions)).toMatchObject({ + ok: false, + conflicts: [{ code: "key_retired", collection: "body", key: "VULCAN" }], + created: [], + }); + }); + + it("requires the CMS default locale, compared canonically", () => { + expect(checkManifest({ ...base, locale: "EN" }, definitions).ok).toBe(true); + expect(checkManifest({ ...base, locale: "es" }, definitions)).toMatchObject( + { + ok: false, + conflicts: [{ code: "locale_mismatch", expected: "en", actual: "es" }], + }, + ); + }); + + it.each([ + ["a non-object manifest", "manifest", ""], + ["a missing locale", { collections: {} }, "locale"], + [ + "an invalid locale tag", + { locale: "not a tag!", collections: {} }, + "locale", + ], + [ + "non-object collections", + { locale: "en", collections: [] }, + "collections", + ], + ])("reports %s", (_label, manifest, path) => { + const result = checkManifest(manifest, empty); + expect(result.ok).toBe(false); + expect(result.issues.map((issue) => issue.path)).toEqual([path]); + }); + + it("reports invalid names, shapes and fields with their paths", () => { + const manifest = { + locale: "en", + collections: { + Body: { shape: "named", entries: {} }, + x: { shape: "rich", entries: {} }, + y: { shape: "text", entries: [] }, + body: { + shape: "named", + entries: { + "bad key": sun, + SUN: { name: "Sun", keywords: ["identity"] }, + }, + }, + ui: { + shape: "text", + entries: { "app.title": " padded", "app.count": 3 }, + }, + }, + }; + const result = checkManifest(manifest, empty); + expect(result.ok).toBe(false); + expect(result.issues.map((issue) => issue.path).sort()).toEqual([ + "collections.Body", + "collections.body.entries.SUN.insight", + "collections.body.entries.bad key", + "collections.ui.entries.app.count", + "collections.ui.entries.app.title", + "collections.x.shape", + "collections.y.entries", + ]); + for (const issue of result.issues) expect(issue.message).toMatch(/\S/); + }); +}); + +describe("checkManifest with prototype-like names", () => { + it("treats them as ordinary new collections and keys", () => { + const manifest = { + locale: "en", + collections: { + constructor: { shape: "text", entries: { toString: "x" } }, + }, + }; + expect(checkManifest(manifest, definitions)).toMatchObject({ + ok: true, + createdCollections: ["constructor"], + created: ["constructor:toString"], + }); + }); +}); diff --git a/test/contract/fixtures/large-manifest.ts b/test/contract/fixtures/large-manifest.ts new file mode 100644 index 0000000..20fd3bb --- /dev/null +++ b/test/contract/fixtures/large-manifest.ts @@ -0,0 +1,2506 @@ +// Generated for type-performance tests: 1,000 text keys (0–3 placeholders, +// ~40–200 characters) and 100 named entries. Not real copy. +import { defineManifest } from "@astrologyengine/cms-contract/manifest"; + +export const largeManifest = defineManifest({ + locale: "en", + collections: { + ui: { + shape: "text", + entries: { + "area0.element0.variant": + "Time shown place retrograde orbit retrograde cusp body place retrograde chart cusp angle system chart orbit shown aspect wheel place {p0} degree chart chart chart.", + "area0.element1.variant": + "Body angle chart transit aspect orbit retrograde natal aspect ruler aspect aspect orbit requested chart angle natal place.", + "area0.element2.variant": + "Requested place degree {p0} transit angle transit body requested requested wheel retrograde transit cusp wheel birth retrograde aspect cusp angle house ruler natal ruler time orbit transit.", + "area0.element3.variant": + "Cusp ruler retrograde chart retrograde birth requested system wheel wheel cusp {p0} house house transit aspect chart body natal natal aspect cusp transit.", + "area0.element4.variant": + "Shown natal system chart cusp transit sign transit natal body angle {p0} birth {p1} retrograde ruler wheel natal body transit angle retrograde.", + "area0.element5.variant": + "{p1} Natal natal system system {p0} degree orbit.", + "area0.element6.variant": + "House natal wheel house time {p0} natal shown birth time time chart orbit chart shown aspect shown place system house ruler requested time house house shown transit.", + "area0.element7.variant": + "Requested orbit degree retrograde retrograde place chart requested cusp degree angle body shown place {p0} shown transit body system angle chart aspect {p1} chart cusp sign birth house.", + "area0.element8.variant": + "{p2} Aspect transit orbit aspect {p1} transit chart cusp wheel {p0} degree angle birth requested sign body birth requested time time requested requested house angle wheel.", + "area0.element9.variant": + "Body wheel orbit house system transit birth cusp body ruler place body wheel angle wheel body retrograde place cusp requested transit retrograde chart degree.", + "area0.element10.variant": + "Chart house {p2} body degree wheel sign degree {p1} angle body shown place cusp natal ruler natal {p0}.", + "area0.element11.variant": + "Sign house house natal body shown degree system.", + "area0.element12.variant": + "Degree degree place requested {p0} aspect system retrograde sign wheel {p1} natal place degree birth angle time cusp sign.", + "area0.element13.variant": + "Wheel cusp time wheel natal aspect wheel time shown ruler requested wheel natal place orbit shown place birth requested chart system chart time angle place.", + "area0.element14.variant": + "Aspect wheel angle house place orbit house aspect house place angle cusp.", + "area0.element15.variant": + "Shown retrograde degree place body degree {p0} birth chart chart requested system degree orbit cusp degree cusp time time {p1} degree system orbit place shown.", + "area0.element16.variant": + "Ruler shown house {p0} natal body requested body aspect ruler time shown time orbit time wheel degree {p1} aspect {p2} cusp requested birth degree house degree wheel requested aspect degree.", + "area0.element17.variant": + "Aspect chart aspect cusp time shown natal time time chart chart requested ruler.", + "area0.element18.variant": + "Sign place transit degree time transit house house sign sign {p0} degree requested place transit system requested sign body {p1} sign {p2} natal birth.", + "area0.element19.variant": + "Requested angle natal house {p0} birth aspect shown time orbit angle natal.", + "area0.element20.variant": + "Orbit chart {p2} cusp degree house {p0} shown retrograde chart angle wheel chart birth ruler wheel sign wheel sign sign {p1} shown shown cusp wheel cusp.", + "area0.element21.variant": + "Chart house transit degree transit orbit aspect aspect degree retrograde retrograde aspect angle degree natal system shown aspect birth time {p0} transit.", + "area0.element22.variant": + "Transit {p0} body requested requested requested natal ruler house {p1} orbit system time.", + "area0.element23.variant": + "Sign shown {p0} angle body wheel birth retrograde {p1} cusp ruler {p2} cusp transit.", + "area0.element24.variant": + "Time shown place shown time sign system time orbit aspect cusp angle cusp house degree orbit sign system retrograde body place angle.", + "area0.element25.variant": + "{p2} {p1} Requested shown aspect cusp natal chart body transit orbit {p0}.", + "area0.element26.variant": + "Body house requested sign natal body shown {p0} requested wheel shown orbit house natal ruler.", + "area0.element27.variant": + "{p0} Body wheel cusp {p2} body requested place chart {p1} place wheel.", + "area0.element28.variant": + "Transit ruler wheel requested angle {p0} transit ruler transit.", + "area0.element29.variant": + "Orbit orbit ruler requested natal cusp degree wheel retrograde.", + "area0.element30.variant": + "Cusp cusp body natal chart shown system transit body orbit system transit angle requested house orbit system transit body ruler transit chart cusp wheel angle cusp.", + "area0.element31.variant": + "Wheel {p1} time retrograde aspect requested chart angle sign cusp shown house time system chart ruler shown {p0} angle natal requested sign orbit shown retrograde house orbit.", + "area0.element32.variant": + "Place wheel {p1} {p0} angle time ruler time orbit chart house transit house time cusp shown system requested body transit body aspect degree shown.", + "area0.element33.variant": + "Transit natal birth house requested natal shown {p1} ruler system aspect cusp natal cusp house retrograde shown system degree aspect {p0} shown.", + "area0.element34.variant": + "Cusp degree angle aspect shown body time house wheel orbit wheel sign system shown orbit transit house sign sign orbit ruler requested cusp aspect place.", + "area0.element35.variant": + "Requested time place aspect cusp degree retrograde place house birth birth system chart body birth {p0} retrograde transit system orbit degree shown place system house place aspect cusp aspect.", + "area0.element36.variant": + "{p1} {p0} House aspect aspect requested orbit natal wheel cusp body orbit shown degree retrograde {p2} wheel place body time birth.", + "area0.element37.variant": + "{p1} Wheel requested body cusp house sign chart chart cusp {p0} sign natal birth wheel cusp shown sign time orbit.", + "area0.element38.variant": + "Birth transit sign birth shown place angle time body chart retrograde sign shown body orbit cusp degree shown shown aspect aspect birth wheel.", + "area0.element39.variant": + "Angle system natal transit birth {p0} ruler natal angle natal body natal angle time shown system time shown.", + "area0.element40.variant": + "Birth body angle birth birth time transit retrograde transit ruler.", + "area0.element41.variant": + "Birth sign natal birth orbit sign cusp orbit chart transit shown time shown degree time requested.", + "area0.element42.variant": + "Birth shown degree sign shown cusp place requested place angle aspect transit natal body degree degree transit cusp.", + "area0.element43.variant": + "Sign orbit {p0} {p1} transit {p2} natal wheel transit natal chart requested.", + "area0.element44.variant": + "Degree place angle ruler {p0} sign wheel time birth requested {p1} natal degree angle requested degree ruler shown degree transit transit chart transit {p2} place.", + "area0.element45.variant": + "Wheel time orbit shown retrograde orbit ruler {p1} cusp {p0} time wheel birth sign birth transit retrograde wheel.", + "area0.element46.variant": + "Ruler {p1} cusp requested orbit system degree natal transit house chart sign shown aspect {p0} wheel sign place house.", + "area0.element47.variant": + "Shown place body shown time wheel transit time time body house transit angle chart wheel ruler retrograde requested aspect body system retrograde aspect.", + "area0.element48.variant": + "Ruler {p0} natal body retrograde time shown angle body chart natal {p1} cusp transit {p2} retrograde time cusp system transit wheel wheel angle.", + "area0.element49.variant": + "Requested chart natal place requested transit degree natal wheel natal requested transit.", + "area1.element50.variant": + "Transit angle system wheel requested orbit requested sign transit orbit wheel sign natal house shown chart angle wheel birth ruler angle {p2} {p0} cusp requested {p1}.", + "area1.element51.variant": + "Time chart cusp shown orbit shown ruler retrograde.", + "area1.element52.variant": + "Orbit place retrograde ruler sign angle sign chart {p1} house shown ruler sign wheel {p0} requested angle shown transit requested.", + "area1.element53.variant": + "Retrograde body retrograde {p0} cusp {p2} angle time time sign body sign aspect {p1} chart place shown sign retrograde.", + "area1.element54.variant": + "Angle system birth natal body natal angle ruler.", + "area1.element55.variant": + "Place natal angle place shown shown house retrograde birth body time cusp place orbit requested transit retrograde cusp place system retrograde place sign cusp system body.", + "area1.element56.variant": + "Shown angle natal requested retrograde natal body system {p0} degree retrograde place chart ruler shown birth natal orbit requested place aspect transit shown.", + "area1.element57.variant": + "Sign sign shown body angle natal {p0} system birth natal system transit sign angle shown shown retrograde requested shown retrograde.", + "area1.element58.variant": + "System retrograde aspect degree house system house wheel orbit natal {p0} sign birth transit degree {p2} {p1} transit sign body.", + "area1.element59.variant": + "Sign {p0} sign {p1} shown aspect time natal birth wheel house.", + "area1.element60.variant": + "Wheel requested angle {p0} degree chart chart requested system aspect time aspect shown degree shown system transit cusp chart place degree ruler sign.", + "area1.element61.variant": + "Sign wheel birth ruler time time place requested degree aspect shown transit birth ruler chart time sign {p1} cusp ruler aspect place degree shown chart transit degree place ruler sign {p0} system.", + "area1.element62.variant": + "Wheel system transit {p1} retrograde {p0} wheel angle natal cusp {p2}.", + "area1.element63.variant": + "Sign birth system transit place house aspect body angle shown natal chart shown natal shown transit shown {p1} retrograde sign cusp {p0} place ruler time.", + "area1.element64.variant": + "Natal transit wheel chart {p1} system requested orbit sign sign time wheel sign body retrograde degree ruler requested house sign {p0} cusp orbit cusp place.", + "area1.element65.variant": + "System chart natal chart sign cusp natal place orbit chart angle system {p1} angle {p0} shown ruler.", + "area1.element66.variant": + "Place retrograde {p0} birth chart birth place wheel {p2} {p1}.", + "area1.element67.variant": + "Shown wheel ruler retrograde aspect system aspect place natal {p0} ruler house place birth degree angle ruler shown birth system angle angle cusp ruler {p1}.", + "area1.element68.variant": + "Aspect system transit {p1} sign birth degree place {p0} transit house natal retrograde degree place wheel chart retrograde body cusp house cusp.", + "area1.element69.variant": + "Degree aspect orbit retrograde {p0} ruler retrograde body angle orbit cusp natal place wheel retrograde shown sign.", + "area1.element70.variant": + "Angle place chart time house orbit cusp transit requested sign sign transit place shown chart orbit cusp aspect.", + "area1.element71.variant": + "Natal {p2} aspect angle {p1} house house {p0} degree.", + "area1.element72.variant": + "Cusp wheel chart transit body angle aspect birth transit body transit {p0}.", + "area1.element73.variant": + "Cusp orbit place wheel birth cusp time natal place retrograde birth transit aspect.", + "area1.element74.variant": "Requested orbit shown angle house system.", + "area1.element75.variant": + "Degree natal orbit transit angle natal house cusp {p0} cusp body retrograde shown ruler sign shown wheel shown house system time ruler degree sign.", + "area1.element76.variant": + "Ruler cusp shown wheel orbit chart {p1} sign sign shown {p0} aspect body time wheel natal.", + "area1.element77.variant": + "Aspect wheel sign natal orbit cusp body time time sign birth {p0} chart cusp cusp angle sign wheel system sign natal natal time {p1} aspect cusp {p2} sign requested body cusp.", + "area1.element78.variant": + "Requested sign ruler retrograde natal requested time transit requested body orbit chart {p0} requested.", + "area1.element79.variant": + "Ruler orbit shown system birth birth degree house sign place place angle wheel aspect body transit transit cusp place body cusp transit sign wheel shown.", + "area1.element80.variant": + "Place body wheel cusp retrograde natal system aspect shown birth house natal transit aspect angle shown angle cusp shown retrograde place sign house natal chart orbit birth retrograde.", + "area1.element81.variant": + "Natal degree aspect place time birth angle {p0} orbit body house system transit body transit cusp transit ruler body.", + "area1.element82.variant": + "Wheel time degree birth orbit birth system house sign requested retrograde birth wheel transit time wheel cusp {p0} time cusp transit wheel requested cusp shown ruler retrograde {p1} birth.", + "area1.element83.variant": + "Angle {p2} requested wheel degree {p1} {p0} sign system.", + "area1.element84.variant": + "Cusp transit chart wheel wheel place birth wheel transit chart place degree degree ruler natal {p0} birth ruler wheel time {p1}.", + "area1.element85.variant": + "Orbit degree transit natal chart house degree ruler body sign wheel sign wheel place cusp degree transit angle ruler degree shown system ruler.", + "area1.element86.variant": + "Time aspect shown cusp natal requested wheel system time time house shown angle time sign requested natal shown aspect body place shown retrograde birth transit requested body natal.", + "area1.element87.variant": + "Degree degree requested transit sign birth orbit ruler birth chart degree angle house natal birth wheel transit angle house body aspect place wheel.", + "area1.element88.variant": + "Transit place shown orbit body {p0} birth ruler orbit degree system ruler aspect chart chart retrograde birth house shown natal birth chart aspect time transit.", + "area1.element89.variant": + "Body body orbit requested aspect retrograde transit ruler degree cusp time body system house body system requested wheel angle system retrograde ruler.", + "area1.element90.variant": + "Chart place wheel system angle wheel degree degree time angle body transit retrograde system wheel natal transit retrograde system wheel orbit.", + "area1.element91.variant": + "{p2} Shown transit requested wheel cusp system natal shown shown {p0} requested chart {p1}.", + "area1.element92.variant": + "Ruler aspect transit orbit body retrograde degree sign cusp {p2} angle {p1} {p0} birth place ruler chart shown natal birth requested cusp chart.", + "area1.element93.variant": + "Time degree place time sign requested angle system degree aspect chart house.", + "area1.element94.variant": + "Requested cusp angle transit orbit time body angle aspect system birth system {p1} {p0} aspect aspect aspect.", + "area1.element95.variant": + "Sign requested ruler chart requested orbit retrograde house sign {p0} chart ruler angle natal degree transit retrograde degree system place wheel requested natal shown angle chart.", + "area1.element96.variant": + "Retrograde place transit aspect system shown angle ruler aspect birth place system transit transit transit house sign requested birth time body chart birth angle chart time.", + "area1.element97.variant": "Birth natal degree degree chart system.", + "area1.element98.variant": + "Body retrograde body shown requested wheel natal transit shown aspect house body cusp birth aspect natal orbit birth degree degree angle place chart.", + "area1.element99.variant": + "Time house body aspect house requested place {p0} birth degree sign time orbit sign aspect birth requested ruler birth wheel time orbit body.", + "area2.element100.variant": + "Birth body birth place time aspect {p0} requested shown transit.", + "area2.element101.variant": + "Birth shown body degree ruler ruler orbit system cusp cusp time {p0} angle aspect retrograde degree house system place aspect time angle shown natal requested degree ruler angle orbit ruler.", + "area2.element102.variant": + "Retrograde transit chart ruler sign requested house {p1} requested {p0} wheel sign natal sign house orbit sign sign house time.", + "area2.element103.variant": + "Degree house shown retrograde requested time angle sign natal ruler orbit place sign degree time house retrograde natal birth birth {p0} body ruler ruler transit {p1} ruler transit.", + "area2.element104.variant": + "Place house cusp birth shown system body {p0} birth {p1} aspect requested degree wheel cusp aspect ruler birth.", + "area2.element105.variant": + "Place sign aspect ruler transit shown sign house aspect time requested wheel.", + "area2.element106.variant": + "Wheel {p0} {p2} transit retrograde house transit ruler body angle time shown {p1} body aspect sign sign body chart house retrograde ruler house.", + "area2.element107.variant": + "Body time orbit body system degree house wheel chart body {p0} degree retrograde natal birth birth ruler retrograde natal ruler sign retrograde time transit degree wheel requested system.", + "area2.element108.variant": + "Degree angle time shown time degree chart house degree aspect degree shown shown requested retrograde angle chart requested house requested birth.", + "area2.element109.variant": + "Angle system body shown ruler wheel retrograde wheel requested system shown house degree sign ruler place cusp ruler transit.", + "area2.element110.variant": + "Orbit sign retrograde aspect birth aspect time time birth transit transit retrograde wheel retrograde degree {p0} transit house wheel.", + "area2.element111.variant": + "{p2} Cusp natal natal orbit {p0} {p1} house wheel.", + "area2.element112.variant": + "Orbit aspect natal requested time orbit ruler body house sign orbit birth ruler wheel degree {p1} {p0} house wheel.", + "area2.element113.variant": + "Aspect system birth orbit house transit body cusp orbit place degree shown sign house degree sign house system transit requested aspect natal angle orbit.", + "area2.element114.variant": + "Natal requested house transit system transit {p2} requested wheel body requested sign {p1} chart degree place {p0} angle cusp transit house system orbit orbit natal.", + "area2.element115.variant": + "Place place natal cusp sign orbit cusp house.", + "area2.element116.variant": + "Transit wheel birth wheel body wheel orbit {p0} retrograde cusp {p2} requested ruler house system {p1} shown house chart natal birth time natal.", + "area2.element117.variant": + "Place cusp birth orbit {p1} shown angle orbit degree transit {p2} place house cusp natal angle system retrograde {p0}.", + "area2.element118.variant": + "Sign system body aspect body orbit sign place place angle birth orbit {p0} sign ruler natal degree shown.", + "area2.element119.variant": + "Retrograde orbit requested requested wheel cusp degree requested house place retrograde house orbit sign orbit place natal place.", + "area2.element120.variant": + "Retrograde natal degree wheel degree natal {p0} {p1} wheel orbit degree retrograde cusp natal body house aspect natal.", + "area2.element121.variant": + "Degree system birth degree angle chart ruler ruler ruler system system angle body requested aspect degree cusp cusp house chart cusp ruler system system aspect aspect time system degree cusp.", + "area2.element122.variant": + "Requested place angle chart ruler time angle sign place natal house degree sign cusp angle degree natal transit {p0} shown body body house house natal house sign place orbit.", + "area2.element123.variant": + "Sign degree system degree system sign chart ruler house aspect aspect retrograde wheel retrograde birth time sign natal {p0} retrograde.", + "area2.element124.variant": + "Ruler sign shown {p0} ruler time cusp retrograde chart transit orbit body aspect.", + "area2.element125.variant": + "Requested birth shown transit body time place place cusp degree place orbit wheel transit retrograde shown sign angle ruler ruler cusp angle angle ruler natal body body time sign.", + "area2.element126.variant": + "Chart aspect cusp orbit system orbit {p0} wheel place birth house transit chart birth.", + "area2.element127.variant": + "{p1} Sign aspect ruler angle {p0} degree wheel birth transit orbit sign transit ruler wheel birth ruler place aspect place angle.", + "area2.element128.variant": + "Sign requested chart retrograde chart retrograde time {p0} {p1} wheel angle time.", + "area2.element129.variant": + "Natal cusp system natal angle aspect transit cusp retrograde degree.", + "area2.element130.variant": + "Time {p1} body wheel {p0} system ruler place place ruler place {p2}.", + "area2.element131.variant": + "Transit angle aspect time requested retrograde.", + "area2.element132.variant": + "Angle natal requested cusp birth system chart shown system retrograde orbit aspect shown degree retrograde orbit natal birth shown transit house orbit orbit requested.", + "area2.element133.variant": + "Transit cusp angle natal system cusp retrograde aspect requested {p0} chart time sign retrograde place ruler shown.", + "area2.element134.variant": + "Place transit {p1} sign orbit birth {p0} orbit retrograde wheel degree natal.", + "area2.element135.variant": + "Body shown system time orbit requested chart shown transit chart wheel cusp place place degree system system wheel orbit time system retrograde transit.", + "area2.element136.variant": + "Birth body house birth {p0} system place birth place {p1} natal transit requested body house natal sign aspect body time transit ruler wheel angle shown system.", + "area2.element137.variant": + "System shown birth chart angle system {p0} requested retrograde.", + "area2.element138.variant": + "House body {p1} {p2} {p0} birth angle angle ruler ruler transit.", + "area2.element139.variant": + "Ruler time {p0} orbit degree body aspect shown.", + "area2.element140.variant": + "{p2} Retrograde system chart retrograde requested shown {p0} requested body sign {p1}.", + "area2.element141.variant": + "Natal chart sign aspect retrograde place requested system angle body transit {p0} degree place aspect aspect retrograde wheel place {p2} house {p1} retrograde.", + "area2.element142.variant": + "Natal angle chart cusp sign angle sign birth {p1} requested cusp system angle place {p0} body {p2} system shown retrograde system.", + "area2.element143.variant": + "Sign natal natal shown chart natal place ruler orbit shown place requested sign time angle cusp.", + "area2.element144.variant": + "Wheel sign natal cusp retrograde aspect transit chart cusp birth angle system time aspect birth orbit time requested system birth ruler.", + "area2.element145.variant": + "Time birth wheel requested ruler requested time natal.", + "area2.element146.variant": + "Ruler degree house ruler transit aspect {p2} degree system {p0} aspect aspect body {p1} requested requested natal degree requested wheel chart retrograde shown aspect sign aspect house time.", + "area2.element147.variant": + "Natal {p0} system time degree cusp body house birth orbit body cusp.", + "area2.element148.variant": + "Aspect requested transit orbit degree time time time {p0} aspect place transit orbit natal orbit chart system house orbit angle natal place {p1} body chart aspect requested body transit system requested requested.", + "area2.element149.variant": + "Birth chart chart orbit {p1} birth body {p0} time degree orbit requested place aspect place body chart.", + "area3.element150.variant": + "Chart natal aspect retrograde house natal chart aspect sign time chart sign degree wheel time transit natal shown body cusp.", + "area3.element151.variant": + "Shown ruler shown natal cusp cusp transit transit natal orbit shown time house retrograde wheel cusp sign system body transit chart transit birth.", + "area3.element152.variant": + "Aspect degree {p0} cusp birth angle wheel retrograde {p1} transit time birth.", + "area3.element153.variant": + "Cusp {p1} natal shown wheel birth {p0} body body requested cusp requested transit chart wheel shown body natal transit natal house {p2} aspect time body retrograde.", + "area3.element154.variant": + "Chart sign place birth {p0} wheel angle retrograde house body {p1} wheel orbit place cusp aspect {p2} time.", + "area3.element155.variant": + "Transit {p2} ruler angle wheel aspect orbit shown cusp ruler cusp wheel aspect cusp system place {p1} house system ruler {p0} time chart angle.", + "area3.element156.variant": + "Aspect orbit ruler transit time {p2} degree birth shown {p0} {p1} wheel.", + "area3.element157.variant": + "House angle requested orbit aspect retrograde cusp chart transit shown place {p0} requested shown chart wheel time degree transit house aspect requested time house orbit.", + "area3.element158.variant": + "{p0} Orbit retrograde place wheel retrograde wheel time birth birth chart shown birth shown {p1} requested {p2} house natal retrograde system degree chart orbit degree aspect aspect ruler birth.", + "area3.element159.variant": + "Sign house aspect time cusp birth house degree chart orbit natal system transit house birth angle {p0} aspect shown.", + "area3.element160.variant": + "Birth {p0} system cusp angle cusp transit {p1} angle shown orbit degree wheel {p2} chart.", + "area3.element161.variant": + "Angle house natal transit {p0} {p1} transit transit system house shown {p2} angle retrograde.", + "area3.element162.variant": + "{p1} Natal cusp requested aspect {p2} ruler natal natal transit aspect shown chart time shown cusp house {p0} shown wheel shown.", + "area3.element163.variant": + "Aspect sign place cusp birth house time {p2} place {p0} orbit {p1}.", + "area3.element164.variant": + "Shown birth transit retrograde body ruler system.", + "area3.element165.variant": + "Degree degree cusp cusp requested {p0} {p2} {p1} time aspect orbit natal.", + "area3.element166.variant": + "Shown house sign birth {p2} degree {p0} ruler cusp time wheel degree wheel house sign place natal body retrograde aspect ruler system transit house {p1} body requested.", + "area3.element167.variant": + "Retrograde ruler {p1} birth natal time chart ruler aspect sign body {p0} cusp orbit transit wheel shown angle {p2} system degree retrograde.", + "area3.element168.variant": + "Sign natal retrograde house time chart time chart house shown body orbit cusp natal transit shown shown natal cusp place cusp orbit aspect time degree sign system chart cusp birth.", + "area3.element169.variant": + "{p1} {p0} Chart system orbit degree wheel chart natal degree cusp birth wheel orbit place angle cusp place wheel.", + "area3.element170.variant": + "Ruler house cusp birth sign {p1} requested transit system angle house wheel retrograde requested wheel system shown birth cusp natal wheel angle sign degree house {p2} orbit cusp wheel natal {p0} sign transit.", + "area3.element171.variant": + "Retrograde birth {p1} requested house shown cusp shown {p0} place shown chart place place orbit sign orbit aspect aspect birth.", + "area3.element172.variant": + "Birth wheel place birth shown angle sign ruler place.", + "area3.element173.variant": + "System system aspect house natal wheel retrograde house ruler system cusp transit wheel house degree transit time birth.", + "area3.element174.variant": + "Requested place orbit time chart birth shown natal requested wheel system shown orbit cusp place aspect requested sign transit transit chart ruler orbit place.", + "area3.element175.variant": + "Sign shown place ruler shown body degree system sign natal {p2} aspect system chart aspect retrograde ruler {p1} sign angle degree angle system orbit {p0} place shown birth transit requested.", + "area3.element176.variant": + "Aspect aspect cusp ruler shown chart retrograde transit {p0} sign angle retrograde time.", + "area3.element177.variant": + "Aspect place {p0} {p1} angle cusp sign place orbit transit body.", + "area3.element178.variant": + "Degree ruler {p1} shown wheel sign chart aspect {p0} shown retrograde system natal chart degree chart house body shown.", + "area3.element179.variant": + "Ruler {p1} ruler body place {p2} chart cusp degree wheel degree angle degree wheel shown cusp system shown {p0} ruler system time angle aspect system retrograde ruler requested chart place system.", + "area3.element180.variant": + "Natal orbit requested angle {p0} cusp system chart time cusp sign wheel body retrograde cusp retrograde place angle house retrograde body requested natal birth requested requested sign shown transit requested retrograde.", + "area3.element181.variant": + "Transit degree body shown {p0} birth requested transit {p1} wheel requested retrograde {p2} requested shown house requested shown degree.", + "area3.element182.variant": + "{p2} Retrograde {p0} house cusp birth time wheel body degree birth {p1} transit requested birth angle place system degree sign chart ruler aspect system ruler transit angle aspect transit time.", + "area3.element183.variant": + "{p2} House shown {p1} system body angle {p0} requested.", + "area3.element184.variant": + "Cusp natal place cusp requested angle birth aspect degree angle wheel wheel retrograde system body wheel transit time degree cusp house.", + "area3.element185.variant": + "Retrograde time angle cusp body shown chart requested {p0} birth shown time house system shown orbit angle requested place requested birth retrograde house.", + "area3.element186.variant": + "Birth {p0} cusp natal chart wheel transit requested chart cusp degree.", + "area3.element187.variant": + "{p1} System body time house wheel cusp transit wheel chart aspect {p0} cusp.", + "area3.element188.variant": + "Angle system house birth cusp angle body house aspect time system orbit natal natal degree shown body transit system shown cusp aspect.", + "area3.element189.variant": + "Shown sign shown ruler wheel shown transit aspect {p1} body natal chart place body shown house degree aspect house birth system {p0} aspect cusp shown shown body.", + "area3.element190.variant": + "Birth sign retrograde {p1} {p2} angle requested {p0} ruler cusp.", + "area3.element191.variant": + "Retrograde system sign wheel ruler sign cusp birth time {p1} shown time retrograde body {p0} orbit.", + "area3.element192.variant": + "Degree chart system retrograde angle angle angle ruler system retrograde body angle cusp requested.", + "area3.element193.variant": + "House degree ruler wheel angle cusp place cusp.", + "area3.element194.variant": + "System body place aspect retrograde cusp house sign aspect system place ruler degree transit orbit house cusp retrograde wheel.", + "area3.element195.variant": + "{p0} Transit body aspect sign place shown natal.", + "area3.element196.variant": + "Requested body birth requested sign sign time house wheel angle shown sign time body house system angle.", + "area3.element197.variant": + "Natal retrograde house system time retrograde aspect body time sign aspect body system system sign natal shown time {p0}.", + "area3.element198.variant": + "Ruler transit shown {p1} house wheel retrograde angle natal {p0}.", + "area3.element199.variant": + "Wheel place angle angle ruler aspect orbit natal cusp degree wheel house birth birth {p0} ruler system orbit house orbit wheel ruler ruler sign.", + "area4.element200.variant": + "Retrograde natal requested system body sign system aspect requested place time aspect angle transit body requested retrograde birth cusp {p0} body birth requested requested.", + "area4.element201.variant": + "Chart orbit degree angle aspect place house transit birth cusp house chart transit retrograde retrograde ruler natal angle chart {p0}.", + "area4.element202.variant": + "Aspect transit {p2} chart {p1} natal birth body degree birth sign orbit house orbit sign sign shown transit {p0} cusp time.", + "area4.element203.variant": + "{p2} Ruler body birth {p0} transit angle aspect retrograde body house aspect body transit degree requested retrograde system wheel {p1} transit aspect body requested.", + "area4.element204.variant": + "Degree time transit house orbit natal time angle sign natal birth sign degree ruler orbit body cusp orbit time cusp ruler chart requested body wheel.", + "area4.element205.variant": + "Chart {p1} place orbit cusp requested house requested aspect degree degree {p0} body birth birth chart house system orbit.", + "area4.element206.variant": + "Transit shown time aspect {p0} chart sign angle ruler shown retrograde birth cusp place requested angle aspect aspect transit wheel angle wheel shown chart {p1} chart.", + "area4.element207.variant": + "Sign ruler time system aspect natal natal sign sign cusp sign system degree body {p1} sign sign system place sign birth system shown shown ruler chart {p0} sign chart time {p2}.", + "area4.element208.variant": + "Cusp requested sign cusp angle ruler orbit {p0} ruler requested retrograde house shown chart requested aspect birth retrograde {p1} birth chart time system orbit chart aspect sign {p2} cusp system cusp.", + "area4.element209.variant": + "Body house time degree ruler time place natal {p1} {p0} aspect body degree.", + "area4.element210.variant": + "Time angle wheel ruler house house system place ruler house retrograde system time orbit angle body time time shown degree cusp ruler {p2} wheel degree angle transit {p1} system system {p0} time body.", + "area4.element211.variant": + "Place orbit degree {p0} chart aspect requested angle {p1} sign body shown transit system birth house wheel requested {p2} birth.", + "area4.element212.variant": + "Natal orbit wheel aspect orbit angle birth sign retrograde ruler transit.", + "area4.element213.variant": + "{p0} Cusp time wheel angle sign transit {p1} aspect angle retrograde time wheel ruler natal transit house birth body body chart ruler aspect aspect transit transit angle natal angle house aspect.", + "area4.element214.variant": + "Sign natal time chart sign natal shown aspect ruler degree sign place shown angle ruler system birth natal birth orbit birth degree requested requested cusp requested.", + "area4.element215.variant": + "Requested place wheel chart place angle time body place chart aspect retrograde time body degree body {p2} requested requested {p0} orbit orbit natal {p1}.", + "area4.element216.variant": + "Orbit cusp time chart time requested {p0} system orbit body requested angle house system cusp cusp orbit aspect aspect retrograde chart requested shown retrograde retrograde ruler place wheel place.", + "area4.element217.variant": + "Body angle birth house cusp angle ruler transit sign {p1} {p0} time transit house birth {p2} wheel body transit natal orbit.", + "area4.element218.variant": "Orbit angle wheel ruler angle ruler {p0}.", + "area4.element219.variant": + "Shown body orbit wheel {p0} retrograde shown system angle requested shown orbit time place degree orbit requested transit aspect transit degree aspect sign house shown aspect angle chart angle cusp aspect.", + "area4.element220.variant": + "House orbit system cusp aspect requested system cusp.", + "area4.element221.variant": + "Requested sign place angle requested {p0} {p1} requested.", + "area4.element222.variant": + "Sign place house transit retrograde angle place birth ruler degree requested birth requested orbit birth ruler requested natal body shown shown house requested transit degree natal time.", + "area4.element223.variant": + "Sign cusp degree degree retrograde house requested chart shown chart.", + "area4.element224.variant": + "Natal orbit chart system transit cusp place place wheel wheel chart cusp time retrograde body ruler wheel birth angle.", + "area4.element225.variant": + "Degree body chart {p1} sign retrograde retrograde shown angle transit place angle {p0} orbit natal transit requested time {p2} birth angle sign ruler body time orbit.", + "area4.element226.variant": + "Place body system degree house {p1} house degree time body {p0} requested natal wheel time retrograde wheel orbit transit orbit cusp ruler transit transit retrograde house sign chart house.", + "area4.element227.variant": + "Sign aspect orbit sign time retrograde transit natal {p0} cusp cusp system angle.", + "area4.element228.variant": + "Shown retrograde sign body {p2} cusp birth shown system sign orbit {p1} body sign cusp orbit birth {p0} ruler aspect sign requested wheel wheel.", + "area4.element229.variant": + "System cusp time time chart chart time time sign natal shown birth body angle degree shown ruler body house angle time ruler place angle orbit degree transit.", + "area4.element230.variant": "Birth sign angle system body body.", + "area4.element231.variant": + "House orbit transit chart degree system requested requested sign orbit birth birth requested house chart system degree chart sign shown place aspect shown wheel retrograde retrograde body.", + "area4.element232.variant": + "Requested chart aspect house house aspect wheel system orbit place.", + "area4.element233.variant": + "Wheel ruler house shown place time requested aspect cusp requested natal sign.", + "area4.element234.variant": + "{p0} Requested natal place requested transit {p1} place body orbit cusp place.", + "area4.element235.variant": + "Chart requested retrograde retrograde ruler house body retrograde natal body {p1} transit natal aspect {p0} sign angle body ruler retrograde aspect birth aspect {p2} place ruler time birth body.", + "area4.element236.variant": + "Orbit orbit system system orbit ruler {p0} birth body {p2} {p1} shown sign transit place angle body degree place chart aspect body cusp.", + "area4.element237.variant": + "Chart aspect system shown requested house place {p0} chart ruler sign wheel {p1} cusp retrograde.", + "area4.element238.variant": + "System ruler birth time aspect house body angle sign cusp cusp wheel ruler.", + "area4.element239.variant": + "Natal orbit wheel ruler requested ruler degree.", + "area4.element240.variant": + "Place cusp requested {p0} {p1} shown birth transit.", + "area4.element241.variant": + "Degree angle orbit wheel natal transit aspect house transit birth cusp shown body degree body place system house angle angle wheel.", + "area4.element242.variant": + "Sign time shown aspect shown wheel house orbit angle chart sign requested transit {p0} {p1} sign sign angle birth orbit transit retrograde transit birth cusp place requested.", + "area4.element243.variant": + "Natal angle angle chart shown system birth requested shown degree transit chart sign natal birth body degree place house requested angle transit sign time transit retrograde.", + "area4.element244.variant": + "Ruler sign orbit cusp system degree requested retrograde natal time transit sign chart time body system system ruler retrograde.", + "area4.element245.variant": + "House sign angle birth time ruler requested shown ruler ruler requested angle cusp retrograde orbit ruler {p0} degree system angle sign sign retrograde shown shown angle wheel retrograde system birth requested.", + "area4.element246.variant": + "Retrograde sign orbit sign retrograde sign aspect {p1} degree {p0} time natal wheel wheel ruler house angle angle requested {p2}.", + "area4.element247.variant": + "Retrograde ruler time shown retrograde cusp orbit birth angle shown retrograde transit sign degree sign body cusp place place degree sign retrograde transit orbit transit sign.", + "area4.element248.variant": + "{p1} Birth body cusp {p0} degree shown retrograde requested {p2} birth angle time.", + "area4.element249.variant": + "Requested aspect requested angle ruler orbit degree shown {p0} place {p1} ruler birth requested body wheel place system shown chart.", + "area5.element250.variant": + "Orbit requested natal shown ruler sign retrograde birth place cusp orbit degree chart orbit aspect sign degree sign.", + "area5.element251.variant": + "House requested ruler {p0} aspect body system birth system orbit shown orbit orbit retrograde ruler angle angle time aspect ruler birth degree.", + "area5.element252.variant": + "Retrograde degree sign {p1} body time shown retrograde retrograde orbit degree orbit natal {p2} {p0} time retrograde system shown natal place wheel sign angle time sign.", + "area5.element253.variant": + "Chart natal system place place time degree place wheel natal {p0}.", + "area5.element254.variant": + "Cusp time angle orbit {p0} requested angle orbit {p1} cusp system natal system sign orbit system retrograde cusp place degree shown.", + "area5.element255.variant": + "House birth chart degree degree birth house angle orbit.", + "area5.element256.variant": + "Natal wheel cusp place cusp birth chart sign aspect transit retrograde cusp degree sign requested system sign wheel wheel.", + "area5.element257.variant": + "Sign sign wheel {p0} aspect body chart body retrograde natal orbit ruler retrograde angle transit chart angle aspect cusp shown system chart transit degree.", + "area5.element258.variant": + "Shown sign transit orbit wheel natal ruler shown place time ruler cusp orbit ruler angle transit orbit {p0} retrograde cusp.", + "area5.element259.variant": + "Retrograde degree aspect place chart ruler time.", + "area5.element260.variant": + "Retrograde place aspect sign orbit time house shown retrograde {p0} ruler house aspect birth requested orbit natal natal orbit system requested aspect chart requested retrograde sign body body house.", + "area5.element261.variant": + "House cusp wheel requested house orbit cusp time ruler system ruler aspect chart natal.", + "area5.element262.variant": + "System sign requested cusp sign degree degree shown chart sign body shown body chart birth birth orbit requested aspect transit {p0}.", + "area5.element263.variant": + "Time system sign body house chart angle house house orbit degree birth orbit system transit ruler requested wheel sign natal system transit birth aspect place orbit retrograde aspect transit.", + "area5.element264.variant": + "Requested sign {p1} shown angle shown place chart chart {p0} ruler.", + "area5.element265.variant": + "House birth birth chart shown aspect chart requested retrograde system retrograde degree wheel time body house.", + "area5.element266.variant": + "Time ruler sign ruler body orbit cusp orbit ruler system wheel time aspect aspect place aspect time requested transit ruler time place wheel system {p0} ruler aspect natal {p1} requested.", + "area5.element267.variant": + "House angle {p1} body orbit sign body {p0} time angle time.", + "area5.element268.variant": + "Shown system transit wheel {p0} retrograde cusp place place ruler orbit retrograde cusp body wheel degree.", + "area5.element269.variant": + "Body system birth cusp {p0} shown degree place sign body ruler retrograde degree wheel {p1} birth birth orbit.", + "area5.element270.variant": + "Body shown shown system {p1} sign requested place degree aspect degree degree {p2} body {p0} place angle body angle sign transit natal time cusp chart.", + "area5.element271.variant": + "Transit cusp system {p1} sign time transit aspect body {p0} retrograde retrograde cusp degree shown natal chart transit transit shown chart cusp transit cusp sign house system.", + "area5.element272.variant": + "Retrograde cusp birth retrograde time wheel {p0} time aspect {p1} {p2} degree.", + "area5.element273.variant": + "Shown {p1} aspect angle sign aspect cusp system birth aspect body wheel sign wheel {p0} degree house place body.", + "area5.element274.variant": + "Ruler ruler angle aspect ruler cusp time aspect orbit sign ruler ruler time orbit transit angle cusp shown time orbit orbit sign {p1} {p0} shown.", + "area5.element275.variant": + "Ruler angle aspect ruler orbit degree orbit transit chart sign aspect place aspect shown ruler aspect wheel house orbit ruler ruler birth.", + "area5.element276.variant": + "Natal ruler ruler natal wheel angle requested transit shown orbit time birth place natal shown requested body {p0} angle.", + "area5.element277.variant": + "Shown time angle cusp transit requested requested {p0} system retrograde time angle aspect body.", + "area5.element278.variant": + "Ruler wheel natal time birth time degree aspect orbit time body birth orbit sign time retrograde time birth sign retrograde sign retrograde.", + "area5.element279.variant": + "Requested chart system shown natal place system time natal natal {p0} system {p2} ruler birth aspect natal natal sign chart cusp birth {p1} sign.", + "area5.element280.variant": + "Orbit requested degree body angle retrograde time cusp shown chart place requested aspect wheel wheel cusp chart cusp time wheel time aspect time angle transit.", + "area5.element281.variant": + "Requested transit birth sign retrograde retrograde system ruler {p0} sign natal place body shown {p2} natal chart retrograde wheel orbit {p1} sign sign degree cusp orbit.", + "area5.element282.variant": + "Cusp system wheel time chart body natal aspect {p1} aspect system ruler angle natal place time chart aspect degree aspect body {p0} transit house natal time transit house birth requested.", + "area5.element283.variant": + "Angle ruler body chart system wheel {p0} {p1} retrograde sign house cusp chart house chart shown ruler body angle.", + "area5.element284.variant": + "Wheel body angle wheel cusp {p0} birth house wheel chart body place birth requested sign natal cusp system ruler house wheel house house transit {p2} sign {p1} retrograde time orbit.", + "area5.element285.variant": + "Ruler orbit aspect wheel birth aspect body shown aspect angle shown aspect ruler {p1} retrograde {p0}.", + "area5.element286.variant": + "Transit {p0} transit degree birth aspect aspect natal sign angle place natal time angle angle transit cusp system orbit place body.", + "area5.element287.variant": + "Natal body angle transit transit system transit system retrograde ruler {p1} {p0} {p2} place cusp.", + "area5.element288.variant": + "Ruler {p0} degree house angle natal aspect body time {p1} aspect time shown angle aspect retrograde shown birth cusp ruler cusp orbit angle body.", + "area5.element289.variant": + "Sign degree natal requested system {p0} wheel orbit angle requested ruler.", + "area5.element290.variant": + "Orbit cusp degree birth wheel body {p1} place sign aspect ruler sign transit {p0} orbit.", + "area5.element291.variant": + "Angle degree sign {p1} {p0} degree time body.", + "area5.element292.variant": + "Transit natal time orbit body place {p1} sign cusp place cusp transit wheel {p0} aspect orbit retrograde natal time house chart ruler birth wheel orbit sign retrograde {p2}.", + "area5.element293.variant": + "Birth degree body retrograde {p0} shown house natal retrograde transit transit angle birth sign body chart requested angle time house chart cusp requested transit sign requested.", + "area5.element294.variant": + "Transit {p0} aspect requested orbit system body transit body birth body system cusp degree ruler cusp.", + "area5.element295.variant": + "House retrograde sign ruler requested {p2} {p1} house birth {p0} retrograde.", + "area5.element296.variant": + "Transit natal body natal sign aspect angle time aspect shown requested natal {p1} orbit degree orbit chart retrograde retrograde sign chart angle cusp {p0} house requested natal.", + "area5.element297.variant": + "Cusp chart aspect retrograde degree ruler orbit requested time birth transit degree house sign {p0} birth ruler retrograde aspect system birth birth chart retrograde orbit.", + "area5.element298.variant": + "Cusp house place aspect {p1} requested requested aspect chart {p2} place body angle requested {p0} retrograde.", + "area5.element299.variant": + "Orbit sign shown degree requested wheel natal degree birth requested body shown orbit transit transit aspect chart degree orbit place time angle ruler shown birth sign.", + "area6.element300.variant": + "Degree cusp {p0} house birth orbit degree house system aspect retrograde house system angle {p1} natal cusp place requested.", + "area6.element301.variant": + "Angle retrograde sign time chart natal natal retrograde wheel system natal sign aspect birth natal requested {p0} angle wheel orbit shown wheel ruler natal degree.", + "area6.element302.variant": + "Birth house angle aspect retrograde ruler shown aspect time system shown requested transit birth requested retrograde retrograde house {p1} {p0} time wheel transit natal body birth.", + "area6.element303.variant": + "Time {p1} natal system aspect wheel house {p0} sign angle system degree body system orbit house chart.", + "area6.element304.variant": + "Cusp ruler angle body house chart angle birth.", + "area6.element305.variant": + "Cusp place ruler ruler natal system {p0} sign.", + "area6.element306.variant": + "Degree retrograde chart orbit aspect cusp natal time angle system wheel cusp chart ruler transit requested aspect cusp retrograde cusp ruler birth birth angle system angle wheel house sign.", + "area6.element307.variant": + "{p1} Sign retrograde {p0} angle degree chart ruler ruler ruler time cusp sign birth.", + "area6.element308.variant": + "Degree birth time sign {p0} {p1} sign aspect degree body house orbit body angle ruler sign.", + "area6.element309.variant": + "Wheel house place birth {p1} sign {p0} angle {p2}.", + "area6.element310.variant": + "Time system transit transit natal angle shown {p0}.", + "area6.element311.variant": + "Wheel system time wheel degree place requested aspect birth aspect place body house cusp cusp {p0} sign wheel {p1} aspect {p2} natal body.", + "area6.element312.variant": + "Place cusp orbit ruler {p0} chart system retrograde retrograde birth aspect system requested house transit system retrograde time degree time shown transit requested sign natal birth degree time.", + "area6.element313.variant": + "Chart system natal chart birth time natal ruler retrograde birth {p0} transit.", + "area6.element314.variant": + "Orbit wheel chart shown ruler orbit time ruler time house house wheel chart wheel cusp body wheel aspect sign retrograde.", + "area6.element315.variant": + "Transit retrograde system place system natal house transit requested place requested time system place wheel degree natal.", + "area6.element316.variant": + "Wheel requested orbit requested transit orbit natal orbit wheel {p1} sign requested wheel {p2} shown time requested birth wheel cusp {p0} sign retrograde wheel degree shown place.", + "area6.element317.variant": + "Cusp natal wheel time cusp sign {p0} shown birth shown aspect degree time shown.", + "area6.element318.variant": + "Aspect retrograde degree orbit angle time transit wheel orbit birth.", + "area6.element319.variant": + "{p1} Cusp wheel wheel shown {p2} system system sign {p0} sign cusp birth chart birth.", + "area6.element320.variant": + "House body {p0} orbit system body body cusp degree orbit shown shown house requested time {p2} system {p1} system.", + "area6.element321.variant": + "Retrograde place orbit transit natal house {p0} place degree transit.", + "area6.element322.variant": + "Place orbit aspect place time retrograde shown wheel {p0} transit requested chart degree system cusp aspect angle sign transit wheel orbit time retrograde.", + "area6.element323.variant": + "Natal wheel {p0} natal time place cusp place shown cusp birth time natal ruler time {p1} cusp retrograde retrograde house cusp birth shown cusp cusp {p2} cusp orbit chart aspect natal sign.", + "area6.element324.variant": + "Orbit body cusp cusp angle chart shown {p0} chart birth.", + "area6.element325.variant": + "System house {p2} {p0} body transit cusp requested {p1} time natal birth angle.", + "area6.element326.variant": + "{p1} Requested wheel requested birth {p0} system transit degree.", + "area6.element327.variant": + "{p2} {p0} House system cusp {p1} retrograde shown orbit chart angle.", + "area6.element328.variant": + "Degree house aspect sign time birth place sign requested {p1} {p0} degree retrograde wheel.", + "area6.element329.variant": + "Cusp {p1} {p0} wheel natal cusp {p2} aspect transit.", + "area6.element330.variant": + "Natal {p0} chart {p2} system wheel natal degree angle cusp {p1} natal body sign angle house.", + "area6.element331.variant": + "Ruler retrograde retrograde {p1} transit house {p0} wheel shown aspect shown time transit.", + "area6.element332.variant": + "House sign {p0} birth orbit ruler sign system aspect requested birth angle orbit retrograde birth.", + "area6.element333.variant": + "{p1} Retrograde degree requested shown house ruler transit ruler time angle aspect ruler place ruler aspect time ruler {p2} natal requested birth wheel ruler transit chart cusp place {p0} chart.", + "area6.element334.variant": + "Place body ruler time transit sign cusp house orbit system place transit shown retrograde house ruler sign place sign time {p0}.", + "area6.element335.variant": + "House aspect requested place birth system body {p1} chart system body {p2} {p0} chart.", + "area6.element336.variant": + "Cusp requested sign degree ruler system cusp place system system body degree chart angle orbit body house chart transit {p0} shown orbit aspect time time body.", + "area6.element337.variant": + "Aspect natal ruler transit transit chart {p0} wheel transit body orbit birth place house.", + "area6.element338.variant": + "Retrograde transit aspect aspect birth ruler house natal house angle natal aspect shown ruler system natal body requested wheel aspect place natal birth {p0} degree requested natal house.", + "area6.element339.variant": + "Degree natal requested system chart natal {p0} aspect chart degree retrograde birth body cusp place orbit cusp retrograde natal natal.", + "area6.element340.variant": + "Body house shown {p0} system {p2} shown chart time {p1} cusp chart.", + "area6.element341.variant": + "Wheel body retrograde natal sign orbit birth cusp transit cusp cusp birth birth requested ruler aspect body orbit natal retrograde retrograde birth {p1} natal body place degree {p0}.", + "area6.element342.variant": + "Aspect house shown wheel shown natal wheel ruler place ruler angle transit angle orbit {p1} retrograde aspect place house transit {p0}.", + "area6.element343.variant": + "Place time cusp cusp shown {p0} {p1} body {p2} retrograde.", + "area6.element344.variant": + "Chart aspect retrograde cusp shown system shown time house cusp place birth body ruler house house requested wheel place aspect chart angle requested house.", + "area6.element345.variant": + "Sign system degree natal body place degree retrograde body requested system birth system body house degree transit body body angle place degree {p0} wheel wheel.", + "area6.element346.variant": + "Chart transit requested cusp {p1} {p0} natal cusp cusp time degree degree sign.", + "area6.element347.variant": + "Orbit body cusp retrograde {p1} time orbit {p0} place natal house {p2} shown requested.", + "area6.element348.variant": + "Ruler sign {p0} system body natal place angle body shown {p1} natal natal aspect.", + "area6.element349.variant": + "Birth orbit shown birth birth system aspect birth ruler time house house body body system birth.", + "area7.element350.variant": + "Angle retrograde birth natal aspect transit aspect place degree angle house birth transit system cusp requested ruler chart orbit degree cusp orbit retrograde retrograde ruler house angle.", + "area7.element351.variant": + "Transit degree shown wheel birth chart cusp sign retrograde body cusp natal system orbit house aspect transit birth system house angle orbit wheel chart body birth wheel.", + "area7.element352.variant": + "Transit {p0} cusp chart sign {p2} aspect {p1} cusp degree body.", + "area7.element353.variant": + "Time body ruler ruler birth angle wheel requested angle requested transit house house transit wheel sign chart wheel chart angle body aspect orbit place chart.", + "area7.element354.variant": + "Natal {p2} {p0} requested transit orbit house system wheel cusp body {p1} requested degree.", + "area7.element355.variant": + "Birth natal cusp ruler natal birth place orbit shown birth wheel degree orbit sign requested orbit birth sign requested natal place.", + "area7.element356.variant": + "Time angle angle transit time angle ruler natal wheel house wheel retrograde retrograde system transit angle requested orbit orbit aspect body wheel natal body sign birth.", + "area7.element357.variant": + "Chart orbit orbit house body requested natal requested sign {p1} time house transit time house house angle house body angle shown {p0} degree sign natal aspect angle degree chart aspect house.", + "area7.element358.variant": + "Aspect system chart angle wheel chart transit birth house.", + "area7.element359.variant": + "Orbit angle sign ruler cusp aspect wheel retrograde natal shown place transit requested chart requested transit birth requested birth time ruler ruler place.", + "area7.element360.variant": + "Birth birth natal shown degree {p1} ruler aspect {p0} shown retrograde shown time {p2} aspect angle cusp.", + "area7.element361.variant": + "{p2} Aspect orbit transit time transit cusp cusp body body {p1} system {p0} sign birth sign orbit ruler ruler place shown aspect.", + "area7.element362.variant": + "Orbit shown degree {p1} time chart shown {p0} angle sign aspect system ruler system cusp chart aspect natal house aspect place.", + "area7.element363.variant": + "Aspect birth angle degree sign chart orbit system body birth system birth place birth body ruler time cusp {p0} wheel system body degree cusp requested house system requested requested shown.", + "area7.element364.variant": + "{p0} {p1} Aspect place cusp sign ruler requested ruler system transit wheel ruler birth transit.", + "area7.element365.variant": + "Transit ruler natal aspect {p0} requested transit {p1} requested {p2} cusp transit natal degree house sign natal place system.", + "area7.element366.variant": + "Shown transit system {p0} ruler requested orbit {p1} orbit birth orbit {p2} natal angle chart wheel place requested system transit house time.", + "area7.element367.variant": + "Requested {p2} sign {p0} shown place sign retrograde degree natal aspect ruler birth {p1} birth place house retrograde orbit transit.", + "area7.element368.variant": + "Requested chart {p0} system orbit aspect system aspect body.", + "area7.element369.variant": + "{p0} Wheel sign house ruler birth ruler chart retrograde orbit time {p2} {p1}.", + "area7.element370.variant": + "Cusp {p1} shown birth birth transit birth house aspect {p0} system requested {p2}.", + "area7.element371.variant": + "Birth wheel place {p1} {p0} retrograde sign shown place natal time degree sign.", + "area7.element372.variant": + "Orbit ruler wheel chart wheel time shown wheel natal house chart {p0} natal ruler system requested natal house chart retrograde natal house {p1} ruler wheel transit.", + "area7.element373.variant": + "Retrograde ruler angle place time place aspect degree {p2} body birth system wheel birth {p0} wheel ruler aspect system {p1} angle cusp birth birth.", + "area7.element374.variant": + "Time place degree house ruler cusp orbit house {p0} house angle retrograde body chart transit house body house time system system system chart time body orbit {p1} shown birth cusp.", + "area7.element375.variant": + "{p1} Aspect orbit place time body body body chart house angle retrograde {p2} {p0} orbit degree house body angle time cusp ruler ruler time transit orbit transit natal chart body shown ruler.", + "area7.element376.variant": + "Degree ruler system orbit {p0} orbit place natal birth body degree time angle shown aspect birth requested place requested wheel.", + "area7.element377.variant": + "Transit time requested time orbit retrograde house aspect wheel chart natal chart {p0} {p1} body body {p2} degree system time.", + "area7.element378.variant": + "Wheel degree {p0} cusp orbit requested transit ruler body sign natal requested {p2} natal place retrograde ruler cusp house birth time retrograde birth cusp {p1} sign wheel sign house transit.", + "area7.element379.variant": + "Cusp ruler wheel angle house angle wheel shown {p0} aspect wheel ruler system transit chart requested requested transit shown sign body orbit birth.", + "area7.element380.variant": + "Time birth time retrograde sign retrograde orbit system cusp aspect birth angle house birth requested orbit birth sign transit body body house body sign chart cusp chart cusp system.", + "area7.element381.variant": + "Degree sign degree degree natal degree birth degree orbit house time chart chart {p1} retrograde place body {p0} cusp.", + "area7.element382.variant": + "Transit angle birth orbit body birth natal chart requested angle time degree ruler wheel.", + "area7.element383.variant": + "{p0} {p2} System shown sign body chart {p1} house orbit.", + "area7.element384.variant": + "House orbit time chart natal chart sign aspect chart natal birth transit wheel aspect system angle place retrograde ruler degree house body.", + "area7.element385.variant": + "Body house requested time time body sign {p0} time.", + "area7.element386.variant": + "Aspect sign house wheel aspect angle time ruler transit natal house birth natal {p1} birth shown {p0} chart natal.", + "area7.element387.variant": + "Place ruler degree transit transit wheel system shown house wheel requested requested retrograde {p0} transit degree transit system angle place birth time time requested system.", + "area7.element388.variant": + "Degree wheel time {p1} {p0} sign natal wheel orbit transit angle aspect natal shown {p2} angle degree requested house birth.", + "area7.element389.variant": + "Retrograde ruler shown place degree cusp place house transit natal orbit transit time retrograde degree wheel place degree place place natal aspect retrograde aspect retrograde degree birth house birth.", + "area7.element390.variant": + "Degree requested natal system aspect ruler sign time body birth house ruler angle shown body house body cusp transit.", + "area7.element391.variant": + "Aspect orbit sign system system system requested wheel {p0} degree house degree.", + "area7.element392.variant": + "Body house requested {p0} birth sign sign chart angle birth ruler orbit sign angle {p1}.", + "area7.element393.variant": + "Ruler house time shown ruler degree birth transit requested sign system {p0} retrograde birth orbit angle system time chart chart birth chart chart body.", + "area7.element394.variant": + "Birth birth aspect requested body natal house body wheel body ruler natal body sign wheel {p0} place degree house natal orbit.", + "area7.element395.variant": + "Retrograde time chart orbit degree wheel ruler ruler angle sign place place orbit degree house time cusp chart transit orbit chart system sign.", + "area7.element396.variant": + "Requested birth retrograde retrograde birth wheel sign chart retrograde system angle {p0} {p1} birth aspect place.", + "area7.element397.variant": + "Requested chart chart aspect transit cusp shown ruler chart body system angle body orbit transit birth sign natal system shown birth place cusp place.", + "area7.element398.variant": + "System retrograde sign place retrograde shown house birth place natal orbit time house degree orbit natal house retrograde ruler shown requested.", + "area7.element399.variant": + "Requested transit chart {p2} house {p0} aspect place cusp time place {p1} requested place.", + "area8.element400.variant": + "Ruler place orbit place degree transit natal time orbit wheel angle time transit system place orbit system retrograde shown cusp orbit retrograde cusp cusp place cusp {p0} degree chart time house.", + "area8.element401.variant": + "Chart time cusp transit system degree {p0} birth chart transit {p2} chart orbit transit {p1} house orbit requested angle time transit system.", + "area8.element402.variant": + "Angle cusp chart wheel transit natal place house cusp natal sign shown body retrograde sign degree {p1} natal place house system retrograde {p2} chart requested birth natal place shown {p0} retrograde house angle.", + "area8.element403.variant": + "Shown house transit wheel body system system natal place system house shown place body {p1} birth sign {p0}.", + "area8.element404.variant": + "Natal aspect house angle angle system house birth degree chart degree house sign ruler aspect wheel birth angle house degree wheel body aspect.", + "area8.element405.variant": + "{p1} Shown wheel {p2} transit transit wheel {p0} transit retrograde aspect house time wheel aspect orbit sign cusp.", + "area8.element406.variant": + "Natal birth system retrograde orbit chart retrograde.", + "area8.element407.variant": + "Shown cusp retrograde {p0} place time requested cusp angle body aspect {p1} transit sign time requested body.", + "area8.element408.variant": + "{p0} Aspect ruler ruler house {p1} place place body requested aspect time.", + "area8.element409.variant": + "{p2} Ruler system {p1} {p0} time orbit orbit degree requested degree transit chart transit time.", + "area8.element410.variant": + "Body angle requested house place cusp transit transit chart system body time body.", + "area8.element411.variant": + "Body degree aspect shown ruler cusp degree birth orbit body {p0} place orbit sign cusp cusp body.", + "area8.element412.variant": + "Retrograde orbit cusp chart orbit ruler retrograde {p1} degree birth orbit {p0} cusp system wheel.", + "area8.element413.variant": + "Requested birth transit orbit aspect time requested house orbit body shown house natal requested cusp chart body {p1} wheel {p0} system retrograde {p2} chart requested shown natal shown time cusp birth.", + "area8.element414.variant": + "Retrograde body cusp degree requested retrograde system transit shown shown system house.", + "area8.element415.variant": + "Retrograde {p0} natal aspect aspect {p1} angle system orbit time {p2} cusp birth chart body ruler body place birth retrograde body.", + "area8.element416.variant": + "Transit shown body body angle transit time wheel house shown birth sign chart birth wheel natal body house degree sign house cusp wheel chart chart wheel degree.", + "area8.element417.variant": + "Time retrograde orbit time house shown transit chart angle requested wheel natal.", + "area8.element418.variant": + "Degree place wheel {p0} requested requested body wheel transit place chart shown.", + "area8.element419.variant": + "Aspect natal body {p0} retrograde degree cusp system retrograde place ruler time orbit shown retrograde birth chart degree retrograde chart aspect natal sign birth cusp place aspect birth requested system ruler.", + "area8.element420.variant": + "Shown sign aspect natal system sign retrograde birth angle orbit chart chart degree angle.", + "area8.element421.variant": + "Birth orbit degree angle {p1} chart house shown ruler aspect time sign system degree cusp natal {p0} natal wheel requested transit degree ruler.", + "area8.element422.variant": + "Body place time house chart chart time orbit transit wheel time house ruler transit {p0} natal house house angle time.", + "area8.element423.variant": "Retrograde ruler cusp sign wheel ruler.", + "area8.element424.variant": + "Aspect cusp degree body transit natal place requested orbit body wheel orbit sign {p0} shown birth house body retrograde natal body birth cusp ruler retrograde transit.", + "area8.element425.variant": + "Time {p0} chart sign retrograde system body retrograde shown cusp place transit time.", + "area8.element426.variant": + "Body angle requested angle shown transit aspect cusp angle birth birth {p1} {p0}.", + "area8.element427.variant": + "Cusp degree angle {p0} shown orbit cusp house sign angle ruler ruler wheel ruler transit angle birth ruler.", + "area8.element428.variant": + "Body system ruler house natal wheel requested {p0} {p1}.", + "area8.element429.variant": + "Ruler ruler chart house house system ruler retrograde {p0} orbit natal body place degree chart angle aspect orbit requested angle.", + "area8.element430.variant": + "Body orbit place birth chart natal wheel aspect aspect birth system retrograde degree body body place chart requested shown place sign ruler orbit.", + "area8.element431.variant": + "Birth transit requested {p2} time orbit aspect house wheel {p1} wheel {p0} wheel body transit requested wheel wheel retrograde.", + "area8.element432.variant": + "House transit {p0} system house angle requested cusp {p1} cusp aspect house angle.", + "area8.element433.variant": + "Body {p0} sign requested time time aspect place requested {p1} chart sign cusp cusp birth.", + "area8.element434.variant": + "Orbit cusp requested aspect house retrograde aspect wheel aspect system.", + "area8.element435.variant": + "Angle orbit wheel wheel requested sign transit sign birth sign natal sign wheel chart transit shown natal {p0} natal {p1} house birth ruler retrograde.", + "area8.element436.variant": + "Degree house body house wheel retrograde {p0} aspect sign body birth transit degree aspect.", + "area8.element437.variant": + "Shown house place birth time birth {p2} requested retrograde birth place requested system ruler ruler {p1} aspect body shown body house degree {p0} shown degree ruler birth time body house cusp.", + "area8.element438.variant": + "Cusp cusp ruler ruler retrograde system system chart shown time birth cusp angle ruler cusp house requested body system time.", + "area8.element439.variant": + "Angle birth orbit chart {p0} cusp body {p1}.", + "area8.element440.variant": + "System body aspect {p1} sign system degree {p0}.", + "area8.element441.variant": + "Birth cusp {p0} requested chart orbit {p1} chart angle chart place house aspect chart cusp system orbit sign.", + "area8.element442.variant": + "Angle wheel wheel ruler ruler time aspect body place sign system shown ruler degree angle shown angle ruler aspect time orbit {p0} aspect shown chart transit system degree body ruler wheel.", + "area8.element443.variant": + "{p0} {p1} Body ruler degree natal natal shown angle time cusp body orbit wheel body body degree retrograde orbit.", + "area8.element444.variant": + "Transit cusp time requested natal wheel sign {p0} degree degree {p1} cusp.", + "area8.element445.variant": + "Aspect aspect {p0} cusp wheel ruler system system natal birth requested orbit transit ruler chart.", + "area8.element446.variant": + "Chart birth cusp angle place {p1} body angle {p0} ruler angle orbit {p2} cusp angle time retrograde house transit body house place angle ruler.", + "area8.element447.variant": + "System ruler sign natal house aspect {p0} shown natal aspect time time body wheel angle retrograde birth degree aspect time angle time degree house retrograde {p1} aspect ruler wheel wheel.", + "area8.element448.variant": + "Orbit place chart {p1} place shown natal requested place requested body orbit {p0}.", + "area8.element449.variant": + "Time degree orbit orbit orbit natal aspect angle shown cusp system time wheel cusp cusp place place ruler ruler.", + "area9.element450.variant": + "Retrograde retrograde body body {p0} sign body place {p1} chart wheel house retrograde degree shown requested time body system natal.", + "area9.element451.variant": + "Wheel requested transit angle degree wheel natal ruler {p0} sign.", + "area9.element452.variant": + "Aspect degree body natal degree sign natal sign cusp requested birth chart {p2} {p1} birth angle ruler birth transit {p0} orbit wheel orbit transit requested.", + "area9.element453.variant": + "Retrograde time chart sign degree time ruler {p1} birth birth cusp degree body sign angle {p0}.", + "area9.element454.variant": + "Chart aspect body shown cusp requested retrograde cusp retrograde system orbit shown chart {p1} orbit orbit orbit {p0}.", + "area9.element455.variant": + "Ruler angle house house {p0} wheel orbit natal ruler system transit chart body place ruler birth orbit time degree place time transit ruler aspect time degree.", + "area9.element456.variant": + "Aspect shown aspect transit cusp wheel birth chart shown shown retrograde {p0} place retrograde angle shown place birth.", + "area9.element457.variant": + "Natal system shown body angle {p2} cusp house wheel ruler time natal {p1} orbit {p0} requested retrograde ruler body degree.", + "area9.element458.variant": + "Shown natal sign aspect house degree chart place sign body {p0} sign natal transit {p2} birth {p1} cusp sign sign.", + "area9.element459.variant": "Cusp sign cusp time system sign.", + "area9.element460.variant": + "Shown requested sign wheel degree place wheel orbit time transit chart body transit ruler orbit place body chart wheel chart natal place.", + "area9.element461.variant": + "Chart angle natal house natal {p0} system system shown house birth chart wheel {p1} body body house place ruler birth requested place system house body chart birth aspect.", + "area9.element462.variant": + "Chart transit orbit retrograde birth {p0} sign retrograde shown orbit natal.", + "area9.element463.variant": + "Orbit angle aspect ruler orbit retrograde retrograde chart body degree body place degree orbit birth house {p0} shown {p1} natal aspect orbit angle sign house wheel birth.", + "area9.element464.variant": + "Requested natal {p0} shown shown transit transit cusp aspect transit aspect degree requested shown wheel degree wheel cusp shown aspect {p1} system system.", + "area9.element465.variant": + "Ruler {p0} natal wheel house natal system time {p2} {p1} orbit retrograde ruler degree.", + "area9.element466.variant": + "Sign ruler degree natal transit transit natal house {p0} house body wheel body body.", + "area9.element467.variant": + "Angle body orbit angle degree chart degree house sign aspect angle natal retrograde house transit place place wheel place chart system orbit house time.", + "area9.element468.variant": + "Chart angle shown body ruler orbit retrograde orbit system retrograde.", + "area9.element469.variant": + "Wheel shown place degree degree time orbit wheel cusp {p1} shown {p2} cusp degree time requested sign shown chart sign house house system cusp {p0} place aspect cusp house.", + "area9.element470.variant": + "Place system cusp ruler aspect {p0} chart place body cusp time chart wheel ruler ruler cusp place sign system.", + "area9.element471.variant": + "Orbit aspect {p0} transit house orbit shown retrograde aspect cusp chart chart place.", + "area9.element472.variant": + "Degree degree place angle retrograde sign birth shown wheel ruler body natal degree.", + "area9.element473.variant": + "Requested requested chart ruler retrograde chart system aspect {p2} {p0} aspect {p1} birth.", + "area9.element474.variant": + "Retrograde requested natal time body place house wheel {p0} chart degree {p1} sign.", + "area9.element475.variant": + "Birth body house aspect {p0} sign aspect natal aspect aspect wheel requested transit system angle aspect wheel sign cusp wheel wheel sign house cusp cusp transit sign place wheel transit.", + "area9.element476.variant": + "House {p0} retrograde aspect retrograde time degree birth retrograde sign orbit sign transit natal cusp cusp place chart house body system wheel aspect shown system cusp shown birth.", + "area9.element477.variant": + "Time angle sign angle body system chart chart shown chart aspect {p0} {p1} sign body retrograde wheel shown house {p2} transit body shown.", + "area9.element478.variant": + "Cusp time natal angle requested chart requested place body retrograde place ruler aspect system house system chart cusp cusp wheel birth house natal sign shown retrograde system cusp sign place.", + "area9.element479.variant": + "Orbit system aspect shown system house house orbit orbit body cusp time body angle house orbit birth time birth sign sign angle body system cusp {p1} transit place degree angle {p0}.", + "area9.element480.variant": + "Body {p0} angle birth birth {p1} degree shown cusp retrograde requested time degree wheel sign {p2} birth time.", + "area9.element481.variant": + "Birth orbit {p0} place retrograde shown body cusp {p1} house angle aspect ruler cusp place retrograde system cusp degree aspect birth.", + "area9.element482.variant": + "Body angle body natal system body birth time requested time system chart transit chart sign orbit house birth birth aspect aspect body natal chart.", + "area9.element483.variant": + "Angle aspect sign ruler birth transit natal {p0} ruler {p1} angle birth {p2} ruler chart aspect.", + "area9.element484.variant": + "Retrograde shown house ruler {p0} requested place chart wheel transit natal cusp natal cusp system wheel wheel place sign house shown ruler birth requested body cusp time orbit birth.", + "area9.element485.variant": + "Sign orbit house sign house wheel sign degree wheel aspect.", + "area9.element486.variant": + "Shown place birth house place birth system aspect birth requested sign natal chart house orbit birth angle.", + "area9.element487.variant": + "House time birth birth degree retrograde system orbit shown.", + "area9.element488.variant": + "{p2} Place transit natal system aspect aspect requested natal angle retrograde chart requested wheel retrograde orbit {p0} body cusp sign house house time {p1} degree body.", + "area9.element489.variant": + "Chart transit degree system aspect sign body system transit ruler body degree house angle orbit house.", + "area9.element490.variant": + "Ruler requested shown body ruler place ruler {p1} {p0} system house wheel sign shown {p2} house transit transit shown wheel.", + "area9.element491.variant": + "Shown shown retrograde degree house ruler requested {p0} chart chart transit system cusp angle requested ruler sign sign wheel place time wheel wheel system time place house.", + "area9.element492.variant": + "{p1} Aspect ruler angle angle natal shown {p0} orbit.", + "area9.element493.variant": + "Orbit wheel cusp time ruler wheel place ruler orbit requested place angle requested {p1} retrograde angle orbit sign body ruler system {p0} body cusp sign transit degree birth house transit place time.", + "area9.element494.variant": + "Retrograde degree retrograde angle house system degree aspect birth requested time chart birth chart orbit aspect system degree degree system degree place sign requested shown natal.", + "area9.element495.variant": + "Cusp degree retrograde degree house wheel requested birth requested angle chart natal natal system body sign place natal wheel orbit shown degree place place ruler.", + "area9.element496.variant": + "Orbit angle cusp {p0} birth system natal degree chart place body cusp aspect requested retrograde angle ruler cusp orbit orbit angle {p1} time wheel requested {p2} retrograde requested retrograde time sign time.", + "area9.element497.variant": + "Ruler house time angle transit chart aspect angle {p0} wheel house transit time orbit birth body ruler degree place sign aspect chart retrograde house retrograde requested body wheel shown system wheel.", + "area9.element498.variant": + "Requested degree time retrograde orbit {p0} retrograde {p2} {p1} birth.", + "area9.element499.variant": + "Ruler body sign time time requested {p1} {p0}.", + "area10.element500.variant": + "Shown transit {p0} shown place {p1} cusp aspect time retrograde sign house natal transit {p2} natal ruler aspect requested.", + "area10.element501.variant": + "Orbit body cusp birth requested shown chart degree house requested system cusp {p0} requested body requested ruler retrograde requested shown orbit body {p1} body body requested cusp birth chart natal place ruler.", + "area10.element502.variant": + "Time {p0} birth aspect transit natal ruler angle degree degree natal requested birth shown shown orbit cusp system wheel cusp birth natal system shown birth transit aspect shown.", + "area10.element503.variant": + "Body degree orbit shown cusp requested place natal transit body house transit orbit shown chart angle natal {p0} birth degree house {p1} degree birth body angle retrograde aspect {p2} retrograde.", + "area10.element504.variant": + "Ruler angle house wheel natal ruler place degree time body birth place sign place body natal degree system sign orbit cusp requested chart orbit sign ruler retrograde natal orbit retrograde.", + "area10.element505.variant": + "Time birth natal natal ruler sign degree retrograde angle {p0} chart ruler {p2} place birth ruler aspect {p1} body birth cusp.", + "area10.element506.variant": + "Birth body aspect wheel cusp system degree ruler orbit system.", + "area10.element507.variant": + "{p0} {p1} Birth place time wheel time sign birth.", + "area10.element508.variant": + "Degree wheel aspect natal transit aspect body orbit orbit system orbit cusp chart birth requested body requested aspect shown.", + "area10.element509.variant": + "{p1} Wheel wheel ruler time shown natal {p0} body angle house wheel angle sign wheel aspect.", + "area10.element510.variant": + "Time angle wheel {p1} place transit retrograde aspect retrograde time house requested wheel {p0} shown wheel degree ruler aspect natal.", + "area10.element511.variant": + "Shown cusp natal wheel {p0} orbit shown natal body body {p1} house natal body aspect.", + "area10.element512.variant": + "Shown aspect body wheel ruler body sign sign.", + "area10.element513.variant": + "Time {p0} transit wheel sign body body retrograde orbit sign {p2} degree birth birth body transit sign body wheel {p1} sign system orbit.", + "area10.element514.variant": + "Body {p1} time cusp shown {p0} time chart ruler transit house degree requested retrograde {p2} retrograde.", + "area10.element515.variant": + "Transit body angle time requested aspect angle shown place body {p1} wheel body shown angle ruler {p0} chart chart.", + "area10.element516.variant": + "Aspect natal time place place birth angle requested birth wheel system birth ruler house degree orbit degree.", + "area10.element517.variant": + "Orbit birth transit transit birth cusp place angle transit place ruler cusp angle place sign requested cusp aspect cusp orbit system wheel cusp natal retrograde angle.", + "area10.element518.variant": + "Birth aspect place birth retrograde ruler house {p0} aspect wheel.", + "area10.element519.variant": + "Angle orbit ruler wheel wheel shown house body system retrograde aspect orbit degree body place house house birth place angle transit place body system system cusp aspect cusp time angle.", + "area10.element520.variant": + "Orbit natal angle system place orbit chart natal {p1} angle birth birth cusp birth orbit angle {p0} degree birth wheel system orbit.", + "area10.element521.variant": + "Retrograde house wheel wheel {p1} time sign degree {p0} time cusp aspect birth aspect degree system requested body ruler orbit body transit body place place {p2} shown angle angle requested.", + "area10.element522.variant": + "Aspect {p0} chart place birth degree transit {p1} sign place system orbit system degree wheel shown.", + "area10.element523.variant": + "Angle requested house house requested aspect house sign aspect orbit retrograde ruler chart wheel degree cusp birth ruler aspect degree retrograde chart retrograde ruler transit time {p1} time {p0}.", + "area10.element524.variant": + "Orbit time ruler shown aspect {p0} sign shown.", + "area10.element525.variant": + "House retrograde degree natal angle body shown wheel cusp orbit natal time {p2} chart body ruler {p1} system time birth house {p0} system retrograde.", + "area10.element526.variant": + "Retrograde ruler orbit aspect {p0} chart transit house house orbit house wheel aspect place birth cusp transit birth body degree.", + "area10.element527.variant": + "Sign wheel cusp time sign orbit shown retrograde ruler natal natal aspect birth house ruler shown natal sign transit degree time transit retrograde {p0} sign aspect aspect body.", + "area10.element528.variant": + "System system degree place degree system {p0} sign transit shown sign orbit ruler shown {p1}.", + "area10.element529.variant": + "Transit shown angle system degree birth ruler requested aspect birth birth transit body shown body place ruler retrograde wheel place.", + "area10.element530.variant": + "Body ruler cusp place body aspect system house place orbit aspect aspect.", + "area10.element531.variant": + "Chart ruler birth house time retrograde body natal requested birth shown orbit chart system aspect house transit.", + "area10.element532.variant": + "Ruler wheel house retrograde orbit degree system time place system wheel system cusp {p0} birth ruler place body orbit angle.", + "area10.element533.variant": + "Birth wheel cusp sign aspect ruler birth ruler degree requested body birth degree orbit body requested {p0} chart retrograde birth angle birth ruler natal requested angle requested angle.", + "area10.element534.variant": + "Cusp body birth {p1} body place {p0} place birth.", + "area10.element535.variant": + "Angle wheel retrograde birth degree {p0} place time system wheel chart ruler natal ruler birth sign angle house place shown angle sign chart body {p1} wheel angle angle requested degree angle.", + "area10.element536.variant": + "System place sign birth birth orbit time transit natal shown requested system natal house retrograde aspect house chart requested natal {p1} shown place birth wheel house {p0} transit chart ruler.", + "area10.element537.variant": + "System wheel wheel system chart ruler transit sign transit chart transit house angle cusp orbit chart angle transit time time chart house degree transit cusp.", + "area10.element538.variant": + "Aspect chart orbit chart {p1} body aspect transit sign wheel {p0} birth time.", + "area10.element539.variant": + "Requested place degree retrograde time birth system chart {p0}.", + "area10.element540.variant": + "House sign {p2} {p1} natal {p0} natal place requested.", + "area10.element541.variant": + "Cusp house sign requested degree transit cusp {p0} system system retrograde shown transit requested {p1} orbit requested chart chart ruler shown house cusp angle angle retrograde retrograde transit birth natal aspect.", + "area10.element542.variant": + "Place orbit wheel angle {p0} angle natal ruler.", + "area10.element543.variant": + "Natal angle degree cusp cusp chart wheel retrograde birth sign wheel degree requested chart cusp time angle.", + "area10.element544.variant": + "{p2} Time body degree time time birth {p1} natal transit birth requested degree time shown time place chart house shown {p0} natal system birth transit transit birth natal degree house.", + "area10.element545.variant": + "Angle angle cusp angle body system house retrograde house time body wheel aspect transit {p1} chart natal {p0} body aspect orbit wheel transit house retrograde aspect natal.", + "area10.element546.variant": + "House ruler degree orbit body time wheel orbit place birth system birth wheel ruler place requested sign degree ruler aspect house place time degree body time sign ruler house.", + "area10.element547.variant": + "Retrograde orbit house retrograde place time retrograde place transit ruler angle angle degree.", + "area10.element548.variant": + "Ruler {p1} transit {p0} degree orbit birth house house.", + "area10.element549.variant": + "Ruler aspect aspect system ruler chart wheel degree wheel sign time {p0} time ruler wheel transit.", + "area11.element550.variant": + "Ruler time orbit angle birth cusp body natal requested birth degree aspect {p1} cusp chart cusp retrograde angle {p2} requested orbit body {p0}.", + "area11.element551.variant": + "Sign chart {p1} {p0} aspect retrograde degree degree time requested.", + "area11.element552.variant": + "Body transit transit birth shown retrograde place shown degree requested shown ruler aspect natal body system orbit time natal wheel shown cusp.", + "area11.element553.variant": + "{p0} Sign place degree place requested sign birth sign wheel chart angle house aspect time body shown orbit sign retrograde house angle ruler requested.", + "area11.element554.variant": + "Shown {p1} sign {p0} {p2} wheel retrograde chart requested house ruler.", + "area11.element555.variant": + "Degree ruler transit natal sign place body orbit shown body.", + "area11.element556.variant": + "Body transit time time angle angle angle system natal orbit house {p0} retrograde wheel shown place body requested place ruler requested.", + "area11.element557.variant": "Body degree place system body orbit.", + "area11.element558.variant": + "Natal body aspect angle angle sign ruler {p1} shown {p2} ruler place birth cusp ruler retrograde {p0} wheel house degree time.", + "area11.element559.variant": + "Wheel system wheel natal cusp cusp sign {p1} body body {p2} chart house ruler sign requested degree time chart {p0} birth birth shown transit body body.", + "area11.element560.variant": + "Time {p0} requested {p1} place body place shown ruler wheel {p2} natal natal sign shown.", + "area11.element561.variant": + "Chart ruler angle time {p1} body wheel {p0} birth chart orbit requested natal aspect transit chart cusp orbit house orbit natal birth chart sign requested retrograde system retrograde natal birth orbit aspect.", + "area11.element562.variant": + "Sign chart birth natal shown degree time aspect chart natal sign place ruler body shown retrograde house orbit system.", + "area11.element563.variant": + "Degree house cusp wheel body requested system shown orbit orbit sign house {p0} house house retrograde angle degree house system sign shown natal chart.", + "area11.element564.variant": + "House natal ruler place natal shown birth house angle chart time chart wheel natal chart orbit natal angle ruler system {p0} sign house birth chart {p1} ruler wheel.", + "area11.element565.variant": + "Place sign sign chart shown aspect wheel.", + "area11.element566.variant": + "Time ruler angle ruler retrograde cusp transit body shown {p0} natal body angle aspect cusp body place degree house cusp aspect degree natal ruler birth body house degree.", + "area11.element567.variant": + "Chart house natal {p0} ruler body {p1} house {p2} shown house place.", + "area11.element568.variant": + "Body time requested retrograde transit {p2} orbit aspect system birth shown {p0} degree cusp wheel {p1} sign degree.", + "area11.element569.variant": + "Sign sign chart cusp house sign place natal body place birth wheel retrograde aspect natal cusp ruler requested time aspect.", + "area11.element570.variant": + "Chart place shown shown requested natal requested house angle retrograde {p1} degree cusp shown natal cusp body angle ruler time natal orbit requested requested {p0} cusp ruler chart requested sign place.", + "area11.element571.variant": + "Aspect transit wheel degree {p0} sign system birth ruler house wheel shown transit cusp birth system aspect requested degree degree transit system birth chart angle requested chart place.", + "area11.element572.variant": + "{p0} Birth shown birth system {p1} retrograde retrograde birth body body.", + "area11.element573.variant": + "Transit aspect degree degree retrograde birth wheel sign sign wheel body {p0} aspect {p1} birth time birth birth body.", + "area11.element574.variant": + "Body {p0} ruler aspect aspect chart angle degree natal cusp sign degree sign.", + "area11.element575.variant": + "Requested cusp {p0} cusp system place body degree wheel {p2} ruler cusp cusp orbit {p1} requested time retrograde birth retrograde place degree house house degree angle sign wheel house house system ruler cusp.", + "area11.element576.variant": + "{p1} Shown house requested {p0} retrograde birth cusp sign system orbit requested degree system {p2} wheel place ruler angle aspect.", + "area11.element577.variant": + "System retrograde system body place transit chart natal requested angle body degree angle system body house.", + "area11.element578.variant": + "Retrograde {p0} angle place house chart wheel birth.", + "area11.element579.variant": + "Angle ruler body transit birth ruler retrograde {p0} time ruler {p1} house cusp {p2} aspect time transit shown natal wheel birth wheel angle sign transit shown angle.", + "area11.element580.variant": + "Place body ruler natal retrograde natal house degree cusp place aspect cusp angle orbit cusp system requested sign body degree {p0} chart natal time.", + "area11.element581.variant": + "Angle birth retrograde system transit place chart orbit aspect retrograde system requested cusp ruler shown natal.", + "area11.element582.variant": + "Natal birth natal place place natal natal place birth time house requested angle birth time place {p0} body system sign orbit chart house body body body house chart ruler.", + "area11.element583.variant": + "Birth system sign house place aspect angle sign body ruler birth time ruler.", + "area11.element584.variant": + "Birth body retrograde {p1} chart time transit birth time retrograde body place place chart birth {p0} angle.", + "area11.element585.variant": "Natal chart system shown place shown.", + "area11.element586.variant": + "Ruler birth place natal {p1} degree degree sign transit {p0} natal angle time.", + "area11.element587.variant": + "Place place birth birth time birth sign body angle requested natal natal aspect requested time transit time system shown transit.", + "area11.element588.variant": + "{p1} Orbit retrograde system shown angle angle aspect chart ruler place house system sign transit sign orbit house system chart system chart angle cusp {p0} degree transit retrograde system wheel requested chart.", + "area11.element589.variant": + "Sign aspect retrograde body place time shown place.", + "area11.element590.variant": + "Sign requested sign degree sign natal sign place wheel cusp retrograde aspect birth orbit aspect natal natal transit retrograde wheel body requested body {p0} ruler requested chart system retrograde transit.", + "area11.element591.variant": + "Cusp wheel shown sign shown orbit cusp house wheel system chart orbit requested angle angle wheel angle angle cusp house {p0} natal system cusp body body time.", + "area11.element592.variant": + "Transit wheel degree aspect cusp time requested place place cusp chart body system {p1} cusp natal {p2} orbit cusp shown time aspect cusp place transit requested orbit requested shown {p0}.", + "area11.element593.variant": + "Ruler degree aspect ruler {p0} chart shown transit {p1} place retrograde degree {p2} requested birth birth.", + "area11.element594.variant": + "Wheel time degree shown chart degree requested {p0} {p2} aspect transit {p1} place cusp.", + "area11.element595.variant": + "Shown retrograde body transit ruler birth cusp angle natal degree retrograde chart place degree {p0} system {p1} orbit.", + "area11.element596.variant": + "Sign body chart orbit natal chart time sign chart natal birth chart system time.", + "area11.element597.variant": + "Cusp ruler angle chart body house chart sign wheel time body body aspect chart retrograde {p2} degree {p0} aspect wheel sign angle {p1} cusp.", + "area11.element598.variant": + "Shown transit requested aspect house ruler chart {p0} angle shown ruler place ruler ruler house angle time time aspect.", + "area11.element599.variant": + "Shown sign degree system body birth retrograde body system place aspect chart.", + "area12.element600.variant": + "Time retrograde birth transit cusp place {p1} {p0}.", + "area12.element601.variant": + "Wheel ruler retrograde ruler degree orbit shown transit sign {p1} natal house place angle sign time {p2} body cusp angle {p0}.", + "area12.element602.variant": + "Degree house wheel body {p0} wheel degree {p1} cusp {p2}.", + "area12.element603.variant": + "Cusp aspect sign degree wheel body aspect cusp chart retrograde requested sign wheel body degree degree shown birth {p0} chart transit time aspect cusp.", + "area12.element604.variant": + "Wheel natal birth transit body aspect aspect transit degree angle degree birth {p0} chart natal system orbit degree degree house aspect retrograde chart.", + "area12.element605.variant": + "Natal angle chart requested sign sign cusp chart angle retrograde system sign body place degree.", + "area12.element606.variant": + "Time degree ruler body time body system {p1} angle place wheel angle natal sign transit cusp angle angle orbit {p2} retrograde {p0}.", + "area12.element607.variant": + "Aspect time chart degree ruler aspect shown angle degree house {p0} ruler aspect body wheel {p1} sign retrograde house house sign aspect natal birth cusp {p2} ruler.", + "area12.element608.variant": + "Aspect retrograde angle orbit aspect transit place sign body sign system wheel aspect sign {p1} {p0} degree angle orbit.", + "area12.element609.variant": + "Body chart orbit cusp retrograde body wheel system orbit time wheel house orbit requested birth cusp system requested house house orbit requested requested chart retrograde retrograde requested.", + "area12.element610.variant": + "Retrograde degree time time retrograde natal house orbit angle body degree shown sign shown cusp degree chart system time orbit natal orbit ruler {p0} {p1}.", + "area12.element611.variant": + "Cusp requested place chart birth chart sign chart shown house {p0} birth {p1} retrograde angle wheel {p2} angle.", + "area12.element612.variant": + "System wheel {p0} chart angle degree transit cusp aspect aspect body.", + "area12.element613.variant": + "Wheel degree birth {p1} {p0} house time {p2} house chart angle requested birth angle system.", + "area12.element614.variant": + "System transit wheel requested system aspect place degree chart retrograde angle body aspect orbit house house sign natal house orbit ruler place.", + "area12.element615.variant": + "Requested system angle angle orbit chart cusp sign angle transit shown cusp system ruler requested angle retrograde system wheel place degree place {p0} house sign requested transit transit.", + "area12.element616.variant": + "Orbit retrograde angle system place transit {p0} natal retrograde.", + "area12.element617.variant": + "Requested {p1} requested orbit retrograde orbit requested shown retrograde aspect {p2} degree body transit natal natal angle requested place {p0}.", + "area12.element618.variant": + "Retrograde place time {p2} place orbit degree requested {p1} cusp time ruler body retrograde time time orbit ruler degree requested place cusp birth body orbit retrograde place requested ruler {p0}.", + "area12.element619.variant": + "Angle {p0} birth birth {p1} chart birth place shown {p2} system place body.", + "area12.element620.variant": + "Transit natal transit time requested system house orbit sign house system body body cusp wheel orbit system time time sign retrograde ruler shown birth shown.", + "area12.element621.variant": + "Transit house transit natal transit house orbit house natal angle angle sign wheel aspect chart requested wheel birth system {p0} birth house cusp orbit sign transit.", + "area12.element622.variant": + "{p0} Natal orbit body place sign natal place shown requested chart natal wheel ruler degree requested transit transit birth degree chart chart cusp orbit house system system cusp body wheel.", + "area12.element623.variant": + "Sign retrograde birth ruler cusp angle house retrograde house house transit system house {p0} orbit place system natal body chart wheel shown chart ruler time degree angle ruler wheel retrograde.", + "area12.element624.variant": + "Requested retrograde retrograde {p0} transit wheel system {p1} wheel orbit.", + "area12.element625.variant": + "Sign natal cusp birth place body retrograde {p0} aspect chart angle {p1} requested house sign degree birth.", + "area12.element626.variant": + "Place shown degree angle birth system place natal wheel aspect house wheel wheel cusp chart body {p0} ruler aspect {p1} time transit body natal body system.", + "area12.element627.variant": + "Angle {p0} natal chart ruler angle place {p2} sign retrograde angle {p1} degree.", + "area12.element628.variant": + "{p2} Chart {p1} orbit ruler chart requested degree {p0} sign cusp degree natal retrograde time degree transit.", + "area12.element629.variant": + "Sign aspect wheel {p1} place degree place body sign {p2} {p0} aspect ruler shown sign birth angle requested requested shown angle time transit chart.", + "area12.element630.variant": + "Body shown birth place retrograde body chart aspect chart orbit orbit body wheel retrograde sign ruler transit birth ruler sign place aspect shown wheel aspect.", + "area12.element631.variant": + "Birth natal orbit house place sign chart house orbit system sign chart birth cusp time requested cusp natal requested requested transit ruler time aspect birth chart shown time wheel shown.", + "area12.element632.variant": + "System transit shown {p0} house body natal {p1} birth body natal system system transit wheel angle shown cusp natal aspect requested ruler.", + "area12.element633.variant": + "Retrograde angle cusp system {p0} ruler {p1} natal ruler wheel orbit.", + "area12.element634.variant": + "Ruler wheel system wheel house house house sign time ruler body body angle time place degree body retrograde cusp cusp {p0} house transit.", + "area12.element635.variant": + "Wheel ruler {p0} aspect house angle {p1} place place angle cusp cusp time natal cusp sign transit house time orbit.", + "area12.element636.variant": + "Shown sign natal sign {p0} natal natal degree degree system shown sign place ruler aspect house birth shown house.", + "area12.element637.variant": + "Natal chart transit transit orbit {p0} birth natal requested degree body transit.", + "area12.element638.variant": + "System angle body transit birth angle aspect ruler transit shown chart transit ruler wheel place {p0} aspect birth retrograde requested system birth.", + "area12.element639.variant": + "Cusp transit cusp natal transit ruler birth shown requested natal orbit body chart body wheel requested {p1} {p0} {p2} house retrograde wheel shown requested system ruler requested wheel natal orbit requested.", + "area12.element640.variant": + "Degree requested degree sign chart aspect transit requested natal house.", + "area12.element641.variant": + "Natal natal wheel system orbit house angle house body.", + "area12.element642.variant": + "System degree orbit orbit {p0} time {p1} ruler shown house time degree body degree.", + "area12.element643.variant": + "{p0} Wheel transit cusp body wheel {p1} angle wheel ruler ruler transit place degree.", + "area12.element644.variant": + "Requested orbit requested transit house sign retrograde degree {p1} birth degree orbit aspect angle birth orbit natal {p0} system house aspect aspect system cusp place sign aspect ruler chart angle orbit orbit.", + "area12.element645.variant": + "{p1} House chart cusp requested natal retrograde chart birth {p0} cusp requested time cusp house sign birth {p2} natal aspect house chart house angle degree sign.", + "area12.element646.variant": + "Chart requested {p1} body {p0} sign degree natal ruler aspect.", + "area12.element647.variant": + "Requested birth {p1} place ruler requested birth retrograde time retrograde retrograde aspect house degree shown degree {p0} house.", + "area12.element648.variant": + "House {p1} place cusp birth aspect birth orbit house natal wheel {p2} transit {p0} birth aspect birth wheel transit.", + "area12.element649.variant": + "Aspect requested angle birth degree {p0} sign transit place aspect transit aspect wheel time.", + "area13.element650.variant": + "Shown transit retrograde transit system {p0} wheel requested chart sign degree orbit angle system.", + "area13.element651.variant": + "Body transit ruler wheel house orbit orbit ruler angle place.", + "area13.element652.variant": + "System shown system transit birth chart ruler {p1} cusp place body ruler house birth {p2} place wheel chart transit {p0} retrograde chart.", + "area13.element653.variant": + "Cusp place place birth wheel {p0} place natal degree aspect transit body orbit orbit sign.", + "area13.element654.variant": + "Place aspect place degree sign cusp retrograde birth shown time aspect place requested house time birth transit birth body.", + "area13.element655.variant": + "{p0} Wheel angle natal {p1} natal orbit aspect wheel time.", + "area13.element656.variant": + "Shown time aspect orbit ruler requested wheel requested shown wheel retrograde wheel transit system shown transit time ruler degree cusp time wheel chart house birth time.", + "area13.element657.variant": + "Orbit degree aspect place aspect sign {p0} wheel birth degree aspect cusp place angle degree birth shown transit place.", + "area13.element658.variant": + "Cusp shown angle system {p0} house natal sign.", + "area13.element659.variant": + "Ruler ruler time orbit house system cusp shown shown degree orbit body time ruler retrograde ruler requested system sign requested chart angle.", + "area13.element660.variant": + "Wheel time system orbit transit wheel orbit body shown transit shown transit orbit body shown retrograde time sign house natal aspect degree shown sign time transit sign sign natal.", + "area13.element661.variant": + "Sign sign chart {p0} degree {p1} body {p2} degree.", + "area13.element662.variant": + "Aspect aspect orbit time system requested system aspect cusp birth requested natal cusp place angle chart transit system system requested natal chart shown birth.", + "area13.element663.variant": + "Cusp system cusp {p0} angle aspect ruler aspect time {p1} chart place degree body.", + "area13.element664.variant": + "Ruler requested transit angle ruler angle chart system angle natal system birth place system cusp retrograde orbit chart time {p0} birth.", + "area13.element665.variant": + "Transit degree house retrograde birth natal degree body {p1} place {p0} sign.", + "area13.element666.variant": + "House time orbit cusp natal ruler transit wheel degree requested {p0} natal requested orbit sign body transit shown.", + "area13.element667.variant": + "Natal shown time transit aspect birth time birth angle cusp requested birth requested retrograde angle {p0} {p1} degree.", + "area13.element668.variant": + "Natal place {p2} retrograde aspect time transit ruler shown sign cusp {p0} {p1} shown time cusp angle shown shown retrograde shown wheel body ruler.", + "area13.element669.variant": + "Retrograde degree chart degree degree requested {p0} cusp time body transit degree orbit retrograde wheel cusp transit place transit chart wheel body body transit body degree time birth.", + "area13.element670.variant": + "House {p1} {p0} system requested chart sign shown birth aspect chart natal requested.", + "area13.element671.variant": + "Aspect orbit sign orbit cusp place place {p0} time chart chart transit requested time shown {p1} system orbit wheel place degree wheel shown retrograde transit degree place natal time birth.", + "area13.element672.variant": + "Body cusp wheel retrograde ruler chart {p1} transit ruler shown natal body {p0} shown wheel house system natal transit body requested system chart shown aspect transit place cusp {p2} angle sign aspect.", + "area13.element673.variant": + "Sign system natal system orbit cusp orbit system chart {p0} angle place transit time angle ruler chart {p1} cusp wheel transit sign aspect system natal time.", + "area13.element674.variant": + "Chart wheel cusp system natal ruler cusp system natal retrograde time sign degree time degree transit sign shown natal house transit wheel house aspect chart.", + "area13.element675.variant": + "Shown angle aspect {p0} chart ruler natal ruler sign degree aspect time house orbit cusp retrograde body angle angle requested angle angle place ruler aspect natal.", + "area13.element676.variant": + "Shown retrograde wheel angle body aspect house body house retrograde transit retrograde system house time cusp requested natal place angle orbit.", + "area13.element677.variant": + "System ruler aspect cusp chart sign natal retrograde system birth degree angle ruler ruler.", + "area13.element678.variant": + "Ruler time birth {p0} birth sign requested house body.", + "area13.element679.variant": + "Natal cusp cusp degree transit angle time wheel cusp ruler sign sign place aspect degree orbit transit cusp ruler aspect transit sign house house shown requested aspect aspect {p0} retrograde sign.", + "area13.element680.variant": + "Sign wheel shown system orbit requested sign birth shown {p0} requested requested aspect place wheel degree sign time.", + "area13.element681.variant": + "Retrograde degree degree {p1} angle orbit chart birth requested birth cusp angle {p0} sign transit requested.", + "area13.element682.variant": + "Cusp place retrograde place time {p0} wheel angle orbit {p2} requested aspect natal system {p1} shown chart shown sign requested orbit sign requested orbit.", + "area13.element683.variant": + "House aspect {p1} {p0} place cusp chart retrograde wheel sign cusp requested aspect ruler.", + "area13.element684.variant": + "Ruler sign natal retrograde requested shown angle {p1} system natal orbit {p0} {p2} angle degree sign system ruler chart transit system requested place.", + "area13.element685.variant": + "Requested system sign degree house cusp retrograde house place orbit body retrograde place.", + "area13.element686.variant": + "System ruler retrograde wheel degree natal orbit angle.", + "area13.element687.variant": + "Body {p0} cusp retrograde time natal retrograde degree natal chart degree {p1} angle.", + "area13.element688.variant": + "Ruler sign place shown transit body cusp sign natal requested degree transit wheel sign wheel time {p0} body ruler retrograde place birth system birth {p1} cusp house shown.", + "area13.element689.variant": + "Wheel {p2} house cusp natal sign place orbit sign birth time orbit sign body natal house {p0} time house requested {p1} shown orbit orbit wheel.", + "area13.element690.variant": + "Degree sign retrograde shown aspect orbit ruler {p1} birth cusp requested requested transit cusp {p2} wheel degree {p0}.", + "area13.element691.variant": + "Ruler aspect sign aspect wheel house retrograde sign requested {p0} natal sign system ruler transit.", + "area13.element692.variant": + "Transit angle chart {p0} angle degree degree orbit requested shown requested system transit requested time birth.", + "area13.element693.variant": + "Degree {p2} retrograde {p1} transit house ruler sign wheel orbit {p0}.", + "area13.element694.variant": + "{p0} System birth sign place house shown chart {p1} sign wheel system.", + "area13.element695.variant": + "Body natal aspect shown cusp sign degree aspect angle wheel orbit.", + "area13.element696.variant": + "Requested body place house degree wheel transit place system place cusp degree ruler time sign house time ruler chart house shown.", + "area13.element697.variant": + "Natal degree angle sign house retrograde place retrograde aspect house cusp cusp body place sign degree natal transit chart body place natal requested sign wheel body.", + "area13.element698.variant": + "{p0} Orbit birth wheel transit {p2} wheel cusp cusp cusp transit orbit sign natal body shown degree shown birth degree cusp transit birth transit {p1} wheel retrograde place aspect body sign.", + "area13.element699.variant": + "Wheel shown shown chart place birth system wheel cusp house natal shown chart angle retrograde house requested shown house.", + "area14.element700.variant": + "Aspect shown aspect degree body orbit birth shown ruler retrograde body body angle {p2} house {p0} degree retrograde {p1} chart.", + "area14.element701.variant": + "Natal degree house {p1} orbit wheel requested house angle body body {p0} birth time.", + "area14.element702.variant": + "Angle aspect {p0} body chart orbit ruler transit wheel birth requested transit system transit sign place aspect transit.", + "area14.element703.variant": + "Angle orbit place wheel degree chart transit requested birth angle degree transit wheel shown wheel sign cusp house ruler degree sign sign natal {p0} retrograde retrograde system cusp cusp.", + "area14.element704.variant": + "Orbit cusp degree system sign ruler time system sign chart {p0} place transit aspect shown.", + "area14.element705.variant": + "Chart {p0} wheel chart cusp birth orbit time orbit sign requested natal {p1} system.", + "area14.element706.variant": + "House time transit place place sign transit {p0} chart retrograde wheel place ruler system sign chart transit chart degree retrograde wheel house system house retrograde place shown house degree ruler.", + "area14.element707.variant": + "Retrograde house shown birth system natal.", + "area14.element708.variant": + "Natal shown degree requested degree ruler shown house requested system system cusp cusp body ruler time orbit chart orbit requested time natal cusp shown.", + "area14.element709.variant": + "Orbit orbit aspect {p1} orbit {p0} chart angle requested shown birth birth body angle.", + "area14.element710.variant": + "Degree angle requested transit chart shown house shown {p0} chart time sign {p1} house retrograde wheel system place requested {p2}.", + "area14.element711.variant": + "Time wheel place sign ruler time place aspect natal {p1} {p0}.", + "area14.element712.variant": + "System wheel system birth body aspect ruler sign time sign transit place aspect sign body retrograde shown cusp ruler transit place degree wheel chart body body shown transit house {p0} {p1} time.", + "area14.element713.variant": "Sign cusp requested shown system birth.", + "area14.element714.variant": + "Requested chart system degree chart retrograde house body house angle sign orbit orbit.", + "area14.element715.variant": + "Place birth birth system sign wheel ruler cusp time degree degree ruler time birth shown {p0} sign natal.", + "area14.element716.variant": + "Natal time sign degree sign aspect orbit {p0} angle wheel system natal {p1} time aspect shown.", + "area14.element717.variant": + "{p0} Aspect wheel angle angle degree birth.", + "area14.element718.variant": "Shown cusp place ruler body angle.", + "area14.element719.variant": + "Retrograde system system sign body birth place natal system natal ruler ruler place retrograde requested degree chart orbit chart house chart birth.", + "area14.element720.variant": + "Wheel shown aspect house wheel birth angle natal birth transit requested degree system natal body chart cusp natal cusp place transit birth system.", + "area14.element721.variant": + "Wheel {p1} chart body ruler orbit chart sign cusp wheel {p0} retrograde cusp place {p2} degree chart system body place.", + "area14.element722.variant": "Natal natal orbit time house cusp {p0}.", + "area14.element723.variant": + "System requested aspect degree house cusp {p1} requested wheel sign aspect degree time retrograde requested place cusp angle aspect aspect aspect orbit aspect degree {p2} cusp system orbit system retrograde {p0}.", + "area14.element724.variant": + "Natal natal ruler chart house body wheel birth place aspect.", + "area14.element725.variant": + "Degree transit requested body chart body wheel ruler degree retrograde wheel ruler place transit birth place angle angle chart body.", + "area14.element726.variant": + "Natal {p0} {p2} natal orbit angle place body time shown {p1}.", + "area14.element727.variant": + "Aspect wheel place natal body requested body requested wheel system.", + "area14.element728.variant": + "{p2} System shown house cusp degree chart ruler cusp place birth {p0} aspect house house shown {p1} requested transit sign transit ruler sign orbit orbit ruler retrograde aspect shown house.", + "area14.element729.variant": + "Sign angle natal degree house {p0} chart transit wheel transit angle time body {p2} chart birth place sign {p1} place aspect.", + "area14.element730.variant": + "Shown birth house ruler degree {p1} transit house {p0}.", + "area14.element731.variant": + "Birth transit time ruler {p0} wheel requested retrograde requested orbit body time system system sign body retrograde shown requested wheel system birth transit place house ruler requested.", + "area14.element732.variant": "Shown wheel cusp {p0} angle ruler orbit.", + "area14.element733.variant": + "Cusp body orbit birth requested shown shown birth wheel body cusp orbit aspect natal aspect shown sign natal degree birth chart retrograde place sign sign birth {p0} transit shown.", + "area14.element734.variant": + "Chart transit chart system system system body cusp wheel place ruler angle transit sign body {p0} time place system orbit system orbit time transit chart transit body place birth chart {p1} house.", + "area14.element735.variant": + "System retrograde system requested angle system requested {p0} chart wheel cusp ruler retrograde shown aspect transit degree ruler house chart time cusp ruler {p1} shown orbit cusp aspect degree.", + "area14.element736.variant": + "Place {p1} house {p2} wheel place {p0} orbit house sign chart degree body chart.", + "area14.element737.variant": + "System degree shown system chart degree retrograde degree ruler time wheel.", + "area14.element738.variant": + "Transit wheel house degree birth aspect time requested natal {p0} place retrograde retrograde {p1} ruler body.", + "area14.element739.variant": + "Wheel house {p0} aspect orbit body birth wheel body system ruler aspect body transit.", + "area14.element740.variant": + "Chart shown time chart natal system wheel ruler transit chart chart time shown {p0} house natal place angle body requested cusp transit requested system birth.", + "area14.element741.variant": + "Orbit {p2} system transit shown {p1} sign chart {p0} shown time orbit body angle.", + "area14.element742.variant": + "Degree {p0} time chart house wheel time aspect place requested ruler place.", + "area14.element743.variant": + "Body body {p0} ruler {p1} transit chart cusp.", + "area14.element744.variant": + "Birth system cusp retrograde {p1} retrograde chart {p2} natal body place transit {p0}.", + "area14.element745.variant": + "Retrograde aspect place wheel sign natal {p0} degree body requested angle angle.", + "area14.element746.variant": + "Orbit aspect {p0} chart cusp chart body house sign orbit wheel transit body requested orbit natal house transit body shown house house transit transit.", + "area14.element747.variant": + "Cusp shown chart house requested transit shown system angle wheel time ruler birth transit ruler angle place orbit ruler orbit ruler angle.", + "area14.element748.variant": + "Birth degree wheel house requested aspect sign sign chart transit wheel orbit system chart body angle house retrograde place system place shown cusp body orbit time angle.", + "area14.element749.variant": + "Requested retrograde orbit cusp wheel natal {p2} wheel place ruler birth retrograde aspect {p0} {p1} ruler body place cusp cusp system place.", + "area15.element750.variant": + "Time angle {p0} birth ruler cusp house time.", + "area15.element751.variant": + "Sign cusp system orbit retrograde orbit wheel {p0} ruler shown birth.", + "area15.element752.variant": + "{p0} Cusp transit place time retrograde requested birth system orbit place shown wheel house chart {p2} retrograde birth {p1} body retrograde.", + "area15.element753.variant": + "Requested orbit transit ruler house degree degree cusp requested birth natal chart requested retrograde transit requested body cusp {p0} birth degree angle {p1}.", + "area15.element754.variant": + "Natal transit sign sign ruler time wheel natal birth angle orbit orbit natal natal angle natal time natal wheel chart {p0} chart aspect body place degree ruler natal.", + "area15.element755.variant": + "Time ruler sign transit {p0} birth time orbit natal transit shown ruler system body {p1} house aspect.", + "area15.element756.variant": + "{p1} Degree cusp {p2} angle {p0} time orbit angle.", + "area15.element757.variant": + "Birth angle birth sign wheel angle retrograde shown angle birth orbit birth cusp {p0} time wheel time natal wheel.", + "area15.element758.variant": + "Place requested requested shown aspect {p1} chart sign angle {p0} requested time.", + "area15.element759.variant": + "{p0} Place {p1} birth time orbit transit cusp body wheel retrograde sign.", + "area15.element760.variant": + "Cusp degree cusp ruler cusp system transit shown system house orbit system cusp requested requested ruler.", + "area15.element761.variant": + "System cusp system {p0} shown time sign transit.", + "area15.element762.variant": + "Transit shown retrograde ruler place ruler birth chart body ruler wheel {p0} cusp {p1} chart sign retrograde birth requested system system place system shown cusp ruler wheel shown ruler natal retrograde.", + "area15.element763.variant": + "Body natal system body aspect chart cusp time house {p0} body natal chart shown sign orbit natal shown time sign aspect wheel shown house time natal.", + "area15.element764.variant": + "Natal aspect shown aspect body time chart aspect sign {p1} birth aspect body place aspect retrograde time requested orbit system natal orbit {p0} orbit {p2} natal wheel orbit system sign degree.", + "area15.element765.variant": + "Sign sign requested transit aspect angle cusp house system {p0}.", + "area15.element766.variant": + "{p0} Retrograde {p2} birth time angle angle place requested birth {p1} body birth wheel.", + "area15.element767.variant": + "Aspect {p0} retrograde {p1} transit aspect ruler orbit degree wheel body house wheel sign natal {p2} place angle degree.", + "area15.element768.variant": + "Shown ruler {p0} cusp chart angle retrograde retrograde wheel ruler aspect body retrograde transit requested place house retrograde shown.", + "area15.element769.variant": + "Degree chart time degree birth natal body natal time angle body place degree orbit retrograde place wheel angle.", + "area15.element770.variant": + "{p0} Body natal wheel cusp house natal {p1} ruler house.", + "area15.element771.variant": + "Aspect body shown chart orbit transit transit aspect degree ruler retrograde.", + "area15.element772.variant": + "{p2} Aspect house shown {p1} time requested angle {p0} natal.", + "area15.element773.variant": + "House place chart orbit requested natal time requested birth aspect wheel chart time place time transit aspect transit place orbit ruler shown wheel transit {p0}.", + "area15.element774.variant": + "Shown time transit chart time cusp birth {p0} orbit.", + "area15.element775.variant": + "Birth sign chart place {p0} cusp {p1} {p2} house time.", + "area15.element776.variant": + "Retrograde chart sign aspect requested sign chart cusp retrograde chart aspect orbit house ruler birth natal place retrograde ruler sign ruler transit ruler ruler body time.", + "area15.element777.variant": + "Natal orbit sign shown chart {p0} retrograde place shown orbit body system time chart body wheel ruler.", + "area15.element778.variant": + "Orbit angle sign degree retrograde cusp body {p0} place birth ruler angle time shown natal wheel degree chart {p1} ruler chart place house.", + "area15.element779.variant": + "Angle natal natal sign angle ruler transit requested house shown.", + "area15.element780.variant": + "Cusp ruler birth birth chart degree angle place house retrograde chart degree system place ruler wheel.", + "area15.element781.variant": + "House birth house requested retrograde {p1} {p0} orbit sign retrograde system birth.", + "area15.element782.variant": + "Birth place cusp angle retrograde orbit body body place birth natal birth retrograde shown system aspect {p0} {p1}.", + "area15.element783.variant": + "Natal transit degree place natal aspect cusp requested system ruler angle chart birth shown place degree transit sign.", + "area15.element784.variant": + "Wheel place {p1} ruler degree {p0} wheel retrograde shown.", + "area15.element785.variant": + "House {p0} chart body house {p2} sign shown retrograde place wheel retrograde shown sign house chart {p1} birth.", + "area15.element786.variant": + "Natal {p1} {p0} body chart natal natal natal shown wheel aspect retrograde wheel natal birth.", + "area15.element787.variant": + "{p0} Retrograde aspect angle body {p1} chart sign body house shown chart ruler orbit requested requested ruler sign retrograde degree orbit ruler.", + "area15.element788.variant": + "Place angle sign angle degree requested wheel house house retrograde angle birth house sign ruler place cusp angle requested wheel degree house.", + "area15.element789.variant": + "Retrograde angle aspect {p0} aspect cusp wheel {p2} aspect sign {p1} time system ruler system angle retrograde.", + "area15.element790.variant": + "Body birth sign angle house wheel wheel {p0} retrograde {p1}.", + "area15.element791.variant": + "House aspect natal degree system natal transit body place requested retrograde aspect chart requested degree requested body house retrograde ruler.", + "area15.element792.variant": + "House retrograde angle angle time angle birth wheel system sign retrograde place requested requested ruler {p0} angle angle requested cusp retrograde.", + "area15.element793.variant": + "System ruler cusp birth {p0} requested sign requested requested house birth cusp time natal wheel.", + "area15.element794.variant": + "Cusp birth system natal orbit house orbit {p0} transit retrograde birth requested retrograde place system time cusp time orbit ruler.", + "area15.element795.variant": + "Time cusp ruler transit time transit {p2} {p1} birth aspect angle time natal birth {p0} house body angle place.", + "area15.element796.variant": + "Orbit transit degree aspect ruler birth {p2} orbit {p0} natal birth {p1} requested orbit natal body degree natal shown requested chart degree ruler transit degree retrograde.", + "area15.element797.variant": + "Wheel {p0} cusp retrograde {p1} house aspect retrograde wheel angle wheel degree retrograde degree birth sign orbit angle.", + "area15.element798.variant": + "Shown aspect chart angle {p0} house {p1} system house aspect retrograde body sign natal house retrograde sign chart wheel birth retrograde.", + "area15.element799.variant": + "Orbit sign shown cusp {p2} aspect sign sign {p1} place retrograde shown system retrograde {p0} transit.", + "area16.element800.variant": + "Natal {p2} time {p1} sign degree wheel chart time system angle cusp wheel {p0} chart transit ruler requested system degree natal birth system house aspect sign orbit chart aspect orbit.", + "area16.element801.variant": + "Aspect system ruler {p0} {p1} place orbit transit.", + "area16.element802.variant": + "Sign ruler body birth house cusp cusp cusp place {p2} ruler cusp sign {p0} {p1} transit chart orbit wheel place angle shown birth.", + "area16.element803.variant": + "Ruler shown chart shown transit house birth body ruler chart time angle requested aspect chart aspect orbit place degree.", + "area16.element804.variant": + "Transit transit house system birth natal {p1} requested aspect natal requested house shown system {p0} transit natal ruler body body chart ruler chart degree transit system.", + "area16.element805.variant": + "Time {p1} {p2} ruler cusp aspect angle time body transit {p0} aspect house body chart natal chart.", + "area16.element806.variant": + "{p0} Angle body retrograde degree house house wheel body ruler degree time sign retrograde chart time body system ruler body requested aspect {p1}.", + "area16.element807.variant": + "Requested angle requested house birth degree body aspect {p0} wheel retrograde wheel house.", + "area16.element808.variant": + "Transit wheel orbit cusp system cusp birth shown time wheel place degree wheel transit cusp requested angle natal retrograde system orbit degree cusp chart aspect birth.", + "area16.element809.variant": + "Ruler requested aspect system {p2} body {p0} place house angle chart sign transit {p1} body retrograde transit system angle house requested aspect transit orbit.", + "area16.element810.variant": + "Retrograde time {p1} body {p0} sign transit {p2} cusp aspect.", + "area16.element811.variant": + "Transit orbit shown transit degree aspect {p0} body angle {p1} time wheel wheel cusp birth birth sign aspect cusp body shown natal requested requested orbit.", + "area16.element812.variant": + "Transit system time cusp transit angle requested orbit sign {p0} system angle system natal cusp orbit requested transit orbit requested aspect place angle house shown time transit orbit angle retrograde.", + "area16.element813.variant": + "Place orbit angle requested house degree wheel shown system angle retrograde shown wheel orbit body {p2} house cusp system transit system {p0} chart {p1}.", + "area16.element814.variant": + "Transit chart requested cusp place requested {p0} wheel system chart {p1} natal house requested birth wheel birth requested degree cusp.", + "area16.element815.variant": + "Degree system transit ruler degree system aspect cusp degree transit sign time birth ruler retrograde degree aspect house time.", + "area16.element816.variant": + "Wheel wheel sign {p0} {p1} place retrograde place sign retrograde birth body.", + "area16.element817.variant": + "Sign natal time place aspect transit transit chart house place angle place requested requested requested time retrograde house orbit natal ruler sign ruler sign transit cusp system angle angle.", + "area16.element818.variant": + "System ruler retrograde sign house shown body cusp {p0} transit sign {p2} {p1}.", + "area16.element819.variant": + "System place chart aspect natal house wheel {p0} house system {p1} aspect wheel.", + "area16.element820.variant": + "Wheel transit {p2} place aspect wheel {p0} body {p1} ruler degree system cusp cusp.", + "area16.element821.variant": + "Time wheel angle natal transit house transit shown system transit aspect cusp system system {p1} orbit house {p0} transit natal.", + "area16.element822.variant": + "Retrograde house cusp degree requested {p0} time wheel retrograde birth shown system sign shown.", + "area16.element823.variant": + "Body chart cusp place {p2} orbit natal retrograde place requested ruler place cusp transit ruler {p1} requested retrograde system {p0} natal house sign aspect system.", + "area16.element824.variant": + "Aspect time sign angle ruler birth sign house cusp transit {p2} body angle wheel cusp wheel cusp wheel natal house body cusp angle {p1} {p0}.", + "area16.element825.variant": + "{p0} Natal retrograde degree system angle house wheel chart place body cusp angle system.", + "area16.element826.variant": + "Birth body natal retrograde place angle place body degree ruler transit ruler requested orbit retrograde ruler system sign sign orbit chart ruler {p0} degree body wheel birth shown place cusp sign.", + "area16.element827.variant": + "Orbit sign wheel transit sign {p1} {p0} house.", + "area16.element828.variant": + "Ruler house natal {p0} orbit retrograde ruler place birth angle requested cusp.", + "area16.element829.variant": + "{p1} {p0} Time transit orbit retrograde birth orbit shown angle time chart angle angle cusp.", + "area16.element830.variant": + "Place retrograde system degree shown aspect natal sign transit orbit time retrograde chart {p0} orbit.", + "area16.element831.variant": + "Transit retrograde orbit retrograde angle birth chart cusp {p0} time chart birth house transit place chart transit {p2} orbit body house {p1}.", + "area16.element832.variant": + "Chart retrograde shown {p0} natal ruler natal place angle chart natal wheel transit natal {p2} angle angle {p1} wheel cusp transit system place ruler shown orbit transit.", + "area16.element833.variant": + "Angle shown place angle retrograde time house ruler {p0} {p1} natal requested angle retrograde.", + "area16.element834.variant": + "Requested time orbit transit birth {p0} natal angle body {p1} cusp shown body chart ruler orbit angle requested degree ruler.", + "area16.element835.variant": + "Chart {p1} angle wheel natal aspect {p0} degree place ruler {p2} degree wheel aspect.", + "area16.element836.variant": + "Shown natal orbit cusp retrograde chart degree shown shown place requested degree degree degree shown transit system body angle retrograde time body transit house wheel cusp degree.", + "area16.element837.variant": + "Transit aspect sign time {p0} chart place orbit retrograde house chart wheel orbit.", + "area16.element838.variant": + "Wheel place chart shown sign aspect orbit natal aspect time requested house birth cusp sign sign ruler angle requested angle time time {p2} retrograde birth {p1} natal transit system angle transit {p0}.", + "area16.element839.variant": + "Cusp place requested ruler transit birth house body system system chart {p0} angle shown cusp angle natal angle angle natal wheel cusp angle.", + "area16.element840.variant": + "Angle ruler chart sign body sign shown house ruler chart angle wheel cusp degree shown time time body cusp shown ruler body sign natal time.", + "area16.element841.variant": + "Shown cusp cusp system system body place chart.", + "area16.element842.variant": + "Time requested body ruler house sign degree degree degree house house requested natal transit shown chart aspect time.", + "area16.element843.variant": + "Orbit degree ruler birth place cusp angle sign {p0} place requested birth natal {p1} cusp wheel ruler shown cusp {p2}.", + "area16.element844.variant": + "Chart time retrograde requested requested degree requested aspect natal retrograde ruler system transit system system degree sign time time time birth house angle wheel angle retrograde.", + "area16.element845.variant": + "House place cusp {p2} natal aspect ruler time cusp {p0} chart requested transit body shown place angle degree natal house {p1} body sign system wheel chart shown orbit.", + "area16.element846.variant": + "House angle chart {p0} {p1} shown place transit aspect.", + "area16.element847.variant": + "Ruler system body transit {p2} requested system angle time {p0} body {p1} degree aspect.", + "area16.element848.variant": + "House wheel shown aspect requested {p0} degree cusp {p1} time {p2} cusp transit wheel system sign system ruler requested place aspect cusp degree house house place time place natal.", + "area16.element849.variant": + "Retrograde {p1} house cusp {p0} chart cusp chart orbit place place requested natal system shown aspect house body sign requested retrograde body place house retrograde retrograde angle house angle.", + "area17.element850.variant": + "Angle shown {p0} body time cusp ruler wheel {p1} house natal degree chart ruler sign place birth body.", + "area17.element851.variant": + "Chart system angle degree sign degree transit ruler.", + "area17.element852.variant": + "Angle angle natal ruler body orbit orbit {p0} aspect {p1} birth cusp sign house {p2} retrograde place degree sign chart.", + "area17.element853.variant": + "System place body shown orbit shown natal birth shown aspect {p2} birth place chart retrograde transit angle {p1} {p0} house ruler place shown angle aspect aspect degree aspect.", + "area17.element854.variant": + "System natal system place house body transit ruler orbit shown chart retrograde chart chart system ruler {p0} house ruler place requested body shown angle chart transit time chart natal time requested.", + "area17.element855.variant": + "Sign ruler transit aspect retrograde orbit {p0} house place birth requested system.", + "area17.element856.variant": + "Time birth {p0} chart house requested retrograde.", + "area17.element857.variant": + "Place place orbit house time degree birth sign place cusp system aspect orbit wheel requested time body wheel aspect body cusp chart ruler house.", + "area17.element858.variant": + "Retrograde natal shown angle degree shown {p0} retrograde wheel degree angle transit house time body sign chart chart birth angle angle aspect cusp angle retrograde place wheel cusp shown retrograde retrograde.", + "area17.element859.variant": + "Cusp {p0} aspect retrograde retrograde time wheel degree sign sign {p1} natal.", + "area17.element860.variant": + "Shown shown retrograde ruler birth {p1} retrograde orbit degree body {p0} chart {p2}.", + "area17.element861.variant": + "Ruler system sign wheel time birth birth place shown degree birth orbit degree system sign degree.", + "area17.element862.variant": + "Aspect birth ruler house aspect {p0} angle system angle system transit {p2} chart body transit {p1} natal retrograde shown chart body.", + "area17.element863.variant": + "Orbit transit transit system wheel aspect birth sign orbit {p0} sign {p2} degree aspect {p1} house.", + "area17.element864.variant": + "Place transit {p1} house chart {p0} system system sign shown orbit.", + "area17.element865.variant": + "Wheel {p0} {p1} angle {p2} system aspect transit house house degree degree body chart requested wheel time ruler sign sign time birth transit sign birth place orbit transit cusp.", + "area17.element866.variant": + "Retrograde transit angle {p0} natal place body cusp place time degree requested shown cusp degree birth birth place aspect birth chart.", + "area17.element867.variant": + "Birth {p2} {p1} angle wheel {p0} house angle time orbit transit.", + "area17.element868.variant": + "Aspect shown degree chart sign body orbit cusp {p0} cusp ruler shown natal place retrograde.", + "area17.element869.variant": + "System shown orbit system wheel birth system house {p0} sign ruler house degree angle retrograde.", + "area17.element870.variant": + "Ruler degree body chart orbit sign ruler degree time requested chart requested retrograde place house time orbit aspect.", + "area17.element871.variant": + "Requested chart aspect cusp birth birth orbit orbit requested sign system requested retrograde shown time sign aspect time ruler {p0} aspect sign place chart chart birth house place birth wheel.", + "area17.element872.variant": + "System time place wheel aspect retrograde time birth aspect chart retrograde requested transit aspect sign degree cusp.", + "area17.element873.variant": + "Aspect retrograde place body time body place house shown sign body body retrograde aspect system angle wheel time transit sign system place.", + "area17.element874.variant": + "Place house transit time wheel {p0} place {p1} system chart.", + "area17.element875.variant": + "{p0} Degree {p1} ruler transit transit degree orbit chart time transit aspect requested shown cusp house house place degree {p2} shown.", + "area17.element876.variant": + "Body natal angle retrograde retrograde {p1} retrograde birth system sign {p0}.", + "area17.element877.variant": + "Cusp time {p1} time {p0} natal ruler chart degree.", + "area17.element878.variant": + "Transit aspect requested angle wheel cusp chart shown retrograde place natal place shown ruler sign {p1} cusp {p0} shown time requested.", + "area17.element879.variant": + "{p0} Angle shown body wheel orbit ruler retrograde aspect requested {p1} body wheel time orbit.", + "area17.element880.variant": + "Time retrograde wheel shown ruler {p2} angle cusp orbit {p1} {p0}.", + "area17.element881.variant": + "Angle ruler shown place house aspect shown shown cusp natal place sign cusp shown body time angle time retrograde cusp.", + "area17.element882.variant": + "Body system orbit orbit degree transit degree body orbit.", + "area17.element883.variant": + "Time body aspect time natal time {p1} transit retrograde angle house shown place chart place {p0} shown cusp orbit system.", + "area17.element884.variant": + "Chart cusp orbit {p0} system {p1} requested angle ruler.", + "area17.element885.variant": + "Aspect body orbit time wheel retrograde degree aspect chart shown transit angle aspect transit orbit aspect natal house requested cusp body retrograde {p0} time chart retrograde retrograde orbit wheel angle.", + "area17.element886.variant": + "Ruler ruler system shown requested shown orbit wheel place shown place retrograde chart degree retrograde system shown retrograde orbit body place cusp time shown.", + "area17.element887.variant": + "Sign time natal {p0} body ruler requested shown orbit body wheel chart body ruler natal chart angle system house shown orbit body time {p1} house body.", + "area17.element888.variant": + "Birth transit chart orbit natal place sign system time system time aspect body birth.", + "area17.element889.variant": + "Requested house {p1} {p0} retrograde cusp degree transit retrograde angle requested {p2} time house retrograde ruler shown house angle place orbit retrograde aspect ruler requested angle place.", + "area17.element890.variant": + "Body body cusp requested cusp transit shown transit house body {p0} orbit birth transit angle ruler body wheel natal {p1} system aspect ruler.", + "area17.element891.variant": + "Wheel cusp aspect house wheel birth orbit chart wheel ruler birth time {p1} {p0} wheel chart orbit wheel orbit birth.", + "area17.element892.variant": + "Sign house retrograde system house {p1} cusp house time degree body house house cusp orbit house transit body retrograde orbit requested {p0} sign angle {p2} aspect retrograde cusp sign cusp orbit.", + "area17.element893.variant": + "Time requested {p1} shown retrograde system wheel body aspect sign shown chart sign {p0} birth transit cusp cusp requested place requested time degree transit house sign time birth shown body.", + "area17.element894.variant": + "Wheel {p0} requested birth time aspect retrograde degree {p1} wheel chart ruler body place natal house aspect orbit {p2} degree requested shown.", + "area17.element895.variant": + "Time {p0} chart chart time place chart cusp ruler degree requested {p1} shown.", + "area17.element896.variant": + "Ruler angle house requested chart place chart transit system wheel body sign place.", + "area17.element897.variant": + "{p2} Aspect {p1} shown sign {p0} birth birth aspect body cusp cusp system retrograde ruler.", + "area17.element898.variant": + "{p1} {p2} Cusp natal body angle degree transit time {p0} retrograde angle.", + "area17.element899.variant": + "Sign wheel chart degree body cusp {p0} {p1} house sign angle orbit retrograde chart body system ruler degree retrograde chart time.", + "area18.element900.variant": + "Sign aspect aspect transit wheel transit ruler ruler place sign sign retrograde transit system retrograde aspect orbit house house sign sign birth aspect wheel birth ruler house time aspect.", + "area18.element901.variant": + "Aspect retrograde transit angle system aspect time time sign cusp.", + "area18.element902.variant": + "Time natal {p0} system transit place ruler {p1} birth house transit sign ruler retrograde aspect cusp natal {p2} natal angle time sign orbit transit body.", + "area18.element903.variant": + "Orbit requested chart place body chart sign transit requested degree degree sign chart place shown ruler {p0} requested sign cusp orbit.", + "area18.element904.variant": + "House degree body body house angle shown degree system {p0} aspect {p1}.", + "area18.element905.variant": + "Chart degree ruler system system retrograde degree wheel ruler chart transit chart retrograde aspect orbit wheel system {p0} orbit cusp {p1} aspect ruler system body ruler.", + "area18.element906.variant": + "Ruler body shown ruler wheel degree ruler retrograde birth degree angle cusp orbit aspect aspect {p0} angle time body requested degree angle degree shown chart.", + "area18.element907.variant": + "Retrograde house house orbit shown degree house time requested angle place wheel ruler cusp degree house ruler.", + "area18.element908.variant": + "Ruler wheel requested system requested place shown.", + "area18.element909.variant": + "Time wheel angle aspect shown retrograde place aspect chart time house house aspect chart transit sign ruler time {p1} aspect {p2} {p0} sign ruler.", + "area18.element910.variant": + "Chart natal degree natal system ruler ruler shown retrograde natal requested time body wheel retrograde birth requested sign aspect transit angle time aspect requested natal angle angle requested.", + "area18.element911.variant": + "Aspect angle birth natal body body transit {p2} {p1} transit retrograde {p0}.", + "area18.element912.variant": + "Requested {p1} transit cusp retrograde requested {p0} {p2} transit natal system ruler.", + "area18.element913.variant": + "Time {p0} birth transit retrograde orbit place aspect body cusp orbit {p1} aspect place natal ruler natal chart shown birth body place {p2} orbit house retrograde orbit orbit aspect place cusp.", + "area18.element914.variant": + "Place chart place time system birth retrograde {p0} wheel requested orbit angle shown body degree ruler place place orbit retrograde place aspect birth retrograde wheel.", + "area18.element915.variant": + "Wheel {p0} ruler {p1} birth shown retrograde aspect natal requested.", + "area18.element916.variant": + "System retrograde aspect angle retrograde angle house chart cusp time sign retrograde ruler chart system.", + "area18.element917.variant": + "Retrograde house sign retrograde sign orbit body wheel angle {p1} natal transit cusp {p2} time natal body body {p0} degree aspect requested retrograde requested.", + "area18.element918.variant": + "{p0} Degree retrograde orbit system angle cusp orbit body {p2} body house body ruler {p1} body orbit angle.", + "area18.element919.variant": + "Time orbit transit natal orbit requested transit house transit body ruler retrograde angle shown shown retrograde system angle shown sign {p0} birth sign cusp ruler aspect aspect.", + "area18.element920.variant": + "Cusp aspect chart time wheel {p0} retrograde system orbit ruler cusp angle {p1} retrograde aspect.", + "area18.element921.variant": + "{p0} Retrograde ruler {p1} house body degree orbit orbit.", + "area18.element922.variant": + "Degree {p1} degree house {p2} house ruler angle orbit chart cusp transit angle angle orbit cusp {p0}.", + "area18.element923.variant": + "Transit {p1} degree ruler {p2} chart {p0} degree aspect chart natal chart wheel natal birth sign cusp.", + "area18.element924.variant": + "Wheel place retrograde aspect sign natal wheel orbit body body transit natal body {p0} requested degree transit ruler place {p2} birth transit requested cusp {p1} natal.", + "area18.element925.variant": + "Cusp retrograde time birth shown sign chart angle degree time natal house sign ruler body shown wheel chart sign wheel transit angle ruler time transit.", + "area18.element926.variant": + "Shown body place transit transit natal place system natal transit place cusp orbit natal time birth ruler natal cusp place house shown cusp transit cusp wheel cusp.", + "area18.element927.variant": + "{p0} Requested chart birth time wheel shown requested system body degree {p1} retrograde requested.", + "area18.element928.variant": + "Natal angle sign body aspect orbit {p0} degree birth chart.", + "area18.element929.variant": + "Body system time chart birth cusp {p2} shown place sign time natal retrograde retrograde transit place birth {p0} aspect birth house {p1} house sign retrograde ruler system house transit body place aspect.", + "area18.element930.variant": + "Ruler retrograde natal time house natal degree shown house body body time transit.", + "area18.element931.variant": + "{p2} Aspect house house time sign degree body shown orbit angle place transit degree birth birth sign retrograde natal requested {p1} birth angle place {p0} sign wheel cusp cusp transit natal shown.", + "area18.element932.variant": + "Retrograde retrograde transit wheel {p0} shown birth ruler aspect retrograde time.", + "area18.element933.variant": + "Sign ruler transit time transit retrograde.", + "area18.element934.variant": + "Wheel wheel aspect body {p0} natal system {p1} body transit natal degree body chart birth {p2} aspect.", + "area18.element935.variant": + "Aspect angle aspect body orbit system wheel time time chart place requested system time shown time aspect transit shown degree transit shown degree time system shown system.", + "area18.element936.variant": + "Chart angle retrograde time retrograde {p1} birth transit sign transit body ruler {p2} {p0} body cusp shown place system degree degree system.", + "area18.element937.variant": + "Degree transit ruler body place house birth angle {p0} time shown natal body {p1}.", + "area18.element938.variant": + "Shown {p1} wheel time degree body house degree aspect {p2} body aspect orbit wheel cusp ruler system birth birth system sign degree retrograde birth ruler angle angle system chart {p0} place sign natal.", + "area18.element939.variant": + "Requested natal system birth time house aspect transit house shown angle {p0} {p2} orbit requested time transit degree requested {p1} place place.", + "area18.element940.variant": + "Retrograde time cusp shown chart {p1} {p2} place {p0} birth time system retrograde house.", + "area18.element941.variant": + "Wheel transit wheel shown shown {p1} orbit {p0} ruler degree wheel.", + "area18.element942.variant": + "Birth system cusp {p0} aspect aspect natal natal natal body natal time.", + "area18.element943.variant": + "Cusp {p0} natal place birth retrograde place orbit cusp house aspect wheel {p1}.", + "area18.element944.variant": + "Ruler angle cusp system transit ruler {p0} wheel shown place angle transit retrograde body wheel shown system angle shown angle house aspect chart.", + "area18.element945.variant": + "Retrograde natal place body natal place birth requested aspect sign chart degree {p1} system retrograde requested birth degree {p0} body wheel body orbit chart body shown.", + "area18.element946.variant": + "Wheel time retrograde sign transit place natal birth cusp place retrograde time birth wheel house shown retrograde angle birth time house house house wheel chart orbit.", + "area18.element947.variant": + "Body chart degree orbit chart requested wheel place chart orbit place natal transit natal {p0} orbit natal time shown wheel orbit ruler transit requested requested system angle transit.", + "area18.element948.variant": + "{p0} Cusp degree chart time shown body birth system place sign orbit retrograde sign chart natal cusp cusp degree chart degree wheel wheel.", + "area18.element949.variant": + "Degree house angle time body cusp requested wheel place body place cusp house shown {p0} shown {p2} shown place retrograde aspect body house birth orbit aspect birth {p1}.", + "area19.element950.variant": + "Degree chart degree birth {p0} house cusp birth degree {p1} requested degree time cusp angle place house aspect time birth degree.", + "area19.element951.variant": + "Sign birth system aspect requested requested retrograde cusp aspect aspect cusp.", + "area19.element952.variant": + "Ruler orbit transit cusp {p0} body birth orbit aspect birth orbit chart transit aspect requested house angle degree.", + "area19.element953.variant": + "Natal aspect system orbit requested requested requested shown {p0} transit shown birth orbit transit shown aspect orbit chart wheel orbit orbit place degree angle body place angle system time requested {p1} sign.", + "area19.element954.variant": + "{p0} Birth wheel degree birth transit system degree.", + "area19.element955.variant": + "Angle sign wheel {p2} chart {p0} ruler degree place retrograde {p1}.", + "area19.element956.variant": + "Ruler cusp aspect transit sign angle shown sign house time angle requested time time birth sign place sign house shown system shown cusp ruler birth wheel transit transit body transit.", + "area19.element957.variant": + "Retrograde house natal sign angle system system time retrograde shown birth transit natal ruler {p0}.", + "area19.element958.variant": + "Degree shown birth angle cusp {p1} sign transit cusp chart sign requested requested time system angle retrograde {p0} requested aspect house orbit shown aspect house natal house.", + "area19.element959.variant": + "Requested wheel angle {p1} angle transit {p0} shown shown natal house ruler angle.", + "area19.element960.variant": + "Natal {p0} sign natal aspect time angle {p1} body.", + "area19.element961.variant": + "Degree requested wheel ruler chart house natal transit body place chart shown retrograde angle retrograde requested retrograde wheel {p0}.", + "area19.element962.variant": + "Ruler place wheel shown {p1} birth aspect {p2} aspect orbit angle angle {p0} cusp.", + "area19.element963.variant": + "Shown time system chart aspect sign aspect shown aspect ruler chart time birth birth body aspect time wheel wheel system requested retrograde {p1} transit wheel shown wheel {p0} wheel.", + "area19.element964.variant": + "{p1} Retrograde body angle system system cusp {p2} {p0}.", + "area19.element965.variant": + "Degree place natal {p0} place sign transit system {p1} chart shown shown time transit time transit transit system time natal house birth ruler system body chart cusp.", + "area19.element966.variant": + "Ruler cusp transit natal natal house retrograde chart body ruler sign requested retrograde natal cusp angle orbit {p0} time {p1} system transit cusp degree requested cusp place angle natal place natal.", + "area19.element967.variant": + "Sign retrograde system retrograde shown birth orbit requested place ruler time birth orbit aspect orbit.", + "area19.element968.variant": + "Angle {p1} place orbit {p0} shown orbit body shown requested house cusp sign retrograde.", + "area19.element969.variant": + "System orbit angle system natal natal chart orbit body requested house natal ruler cusp orbit retrograde ruler birth shown aspect birth degree natal body orbit.", + "area19.element970.variant": + "System angle place angle natal system wheel transit angle time time natal time birth retrograde wheel ruler house ruler requested aspect {p0} shown aspect place house cusp requested system.", + "area19.element971.variant": + "Requested time angle transit natal sign natal requested house aspect cusp place time sign wheel angle system degree retrograde angle.", + "area19.element972.variant": "Aspect wheel body system degree time.", + "area19.element973.variant": + "Transit ruler place orbit natal shown body {p1} retrograde angle system aspect retrograde chart system chart {p0} sign ruler chart place place house transit chart transit requested natal body transit.", + "area19.element974.variant": + "Place degree birth angle system place retrograde aspect aspect aspect natal shown place {p1} ruler ruler orbit transit place wheel natal ruler wheel degree ruler shown angle natal ruler {p0} system natal.", + "area19.element975.variant": + "Wheel natal angle {p0} natal time time retrograde angle natal house wheel birth {p2} wheel degree requested place aspect chart degree house angle aspect degree requested sign time sign {p1} angle wheel orbit.", + "area19.element976.variant": + "Birth place birth birth retrograde natal house system sign place system system system transit cusp transit cusp birth wheel system cusp {p0} birth requested.", + "area19.element977.variant": + "Chart system degree system birth sign system time orbit aspect degree ruler sign chart transit birth house degree.", + "area19.element978.variant": + "Birth house chart wheel retrograde retrograde {p0} angle chart angle place wheel body body degree wheel angle {p1} body house time sign sign birth cusp time retrograde natal.", + "area19.element979.variant": + "Orbit chart shown degree degree chart system system system aspect orbit aspect orbit time body sign requested birth ruler transit transit body angle house place.", + "area19.element980.variant": + "Time ruler {p0} requested {p1} natal birth wheel wheel.", + "area19.element981.variant": + "Birth {p1} {p0} shown cusp angle degree chart aspect retrograde house birth requested {p2} shown aspect body.", + "area19.element982.variant": + "Ruler retrograde ruler wheel degree time house house angle shown retrograde {p0} {p2} {p1}.", + "area19.element983.variant": + "Requested aspect cusp system shown body cusp ruler {p0} house requested time retrograde cusp degree body body chart time sign.", + "area19.element984.variant": + "Place shown {p0} body chart cusp wheel retrograde chart birth ruler {p1} birth.", + "area19.element985.variant": + "Natal body retrograde aspect shown system natal requested house chart time {p1} cusp body house time retrograde cusp system {p2} shown {p0} angle transit.", + "area19.element986.variant": + "Shown aspect wheel house natal ruler retrograde {p0} place aspect.", + "area19.element987.variant": + "{p1} Natal sign retrograde angle house retrograde time aspect wheel ruler system birth ruler house body time time aspect cusp natal birth retrograde chart house body {p0} time sign chart orbit.", + "area19.element988.variant": + "Time system system shown sign orbit sign retrograde.", + "area19.element989.variant": + "Degree ruler natal place system system transit sign natal {p0} birth orbit degree transit {p1} time system birth angle orbit system cusp natal degree angle chart shown place aspect birth.", + "area19.element990.variant": + "Orbit orbit transit body requested system degree retrograde birth degree natal orbit angle wheel birth body retrograde retrograde sign chart place chart shown house degree system system place time time.", + "area19.element991.variant": + "Chart birth birth requested house angle aspect place house transit natal angle chart angle cusp shown time natal chart sign ruler orbit retrograde system wheel wheel.", + "area19.element992.variant": + "Natal cusp time cusp chart place angle ruler place birth {p0} {p1} place sign birth.", + "area19.element993.variant": + "Transit natal natal requested {p1} place chart transit place cusp requested angle ruler shown shown chart {p0} birth time orbit retrograde sign wheel natal transit angle cusp requested natal.", + "area19.element994.variant": + "Ruler place house shown sign house shown transit time system angle time transit natal chart shown house body birth ruler time body aspect shown degree chart body system natal birth.", + "area19.element995.variant": + "Birth requested body house ruler wheel natal aspect cusp body orbit chart birth birth angle place retrograde house system transit orbit retrograde degree orbit.", + "area19.element996.variant": + "Place {p0} angle time aspect wheel degree cusp cusp body natal time place requested transit transit orbit shown cusp time body time ruler.", + "area19.element997.variant": + "{p0} Chart transit ruler retrograde time angle aspect chart natal {p1} angle {p2} shown aspect ruler aspect transit orbit time.", + "area19.element998.variant": + "Aspect angle {p0} {p2} natal body body natal system ruler natal orbit house degree house degree cusp requested ruler {p1} sign place time birth.", + "area19.element999.variant": + "Ruler cusp system body time place orbit orbit chart time {p2} transit birth wheel requested wheel {p0} body cusp {p1} ruler.", + }, + }, + body: { + shape: "named", + entries: { + B0: { + name: "Body 0", + insight: "Insight number 0 for this body.", + keywords: ["k0", "shared"], + }, + B1: { + name: "Body 1", + insight: "Insight number 1 for this body.", + keywords: ["k1", "shared"], + }, + B2: { + name: "Body 2", + insight: "Insight number 2 for this body.", + keywords: ["k2", "shared"], + }, + B3: { + name: "Body 3", + insight: "Insight number 3 for this body.", + keywords: ["k3", "shared"], + }, + B4: { + name: "Body 4", + insight: "Insight number 4 for this body.", + keywords: ["k4", "shared"], + }, + B5: { + name: "Body 5", + insight: "Insight number 5 for this body.", + keywords: ["k5", "shared"], + }, + B6: { + name: "Body 6", + insight: "Insight number 6 for this body.", + keywords: ["k6", "shared"], + }, + B7: { + name: "Body 7", + insight: "Insight number 7 for this body.", + keywords: ["k7", "shared"], + }, + B8: { + name: "Body 8", + insight: "Insight number 8 for this body.", + keywords: ["k8", "shared"], + }, + B9: { + name: "Body 9", + insight: "Insight number 9 for this body.", + keywords: ["k9", "shared"], + }, + B10: { + name: "Body 10", + insight: "Insight number 10 for this body.", + keywords: ["k10", "shared"], + }, + B11: { + name: "Body 11", + insight: "Insight number 11 for this body.", + keywords: ["k11", "shared"], + }, + B12: { + name: "Body 12", + insight: "Insight number 12 for this body.", + keywords: ["k12", "shared"], + }, + B13: { + name: "Body 13", + insight: "Insight number 13 for this body.", + keywords: ["k13", "shared"], + }, + B14: { + name: "Body 14", + insight: "Insight number 14 for this body.", + keywords: ["k14", "shared"], + }, + B15: { + name: "Body 15", + insight: "Insight number 15 for this body.", + keywords: ["k15", "shared"], + }, + B16: { + name: "Body 16", + insight: "Insight number 16 for this body.", + keywords: ["k16", "shared"], + }, + B17: { + name: "Body 17", + insight: "Insight number 17 for this body.", + keywords: ["k17", "shared"], + }, + B18: { + name: "Body 18", + insight: "Insight number 18 for this body.", + keywords: ["k18", "shared"], + }, + B19: { + name: "Body 19", + insight: "Insight number 19 for this body.", + keywords: ["k19", "shared"], + }, + B20: { + name: "Body 20", + insight: "Insight number 20 for this body.", + keywords: ["k20", "shared"], + }, + B21: { + name: "Body 21", + insight: "Insight number 21 for this body.", + keywords: ["k21", "shared"], + }, + B22: { + name: "Body 22", + insight: "Insight number 22 for this body.", + keywords: ["k22", "shared"], + }, + B23: { + name: "Body 23", + insight: "Insight number 23 for this body.", + keywords: ["k23", "shared"], + }, + B24: { + name: "Body 24", + insight: "Insight number 24 for this body.", + keywords: ["k24", "shared"], + }, + B25: { + name: "Body 25", + insight: "Insight number 25 for this body.", + keywords: ["k25", "shared"], + }, + B26: { + name: "Body 26", + insight: "Insight number 26 for this body.", + keywords: ["k26", "shared"], + }, + B27: { + name: "Body 27", + insight: "Insight number 27 for this body.", + keywords: ["k27", "shared"], + }, + B28: { + name: "Body 28", + insight: "Insight number 28 for this body.", + keywords: ["k28", "shared"], + }, + B29: { + name: "Body 29", + insight: "Insight number 29 for this body.", + keywords: ["k29", "shared"], + }, + B30: { + name: "Body 30", + insight: "Insight number 30 for this body.", + keywords: ["k30", "shared"], + }, + B31: { + name: "Body 31", + insight: "Insight number 31 for this body.", + keywords: ["k31", "shared"], + }, + B32: { + name: "Body 32", + insight: "Insight number 32 for this body.", + keywords: ["k32", "shared"], + }, + B33: { + name: "Body 33", + insight: "Insight number 33 for this body.", + keywords: ["k33", "shared"], + }, + B34: { + name: "Body 34", + insight: "Insight number 34 for this body.", + keywords: ["k34", "shared"], + }, + B35: { + name: "Body 35", + insight: "Insight number 35 for this body.", + keywords: ["k35", "shared"], + }, + B36: { + name: "Body 36", + insight: "Insight number 36 for this body.", + keywords: ["k36", "shared"], + }, + B37: { + name: "Body 37", + insight: "Insight number 37 for this body.", + keywords: ["k37", "shared"], + }, + B38: { + name: "Body 38", + insight: "Insight number 38 for this body.", + keywords: ["k38", "shared"], + }, + B39: { + name: "Body 39", + insight: "Insight number 39 for this body.", + keywords: ["k39", "shared"], + }, + B40: { + name: "Body 40", + insight: "Insight number 40 for this body.", + keywords: ["k40", "shared"], + }, + B41: { + name: "Body 41", + insight: "Insight number 41 for this body.", + keywords: ["k41", "shared"], + }, + B42: { + name: "Body 42", + insight: "Insight number 42 for this body.", + keywords: ["k42", "shared"], + }, + B43: { + name: "Body 43", + insight: "Insight number 43 for this body.", + keywords: ["k43", "shared"], + }, + B44: { + name: "Body 44", + insight: "Insight number 44 for this body.", + keywords: ["k44", "shared"], + }, + B45: { + name: "Body 45", + insight: "Insight number 45 for this body.", + keywords: ["k45", "shared"], + }, + B46: { + name: "Body 46", + insight: "Insight number 46 for this body.", + keywords: ["k46", "shared"], + }, + B47: { + name: "Body 47", + insight: "Insight number 47 for this body.", + keywords: ["k47", "shared"], + }, + B48: { + name: "Body 48", + insight: "Insight number 48 for this body.", + keywords: ["k48", "shared"], + }, + B49: { + name: "Body 49", + insight: "Insight number 49 for this body.", + keywords: ["k49", "shared"], + }, + B50: { + name: "Body 50", + insight: "Insight number 50 for this body.", + keywords: ["k50", "shared"], + }, + B51: { + name: "Body 51", + insight: "Insight number 51 for this body.", + keywords: ["k51", "shared"], + }, + B52: { + name: "Body 52", + insight: "Insight number 52 for this body.", + keywords: ["k52", "shared"], + }, + B53: { + name: "Body 53", + insight: "Insight number 53 for this body.", + keywords: ["k53", "shared"], + }, + B54: { + name: "Body 54", + insight: "Insight number 54 for this body.", + keywords: ["k54", "shared"], + }, + B55: { + name: "Body 55", + insight: "Insight number 55 for this body.", + keywords: ["k55", "shared"], + }, + B56: { + name: "Body 56", + insight: "Insight number 56 for this body.", + keywords: ["k56", "shared"], + }, + B57: { + name: "Body 57", + insight: "Insight number 57 for this body.", + keywords: ["k57", "shared"], + }, + B58: { + name: "Body 58", + insight: "Insight number 58 for this body.", + keywords: ["k58", "shared"], + }, + B59: { + name: "Body 59", + insight: "Insight number 59 for this body.", + keywords: ["k59", "shared"], + }, + B60: { + name: "Body 60", + insight: "Insight number 60 for this body.", + keywords: ["k60", "shared"], + }, + B61: { + name: "Body 61", + insight: "Insight number 61 for this body.", + keywords: ["k61", "shared"], + }, + B62: { + name: "Body 62", + insight: "Insight number 62 for this body.", + keywords: ["k62", "shared"], + }, + B63: { + name: "Body 63", + insight: "Insight number 63 for this body.", + keywords: ["k63", "shared"], + }, + B64: { + name: "Body 64", + insight: "Insight number 64 for this body.", + keywords: ["k64", "shared"], + }, + B65: { + name: "Body 65", + insight: "Insight number 65 for this body.", + keywords: ["k65", "shared"], + }, + B66: { + name: "Body 66", + insight: "Insight number 66 for this body.", + keywords: ["k66", "shared"], + }, + B67: { + name: "Body 67", + insight: "Insight number 67 for this body.", + keywords: ["k67", "shared"], + }, + B68: { + name: "Body 68", + insight: "Insight number 68 for this body.", + keywords: ["k68", "shared"], + }, + B69: { + name: "Body 69", + insight: "Insight number 69 for this body.", + keywords: ["k69", "shared"], + }, + B70: { + name: "Body 70", + insight: "Insight number 70 for this body.", + keywords: ["k70", "shared"], + }, + B71: { + name: "Body 71", + insight: "Insight number 71 for this body.", + keywords: ["k71", "shared"], + }, + B72: { + name: "Body 72", + insight: "Insight number 72 for this body.", + keywords: ["k72", "shared"], + }, + B73: { + name: "Body 73", + insight: "Insight number 73 for this body.", + keywords: ["k73", "shared"], + }, + B74: { + name: "Body 74", + insight: "Insight number 74 for this body.", + keywords: ["k74", "shared"], + }, + B75: { + name: "Body 75", + insight: "Insight number 75 for this body.", + keywords: ["k75", "shared"], + }, + B76: { + name: "Body 76", + insight: "Insight number 76 for this body.", + keywords: ["k76", "shared"], + }, + B77: { + name: "Body 77", + insight: "Insight number 77 for this body.", + keywords: ["k77", "shared"], + }, + B78: { + name: "Body 78", + insight: "Insight number 78 for this body.", + keywords: ["k78", "shared"], + }, + B79: { + name: "Body 79", + insight: "Insight number 79 for this body.", + keywords: ["k79", "shared"], + }, + B80: { + name: "Body 80", + insight: "Insight number 80 for this body.", + keywords: ["k80", "shared"], + }, + B81: { + name: "Body 81", + insight: "Insight number 81 for this body.", + keywords: ["k81", "shared"], + }, + B82: { + name: "Body 82", + insight: "Insight number 82 for this body.", + keywords: ["k82", "shared"], + }, + B83: { + name: "Body 83", + insight: "Insight number 83 for this body.", + keywords: ["k83", "shared"], + }, + B84: { + name: "Body 84", + insight: "Insight number 84 for this body.", + keywords: ["k84", "shared"], + }, + B85: { + name: "Body 85", + insight: "Insight number 85 for this body.", + keywords: ["k85", "shared"], + }, + B86: { + name: "Body 86", + insight: "Insight number 86 for this body.", + keywords: ["k86", "shared"], + }, + B87: { + name: "Body 87", + insight: "Insight number 87 for this body.", + keywords: ["k87", "shared"], + }, + B88: { + name: "Body 88", + insight: "Insight number 88 for this body.", + keywords: ["k88", "shared"], + }, + B89: { + name: "Body 89", + insight: "Insight number 89 for this body.", + keywords: ["k89", "shared"], + }, + B90: { + name: "Body 90", + insight: "Insight number 90 for this body.", + keywords: ["k90", "shared"], + }, + B91: { + name: "Body 91", + insight: "Insight number 91 for this body.", + keywords: ["k91", "shared"], + }, + B92: { + name: "Body 92", + insight: "Insight number 92 for this body.", + keywords: ["k92", "shared"], + }, + B93: { + name: "Body 93", + insight: "Insight number 93 for this body.", + keywords: ["k93", "shared"], + }, + B94: { + name: "Body 94", + insight: "Insight number 94 for this body.", + keywords: ["k94", "shared"], + }, + B95: { + name: "Body 95", + insight: "Insight number 95 for this body.", + keywords: ["k95", "shared"], + }, + B96: { + name: "Body 96", + insight: "Insight number 96 for this body.", + keywords: ["k96", "shared"], + }, + B97: { + name: "Body 97", + insight: "Insight number 97 for this body.", + keywords: ["k97", "shared"], + }, + B98: { + name: "Body 98", + insight: "Insight number 98 for this body.", + keywords: ["k98", "shared"], + }, + B99: { + name: "Body 99", + insight: "Insight number 99 for this body.", + keywords: ["k99", "shared"], + }, + }, + }, + }, +}); diff --git a/test/contract/manifest.performance.test.ts b/test/contract/manifest.performance.test.ts new file mode 100644 index 0000000..67abe38 --- /dev/null +++ b/test/contract/manifest.performance.test.ts @@ -0,0 +1,22 @@ +import type { + EntryOf, + ParamsOf, + TextKeys, +} from "@astrologyengine/cms-contract/manifest"; +import type { NamedFields } from "@astrologyengine/cms-contract/shapes"; +import { describe, expectTypeOf, it } from "vitest"; +import { largeManifest } from "./fixtures/large-manifest"; + +type L = typeof largeManifest; + +type Key = TextKeys; +/** Every key's param names; resolving this forces all 1,000 ParamsOf types. */ +type ParamNames = { [K in Key]: keyof ParamsOf }[Key]; + +describe("manifest types at scale (1,000 text keys)", () => { + it("resolves keys and params", () => { + expectTypeOf().toBeString(); + expectTypeOf().toEqualTypeOf<"p0" | "p1" | "p2">(); + expectTypeOf>().toEqualTypeOf(); + }); +}); diff --git a/test/contract/manifest.types.test.ts b/test/contract/manifest.types.test.ts new file mode 100644 index 0000000..ae495aa --- /dev/null +++ b/test/contract/manifest.types.test.ts @@ -0,0 +1,131 @@ +import { + defineManifest, + type CollectionsOf, + type EntryOf, + type KeysOf, + type ParamsOf, + type TextCollectionsOf, + type TextKeys, +} from "@astrologyengine/cms-contract/manifest"; +import type { + NamedFields, + ReferenceFields, + TextFields, +} from "@astrologyengine/cms-contract/shapes"; +import { describe, expect, expectTypeOf, it } from "vitest"; + +const manifest = defineManifest({ + locale: "en", + collections: { + body: { + shape: "named", + entries: { + SUN: { name: "Sun", insight: "Identity.", keywords: ["identity"] }, + MOON: { name: "Moon", insight: "Feeling.", keywords: ["feeling"] }, + }, + }, + house: { + shape: "reference", + entries: { "1": { insight: "Self.", keywords: ["self"] } }, + }, + ui: { + shape: "text", + entries: { + "app.title": "Explorer", + "app.status.updating": "Showing {shown}; you asked for {requested}.", + "chart.house.name": "House {number}", + }, + }, + errors: { shape: "text", entries: { "error.failed": "Failed." } }, + }, +}); +type M = typeof manifest; + +/** The kind of `t()` the website builds on these helpers. */ +const t = >( + key: K, + _params: ParamsOf, +): string => key; + +describe("manifest types", () => { + it("defineManifest returns the manifest unchanged", () => { + expect(defineManifest(manifest)).toBe(manifest); + }); + + it("lists collections and text collections", () => { + expectTypeOf>().toEqualTypeOf< + "body" | "house" | "ui" | "errors" + >(); + expectTypeOf>().toEqualTypeOf<"ui" | "errors">(); + }); + + it("lists keys per collection", () => { + expectTypeOf>().toEqualTypeOf<"SUN" | "MOON">(); + expectTypeOf>().toEqualTypeOf<"1">(); + expectTypeOf>().toEqualTypeOf< + "app.title" | "app.status.updating" | "chart.house.name" + >(); + }); + + it("derives params from the English text", () => { + expectTypeOf>().toEqualTypeOf<{ + shown: string | number; + requested: string | number; + }>(); + expectTypeOf>().toEqualTypeOf<{ + number: string | number; + }>(); + expectTypeOf>().toEqualTypeOf<{}>(); + }); + + it("gives each entry its shape's fields", () => { + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + }); + + it("rejects unknown keys and wrong params at compile time", () => { + expectTypeOf( + t("app.status.updating", { shown: 1, requested: "2" }), + ).toBeString(); + expectTypeOf(t("app.title", {})).toBeString(); + // @ts-expect-error unknown key + t("app.titel", {}); + // @ts-expect-error missing param + t("app.status.updating", { shown: 1 }); + // @ts-expect-error extra param + t("app.status.updating", { shown: 1, requested: 2, extra: 3 }); + // @ts-expect-error key from another text collection + t("error.failed", {}); + }); + + it("limits text helpers to text collections", () => { + // @ts-expect-error body is a named collection + expectTypeOf>().toBeNever(); + // @ts-expect-error unknown collection + expectTypeOf>().toBeNever(); + }); + + it("checks entries against their shape", () => { + defineManifest({ + locale: "en", + collections: { + // @ts-expect-error named entries need a name + body: { + shape: "named", + entries: { SUN: { insight: "x", keywords: ["a"] } }, + }, + }, + }); + defineManifest({ + locale: "en", + // @ts-expect-error unknown shape + collections: { x: { shape: "rich", entries: {} } }, + }); + defineManifest({ + locale: "en", + // @ts-expect-error text entries are strings + collections: { ui: { shape: "text", entries: { a: { text: "x" } } } }, + }); + }); +}); diff --git a/test/contract/placeholders.test.ts b/test/contract/placeholders.test.ts new file mode 100644 index 0000000..655253e --- /dev/null +++ b/test/contract/placeholders.test.ts @@ -0,0 +1,21 @@ +import { + placeholdersIn, + samePlaceholders, +} from "@astrologyengine/cms-contract/placeholders"; +import { describe, expect, it } from "vitest"; + +describe("placeholdersIn", () => { + it("extracts unique names in order of appearance", () => { + expect(placeholdersIn("{b} and {a} then {b}; not { c } or {1x}")).toEqual([ + "b", + "a", + ]); + }); +}); + +describe("samePlaceholders", () => { + it("compares as sets", () => { + expect(samePlaceholders(["a", "b"], ["b", "a"])).toBe(true); + expect(samePlaceholders(["a"], ["a", "b"])).toBe(false); + }); +}); diff --git a/test/contract/placeholders.types.test.ts b/test/contract/placeholders.types.test.ts new file mode 100644 index 0000000..b4d720b --- /dev/null +++ b/test/contract/placeholders.types.test.ts @@ -0,0 +1,52 @@ +import { + placeholdersIn, + type PlaceholdersOf, +} from "@astrologyengine/cms-contract/placeholders"; +import { describe, expect, expectTypeOf, it } from "vitest"; + +// Type-level cases are checked by `bun run check`; each also asserts the +// runtime extractor agrees, so the two definitions can't drift apart. +type Ten = `${S}${S}${S}${S}${S}${S}${S}${S}${S}${S}`; +type Thousand = Ten>>; +/** A literal type over 2,000 characters long. */ +type Long = `${Thousand<"x">}{first}${Thousand<"y">}{second}`; +const long = `${"x".repeat(1000)}{first}${"y".repeat(1000)}{second}` as Long; + +describe("PlaceholdersOf", () => { + it("is never without placeholders", () => { + expectTypeOf>().toEqualTypeOf(); + expect(placeholdersIn("Plain text.")).toEqual([]); + }); + + it("names one placeholder", () => { + expectTypeOf>().toEqualTypeOf<"name">(); + expect(placeholdersIn("Hi {name}!")).toEqual(["name"]); + }); + + it("deduplicates repeats and handles adjacent placeholders", () => { + expectTypeOf>().toEqualTypeOf<"a" | "b">(); + expect(placeholdersIn("{a}{b} and {a}")).toEqual(["a", "b"]); + }); + + it("ignores braces that don't hold an identifier", () => { + expectTypeOf< + PlaceholdersOf<"{ c } {1x} {} {ok_1} {a-b}"> + >().toEqualTypeOf<"ok_1">(); + expect(placeholdersIn("{ c } {1x} {} {ok_1} {a-b}")).toEqual(["ok_1"]); + }); + + it("finds the innermost identifier in nested or unbalanced braces", () => { + expectTypeOf>().toEqualTypeOf<"b" | "c">(); + expect(placeholdersIn("{a{b} {{c}}")).toEqual(["b", "c"]); + }); + + it("handles long text", () => { + expect(long.length).toBeGreaterThan(2000); + expectTypeOf>().toEqualTypeOf<"first" | "second">(); + expect(placeholdersIn(long)).toEqual(["first", "second"]); + }); + + it("is string for non-literal text", () => { + expectTypeOf>().toEqualTypeOf(); + }); +}); diff --git a/test/contract/shapes.test.ts b/test/contract/shapes.test.ts new file mode 100644 index 0000000..7dcb258 --- /dev/null +++ b/test/contract/shapes.test.ts @@ -0,0 +1,136 @@ +import { isShape, validateFields } from "@astrologyengine/cms-contract/shapes"; +import { describe, expect, it } from "vitest"; + +const sun = { + name: "Sun", + insight: "The Sun symbolizes identity.", + keywords: ["identity", "purpose"], +}; + +const pathsOf = (result: ReturnType) => + result.ok ? [] : result.issues.map((issue) => issue.path); + +describe("validateFields", () => { + it("accepts each shape and returns the fields", () => { + expect(validateFields("named", sun)).toEqual({ ok: true, fields: sun }); + expect( + validateFields("reference", { insight: "Presence.", keywords: ["a"] }), + ).toEqual({ + ok: true, + fields: { insight: "Presence.", keywords: ["a"] }, + }); + expect(validateFields("text", { text: "Explore\nyour chart." })).toEqual({ + ok: true, + fields: { text: "Explore\nyour chart." }, + }); + }); + + it("accepts values at the limits", () => { + expect( + validateFields("named", { + name: "n".repeat(100), + insight: "i".repeat(2000), + keywords: Array(8).fill("k".repeat(50)), + }).ok, + ).toBe(true); + expect(validateFields("text", { text: "t".repeat(2000) }).ok).toBe(true); + }); + + it.each([ + ["missing field", { name: "Sun", keywords: ["a"] }, ["insight"]], + [ + "unknown field", + { name: "Sun", insight: "x", keywords: ["a"], extra: 1 }, + ["extra"], + ], + ["empty name", { name: "", insight: "x", keywords: ["a"] }, ["name"]], + ["padded name", { name: " Sun", insight: "x", keywords: ["a"] }, ["name"]], + [ + "blank insight", + { name: "Sun", insight: " ", keywords: ["a"] }, + ["insight"], + ], + ["non-string name", { name: 1, insight: "x", keywords: ["a"] }, ["name"]], + ["no keywords", { name: "Sun", insight: "x", keywords: [] }, ["keywords"]], + [ + "too many keywords", + { name: "Sun", insight: "x", keywords: Array(9).fill("a") }, + ["keywords"], + ], + [ + "keywords not an array", + { name: "Sun", insight: "x", keywords: "a" }, + ["keywords"], + ], + [ + "empty keyword", + { name: "Sun", insight: "x", keywords: ["a", ""] }, + ["keywords.1"], + ], + [ + "long keyword", + { name: "Sun", insight: "x", keywords: ["k".repeat(51)] }, + ["keywords.0"], + ], + [ + "long name", + { name: "n".repeat(101), insight: "x", keywords: ["a"] }, + ["name"], + ], + [ + "long insight", + { name: "Sun", insight: "i".repeat(2001), keywords: ["a"] }, + ["insight"], + ], + ["not an object", "Sun", [""]], + ["an array", [sun], [""]], + ["null", null, [""]], + ])("rejects a named entry with %s", (_label, fields, paths) => { + const result = validateFields("named", fields); + expect(result.ok).toBe(false); + expect(pathsOf(result)).toEqual(paths); + if (!result.ok) + for (const issue of result.issues) expect(issue.message).toMatch(/\S/); + }); + + it("reports every issue, not just the first", () => { + expect( + pathsOf( + validateFields("named", { name: "", keywords: [], extra: 1 }), + ).sort(), + ).toEqual(["extra", "insight", "keywords", "name"]); + }); + + it("rejects a name on reference entries and extra fields on text", () => { + expect( + pathsOf( + validateFields("reference", { + name: "x", + insight: "x", + keywords: ["a"], + }), + ), + ).toEqual(["name"]); + expect(pathsOf(validateFields("text", { text: "x", name: "x" }))).toEqual([ + "name", + ]); + }); + + it.each([ + ["empty", { text: "" }], + ["blank", { text: " " }], + ["padded", { text: "x\n" }], + ["too long", { text: "t".repeat(2001) }], + ["not a string", { text: ["x"] }], + ])("rejects %s text", (_label, fields) => { + expect(pathsOf(validateFields("text", fields))).toEqual(["text"]); + }); +}); + +describe("isShape", () => { + it("recognises the three shapes only", () => { + expect(["named", "reference", "text"].every(isShape)).toBe(true); + expect(isShape("rich")).toBe(false); + expect(isShape(undefined)).toBe(false); + }); +}); diff --git a/test/contract/sync-client.test.ts b/test/contract/sync-client.test.ts new file mode 100644 index 0000000..4a2b8b9 --- /dev/null +++ b/test/contract/sync-client.test.ts @@ -0,0 +1,140 @@ +import { + isCmsError, + fetchDefinitions, + fetchSyncState, + syncManifest, +} from "@astrologyengine/cms-contract/sync"; +import { describe, expect, it } from "vitest"; + +type Call = { url: string; method: string; headers: Headers; body: unknown }; + +/** A fetch that records requests and answers with the given responses in order. */ +const stub = (...responses: (Response | Error)[]) => { + const calls: Call[] = []; + const fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { + calls.push({ + url: String(input), + method: init?.method ?? "GET", + headers: new Headers(init?.headers), + body: init?.body ? JSON.parse(String(init.body)) : undefined, + }); + const next = responses.shift()!; + if (next instanceof Error) throw next; + return next; + }) as typeof globalThis.fetch; + return { fetch, calls }; +}; + +const json = (body: unknown, status = 200) => + new Response(JSON.stringify(body), { + status, + headers: { "content-type": "application/json" }, + }); + +const origin = "https://cms.example.test/"; +const token = "t".repeat(40); +const definitions = { default: "en", version: 3, collections: {} }; +const result = { + commit: "a".repeat(40), + changed: true, + version: 4, + createdCollections: [], + created: ["ui:x"], + reactivated: [], + unused: [], + refreshed: [], + drift: [], +}; + +describe("fetchDefinitions", () => { + it("GETs the public definitions without credentials", async () => { + const { fetch, calls } = stub(json(definitions)); + expect(await fetchDefinitions({ origin, fetch })).toEqual(definitions); + expect(calls).toHaveLength(1); + expect(calls[0]!.url).toBe("https://cms.example.test/v1/definitions"); + expect(calls[0]!.method).toBe("GET"); + expect(calls[0]!.headers.has("authorization")).toBe(false); + }); +}); + +describe("fetchSyncState", () => { + it("GETs the admin sync state with the token", async () => { + const state = { head: null, recent: [] }; + const { fetch, calls } = stub(json(state)); + expect(await fetchSyncState({ origin, token, fetch })).toEqual(state); + expect(calls[0]!.url).toBe("https://cms.example.test/v1/admin/sync"); + expect(calls[0]!.headers.get("authorization")).toBe(`Bearer ${token}`); + }); +}); + +describe("syncManifest", () => { + const request = { + commit: "a".repeat(40), + expected: null, + manifest: { locale: "en", collections: {} }, + }; + + it("POSTs the manifest with token and actor and returns the summary", async () => { + const { fetch, calls } = stub(json(result)); + expect( + await syncManifest({ origin, token, fetch, actor: "web-ci", ...request }), + ).toEqual(result); + expect(calls[0]).toMatchObject({ + url: "https://cms.example.test/v1/admin/sync", + method: "POST", + body: request, + }); + expect(calls[0]!.headers.get("content-type")).toBe("application/json"); + expect(calls[0]!.headers.get("authorization")).toBe(`Bearer ${token}`); + expect(calls[0]!.headers.get("x-cms-actor")).toBe("web-ci"); + }); + + it("omits the actor header unless given", async () => { + const { fetch, calls } = stub(json(result)); + await syncManifest({ origin, token, fetch, ...request }); + expect(calls[0]!.headers.has("x-cms-actor")).toBe(false); + }); + + it.each([ + [ + 409, + { + code: "definition_conflict", + message: "Conflicts.", + conflicts: [{ code: "key_retired", collection: "ui", key: "x" }], + }, + ], + [412, { code: "precondition_failed", message: "Another sync." }], + [401, { code: "unauthorized", message: "Token." }], + ])( + "throws CmsError for %i with the CMS code and details", + async (status, error) => { + const { fetch } = stub(json({ error }, status)); + const thrown = await syncManifest({ + origin, + token, + fetch, + ...request, + }).catch((caught: unknown) => caught); + expect(thrown).toBeInstanceOf(Error); + expect(isCmsError(thrown)).toBe(true); + const { code, message, ...details } = error; + expect(thrown).toMatchObject({ status, code, message, details }); + }, + ); + + it("reports non-JSON error bodies and network failures", async () => { + const html = stub(new Response("

Bad gateway

", { status: 502 })); + await expect( + syncManifest({ origin, token, fetch: html.fetch, ...request }), + ).rejects.toMatchObject({ status: 502, code: "http_error" }); + const down = stub(new TypeError("fetch failed")); + await expect( + fetchDefinitions({ origin, fetch: down.fetch }), + ).rejects.toMatchObject({ + status: 0, + code: "network_error", + message: expect.stringContaining("fetch failed"), + }); + }); +}); diff --git a/test/fields.test.ts b/test/fields.test.ts index d4690ea..65cd885 100644 --- a/test/fields.test.ts +++ b/test/fields.test.ts @@ -1,10 +1,9 @@ import { describe, expect, it } from "vitest"; import { validateFields } from "../src/fields"; -import { placeholdersIn, samePlaceholders } from "../src/placeholders"; -import { testCatalog } from "./fixtures"; +import { testRegistry } from "./fixtures"; const ok = (collection: string, key: string, fields: unknown) => - validateFields(testCatalog, collection, key, fields); + validateFields(testRegistry, collection, key, fields); describe("validateFields", () => { it("accepts a named reference entry", () => { @@ -87,16 +86,3 @@ describe("validateFields", () => { }); }); }); - -describe("placeholders", () => { - it("extracts unique names in order of appearance", () => { - expect(placeholdersIn("{b} and {a} then {b}; not { c } or {1x}")).toEqual([ - "b", - "a", - ]); - }); - it("compares as sets", () => { - expect(samePlaceholders(["a", "b"], ["b", "a"])).toBe(true); - expect(samePlaceholders(["a"], ["a", "b"])).toBe(false); - }); -}); diff --git a/test/fixtures.ts b/test/fixtures.ts index c367511..a0a991e 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -1,7 +1,11 @@ -import { defineCatalog } from "../src/catalog-schema"; +import type { Shape } from "@astrologyengine/cms-contract/shapes"; +import type { Registry } from "../src/registry"; -/** Small catalog for route tests; the real one is tested separately. */ -export const testCatalog = defineCatalog({ +/** + * Small catalog for route tests (collection → shape, key → placeholders); + * `resetDb` registers it as active keys. The real one is tested separately. + */ +export const testCatalog = { body: { shape: "named", keys: { SUN: [], MOON: [], MARS: [] }, @@ -14,7 +18,31 @@ export const testCatalog = defineCatalog({ "app.previous": ["date", "place"], }, }, -}); +} as const; + +/** Registry with every key of a catalog-shaped object active. */ +export const registryFrom = ( + catalog: Record< + string, + { shape: Shape; keys: Record } + >, +): Registry => + Object.fromEntries( + Object.entries(catalog).map(([name, { shape, keys }]) => [ + name, + { + shape, + keys: Object.fromEntries( + Object.entries(keys).map(([key, placeholders]) => [ + key, + { placeholders: [...placeholders], status: "active" as const }, + ]), + ), + }, + ]), + ); + +export const testRegistry = registryFrom(testCatalog); export const sun = { name: "Sun", diff --git a/test/helpers.ts b/test/helpers.ts index 81c01a4..07a5ebf 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -1,12 +1,13 @@ import { env } from "cloudflare:workers"; import { createApp } from "../src/app"; -import { testCatalog } from "./fixtures"; +import type { Registry } from "../src/registry"; +import { testRegistry } from "./fixtures"; export const ADMIN_TOKEN = "test-admin-token-0123456789abcdefghijklmnop"; -const app = createApp(testCatalog); +const app = createApp(); -/** Requests against an app built from the small test catalog. */ +/** Requests against the app; `resetDb` registers the small test catalog. */ export const call = async ( path: string, init?: RequestInit, @@ -32,16 +33,55 @@ export const admin = ( }); }; -/** Tests in one file share D1 state; files are isolated from each other. */ -export const resetDb = async () => { +const STAMP = "2026-01-01T00:00:00.000Z"; + +/** Insert collections and keys (existing rows are left alone). */ +export const registerKeys = async (registry: Registry) => { + const statements: D1PreparedStatement[] = []; + for (const [name, { shape, keys }] of Object.entries(registry)) { + statements.push( + env.DB.prepare( + "INSERT INTO collections (name, shape, created_at) VALUES (?, ?, ?) ON CONFLICT DO NOTHING", + ).bind(name, shape, STAMP), + ); + for (const [key, { placeholders, status }] of Object.entries(keys)) + statements.push( + env.DB.prepare( + `INSERT INTO keys (collection, key, placeholders, status, created_at, updated_at) + VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT DO NOTHING`, + ).bind(name, key, JSON.stringify(placeholders), status, STAMP, STAMP), + ); + } + if (statements.length) await env.DB.batch(statements); +}; + +/** + * Empty content and registry, then register `registry`. Tests in one file + * share D1 state; files are isolated. + */ +export const resetDbWith = async (registry: Registry) => { await env.DB.batch([ env.DB.prepare("DELETE FROM translations"), env.DB.prepare("DELETE FROM revisions"), + env.DB.prepare("DELETE FROM syncs"), + env.DB.prepare("DELETE FROM keys"), + env.DB.prepare("DELETE FROM collections"), + // `expected` must name the current commit to pass the sync_head trigger. + env.DB.prepare( + "UPDATE sync_head SET expected = commit_sha, commit_sha = NULL, updated_at = NULL", + ), env.DB.prepare("DELETE FROM locales WHERE is_default = 0"), env.DB.prepare("UPDATE meta SET value = 1 WHERE key = 'content_version'"), ]); + await registerKeys(registry); }; +/** `resetDbWith` the test catalog; safe as `beforeEach(resetDb)`. */ +export const resetDb = () => resetDbWith(testRegistry); + +/** A full 40-character commit SHA for tests: `sha(1)` is `000…001`. */ +export const sha = (n: number) => n.toString(16).padStart(40, "0"); + export const addLocale = async ( code: string, { @@ -58,17 +98,36 @@ export const addLocale = async ( .run(); }; +const shapeOf = (fields: unknown) => + typeof fields === "object" && fields !== null && "text" in fields + ? "text" + : typeof fields === "object" && fields !== null && "name" in fields + ? "named" + : "reference"; + +/** + * Store a translation directly. A key that isn't registered yet is registered + * as `unused` (its collection's shape guessed from the fields): served and + * editable, but not in the website's current manifest. + */ export const addTranslation = async ( collection: string, key: string, locale: string, fields: unknown, + origin: "sync" | "editor" = "editor", ) => { + await registerKeys({ + [collection]: { + shape: shapeOf(fields), + keys: { [key]: { placeholders: [], status: "unused" } }, + }, + }); await env.DB.prepare( - `INSERT INTO translations (collection, key, locale, fields, revision, updated_at) - VALUES (?, ?, ?, ?, 1, '2026-01-01T00:00:00.000Z')`, + `INSERT INTO translations (collection, key, locale, fields, revision, origin, updated_at) + VALUES (?, ?, ?, ?, 1, ?, ?)`, ) - .bind(collection, key, locale, JSON.stringify(fields)) + .bind(collection, key, locale, JSON.stringify(fields), origin, STAMP) .run(); }; diff --git a/test/public-content.test.ts b/test/public-content.test.ts index d81fc04..8928300 100644 --- a/test/public-content.test.ts +++ b/test/public-content.test.ts @@ -3,6 +3,7 @@ import { addLocale, addTranslation, call, + registerKeys, resetDb, setVersion, } from "./helpers"; @@ -65,16 +66,30 @@ describe("GET /v1/content/:locale", () => { expect(body.locale).toBe("es-419"); }); - it("excludes orphaned translations", async () => { + it("serves unused keys and omits deleted ones", async () => { + await registerKeys({ + body: { + shape: "named", + keys: { VULCAN: { placeholders: [], status: "deleted" } }, + }, + ghost: { + shape: "text", + keys: { "only.deleted": { placeholders: [], status: "deleted" } }, + }, + }); + // addTranslation registers unknown keys as unused. await addTranslation("body", "PLUTO", "en", { ...sun, name: "Pluto" }); await addTranslation("planet", "SUN", "en", sun); + await addTranslation("body", "VULCAN", "en", { ...sun, name: "Vulcan" }); + await addTranslation("ghost", "only.deleted", "en", title); const body = await ( await call("/v1/content/en") ).json<{ entries: Record>; }>(); - expect(body.entries.body).toEqual({}); - expect(body.entries).not.toHaveProperty("planet"); + expect(body.entries.body).toEqual({ PLUTO: { ...sun, name: "Pluto" } }); + expect(body.entries.planet).toEqual({ SUN: sun }); + expect(body.entries).not.toHaveProperty("ghost"); }); it.each([ @@ -138,6 +153,27 @@ describe("GET /v1/content/:locale/:collection/:key", () => { }); }); + it("serves unused keys and answers 404 unknown_entry for deleted ones", async () => { + await registerKeys({ + body: { + shape: "named", + keys: { VULCAN: { placeholders: [], status: "deleted" } }, + }, + }); + await addTranslation("body", "PLUTO", "en", { ...sun, name: "Pluto" }); + await addTranslation("body", "VULCAN", "en", { ...sun, name: "Vulcan" }); + expect( + await (await call("/v1/content/en/body/PLUTO")).json(), + ).toMatchObject({ + fields: { name: "Pluto" }, + }); + const deleted = await call("/v1/content/en/body/VULCAN"); + expect(deleted.status).toBe(404); + expect(await deleted.json()).toMatchObject({ + error: { code: "unknown_entry" }, + }); + }); + it("answers 404 not_found for an untranslated catalog entry", async () => { const response = await call("/v1/content/en/body/MARS"); expect(response.status).toBe(404); diff --git a/test/public-definitions.test.ts b/test/public-definitions.test.ts new file mode 100644 index 0000000..d6d4c10 --- /dev/null +++ b/test/public-definitions.test.ts @@ -0,0 +1,82 @@ +import { beforeEach, describe, expect, it } from "vitest"; +import { + addTranslation, + call, + registerKeys, + resetDb, + setVersion, +} from "./helpers"; +import { sun } from "./fixtures"; + +beforeEach(async () => { + await resetDb(); + await registerKeys({ + body: { + shape: "named", + keys: { + PLUTO: { placeholders: [], status: "unused" }, + VULCAN: { placeholders: [], status: "deleted" }, + }, + }, + }); + await addTranslation("body", "SUN", "en", sun); + await setVersion(9); +}); + +const active = { placeholders: [], status: "active" }; + +describe("GET /v1/definitions", () => { + it("lists every collection and key, deleted ones included, without text", async () => { + const response = await call("/v1/definitions"); + expect(response.status).toBe(200); + expect(await response.json()).toEqual({ + default: "en", + version: 9, + collections: { + body: { + shape: "named", + keys: { + MARS: active, + MOON: active, + PLUTO: { placeholders: [], status: "unused" }, + SUN: active, + VULCAN: { placeholders: [], status: "deleted" }, + }, + }, + house: { shape: "reference", keys: { "1": active, "2": active } }, + ui: { + shape: "text", + keys: { + "app.previous": { + placeholders: ["date", "place"], + status: "active", + }, + "landing.title": active, + }, + }, + }, + }); + }); + + it("is public, cacheable and revalidates by content version", async () => { + const response = await call("/v1/definitions"); + expect(response.headers.get("cache-control")).toBe( + "public, max-age=60, stale-while-revalidate=600", + ); + expect(response.headers.get("etag")).toBe('"v9"'); + const revalidated = await call("/v1/definitions", { + headers: { "if-none-match": '"v9"' }, + }); + expect(revalidated.status).toBe(304); + }); + + it("allows the site origins like other public routes", async () => { + const site = "https://staging.example.test"; + const response = await call( + "/v1/definitions", + { headers: { origin: site } }, + { CMS_ALLOWED_ORIGINS: site }, + ); + expect(response.headers.get("access-control-allow-origin")).toBe(site); + }); +}); diff --git a/test/worker.test.ts b/test/worker.test.ts index a5bb739..e1ce42d 100644 --- a/test/worker.test.ts +++ b/test/worker.test.ts @@ -1,13 +1,15 @@ import { env, exports } from "cloudflare:workers"; import { describe, expect, it } from "vitest"; -import { catalog } from "../src/catalog"; -import { seedSql, type SeedFile } from "../src/seed"; +import { catalog } from "@astrologyengine/cms-contract/catalog"; +import { registrySql, seedSql, type SeedFile } from "../src/seed"; import seedJson from "@astrologyengine/cms-contract/seed/en.json"; // Wiring check of the deployed entry point (real catalog + seed). describe("worker entry", () => { it("serves every catalog entry in English after seeding", async () => { - const sql = seedSql(seedJson as SeedFile, "2026-11-10T00:00:00.000Z"); + const stamp = "2026-11-10T00:00:00.000Z"; + const sql = + registrySql(catalog, stamp) + seedSql(seedJson as SeedFile, stamp); await env.DB.batch( sql .split("\n") diff --git a/wrangler.jsonc b/wrangler.jsonc index a9d2f34..05c8f44 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -40,7 +40,7 @@ { "binding": "DB", "database_name": "astrology-engine-cms-staging", - "database_id": "REPLACE_WITH_STAGING_DATABASE_ID", + "database_id": "e3aa4fd2-9aeb-4423-b24b-4fe0b281b4ec", "migrations_dir": "migrations", }, ], @@ -57,7 +57,7 @@ { "binding": "DB", "database_name": "astrology-engine-cms-alpha", - "database_id": "REPLACE_WITH_ALPHA_DATABASE_ID", + "database_id": "e55d2c4e-f2c6-47ad-a46c-bdf9a968289d", "migrations_dir": "migrations", }, ],