create-keystone-app 0.0.0-rc-20250210004303

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Thinkmill Labs Pty Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # create-keystone-app
2
+
3
+ <br>
4
+ <p>Keystone helps you build faster and scale further than any other CMS or App Framework. Describe your schema, and get a powerful GraphQL API & beautiful Management UI for your content and data.</p>
5
+ <p>No boilerplate or bootstrapping – just elegant APIs to help you ship the code that matters without sacrificing the flexibility or power of a bespoke back-end.
6
+ </p>
7
+
8
+ For help with this package join the conversation in [Slack](https://community.keystonejs.com/), or on [GitHub](https://github.com/keystonejs/keystone/).
9
+
10
+ Visit <https://keystonejs.com/> for docs, and [follow @keystonejs on Twitter](https://twitter.com/keystonejs) for the latest updates.
package/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './dist/create-keystone-app.esm.js'
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLWtleXN0b25lLWFwcC5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs/promises');
4
+ var path = require('node:path');
5
+ var node_url = require('node:url');
6
+ var c = require('chalk');
7
+ var enquirer = require('enquirer');
8
+ var execa = require('execa');
9
+ var getPackageJson = require('package-json');
10
+ var meow = require('meow');
11
+ var ora = require('ora');
12
+
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
+
15
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
16
+ var path__default = /*#__PURE__*/_interopDefault(path);
17
+ var c__default = /*#__PURE__*/_interopDefault(c);
18
+ var enquirer__default = /*#__PURE__*/_interopDefault(enquirer);
19
+ var execa__default = /*#__PURE__*/_interopDefault(execa);
20
+ var getPackageJson__default = /*#__PURE__*/_interopDefault(getPackageJson);
21
+ var meow__default = /*#__PURE__*/_interopDefault(meow);
22
+ var ora__default = /*#__PURE__*/_interopDefault(ora);
23
+
24
+ var thisPackage = {
25
+ name: "create-keystone-app",
26
+ version: "0.0.0-rc-20250210004303",
27
+ license: "MIT",
28
+ type: "module",
29
+ main: "dist/create-keystone-app.cjs.js",
30
+ module: "dist/create-keystone-app.esm.js",
31
+ repository: "https://github.com/keystonejs/keystone/tree/main/packages/create",
32
+ bin: "./cli.js",
33
+ exports: {
34
+ ".": {
35
+ types: "./dist/create-keystone-app.cjs.js",
36
+ module: "./dist/create-keystone-app.esm.js",
37
+ "default": "./dist/create-keystone-app.cjs.js"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ preconstruct: {
42
+ entrypoints: [
43
+ "index.ts"
44
+ ]
45
+ },
46
+ dependencies: {
47
+ chalk: "^4.1.2",
48
+ enquirer: "^2.4.1",
49
+ execa: "^5.1.1",
50
+ meow: "^9.0.0",
51
+ ora: "^8.0.1",
52
+ "package-json": "^10.0.0"
53
+ },
54
+ files: [
55
+ "dist",
56
+ "starter",
57
+ "cli.js"
58
+ ]
59
+ };
60
+
61
+ async function checkVersion() {
62
+ const {
63
+ version: upstream
64
+ } = await getPackageJson__default["default"]('create-keystone-app');
65
+ if (upstream === thisPackage.version) return;
66
+ console.error(`⚠️ You're running an old version of create-keystone-app, please update to ${upstream}`);
67
+ }
68
+ class UserError extends Error {}
69
+ const __dirname$1 = path__default["default"].dirname(node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || new URL('dist/create-keystone-app.cjs.js', document.baseURI).href))));
70
+ const starterDir = path__default["default"].normalize(`${__dirname$1}/../starter`);
71
+ const cli = meow__default["default"](`
72
+ Usage
73
+ $ create-keystone-app [directory]
74
+ `);
75
+ async function normalizeArgs() {
76
+ let directory = cli.input[0];
77
+ if (!directory) {
78
+ ({
79
+ directory
80
+ } = await enquirer__default["default"].prompt({
81
+ type: 'input',
82
+ name: 'directory',
83
+ message: 'What directory should create-keystone-app generate your app into?',
84
+ validate: x => !!x
85
+ }));
86
+ process.stdout.write('\n');
87
+ }
88
+ return {
89
+ directory: path__default["default"].resolve(directory)
90
+ };
91
+ }
92
+ (async (_process$env$npm_conf, _process$env$npm_conf2) => {
93
+ process.stdout.write('\n');
94
+ console.log(`✨ You're about to generate a project using ${c__default["default"].bold('Keystone 6')} packages.`);
95
+ await checkVersion();
96
+ const normalizedArgs = await normalizeArgs();
97
+ const nextCwd = normalizedArgs.directory;
98
+ await fs__default["default"].mkdir(nextCwd);
99
+ await Promise.all(['_gitignore', 'schema.ts', 'package.json', 'tsconfig.json', 'keystone.ts', 'auth.ts', 'README.md'].map(filename => fs__default["default"].copyFile(path__default["default"].join(starterDir, filename), path__default["default"].join(normalizedArgs.directory, filename.replace(/^_/, '.')))));
100
+ const [packageManager] = (_process$env$npm_conf = (_process$env$npm_conf2 = process.env.npm_config_user_agent) === null || _process$env$npm_conf2 === void 0 ? void 0 : _process$env$npm_conf2.split('/', 1)) !== null && _process$env$npm_conf !== void 0 ? _process$env$npm_conf : ['npm'];
101
+ const spinner = ora__default["default"](`Installing dependencies with ${packageManager}. This may take a few minutes.`).start();
102
+ try {
103
+ await execa__default["default"](packageManager, ['install'], {
104
+ cwd: nextCwd
105
+ });
106
+ spinner.succeed(`Installed dependencies with ${packageManager}.`);
107
+ } catch (err) {
108
+ spinner.fail(`Failed to install with ${packageManager}.`);
109
+ throw err;
110
+ }
111
+ const relativeProjectDir = path__default["default"].relative(process.cwd(), normalizedArgs.directory);
112
+ process.stdout.write('\n');
113
+ console.log(`🎉 Keystone created a starter project in: ${c__default["default"].bold(relativeProjectDir)}
114
+
115
+ ${c__default["default"].bold('To launch your app, run:')}
116
+
117
+ - cd ${relativeProjectDir}
118
+ - ${packageManager} run dev
119
+
120
+ ${c__default["default"].bold('Next steps:')}
121
+
122
+ - Read ${c__default["default"].bold(`${relativeProjectDir}${path__default["default"].sep}README.md`)} for additional getting started details.
123
+ - Edit ${c__default["default"].bold(`${relativeProjectDir}${path__default["default"].sep}keystone.ts`)} to customize your app.
124
+ - Star Keystone on GitHub (https://github.com/keystonejs/keystone)
125
+ `);
126
+ })().catch(err => {
127
+ if (err instanceof UserError) {
128
+ console.error(err.message);
129
+ } else {
130
+ console.error(err);
131
+ }
132
+ process.exit(1);
133
+ });
@@ -0,0 +1,120 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import c from 'chalk';
5
+ import enquirer from 'enquirer';
6
+ import execa from 'execa';
7
+ import getPackageJson from 'package-json';
8
+ import meow from 'meow';
9
+ import ora from 'ora';
10
+
11
+ var thisPackage = {
12
+ name: "create-keystone-app",
13
+ version: "0.0.0-rc-20250210004303",
14
+ license: "MIT",
15
+ type: "module",
16
+ main: "dist/create-keystone-app.cjs.js",
17
+ module: "dist/create-keystone-app.esm.js",
18
+ repository: "https://github.com/keystonejs/keystone/tree/main/packages/create",
19
+ bin: "./cli.js",
20
+ exports: {
21
+ ".": {
22
+ types: "./dist/create-keystone-app.cjs.js",
23
+ module: "./dist/create-keystone-app.esm.js",
24
+ "default": "./dist/create-keystone-app.cjs.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ preconstruct: {
29
+ entrypoints: [
30
+ "index.ts"
31
+ ]
32
+ },
33
+ dependencies: {
34
+ chalk: "^4.1.2",
35
+ enquirer: "^2.4.1",
36
+ execa: "^5.1.1",
37
+ meow: "^9.0.0",
38
+ ora: "^8.0.1",
39
+ "package-json": "^10.0.0"
40
+ },
41
+ files: [
42
+ "dist",
43
+ "starter",
44
+ "cli.js"
45
+ ]
46
+ };
47
+
48
+ async function checkVersion() {
49
+ const {
50
+ version: upstream
51
+ } = await getPackageJson('create-keystone-app');
52
+ if (upstream === thisPackage.version) return;
53
+ console.error(`⚠️ You're running an old version of create-keystone-app, please update to ${upstream}`);
54
+ }
55
+ class UserError extends Error {}
56
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
57
+ const starterDir = path.normalize(`${__dirname}/../starter`);
58
+ const cli = meow(`
59
+ Usage
60
+ $ create-keystone-app [directory]
61
+ `);
62
+ async function normalizeArgs() {
63
+ let directory = cli.input[0];
64
+ if (!directory) {
65
+ ({
66
+ directory
67
+ } = await enquirer.prompt({
68
+ type: 'input',
69
+ name: 'directory',
70
+ message: 'What directory should create-keystone-app generate your app into?',
71
+ validate: x => !!x
72
+ }));
73
+ process.stdout.write('\n');
74
+ }
75
+ return {
76
+ directory: path.resolve(directory)
77
+ };
78
+ }
79
+ (async (_process$env$npm_conf, _process$env$npm_conf2) => {
80
+ process.stdout.write('\n');
81
+ console.log(`✨ You're about to generate a project using ${c.bold('Keystone 6')} packages.`);
82
+ await checkVersion();
83
+ const normalizedArgs = await normalizeArgs();
84
+ const nextCwd = normalizedArgs.directory;
85
+ await fs.mkdir(nextCwd);
86
+ await Promise.all(['_gitignore', 'schema.ts', 'package.json', 'tsconfig.json', 'keystone.ts', 'auth.ts', 'README.md'].map(filename => fs.copyFile(path.join(starterDir, filename), path.join(normalizedArgs.directory, filename.replace(/^_/, '.')))));
87
+ const [packageManager] = (_process$env$npm_conf = (_process$env$npm_conf2 = process.env.npm_config_user_agent) === null || _process$env$npm_conf2 === void 0 ? void 0 : _process$env$npm_conf2.split('/', 1)) !== null && _process$env$npm_conf !== void 0 ? _process$env$npm_conf : ['npm'];
88
+ const spinner = ora(`Installing dependencies with ${packageManager}. This may take a few minutes.`).start();
89
+ try {
90
+ await execa(packageManager, ['install'], {
91
+ cwd: nextCwd
92
+ });
93
+ spinner.succeed(`Installed dependencies with ${packageManager}.`);
94
+ } catch (err) {
95
+ spinner.fail(`Failed to install with ${packageManager}.`);
96
+ throw err;
97
+ }
98
+ const relativeProjectDir = path.relative(process.cwd(), normalizedArgs.directory);
99
+ process.stdout.write('\n');
100
+ console.log(`🎉 Keystone created a starter project in: ${c.bold(relativeProjectDir)}
101
+
102
+ ${c.bold('To launch your app, run:')}
103
+
104
+ - cd ${relativeProjectDir}
105
+ - ${packageManager} run dev
106
+
107
+ ${c.bold('Next steps:')}
108
+
109
+ - Read ${c.bold(`${relativeProjectDir}${path.sep}README.md`)} for additional getting started details.
110
+ - Edit ${c.bold(`${relativeProjectDir}${path.sep}keystone.ts`)} to customize your app.
111
+ - Star Keystone on GitHub (https://github.com/keystonejs/keystone)
112
+ `);
113
+ })().catch(err => {
114
+ if (err instanceof UserError) {
115
+ console.error(err.message);
116
+ } else {
117
+ console.error(err);
118
+ }
119
+ process.exit(1);
120
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "create-keystone-app",
3
+ "version": "0.0.0-rc-20250210004303",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "dist/create-keystone-app.cjs.js",
7
+ "module": "dist/create-keystone-app.esm.js",
8
+ "repository": "https://github.com/keystonejs/keystone/tree/main/packages/create",
9
+ "bin": "./cli.js",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/create-keystone-app.cjs.js",
13
+ "module": "./dist/create-keystone-app.esm.js",
14
+ "default": "./dist/create-keystone-app.cjs.js"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "preconstruct": {
19
+ "entrypoints": [
20
+ "index.ts"
21
+ ]
22
+ },
23
+ "dependencies": {
24
+ "chalk": "^4.1.2",
25
+ "enquirer": "^2.4.1",
26
+ "execa": "^5.1.1",
27
+ "meow": "^9.0.0",
28
+ "ora": "^8.0.1",
29
+ "package-json": "^10.0.0"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "starter",
34
+ "cli.js"
35
+ ]
36
+ }
@@ -0,0 +1,52 @@
1
+ # Keystone Project Starter
2
+
3
+ Welcome to Keystone!
4
+
5
+ Run
6
+
7
+ ```
8
+ npm run dev
9
+ ```
10
+
11
+ To view the config for your new app, look at [./keystone.ts](./keystone.ts)
12
+
13
+ This project starter is designed to give you a sense of the power Keystone can offer you, and show off some of its main features. It's also a pretty simple setup if you want to build out from it.
14
+
15
+ We recommend you use this alongside our [getting started walkthrough](https://keystonejs.com/docs/walkthroughs/getting-started-with-create-keystone-app) which will walk you through what you get as part of this starter.
16
+
17
+ If you want an overview of all the features Keystone offers, check out our [features](https://keystonejs.com/why-keystone#features) page.
18
+
19
+ ## Some Quick Notes On Getting Started
20
+
21
+ ### Changing the database
22
+
23
+ We've set you up with an [SQLite database](https://keystonejs.com/docs/apis/config#sqlite) for ease-of-use. If you're wanting to use PostgreSQL, you can!
24
+
25
+ Just change the `db` property on line 16 of the Keystone file [./keystone.ts](./keystone.ts) to
26
+
27
+ ```typescript
28
+ db: {
29
+ provider: 'postgresql',
30
+ url: process.env.DATABASE_URL || 'DATABASE_URL_TO_REPLACE',
31
+ }
32
+ ```
33
+
34
+ And provide your database url from PostgreSQL.
35
+
36
+ For more on database configuration, check out or [DB API Docs](https://keystonejs.com/docs/apis/config#db)
37
+
38
+ ### Auth
39
+
40
+ We've put auth into its own file to make this humble starter easier to navigate. To explore it without auth turned on, comment out the `isAccessAllowed` on line 21 of the Keystone file [./keystone.ts](./keystone.ts).
41
+
42
+ For more on auth, check out our [Authentication API Docs](https://keystonejs.com/docs/apis/auth#authentication-api)
43
+
44
+ ### Adding a frontend
45
+
46
+ As a Headless CMS, Keystone can be used with any frontend that uses GraphQL. It provides a GraphQL endpoint you can write queries against at `/api/graphql` (by default [http://localhost:3000/api/graphql](http://localhost:3000/api/graphql)). At Thinkmill, we tend to use [Next.js](https://nextjs.org/) and [Apollo GraphQL](https://www.apollographql.com/docs/react/get-started/) as our frontend and way to write queries, but if you have your own favourite, feel free to use it.
47
+
48
+ A walkthrough on how to do this is forthcoming, but in the meantime our [todo example](https://github.com/keystonejs/keystone-react-todo-demo) shows a Keystone set up with a frontend. For a more full example, you can also look at an example app we built for [Prisma Day 2021](https://github.com/keystonejs/prisma-day-2021-workshop)
49
+
50
+ ### Embedding Keystone in a Next.js frontend
51
+
52
+ While Keystone works as a standalone app, you can embed your Keystone app into a [Next.js](https://nextjs.org/) app. This is quite a different setup to the starter, and we recommend checking out our walkthrough for that [here](https://keystonejs.com/docs/walkthroughs/embedded-mode-with-sqlite-nextjs#how-to-embed-keystone-sq-lite-in-a-next-js-app).
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ .keystone/
3
+ keystone.db
4
+ *.log
@@ -0,0 +1,59 @@
1
+ // Welcome to some authentication for Keystone
2
+ //
3
+ // This is using @keystone-6/auth to add the following
4
+ // - A sign-in page for your Admin UI
5
+ // - A cookie-based stateless session strategy
6
+ // - Using a User email as the identifier
7
+ // - 30 day cookie expiration
8
+ //
9
+ // This file does not configure what Users can do, and the default for this starter
10
+ // project is to allow anyone - logged-in or not - to do anything.
11
+ //
12
+ // If you want to prevent random people on the internet from accessing your data,
13
+ // you can find out how by reading https://keystonejs.com/docs/guides/auth-and-access-control
14
+ //
15
+ // If you want to learn more about how our out-of-the-box authentication works, please
16
+ // read https://keystonejs.com/docs/apis/auth#authentication-api
17
+
18
+ import { randomBytes } from 'node:crypto'
19
+ import { createAuth } from '@keystone-6/auth'
20
+
21
+ // see https://keystonejs.com/docs/apis/session for the session docs
22
+ import { statelessSessions } from '@keystone-6/core/session'
23
+
24
+ // withAuth is a function we can use to wrap our base configuration
25
+ const { withAuth } = createAuth({
26
+ listKey: 'User',
27
+ identityField: 'email',
28
+
29
+ // this is a GraphQL query fragment for fetching what data will be attached to a context.session
30
+ // this can be helpful for when you are writing your access control functions
31
+ // you can find out more at https://keystonejs.com/docs/guides/auth-and-access-control
32
+ sessionData: 'name createdAt',
33
+ secretField: 'password',
34
+
35
+ // WARNING: remove initFirstItem functionality in production
36
+ // see https://keystonejs.com/docs/config/auth#init-first-item for more
37
+ initFirstItem: {
38
+ // if there are no items in the database, by configuring this field
39
+ // you are asking the Keystone AdminUI to create a new user
40
+ // providing inputs for these fields
41
+ fields: ['name', 'email', 'password'],
42
+
43
+ // it uses context.sudo() to do this, which bypasses any access control you might have
44
+ // you shouldn't use this in production
45
+ },
46
+ })
47
+
48
+ // statelessSessions uses cookies for session tracking
49
+ // these cookies have an expiry, in seconds
50
+ // we use an expiry of 30 days for this starter
51
+ const sessionMaxAge = 60 * 60 * 24 * 30
52
+
53
+ // you can find out more at https://keystonejs.com/docs/apis/session#session-api
54
+ const session = statelessSessions({
55
+ maxAge: sessionMaxAge,
56
+ secret: process.env.SESSION_SECRET,
57
+ })
58
+
59
+ export { withAuth, session }
@@ -0,0 +1,29 @@
1
+ // Welcome to Keystone!
2
+ //
3
+ // This file is what Keystone uses as the entry-point to your headless backend
4
+ //
5
+ // Keystone imports the default export of this file, expecting a Keystone configuration object
6
+ // you can find out more at https://keystonejs.com/docs/apis/config
7
+
8
+ import { config } from '@keystone-6/core'
9
+
10
+ // to keep this file tidy, we define our schema in a different file
11
+ import { lists } from './schema'
12
+
13
+ // authentication is configured separately here too, but you might move this elsewhere
14
+ // when you write your list-level access control functions, as they typically rely on session data
15
+ import { withAuth, session } from './auth'
16
+
17
+ export default withAuth(
18
+ config({
19
+ db: {
20
+ // we're using sqlite for the fastest startup experience
21
+ // for more information on what database might be appropriate for you
22
+ // see https://keystonejs.com/docs/guides/choosing-a-database#title
23
+ provider: 'sqlite',
24
+ url: 'file:./keystone.db',
25
+ },
26
+ lists,
27
+ session,
28
+ })
29
+ )
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "keystone-app",
3
+ "version": "1.0.3",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "keystone dev",
7
+ "start": "keystone start",
8
+ "build": "keystone build"
9
+ },
10
+ "dependencies": {
11
+ "@keystone-6/auth": "^8.0.0",
12
+ "@keystone-6/core": "^6.0.0",
13
+ "@keystone-6/fields-document": "^9.0.0",
14
+ "typescript": "^5.5.0"
15
+ }
16
+ }
@@ -0,0 +1,150 @@
1
+ // Welcome to your schema
2
+ // Schema driven development is Keystone's modus operandi
3
+ //
4
+ // This file is where we define the lists, fields and hooks for our data.
5
+ // If you want to learn more about how lists are configured, please read
6
+ // - https://keystonejs.com/docs/config/lists
7
+
8
+ import { list } from '@keystone-6/core'
9
+ import { allowAll } from '@keystone-6/core/access'
10
+
11
+ // see https://keystonejs.com/docs/fields/overview for the full list of fields
12
+ // this is a few common fields for an example
13
+ import {
14
+ text,
15
+ relationship,
16
+ password,
17
+ timestamp,
18
+ select,
19
+ } from '@keystone-6/core/fields'
20
+
21
+ // the document field is a more complicated field, so it has it's own package
22
+ import { document } from '@keystone-6/fields-document'
23
+ // if you want to make your own fields, see https://keystonejs.com/docs/guides/custom-fields
24
+
25
+ // when using Typescript, you can refine your types to a stricter subset by importing
26
+ // the generated types from '.keystone/types'
27
+ import { type Lists } from '.keystone/types'
28
+
29
+ export const lists = {
30
+ User: list({
31
+ // WARNING
32
+ // for this starter project, anyone can create, query, update and delete anything
33
+ // if you want to prevent random people on the internet from accessing your data,
34
+ // you can find out more at https://keystonejs.com/docs/guides/auth-and-access-control
35
+ access: allowAll,
36
+
37
+ // this is the fields for our User list
38
+ fields: {
39
+ // by adding isRequired, we enforce that every User should have a name
40
+ // if no name is provided, an error will be displayed
41
+ name: text({ validation: { isRequired: true } }),
42
+
43
+ email: text({
44
+ validation: { isRequired: true },
45
+ // by adding isIndexed: 'unique', we're saying that no user can have the same
46
+ // email as another user - this may or may not be a good idea for your project
47
+ isIndexed: 'unique',
48
+ }),
49
+
50
+ password: password({ validation: { isRequired: true } }),
51
+
52
+ // we can use this field to see what Posts this User has authored
53
+ // more on that in the Post list below
54
+ posts: relationship({ ref: 'Post.author', many: true }),
55
+
56
+ createdAt: timestamp({
57
+ // this sets the timestamp to Date.now() when the user is first created
58
+ defaultValue: { kind: 'now' },
59
+ }),
60
+ },
61
+ }),
62
+
63
+ Post: list({
64
+ // WARNING
65
+ // for this starter project, anyone can create, query, update and delete anything
66
+ // if you want to prevent random people on the internet from accessing your data,
67
+ // you can find out more at https://keystonejs.com/docs/guides/auth-and-access-control
68
+ access: allowAll,
69
+
70
+ // this is the fields for our Post list
71
+ fields: {
72
+ title: text({ validation: { isRequired: true } }),
73
+
74
+ // the document field can be used for making rich editable content
75
+ // you can find out more at https://keystonejs.com/docs/guides/document-fields
76
+ content: document({
77
+ formatting: true,
78
+ layouts: [
79
+ [1, 1],
80
+ [1, 1, 1],
81
+ [2, 1],
82
+ [1, 2],
83
+ [1, 2, 1],
84
+ ],
85
+ links: true,
86
+ dividers: true,
87
+ }),
88
+
89
+ // with this field, you can set a User as the author for a Post
90
+ author: relationship({
91
+ // we could have used 'User', but then the relationship would only be 1-way
92
+ ref: 'User.posts',
93
+
94
+ // this is some customisations for changing how this will look in the AdminUI
95
+ ui: {
96
+ displayMode: 'cards',
97
+ cardFields: ['name', 'email'],
98
+ inlineEdit: { fields: ['name', 'email'] },
99
+ linkToItem: true,
100
+ inlineConnect: true,
101
+ },
102
+
103
+ // a Post can only have one author
104
+ // this is the default, but we show it here for verbosity
105
+ many: false,
106
+ }),
107
+
108
+ // with this field, you can add some Tags to Posts
109
+ tags: relationship({
110
+ // we could have used 'Tag', but then the relationship would only be 1-way
111
+ ref: 'Tag.posts',
112
+
113
+ // a Post can have many Tags, not just one
114
+ many: true,
115
+
116
+ // this is some customisations for changing how this will look in the AdminUI
117
+ ui: {
118
+ displayMode: 'cards',
119
+ cardFields: ['name'],
120
+ inlineEdit: { fields: ['name'] },
121
+ linkToItem: true,
122
+ inlineConnect: true,
123
+ inlineCreate: { fields: ['name'] },
124
+ },
125
+ }),
126
+ },
127
+ }),
128
+
129
+ // this last list is our Tag list, it only has a name field for now
130
+ Tag: list({
131
+ // WARNING
132
+ // for this starter project, anyone can create, query, update and delete anything
133
+ //
134
+ // if you want to prevent random people on the internet from accessing your data,
135
+ // you can find out more at https://keystonejs.com/docs/guides/auth-and-access-control
136
+ access: allowAll,
137
+
138
+ // dont show this list in the AdminUI
139
+ ui: {
140
+ hideNavigation: true,
141
+ },
142
+
143
+ // this is the fields for our Tag list
144
+ fields: {
145
+ name: text(),
146
+ // this can be helpful to find out all the Posts associated with a Tag
147
+ posts: relationship({ ref: 'Post.tags', many: true }),
148
+ },
149
+ }),
150
+ } satisfies Lists
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "commonjs",
5
+ "strict": true,
6
+ "noEmit": true,
7
+ "esModuleInterop": true,
8
+ "forceConsistentCasingInFileNames": true
9
+ }
10
+ }