UNPKG

6.06 kBMarkdownView Raw
1<h2 align="center">
2 <img src="https://cotype.dev/logo.svg" alt="cotype" />
3</h2>
4
5<p align="center">
6 <a href="https://circleci.com/gh/cotype/core/tree/master">
7 <img src="https://circleci.com/gh/cotype/core/tree/master.svg?style=shield" alt="CircleCI">
8 </a>
9 <a href="https://www.npmjs.com/package/@cotype/core">
10 <img src="https://img.shields.io/npm/v/@cotype/core.svg" alt="npm package">
11 </a>
12 <a href="https://codecov.io/gh/cotype/core/">
13 <img src="https://img.shields.io/codecov/c/gh/cotype/core/master.svg" alt="Codecov">
14 </a>
15 <a href="https://github.com/semantic-release/semantic-release">
16 <img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release">
17 </a>
18 <a href="https://greenkeeper.io/">
19 <img src="https://badges.greenkeeper.io/cotype/core.svg" alt="Greenkeeper">
20 </a>
21</p>
22<p>&nbsp;</p>
23
24Cotype manages structured content that can accessed via APIs.
25The system itself is not concerned with the actual rendering of the data - this is left completely to the consumer which could be a server that generates HTML, a client-rendered web app or a native app that reads the data via HTTP.
26
27---
28
29> Cotype is not free software.
30> In order to run cotype on a public server you must purchase a valid license.
31> Please contact info@cellular.de for inquiries.
32
33---
34
35## Install
36
37`npm install @cotype/core`
38
39## Usage
40
41```ts
42// server.ts
43import { init, Opts /* ... */ } from "@cotype/core";
44
45const port = 1337;
46const opts: Opts = {
47 /* ...see https://github.com/cotype/core#options */
48};
49
50/* Init cotype and receive express app */
51init(opts).then(({ app }) => {
52 /* Make the app listen on a specific port
53 * see https://nodejs.org/api/net.html#net_server_listen */
54 app.listen(port, () =>
55 console.log(`Cotype listening on http://localhost:${port}!`)
56 );
57}, console.error);
58```
59
60## Options
61
62- #### `models?: ModelOpts[]`
63
64 Describes what content types exist, which fields they have and how they are edited.
65
66- #### `persistenceAdapter: Promise<PersistenceAdapter>`
67
68 Adapter providing the database connection of the server.
69
70 Cotype provides a [Knex.js](https://knexjs.org/) adapter that can be configured
71 with a [Knex configuration object](https://knexjs.org/#Installation-client).
72
73 ```ts
74 import { init, knexAdapter } from "@cotype/core";
75
76 init({
77 /* ... */
78 persistenceAdapter: knexAdapter({
79 /* see https://knexjs.org/#Installation-client */
80 })
81 });
82 ```
83
84- #### `storage: Storage`
85
86 When files are uploaded, the meta data is stored in the database while the
87 binary data is stored using this adapter.
88
89 Cotype comes with an adapter that stores all data on the local file system.
90
91 ```ts
92 import { init, FsStorage } from "@cotype/core";
93
94 init({
95 /* ... */
96 storage: new FsStorage("./uploads")
97 });
98 ```
99
100- #### `thumbnailProvider: ThumbnailProvider`
101
102 Thumbnail creator for uploaded image files.
103 Cotype does not come with a default provider for size-reasons.
104
105 Please see [`@cotype/local-thumbnail-provider`](https://github.com/cotype/local-thumbnail-provider) for a straight-forward implementation.
106
107* #### `basePath?: string`
108
109 **Default: `/`**
110
111 Can be used to mount the app on a sub-path.
112 For example `http://localhost:3000/cms`.
113
114 ```ts
115 import { init } from "@cotype/core";
116
117 init({
118 /* ... */
119 basePath: "/cms"
120 });
121 ```
122
123- #### `sessionOpts?: SessionOpts`
124
125 The server uses a [cookie-session](https://github.com/expressjs/cookie-session)
126 that holds nothing but the user's id.
127
128 See [cookie-session#options](https://github.com/expressjs/cookie-session#options)
129 for details.
130
131 The cookie is signed to prevent any sort of tampering. Therefore a secret must
132 be provided using `sessionOpts.secret` or via the `SESSION_SECRET` env var. If
133 omitted, a random string will be generated, which means that sessions will
134 become invalid once the server is restarted.
135
136- #### `migrationDir?: string`
137
138 Absolute path to a directory containing content migration scripts. The scripts
139 are read in alphabetic order and executed only once. Each script must export a
140 function that takes exactly one argument: a [MigrationContext](https://github.com/cotype/core/blob/feature/content-migrations/src/persistence/MigrationContext.ts).
141
142## How it works
143
144### Content APIs
145
146The data can be accessed via REST. The server provides an interactive API explorer that developers can use to browse the content model.
147
148NOTE: THe content API is read-only. Modifying content is only possible via the management API that is used by the UI.
149
150### Content Model
151
152The content model is defined using only primitives, so it can be serialized into JSON. It describes what content types exist, which fields they have and how they are edited.
153
154For a list of available content models check out the [typings file](typings/models.d.ts).
155
156Currently the content model is part of the server and changes require a re-deployment/restart in order to take effect. But since the model is plain JSON it would be pretty easy to manage content types directly in the CMS and store is alongside the data.
157
158### Data Storage
159
160The data is stored in a Database. Built-In entities (like users, roles, etc.) live in a traditional relational model, whereas all content is stored as JSON in a common table. Content is immutable and each change creates a new revision. If the publish/draft system is enabled for a given content type, API clients won't see the changes until they are published (or a preview is requested).
161
162There are two materialized views (one for all published, one for the latest versions) that have indexes on the JSON data as well as a full-text index for searching.
163
164## Contributing
165
166Pull-Requests, Issues, Feedback, Coffee and positive thoughts are very welcome!
167
168If you want to work on this project locally using the development environment
169or want to know more about what we consider "internal stuff", please refer
170to the [contribution guidelines](https://github.com/cotype/core/blob/master/CONTRIBUTING.md)
171
\No newline at end of file