diff --git a/ADR.md b/ADR.md index 775e837..93c0bd2 100644 --- a/ADR.md +++ b/ADR.md @@ -118,3 +118,20 @@ Consequences: Every application of the store works on the same rows and refuses conflicts, and changes of the tables reach them with a release of the toolkit. The objects' keys are in `jsonb`'s order. The store is tested against a real PostgreSQL server, which the release workflow does not have, so `npm test` runs on the developer's machine. + +## ADR-6: A fourth entry point, /shared, exports the shared types and constants + +Status: Accepted + +Context: An application keeps the types of its API in one file that its server and its web +application both import. When those types name types of the toolkit, such as `TfModule`, the file +must import them from an entry point both sides can resolve: `/server` brings Fastify and `pg` +into the web application's type check, `/web` brings React and MUI into the server's. + +Decision: `shared/index.ts` is the entry point `/shared`, built and exported like the other three. +It exports the types and constants of `shared/`, the credential types and the types and name +patterns of the tfvars store, and no code that needs a peer dependency. `/server` and `/web` keep +exporting them too. + +Consequences: An application's shared API types import from `/shared` without the code of either +side. A type added to `shared/` is exported from `/shared` as well as from the side that uses it. diff --git a/CHANGELOG.md b/CHANGELOG.md index 18663f7..3248ad4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.5.0 + +feature: the entry point /shared exports the types and constants a server and its web application share. + +- `@koszewscy/sk-react-toolkit/shared` exports the credential types, `TfModule`, `TfInstance`, + `TfvarsFileStatus` and the name patterns of the tfvars store, for the API types of an + application imported by both its server and its web application. + ## 0.4.0 feature: the tfvars store keeps Terraform modules, their instances and the instances' variable files in PostgreSQL. diff --git a/README.md b/README.md index f3d1e92..6038681 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ source: Node 26 runs the server helpers, and the application's Vite build compil The package is `@koszewscy/sk-react-toolkit`, published to the npm registry of Gitea, `https://gitea.koszewscy.waw.pl/api/packages/koszewscy/npm/`. An application depends on a -published version and imports `@koszewscy/sk-react-toolkit/server`, `/web` and `/vite`. Its +published version and imports `@koszewscy/sk-react-toolkit/server`, `/shared`, `/web` and `/vite`. Its `.npmrc` names the registry of the scope: ```ini @@ -66,6 +66,13 @@ code; `vite` for the Vite helpers. | `CredentialStore`, `credentialProblems`, `credentialValues`, `registerCredentialRoutes`, `POSTGRESQL_KIND` | the credential store; see [Credential store](#credential-store) | | `createTfvarsStore`, `versionOf`, `tfvarsText`, `TfModule`, `TfInstance`, `TfvarsFileStatus`, `TF_NAME_PATTERN`, `TFVARS_FILE_PATTERN`, `STATE_SCHEMA_PATTERN` | the Terraform modules, their instances and their variable files in PostgreSQL; see [Tfvars store](#tfvars-store) | +## sk-react-toolkit/shared + +The types and constants of `/server` and `/web` that a server and its web application share, for +API types imported by both, without the code of either: `CredentialField`, `CredentialKind`, +`CredentialProfile`, `CredentialsDocument`, `TfModule`, `TfInstance`, `TfvarsFileStatus`, +`TF_NAME_PATTERN`, `TFVARS_FILE_PATTERN` and `STATE_SCHEMA_PATTERN`. + ## sk-react-toolkit/web | Export | Purpose | diff --git a/build.mjs b/build.mjs index 3bd11cd..363f1c0 100755 --- a/build.mjs +++ b/build.mjs @@ -10,7 +10,7 @@ import { join } from 'node:path'; const ROOT = import.meta.dirname; const DIST = join(ROOT, 'dist'); -const ENTRIES = ['server', 'web', 'vite']; +const ENTRIES = ['server', 'shared', 'web', 'vite']; function fail(message) { console.error(`build: ${message}`); @@ -23,7 +23,7 @@ if (tsc.error) fail(`tsc: ${tsc.error.message}; run npm ci first`); if (tsc.status !== 0) process.exit(tsc.status ?? 1); // The declarations import the other declarations by their .js names, as the compiled JavaScript does. -for (const entry of [...ENTRIES, 'shared']) { +for (const entry of ENTRIES) { for (const file of readdirSync(join(DIST, entry)).filter((name) => name.endsWith('.d.ts'))) { const path = join(DIST, entry, file); writeFileSync(path, readFileSync(path, 'utf8').replace(/(from\s+|import\s+)(['"])(\.{1,2}\/[^'"]+)\.tsx?\2/g, '$1$2$3.js$2')); diff --git a/package-lock.json b/package-lock.json index e549d11..cc2053c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@koszewscy/sk-react-toolkit", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@koszewscy/sk-react-toolkit", - "version": "0.4.0", + "version": "0.5.0", "devDependencies": { "@emotion/react": "^11.14.0", "@emotion/styled": "^11.14.1", diff --git a/package.json b/package.json index 8a735fb..f716f31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@koszewscy/sk-react-toolkit", - "version": "0.4.0", + "version": "0.5.0", "description": "Shared code of the React and Fastify web applications: web components, server helpers and the Vite font plugin.", "private": true, "type": "module", @@ -13,6 +13,7 @@ }, "exports": { "./server": "./server/index.ts", + "./shared": "./shared/index.ts", "./web": "./web/index.ts", "./vite": "./vite/index.ts" }, diff --git a/shared/index.ts b/shared/index.ts new file mode 100644 index 0000000..3db9876 --- /dev/null +++ b/shared/index.ts @@ -0,0 +1,3 @@ +export type { CredentialField, CredentialKind, CredentialProfile, CredentialsDocument } from './credentials.ts' +export type { TfInstance, TfModule, TfvarsFileStatus } from './tfvars.ts' +export { STATE_SCHEMA_PATTERN, TFVARS_FILE_PATTERN, TF_NAME_PATTERN } from './tfvars.ts'