Skip to content

Commit

Permalink
Consolidate modules
Browse files Browse the repository at this point in the history
- media to it's own folder
- various files into utils folder
- graphql-request-client into graphql folder
- rename testData -> test-data
  • Loading branch information
CobyPear committed Sep 30, 2021
1 parent e26fab2 commit ae33d33
Show file tree
Hide file tree
Showing 27 changed files with 74 additions and 45 deletions.
6 changes: 3 additions & 3 deletions packages/sitecore-jss/src/graphql/app-root-query.ts
@@ -1,6 +1,6 @@
import { GraphQLClient } from '../graphql-request-client';
import { SitecoreTemplateId } from '../constants';
import debug from '../debug';
import { GraphQLClient } from './graphql-request-client';
import { SitecoreTemplateId } from '../utils/constants';
import debug from '../utils/debug';

/** @private */
export const siteNameError = 'The site name must be a non-empty string';
Expand Down
Expand Up @@ -5,7 +5,7 @@ import spies from 'chai-spies';
import nock from 'nock';
import { GraphQLRequestClient } from './graphql-request-client';
import debugApi from 'debug';
import debug from './debug';
import debug from '../utils/debug';

use(spies);

Expand Down
@@ -1,6 +1,6 @@
import { GraphQLClient as Client, ClientError } from 'graphql-request';
import { DocumentNode } from 'graphql';
import debuggers, { Debugger } from './debug';
import debuggers, { Debugger } from '../utils/debug';

/**
* An interface for GraphQL clients for Sitecore APIs
Expand Down
6 changes: 3 additions & 3 deletions packages/sitecore-jss/src/graphql/graphql.test.ts
@@ -1,10 +1,10 @@
/* eslint-disable no-unused-expressions */
import { expect } from 'chai';
import { getAppRootId, siteNameError, languageError } from './app-root-query';
import { GraphQLRequestClient } from '../graphql-request-client';
import appRootQueryResponse from '../testData/mockAppRootQueryResponse.json';
import { GraphQLRequestClient } from './graphql-request-client';
import appRootQueryResponse from '../test-data/mockAppRootQueryResponse.json';
import nock from 'nock';
import { SitecoreTemplateId } from '../constants';
import { SitecoreTemplateId } from '../utils/constants';

// Todo: Instead of creating a GraphQLRequestClient instance, we can use the
// GraphQLClient interface. This would be a better mock. Potentially create a
Expand Down
5 changes: 5 additions & 0 deletions packages/sitecore-jss/src/graphql/index.ts
@@ -1,4 +1,9 @@
export { getAppRootId, AppRootQueryResult } from './app-root-query';
export {
GraphQLClient,
GraphQLRequestClient,
GraphQLRequestClientConfig,
} from './graphql-request-client';
export {
SearchQueryResult,
SearchQueryVariables,
Expand Down
2 changes: 1 addition & 1 deletion packages/sitecore-jss/src/graphql/search-service.ts
@@ -1,4 +1,4 @@
import { GraphQLClient } from '../graphql-request-client';
import { GraphQLClient } from './graphql-request-client';
import { DocumentNode } from 'graphql';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/sitecore-jss/src/i18n/dictionary-service.ts
@@ -1,4 +1,4 @@
import { CacheClient, CacheOptions, MemoryCacheClient } from '../cache-client';
import { CacheClient, CacheOptions, MemoryCacheClient } from '../utils/cache-client';

/**
* Object model for Sitecore dictionary phrases
Expand Down
@@ -1,11 +1,11 @@
import { expect } from 'chai';
import nock from 'nock';
import { SitecoreTemplateId } from '../constants';
import { GraphQLClient, GraphQLRequestClient } from '../graphql-request-client';
import { SitecoreTemplateId } from '../utils/constants';
import { GraphQLClient, GraphQLRequestClient } from '../graphql/graphql-request-client';
import { queryError, GraphQLDictionaryServiceConfig } from './graphql-dictionary-service';
import { GraphQLDictionaryService } from '.';
import dictionaryQueryResponse from '../testData/mockDictionaryQueryResponse.json';
import appRootQueryResponse from '../testData/mockAppRootQueryResponse.json';
import dictionaryQueryResponse from '../test-data/mockDictionaryQueryResponse.json';
import appRootQueryResponse from '../test-data/mockAppRootQueryResponse.json';

class TestService extends GraphQLDictionaryService {
public client: GraphQLClient;
Expand Down
8 changes: 4 additions & 4 deletions packages/sitecore-jss/src/i18n/graphql-dictionary-service.ts
@@ -1,9 +1,9 @@
import { GraphQLClient, GraphQLRequestClient } from '../graphql-request-client';
import { SitecoreTemplateId } from '../constants';
import { GraphQLClient, GraphQLRequestClient } from '../graphql/graphql-request-client';
import { SitecoreTemplateId } from '../utils/constants';
import { DictionaryPhrases, DictionaryServiceBase } from './dictionary-service';
import { CacheOptions } from '../cache-client';
import { CacheOptions } from '../utils/cache-client';
import { getAppRootId, SearchServiceConfig, SearchQueryService } from '../graphql';
import debug from '../debug';
import debug from '../utils/debug';

/** @private */
export const queryError =
Expand Down
Expand Up @@ -3,7 +3,7 @@ import spies from 'chai-spies';
import { RestDictionaryService, RestDictionaryServiceData } from './rest-dictionary-service';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { AxiosDataFetcher } from '../axios-fetcher';
import { AxiosDataFetcher } from '../utils/axios-fetcher';

use(spies);

Expand Down
8 changes: 4 additions & 4 deletions packages/sitecore-jss/src/i18n/rest-dictionary-service.ts
@@ -1,8 +1,8 @@
import { AxiosDataFetcher } from '../axios-fetcher';
import { HttpDataFetcher, fetchData } from '../data-fetcher';
import { AxiosDataFetcher } from '../utils/axios-fetcher';
import { HttpDataFetcher, fetchData } from '../utils/data-fetcher';
import { DictionaryPhrases, DictionaryServiceBase } from './dictionary-service';
import { CacheOptions } from '../cache-client';
import debug from '../debug';
import { CacheOptions } from '../utils/cache-client';
import debug from '../utils/debug';

/**
* A reply from the REST Sitecore Dictionary Service
Expand Down
38 changes: 24 additions & 14 deletions packages/sitecore-jss/src/index.ts
@@ -1,27 +1,19 @@
// NOTE: all imports are now named as to not make breaking changes
// and to keep react-native working with cjs modules.
// This will very likely change again when sub-modules are added.

import * as mediaApi from './media-api';
import * as constants from './constants';

export { mediaApi, constants };
export { default as debug, Debugger } from './debug';
export { HttpDataFetcher, HttpResponse, fetchData } from './data-fetcher';
export {
GraphQLClient,
GraphQLRequestClient,
GraphQLRequestClientConfig,
} from './graphql-request-client';
export { AxiosDataFetcher, AxiosDataFetcherConfig } from './axios-fetcher';
export {
AppRootQueryResult,
SearchQueryResult,
SearchQueryService,
SearchQueryVariables,
SearchServiceConfig,
getAppRootId,
// grapql-request-client
GraphQLClient,
GraphQLRequestClient,
GraphQLRequestClientConfig,
} from './graphql';

export {
ExperienceEditor,
HorizonEditor,
Expand All @@ -31,9 +23,27 @@ export {
resetEditorChromes,
resetExperienceEditorChromes,
resolveUrl,
// debug
debug,
Debugger,
// axios-fetcher
AxiosDataFetcher,
AxiosDataFetcherConfig,
// cache-client
CacheClient,
CacheOptions,
MemoryCacheClient,
// data-fetcher
HttpDataFetcher,
HttpResponse,
fetchData,
// constants
constants,
} from './utils';
export { CacheClient, CacheOptions, MemoryCacheClient } from './cache-client';

export { mediaApi } from './media';

// dictionary-service (i18n)
export {
DictionaryPhrases,
DictionaryService,
Expand Down
4 changes: 2 additions & 2 deletions packages/sitecore-jss/src/layout/graphql-layout-service.ts
@@ -1,7 +1,7 @@
import { LayoutServiceBase } from './layout-service';
import { LayoutServiceData } from './models';
import { GraphQLClient, GraphQLRequestClient } from '../graphql-request-client';
import debug from '../debug';
import { GraphQLClient, GraphQLRequestClient } from '../graphql/graphql-request-client';
import debug from '../utils/debug';

export type GraphQLLayoutServiceConfig = {
/**
Expand Down
Expand Up @@ -4,7 +4,7 @@ import spies from 'chai-spies';
import { IncomingMessage, ServerResponse } from 'http';
import axios, { AxiosRequestConfig } from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { AxiosDataFetcher } from '../axios-fetcher';
import { AxiosDataFetcher } from '../utils/axios-fetcher';
import { RestLayoutService } from './rest-layout-service';
import { LayoutServiceData, PlaceholderData } from './models';

Expand Down
6 changes: 3 additions & 3 deletions packages/sitecore-jss/src/layout/rest-layout-service.ts
Expand Up @@ -2,9 +2,9 @@ import { AxiosRequestConfig, AxiosResponse } from 'axios';
import { IncomingMessage, ServerResponse } from 'http';
import { LayoutServiceBase } from './layout-service';
import { PlaceholderData, LayoutServiceData } from './models';
import { AxiosDataFetcher, AxiosDataFetcherConfig } from '../axios-fetcher';
import { HttpDataFetcher, fetchData } from '../data-fetcher';
import debug from '../debug';
import { AxiosDataFetcher, AxiosDataFetcherConfig } from '../utils/axios-fetcher';
import { HttpDataFetcher, fetchData } from '../utils/data-fetcher';
import debug from '../utils/debug';

interface FetchParams {
[param: string]: string | number | boolean;
Expand Down
3 changes: 3 additions & 0 deletions packages/sitecore-jss/src/media/index.ts
@@ -0,0 +1,3 @@
import * as mediaApi from './media-api';

export { mediaApi };
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
import resolveUrl from './utils/resolve-url';
import resolveUrl from './resolve-url';
import { ParsedUrlQueryInput } from 'querystring';

/**
Expand Down
@@ -1,5 +1,5 @@
import debug from 'debug';
import isServer from './utils/is-server';
import isServer from './is-server';

const rootNamespace = 'sitecore-jss';

Expand Down
11 changes: 11 additions & 0 deletions packages/sitecore-jss/src/utils/index.ts
@@ -1,6 +1,17 @@
import isServer from './is-server';
import resolveUrl from './resolve-url';
import * as constants from './constants';
import { default as debug, Debugger } from './debug';
import { AxiosDataFetcher, AxiosDataFetcherConfig } from './axios-fetcher';
import { HttpDataFetcher, HttpResponse, fetchData } from './data-fetcher';
import { CacheClient, CacheOptions, MemoryCacheClient } from './cache-client';

export { constants };
export { debug, Debugger };
export { isServer, resolveUrl };
export { AxiosDataFetcher, AxiosDataFetcherConfig };
export { HttpDataFetcher, HttpResponse, fetchData };
export { CacheClient, CacheOptions, MemoryCacheClient };
export {
ExperienceEditor,
HorizonEditor,
Expand Down

0 comments on commit ae33d33

Please sign in to comment.