Skip to content

Commit

Permalink
Restructure keystone package
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Apr 4, 2019
1 parent 0a2c11b commit b4dcf44
Show file tree
Hide file tree
Showing 29 changed files with 140 additions and 51 deletions.
13 changes: 13 additions & 0 deletions .changeset/06b7f52d/changes.json
@@ -0,0 +1,13 @@
{
"releases": [
{ "name": "@keystone-alpha/api-tests", "type": "patch" },
{ "name": "@keystone-alpha/demo-project-blog", "type": "patch" },
{ "name": "@keystone-alpha/adapter-knex", "type": "patch" },
{ "name": "@keystone-alpha/adapter-mongoose", "type": "patch" },
{ "name": "@keystone-alpha/keystone", "type": "patch" },
{ "name": "@keystone-alpha/cypress-project-access-control", "type": "patch" },
{ "name": "@keystone-alpha/cypress-project-login", "type": "patch" },
{ "name": "@keystone-alpha/cypress-project-twitter-login", "type": "patch" }
],
"dependents": []
}
1 change: 1 addition & 0 deletions .changeset/06b7f52d/changes.md
@@ -0,0 +1 @@
- Use named exports from @keystone-alpha/keystone package.
63 changes: 63 additions & 0 deletions .changeset/894c5860/changes.json
@@ -0,0 +1,63 @@
{
"releases": [{ "name": "@keystone-alpha/keystone", "type": "major" }],
"dependents": [
{
"name": "@keystone-alpha/adapter-knex",
"type": "patch",
"dependencies": ["@keystone-alpha/keystone"]
},
{
"name": "@keystone-alpha/adapter-mongoose",
"type": "patch",
"dependencies": ["@keystone-alpha/keystone"]
},
{
"name": "@keystone-alpha/test-utils",
"type": "patch",
"dependencies": [
"@keystone-alpha/adapter-knex",
"@keystone-alpha/adapter-mongoose",
"@keystone-alpha/keystone"
]
},
{
"name": "@keystone-alpha/demo-project-blog",
"type": "patch",
"dependencies": ["@keystone-alpha/adapter-mongoose", "@keystone-alpha/keystone"]
},
{
"name": "@keystone-alpha/demo-project-todo",
"type": "patch",
"dependencies": ["@keystone-alpha/adapter-mongoose", "@keystone-alpha/keystone"]
},
{
"name": "@keystone-alpha/cypress-project-access-control",
"type": "patch",
"dependencies": ["@keystone-alpha/adapter-mongoose", "@keystone-alpha/keystone"]
},
{
"name": "@keystone-alpha/cypress-project-basic",
"type": "patch",
"dependencies": ["@keystone-alpha/adapter-mongoose", "@keystone-alpha/keystone"]
},
{
"name": "@keystone-alpha/cypress-project-login",
"type": "patch",
"dependencies": ["@keystone-alpha/adapter-mongoose", "@keystone-alpha/keystone"]
},
{
"name": "@keystone-alpha/cypress-project-twitter-login",
"type": "patch",
"dependencies": ["@keystone-alpha/adapter-mongoose", "@keystone-alpha/keystone"]
},
{
"name": "@keystone-alpha/api-tests",
"type": "patch",
"dependencies": [
"@keystone-alpha/adapter-mongoose",
"@keystone-alpha/test-utils",
"@keystone-alpha/keystone"
]
}
]
}
1 change: 1 addition & 0 deletions .changeset/894c5860/changes.md
@@ -0,0 +1 @@
- Make all parts of the API available as named exports.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -265,11 +265,10 @@ list used for authentication in `index.js`:

<!-- prettier-ignore -->
```javascript
const { Keystone } = require('@keystone-alpha/keystone');
const { Keystone, PasswordAuth } = require('@keystone-alpha/keystone');
const { AdminUI } = require('@keystone-alpha/admin-ui');
const { MongooseAdapter } = require('@keystone-alpha/adapter-mongoose');
const { Text, Password } = require('@keystone-alpha/fields');
const PasswordAuth = require('@keystone-alpha/keystone/auth/Password');

const keystone = new Keystone({
name: 'Keystone With Auth',
Expand Down
3 changes: 1 addition & 2 deletions api-tests/auth-header.test.js
@@ -1,8 +1,7 @@
const supertest = require('supertest-light');
const { Keystone } = require('@keystone-alpha/keystone');
const { Keystone, PasswordAuthStrategy } = require('@keystone-alpha/keystone');
const { Text, Password } = require('@keystone-alpha/fields');
const { WebServer } = require('@keystone-alpha/server');
const PasswordAuthStrategy = require('@keystone-alpha/keystone/auth/Password');
const bodyParser = require('body-parser');
const cookieSignature = require('cookie-signature');
const { multiAdapterRunners } = require('@keystone-alpha/test-utils');
Expand Down
3 changes: 1 addition & 2 deletions demo-projects/blog/index.js
@@ -1,7 +1,6 @@
//imports for Keystone app core
const { AdminUI } = require('@keystone-alpha/admin-ui');
const { Keystone } = require('@keystone-alpha/keystone');
const PasswordAuthStrategy = require('@keystone-alpha/keystone/auth/Password');
const { Keystone, PasswordAuthStrategy } = require('@keystone-alpha/keystone');
const { MongooseAdapter } = require('@keystone-alpha/adapter-mongoose');

const { staticRoute, staticPath } = require('./config');
Expand Down
2 changes: 1 addition & 1 deletion docs/discussions/authentication.md
Expand Up @@ -31,7 +31,7 @@ Here, we will setup a `PasswordAuthStrategy` instance:
```javascript
const { AdminUI } = require('@keystone-alpha/admin-ui');
const { Text, Password } = require('@keystone-alpha/fields');
const PasswordAuth = require('@keystone-alpha/keystone/auth/Password');
const { PasswordAuthStrategy } = require('@keystone-alpha/keystone');

const keystone = keystone.createList('User', {
// ...
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-knex/index.js
Expand Up @@ -4,7 +4,7 @@ const {
BaseKeystoneAdapter,
BaseListAdapter,
BaseFieldAdapter,
} = require('@keystone-alpha/keystone/adapters');
} = require('@keystone-alpha/keystone');
const {
objMerge,
flatten,
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-mongoose/index.js
Expand Up @@ -14,7 +14,7 @@ const {
BaseKeystoneAdapter,
BaseListAdapter,
BaseFieldAdapter,
} = require('@keystone-alpha/keystone/adapters');
} = require('@keystone-alpha/keystone');
const joinBuilder = require('@keystone-alpha/mongo-join-builder');
const logger = require('@keystone-alpha/logger')('mongoose');

Expand Down
16 changes: 15 additions & 1 deletion packages/keystone/index.js
@@ -1 +1,15 @@
exports.Keystone = require('./Keystone');
const Keystone = require('./lib/Keystone');
const PasswordAuthStrategy = require('./lib/auth/Password');
const TwitterAuthStrategy = require('./lib/auth/Twitter');
const { FacebookAuthStrategy } = require('./lib/auth/Facebook');
const { BaseKeystoneAdapter, BaseListAdapter, BaseFieldAdapter } = require('./lib/adapters');

module.exports = {
Keystone,
PasswordAuthStrategy,
TwitterAuthStrategy,
FacebookAuthStrategy,
BaseKeystoneAdapter,
BaseListAdapter,
BaseFieldAdapter,
};
File renamed without changes.
File renamed without changes.
Expand Up @@ -19,8 +19,6 @@ const { parseListAccess } = require('@keystone-alpha/access-control');

const logger = require('@keystone-alpha/logger');

const { Text, Checkbox, Float, Relationship } = require('@keystone-alpha/fields');

const gql = require('graphql-tag');
const graphqlLogger = logger('graphql');
const keystoneLogger = logger('keystone');
Expand Down Expand Up @@ -54,30 +52,6 @@ const labelToPath = str =>

const labelToClass = str => str.replace(/\s+/g, '');

const nativeTypeMap = new Map([
[
Boolean,
{
name: 'Boolean',
keystoneType: Checkbox,
},
],
[
String,
{
name: 'String',
keystoneType: Text,
},
],
[
Number,
{
name: 'Number',
keystoneType: Float,
},
],
]);

const opToType = {
read: 'query',
create: 'mutation',
Expand All @@ -86,6 +60,32 @@ const opToType = {
};

const mapNativeTypeToKeystoneType = (type, listKey, fieldPath) => {
const { Text, Checkbox, Float } = require('@keystone-alpha/fields');

const nativeTypeMap = new Map([
[
Boolean,
{
name: 'Boolean',
keystoneType: Checkbox,
},
],
[
String,
{
name: 'String',
keystoneType: Text,
},
],
[
Number,
{
name: 'Number',
keystoneType: Float,
},
],
]);

if (!nativeTypeMap.has(type)) {
return type;
}
Expand Down Expand Up @@ -1054,6 +1054,7 @@ module.exports = class List {
}

async _nestedMutation(mutationState, context, mutation) {
const { Relationship } = require('@keystone-alpha/fields');
// Set up a fresh mutation state if we're the root mutation
const isRootMutation = !mutationState;
if (isRootMutation) {
Expand Down
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,5 @@
const passport = require('passport');
const PassportFacebook = require('passport-facebook');
const { Text, Relationship } = require('@keystone-alpha/fields');

const FIELD_FACEBOOK_ID = 'facebookId';
const FIELD_FACEBOOK_USERNAME = 'facebookUsername';
Expand Down Expand Up @@ -30,6 +29,8 @@ class FacebookAuthStrategy {
};

if (!this.getSessionList()) {
const { Text, Relationship } = require('@keystone-alpha/fields');

// TODO: Set read permissions to be 'internal' (within keystone) only so
// it doesn't expose a graphQL endpoint, or can be read or modified by
// another user
Expand Down
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,5 @@
const passport = require('passport');
const PassportTwitter = require('passport-twitter');
const { Text, Relationship } = require('@keystone-alpha/fields');

const FIELD_TWITTER_ID = 'twitterId';
const FIELD_TWITTER_USERNAME = 'twitterUsername';
Expand Down Expand Up @@ -31,6 +30,8 @@ class TwitterAuthStrategy {
};

if (!this.getSessionList()) {
const { Text, Relationship } = require('@keystone-alpha/fields');

// TODO: Set read permissions to be 'internal' (within keystone) only so
// it doesn't expose a graphQL endpoint, or can be read or modified by
// another user
Expand Down
4 changes: 2 additions & 2 deletions packages/keystone/tests/Keystone.test.js
@@ -1,5 +1,5 @@
const Keystone = require('../Keystone');
const List = require('../List');
const Keystone = require('../lib/Keystone');
const List = require('../lib/List');
const { Text, Relationship } = require('@keystone-alpha/fields');

class MockType {
Expand Down
4 changes: 2 additions & 2 deletions packages/keystone/tests/List.test.js
Expand Up @@ -6,8 +6,8 @@ jest.doMock('@keystone-alpha/logger', () => {
return jest.fn(() => ({ warn: () => {}, log: () => {}, debug: () => {}, info: () => {} }));
});

const List = require('../List');
const { AccessDeniedError } = require('../List/graphqlErrors');
const List = require('../lib/List');
const { AccessDeniedError } = require('../lib/List/graphqlErrors');
const { Text, Checkbox, Float, Relationship } = require('@keystone-alpha/fields');
const { getType } = require('@keystone-alpha/utils');
const path = require('path');
Expand Down
Expand Up @@ -2,7 +2,7 @@ const {
mergeRelationships,
unmergeRelationships,
createRelationships,
} = require('./relationship-utils');
} = require('../lib/Keystone/relationship-utils');
const { Text, Relationship } = require('@keystone-alpha/fields');

describe('mergeRelationships', () => {
Expand Down
3 changes: 1 addition & 2 deletions test-projects/access-control/index.js
@@ -1,7 +1,6 @@
const { AdminUI } = require('@keystone-alpha/admin-ui');
const { Keystone } = require('@keystone-alpha/keystone');
const { Keystone, PasswordAuthStrategy } = require('@keystone-alpha/keystone');
const { Text, Password, Select } = require('@keystone-alpha/fields');
const PasswordAuthStrategy = require('@keystone-alpha/keystone/auth/Password');
const { objMerge } = require('@keystone-alpha/utils');
const {
getStaticListName,
Expand Down
2 changes: 1 addition & 1 deletion test-projects/facebook-login/facebook.js
@@ -1,4 +1,4 @@
const FacebookAuthStrategy = require('@keystone-alpha/keystone/auth/Facebook');
const { FacebookAuthStrategy } = require('@keystone-alpha/keystone');
const { startAuthedSession, endAuthedSession } = require('@keystone-alpha/session');

const { appURL, facebookAppKey, facebookAppSecret } = require('./config');
Expand Down
3 changes: 1 addition & 2 deletions test-projects/login/index.js
@@ -1,7 +1,6 @@
const { AdminUI } = require('@keystone-alpha/admin-ui');
const { Keystone } = require('@keystone-alpha/keystone');
const { Keystone, PasswordAuthStrategy } = require('@keystone-alpha/keystone');
const { Text, Password, Relationship } = require('@keystone-alpha/fields');
const PasswordAuthStrategy = require('@keystone-alpha/keystone/auth/Password');

const { MongooseAdapter } = require('@keystone-alpha/adapter-mongoose');

Expand Down
3 changes: 1 addition & 2 deletions test-projects/twitter-login/index.js
@@ -1,5 +1,5 @@
const { AdminUI } = require('@keystone-alpha/admin-ui');
const { Keystone } = require('@keystone-alpha/keystone');
const { Keystone, PasswordAuthStrategy } = require('@keystone-alpha/keystone');
const {
File,
Text,
Expand All @@ -9,7 +9,6 @@ const {
Password,
CloudinaryImage,
} = require('@keystone-alpha/fields');
const PasswordAuthStrategy = require('@keystone-alpha/keystone/auth/Password');
const { CloudinaryAdapter, LocalFileAdapter } = require('@keystone-alpha/file-adapters');

const { staticRoute, staticPath, cloudinary } = require('./config');
Expand Down
2 changes: 1 addition & 1 deletion test-projects/twitter-login/twitter.js
@@ -1,4 +1,4 @@
const TwitterAuthStrategy = require('@keystone-alpha/keystone/auth/Twitter');
const { TwitterAuthStrategy } = require('@keystone-alpha/keystone');
const { startAuthedSession, endAuthedSession } = require('@keystone-alpha/session');
const { appURL, twitterAppKey, twitterAppSecret } = require('./config');

Expand Down

0 comments on commit b4dcf44

Please sign in to comment.