cogens 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +14 -5
- package/dist/admin/app.d.ts +21 -0
- package/dist/admin/app.d.ts.map +1 -0
- package/dist/admin/app.js +561 -0
- package/dist/admin/app.js.map +1 -0
- package/dist/admin/assets.d.ts +17 -0
- package/dist/admin/assets.d.ts.map +1 -0
- package/dist/admin/assets.js +51 -0
- package/dist/admin/assets.js.map +1 -0
- package/dist/admin/fields.d.ts +27 -0
- package/dist/admin/fields.d.ts.map +1 -0
- package/dist/admin/fields.js +128 -0
- package/dist/admin/fields.js.map +1 -0
- package/dist/admin/forms.d.ts +18 -0
- package/dist/admin/forms.d.ts.map +1 -0
- package/dist/admin/forms.js +53 -0
- package/dist/admin/forms.js.map +1 -0
- package/dist/admin/index.d.ts +15 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +13 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/rules.d.ts +24 -0
- package/dist/admin/rules.d.ts.map +1 -0
- package/dist/admin/rules.js +51 -0
- package/dist/admin/rules.js.map +1 -0
- package/dist/admin/types.d.ts +96 -0
- package/dist/admin/types.d.ts.map +1 -0
- package/dist/admin/types.js +2 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/admin/views.d.ts +109 -0
- package/dist/admin/views.d.ts.map +1 -0
- package/dist/admin/views.js +202 -0
- package/dist/admin/views.js.map +1 -0
- package/dist/auth/handoff.d.ts +27 -0
- package/dist/auth/handoff.d.ts.map +1 -0
- package/dist/auth/handoff.js +41 -0
- package/dist/auth/handoff.js.map +1 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/password.d.ts +48 -0
- package/dist/auth/password.d.ts.map +1 -0
- package/dist/auth/password.js +154 -0
- package/dist/auth/password.js.map +1 -0
- package/dist/auth/principal.d.ts +30 -0
- package/dist/auth/principal.d.ts.map +1 -0
- package/dist/auth/principal.js +30 -0
- package/dist/auth/principal.js.map +1 -0
- package/dist/auth/session.d.ts +68 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +92 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/core/access/ability.d.ts +24 -0
- package/dist/core/access/ability.d.ts.map +1 -0
- package/dist/core/access/ability.js +64 -0
- package/dist/core/access/ability.js.map +1 -0
- package/dist/core/access/can.d.ts +41 -0
- package/dist/core/access/can.d.ts.map +1 -0
- package/dist/core/access/can.js +38 -0
- package/dist/core/access/can.js.map +1 -0
- package/dist/core/access/compile.d.ts +12 -0
- package/dist/core/access/compile.d.ts.map +1 -0
- package/dist/core/access/compile.js +53 -0
- package/dist/core/access/compile.js.map +1 -0
- package/dist/core/access/permits.d.ts +24 -0
- package/dist/core/access/permits.d.ts.map +1 -0
- package/dist/core/access/permits.js +29 -0
- package/dist/core/access/permits.js.map +1 -0
- package/dist/core/access/when.d.ts +6 -0
- package/dist/core/access/when.d.ts.map +1 -0
- package/dist/core/access/when.js +64 -0
- package/dist/core/access/when.js.map +1 -0
- package/dist/core/access/where.d.ts +25 -0
- package/dist/core/access/where.d.ts.map +1 -0
- package/dist/core/access/where.js +81 -0
- package/dist/core/access/where.js.map +1 -0
- package/dist/core/columns.d.ts +6 -0
- package/dist/core/columns.d.ts.map +1 -0
- package/dist/core/columns.js +6 -0
- package/dist/core/columns.js.map +1 -0
- package/dist/core/config/define.d.ts +101 -0
- package/dist/core/config/define.d.ts.map +1 -0
- package/dist/core/config/define.js +97 -0
- package/dist/core/config/define.js.map +1 -0
- package/dist/core/config/field.d.ts +71 -0
- package/dist/core/config/field.d.ts.map +1 -0
- package/dist/core/config/field.js +64 -0
- package/dist/core/config/field.js.map +1 -0
- package/dist/core/errors.d.ts +66 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +94 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +31 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +20 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/media/index.d.ts +36 -0
- package/dist/core/media/index.d.ts.map +1 -0
- package/dist/core/media/index.js +99 -0
- package/dist/core/media/index.js.map +1 -0
- package/dist/core/principal.d.ts +28 -0
- package/dist/core/principal.d.ts.map +1 -0
- package/dist/core/principal.js +25 -0
- package/dist/core/principal.js.map +1 -0
- package/dist/core/store/assets.d.ts +3 -0
- package/dist/core/store/assets.d.ts.map +1 -0
- package/dist/core/store/assets.js +3 -0
- package/dist/core/store/assets.js.map +1 -0
- package/dist/core/store/cms.d.ts +53 -0
- package/dist/core/store/cms.d.ts.map +1 -0
- package/dist/core/store/cms.js +154 -0
- package/dist/core/store/cms.js.map +1 -0
- package/dist/core/store/content.d.ts +57 -0
- package/dist/core/store/content.d.ts.map +1 -0
- package/dist/core/store/content.js +455 -0
- package/dist/core/store/content.js.map +1 -0
- package/dist/core/store/sql.d.ts +88 -0
- package/dist/core/store/sql.d.ts.map +1 -0
- package/dist/core/store/sql.js +149 -0
- package/dist/core/store/sql.js.map +1 -0
- package/dist/core/store/types.d.ts +107 -0
- package/dist/core/store/types.d.ts.map +1 -0
- package/dist/core/store/types.js +2 -0
- package/dist/core/store/types.js.map +1 -0
- package/dist/core/testing/index.d.ts +27 -0
- package/dist/core/testing/index.d.ts.map +1 -0
- package/dist/core/testing/index.js +60 -0
- package/dist/core/testing/index.js.map +1 -0
- package/dist/migrations-tool/bin.d.ts +3 -0
- package/dist/migrations-tool/bin.d.ts.map +1 -0
- package/dist/migrations-tool/bin.js +40 -0
- package/dist/migrations-tool/bin.js.map +1 -0
- package/dist/migrations-tool/index.d.ts +16 -0
- package/dist/migrations-tool/index.d.ts.map +1 -0
- package/dist/migrations-tool/index.js +24 -0
- package/dist/migrations-tool/index.js.map +1 -0
- package/dist/testing/db.d.ts +16 -0
- package/dist/testing/db.d.ts.map +1 -0
- package/dist/testing/db.js +43 -0
- package/dist/testing/db.js.map +1 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +33 -11
- package/src/core/config/define.ts +1 -1
- package/src/core/store/cms.ts +1 -1
- package/src/migrations-tool/bin.ts +34 -0
- package/{scripts/print-migration.ts → src/migrations-tool/index.ts} +6 -19
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- The package now ships compiled JavaScript (ES modules) with `.d.ts` declarations, declaration maps and source maps in `dist/`. `exports` point there, so Node 20 or later, Vitest and Node scripts can import it; Node refuses `.ts` files under `node_modules`. Wrangler and Bun are unaffected.
|
|
6
|
+
- `cogens-print-migration` runs under Node (`#!/usr/bin/env node`): `.js` and `.mjs` configs always, `.ts` configs on a Node that strips types. The printer moved from `scripts/print-migration.ts` to `src/migrations-tool/`; the `cogens/migrations-tool` import is unchanged, and `cogens/scripts/print-migration.ts` is gone.
|
|
7
|
+
- `scripts/build-admin-editor.ts` stays Bun-only and stays a shipped `.ts` script.
|
|
8
|
+
- `engines` gains `node >=20`.
|
|
9
|
+
|
|
10
|
+
## 0.2.0
|
|
11
|
+
|
|
12
|
+
- Renamed from coauthcms to cogens. Publishable: README for a public audience, `LICENSE` and `NOTICE`, `hono` pinned to `~4.12.2`.
|
|
13
|
+
- Editor plugins receive the field's type and name and replace the built-in directive syntax; `createTestDb`; `migrations-tool` and `scripts` exports.
|
|
14
|
+
|
|
15
|
+
## 0.1.1
|
|
16
|
+
|
|
17
|
+
- Sinfon's directive syntax applies only to notebook fields in the admin.
|
|
18
|
+
|
|
19
|
+
## 0.1.0
|
|
20
|
+
|
|
21
|
+
- Extracted from Sinfon's `site/packages` (a multi-tenant fork of Koguma): content types, access rules, principals, the server-rendered admin and the session tables.
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ The package's `dependencies` are those three and no more; a test (`test/boundary
|
|
|
18
18
|
|
|
19
19
|
It is a library you embed in your own Worker. It is not a hosted service, a standalone CMS with its own sign-in for end users, or a React dashboard: you supply the sign-in and say who is calling; the package supplies the store, the access checks and a small server-rendered admin. It was written for [Sinfon](https://sinfon.app), the first host, and is used there.
|
|
20
20
|
|
|
21
|
-
Status: 0.2.
|
|
21
|
+
Status: 0.2.1, pre-1.0. The API may change before 1.0.
|
|
22
22
|
|
|
23
23
|
## Install
|
|
24
24
|
|
|
@@ -28,13 +28,15 @@ bun add cogens
|
|
|
28
28
|
npm install cogens
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
It runs in Cloudflare Workers (Wrangler), Node 20 or later (scripts, Vitest, any bundler) and Bun. The package ships compiled ES modules with type declarations in `dist/`, so none of them needs a TypeScript loader. The types name Cloudflare's `D1Database` and `R2Bucket`, so a TypeScript host adds `@cloudflare/workers-types` to its `types`.
|
|
32
|
+
|
|
33
|
+
Two tools are not Node's: `scripts/build-admin-editor.ts` (the admin's editor bundle) uses `Bun.build` and runs under Bun only, and `cogens-print-migration` loads a `.ts` config only under Bun or a Node that strips types (see Migrations).
|
|
32
34
|
|
|
33
35
|
To use an unreleased commit, pin it: `bun add github:vikramrojo/cogens#<commit>`.
|
|
34
36
|
|
|
35
37
|
## Quick start
|
|
36
38
|
|
|
37
|
-
Define one owned type and read an entry back as its owner.
|
|
39
|
+
Define one owned type and read an entry back as its owner. This walk-through uses [Bun](https://bun.sh) 1.4 or later to run a `.ts` file; the package itself needs only Node 20 or later (or Bun, or Workers).
|
|
38
40
|
|
|
39
41
|
```sh
|
|
40
42
|
mkdir hello && cd hello
|
|
@@ -337,7 +339,7 @@ const cms = createCms({ config, db: t.db });
|
|
|
337
339
|
await t.dispose();
|
|
338
340
|
```
|
|
339
341
|
|
|
340
|
-
`migrationLines(types)` returns the SQL lines `cogens-print-migration` prints for a list of content types, so a test can compare them with your migration file. The
|
|
342
|
+
`migrationLines(types)` returns the SQL lines `cogens-print-migration` prints for a list of content types, so a test can compare them with your migration file. The editor build script resolves by name: `cogens/scripts/build-admin-editor.ts`.
|
|
341
343
|
|
|
342
344
|
## Migrations
|
|
343
345
|
|
|
@@ -350,9 +352,12 @@ SQL files a host applies, in this order (copy them into your Wrangler `migration
|
|
|
350
352
|
A rule or `where` may name only the built-in columns and a type's `indexed` fields; an indexed field is a virtual generated column over the entry's JSON (SQLite's `ALTER TABLE ADD COLUMN` allows only virtual ones, and they can be indexed), plus a partial unique index on `(content_type, slug)` for types with `uniqueSlug`. Print them from a config file whose default export is `{ contentTypes }` (what `defineConfig` returns):
|
|
351
353
|
|
|
352
354
|
```sh
|
|
353
|
-
bunx cogens-print-migration site.config.ts
|
|
355
|
+
bunx --bun cogens-print-migration site.config.ts # Bun: any config file, .ts included
|
|
356
|
+
npx cogens-print-migration site.config.mjs # Node: a .js or .mjs config
|
|
354
357
|
```
|
|
355
358
|
|
|
359
|
+
The command's shebang is `node`, so plain `bunx` also runs it under Node; `bunx --bun` runs it under Bun. Under Node the command imports the config as written. A `.js` or `.mjs` config always works; a `.ts` config works only on a Node that strips types (22.18 or later, and 24), in a project whose `package.json` has `"type": "module"`, and only if its own imports resolve there. Otherwise use `bunx --bun`, or compile the config. The same lines come from `migrationLines(contentTypes)` in `cogens/migrations-tool`.
|
|
360
|
+
|
|
356
361
|
Put the printed lines in a migration of your own. At startup, on first use, the store compares them with `PRAGMA table_xinfo(entries)` and fails naming the type and field if one is missing.
|
|
357
362
|
|
|
358
363
|
**A database that already has Koguma's `entries` and `assets`** (its own `0001`) must not apply `0001_entries.sql`, whose `CREATE TABLE IF NOT EXISTS` would skip the tables and leave the new columns missing. Apply `migrations/koguma-upgrade.sql` instead, which adds the four columns, `assets.owner_id` and the indexes. A host that already added those columns itself skips both. The auth tables are independent of either. Nothing in these files names any host's tables.
|
|
@@ -369,10 +374,14 @@ Put the printed lines in a migration of your own. At startup, on first use, the
|
|
|
369
374
|
|
|
370
375
|
```sh
|
|
371
376
|
bun install
|
|
377
|
+
bun run build # src/ to dist/ (tsc, tsconfig.build.json); the tests import the package by name, so they need it
|
|
372
378
|
bun test # the package's tests, the example Worker in Miniflare included
|
|
379
|
+
bun run test # build, then test
|
|
373
380
|
bun run typecheck # src, the example, the scripts
|
|
374
381
|
```
|
|
375
382
|
|
|
383
|
+
`dist/` is not committed. `npm publish` runs `prepublishOnly` (build, then test), so a published package always has a fresh build.
|
|
384
|
+
|
|
376
385
|
## Contributing
|
|
377
386
|
|
|
378
387
|
Issues are welcome: bug reports, questions, and notes on where the access rules or the docs surprised you. Pull requests are welcome by arrangement: open an issue first to agree the change, since the package is small on purpose (see the import boundary above). Run `bun test` and `bun run typecheck` before sending anything.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createAdmin: the admin's routes as a Hono app for the host to mount where it
|
|
3
|
+
* likes. Every read and write of entries goes through `cms.content.as(principal)`
|
|
4
|
+
* for the principal the host resolved, so the admin can do nothing the type's
|
|
5
|
+
* rules refuse that caller; `cms.access.rulesFor` only decides what to draw.
|
|
6
|
+
*
|
|
7
|
+
* app.route('/admin2', createAdmin({ cms, resolvePrincipal, mount: '/admin2' }))
|
|
8
|
+
*
|
|
9
|
+
* Writes are forms that POST and answer 303. They are refused unless they are
|
|
10
|
+
* form posts from the admin's own origin (hono/csrf, plus a content-type check,
|
|
11
|
+
* since csrf looks only at form content types), and every page carries a content
|
|
12
|
+
* security policy that names the admin's script, the editor and the stylesheets.
|
|
13
|
+
*/
|
|
14
|
+
import { Hono } from 'hono';
|
|
15
|
+
import { type HostPrincipal } from '../core/index.ts';
|
|
16
|
+
import type { AdminAssets, AdminOptions } from './types.ts';
|
|
17
|
+
export declare const DEFAULT_ASSETS: AdminAssets;
|
|
18
|
+
export declare function createAdmin<H extends HostPrincipal = never>(options: AdminOptions<H>): Hono<any>;
|
|
19
|
+
/** Mounts the admin on a host app: `mountAdmin(app, '/admin2', options)`. */
|
|
20
|
+
export declare function mountAdmin<H extends HostPrincipal = never>(host: Hono<any>, path: string, options: Omit<AdminOptions<H>, 'mount'>): void;
|
|
21
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/admin/app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAI1C,OAAO,EAEyC,KAAK,aAAa,EACjE,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK,EAAe,WAAW,EAAE,YAAY,EAAmC,MAAM,YAAY,CAAC;AAM1G,eAAO,MAAM,cAAc,EAAE,WAM5B,CAAC;AAYF,wBAAgB,WAAW,CAAC,CAAC,SAAS,aAAa,GAAG,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAyiBhG;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,CAAC,SAAS,aAAa,GAAG,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,CAExI"}
|