@enonic-types/guillotine 0.0.1 → 7.1.0-B1

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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Guillotine types
2
2
 
3
- ## Use
3
+ Type definitions for [Guillotine](https://market.enonic.com/vendors/enonic/guillotine) - augmentable GraphQL Content API for Enonic XP.
4
+
5
+ ## Usage
4
6
 
5
7
  ```ts
6
8
  import type {GraphQL, Extensions} from '@enonic-types/guillotine';
@@ -14,44 +16,44 @@ const MY_FIELD_NAME = 'myField';
14
16
 
15
17
 
16
18
  export const extensions = (graphQL: GraphQL): Extensions => {
17
- return {
18
- types: {
19
- [MY_OBJECT_TYPE_NAME]: {
20
- description: 'Description for my object type',
21
- fields: {
22
- myString: {
23
- type: graphQL.nonNull(graphQL.GraphQLString),
24
- }
25
- }
26
- }
27
- },
28
- creationCallbacks: {
29
- [ObjectTypeName.Content]: (params) => {
30
- params.addFields({
31
- [MY_FIELD_NAME]: {
32
- type: graphQL.reference(MY_OBJECT_TYPE_NAME) // nullable
33
- }
34
- });
35
- }
36
- },
37
- resolvers: {
38
- [ObjectTypeName.Content]: {
39
- [MY_FIELD_NAME]: () => {
40
- const {
41
- // args,
42
- // localContext,
43
- source: content
44
- } = env;
45
- if (content.type === 'portal:fragment') {
46
- return null;
47
- }
48
- return {
49
- myString: 'Hello, World!'
50
- }
51
- },
52
- }
53
- }
54
- }
19
+ return {
20
+ types: {
21
+ [MY_OBJECT_TYPE_NAME]: {
22
+ description: 'Description for my object type',
23
+ fields: {
24
+ myString: {
25
+ type: graphQL.nonNull(graphQL.GraphQLString),
26
+ }
27
+ }
28
+ }
29
+ },
30
+ creationCallbacks: {
31
+ [ObjectTypeName.Content]: (params) => {
32
+ params.addFields({
33
+ [MY_FIELD_NAME]: {
34
+ type: graphQL.reference(MY_OBJECT_TYPE_NAME)
35
+ }
36
+ });
37
+ }
38
+ },
39
+ resolvers: {
40
+ [ObjectTypeName.Content]: {
41
+ [MY_FIELD_NAME]: () => {
42
+ const {
43
+ // args,
44
+ // localContext,
45
+ source: content
46
+ } = env;
47
+ if (content.type === 'portal:fragment') {
48
+ return null;
49
+ }
50
+ return {
51
+ myString: 'Hello, World!'
52
+ }
53
+ },
54
+ }
55
+ }
56
+ }
55
57
  };
56
58
 
57
59
  ```
package/advanced.ts CHANGED
@@ -121,7 +121,9 @@ export type {
121
121
  } from './guillotine'
122
122
 
123
123
  export type {
124
+ BaseFolderContent,
124
125
  MediaImageContent,
126
+ PortalSiteContent,
125
127
  } from './xp'
126
128
 
127
129
 
@@ -6,20 +6,22 @@ import type {LocalContext} from '../graphQL/LocalContext'
6
6
 
7
7
 
8
8
  export declare interface DataFetchingEnvironment<
9
- Args extends Record<string, any> = Record<string, any>,
10
- Source extends unknown = unknown,
9
+ ARGS extends Record<string, any> = Record<string, any>,
10
+ LOCAL_CONTEXT extends LocalContextRecord = LocalContextRecord,
11
+ SOURCE extends unknown = unknown,
11
12
  > {
12
- args: Args
13
- localContext: LocalContext
14
- source: Source
13
+ args: ARGS
14
+ localContext: LocalContext<LOCAL_CONTEXT>
15
+ source: SOURCE
15
16
  }
16
17
 
17
18
  export declare interface Resolver<
18
- Args extends Record<string, any> = Record<string, any>,
19
- Source extends unknown = unknown,
20
- Return = any
19
+ ARGS extends Record<string, any> = Record<string, any>,
20
+ LOCAL_CONTEXT extends LocalContextRecord = LocalContextRecord,
21
+ SOURCE extends unknown = unknown,
22
+ RETURN_TYPE = any
21
23
  > {
22
- (env: DataFetchingEnvironment<Args,Source>): Return
24
+ (env: DataFetchingEnvironment<ARGS,LOCAL_CONTEXT,SOURCE>): RETURN_TYPE
23
25
  }
24
26
 
25
27
  export declare type Resolvers = PartialRecord<
@@ -8,16 +8,47 @@ import type {
8
8
  } from './LocalContext'
9
9
 
10
10
 
11
+ // https://developer.enonic.com/docs/guillotine/stable/extending/resolvers#createdatafetcherresult
12
+ //
13
+ // If parentLocalContext is not provided, then localContext will override
14
+ // parentLocalContext.
15
+ //
16
+ // Otherwise, localContext will be merged with parentLocalContext and
17
+ // localContext will override parentLocalContext if they have the same keys.
18
+ //
19
+ // If localContext is not provided, then parentLocalContext will be used as
20
+ // localContext.
21
+
22
+
11
23
  export declare interface CreateDataFetcherResultParams<
12
- In extends LocalContextRecord = LocalContext,
13
- Out extends LocalContextRecord = LocalContext
24
+ DATA extends any,
25
+ LOCAL_CONTEXT extends LocalContextRecord = LocalContext,
26
+ PARENT_LOCAL_CONTEXT extends LocalContextRecord = LocalContext
14
27
  > {
15
28
  data: ScriptValue // NOTE: ScriptValue type is expected to exist in global scope
16
- localContext?: LocalContext<Out>
17
- parentLocalContext?: LocalContext<In>
29
+ localContext?: LocalContext<LOCAL_CONTEXT>
30
+ parentLocalContext?: LocalContext<PARENT_LOCAL_CONTEXT>
31
+ }
32
+
33
+ // NOTE: Same as DataFetchingEnvironment without args.
34
+ export interface DataFetcherResult<
35
+ DATA extends any,
36
+ LOCAL_CONTEXT extends LocalContextRecord = LocalContext
37
+ > {
38
+ // args, // Depends on the field resolver
39
+ localContext: LocalContext<LOCAL_CONTEXT>
40
+ source: DATA,
18
41
  }
19
42
 
20
43
  export declare type CreateDataFetcherResult = <
21
- In extends LocalContextRecord = LocalContext,
22
- Out extends LocalContextRecord = LocalContext
23
- >(params: CreateDataFetcherResultParams<In,Out>) => LocalContext<In&Out>
44
+ DATA extends any,
45
+ LOCAL_CONTEXT extends LocalContextRecord = LocalContext,
46
+ PARENT_LOCAL_CONTEXT extends LocalContextRecord = LocalContext
47
+ >(params: CreateDataFetcherResultParams<
48
+ DATA,
49
+ LOCAL_CONTEXT,
50
+ PARENT_LOCAL_CONTEXT,
51
+ >) => DataFetcherResult<
52
+ DATA,
53
+ LocalContext<PARENT_LOCAL_CONTEXT & LOCAL_CONTEXT>
54
+ >
@@ -1,9 +1,19 @@
1
1
  export declare type LocalContextRecord = Record<string,string|number|boolean|null>
2
2
 
3
+
4
+ // The documentation:
5
+ // https://developer.enonic.com/docs/guillotine/stable/extending/resolvers
6
+ //
7
+ // Says:
8
+ // If parentLocalContext is not provided, then localContext will override
9
+ // parentLocalContext.
10
+ //
11
+ // This means that is possible to remove branch, project and siteKey in some
12
+ // parent createDataFetcherResult. Which is why the Partial<> is used.
3
13
  export declare type LocalContext<
4
14
  T extends LocalContextRecord = LocalContextRecord
5
- > = {
15
+ > = Partial<{
6
16
  branch: string
7
17
  project: string
8
18
  siteKey?: string
9
- } & T
19
+ }> & T
@@ -12,7 +12,11 @@ import type {
12
12
  PartialRecord,
13
13
  ValueOf,
14
14
  } from '../Utils'
15
- import type {CreateDataFetcherResult} from './CreateDataFetcherResult'
15
+ import type {
16
+ CreateDataFetcherResult,
17
+ CreateDataFetcherResultParams,
18
+ DataFetcherResult,
19
+ } from './CreateDataFetcherResult'
16
20
  import type {
17
21
  GraphQLEnumType,
18
22
  GraphQLEnumTypeName,
package/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  // Make sure ScriptValue type exists in global scope:
2
2
  /// <reference types="@enonic-types/global"/>
3
3
 
4
+ import type {CreateDataFetcherResult} from './graphQL/CreateDataFetcherResult'
5
+ import type {Resolver} from './extensions/Resolvers'
4
6
 
5
7
  declare const __name: unique symbol
6
8
 
@@ -11,6 +13,25 @@ declare type BrandGraphQLScalarType<
11
13
  [__name]: GQL_SCALAR_TYPE_NAME
12
14
  }
13
15
 
16
+
17
+ export type {
18
+ CreateDataFetcherResult,
19
+ CreateDataFetcherResultParams,
20
+ DataFetcherResult,
21
+ } from './graphQL/CreateDataFetcherResult'
22
+
23
+ export type {
24
+ LocalContext,
25
+ LocalContextRecord,
26
+ } from './graphQL/LocalContext'
27
+
28
+ export type {
29
+ DataFetchingEnvironment,
30
+ Resolver,
31
+ // Resolvers, // NOTE: This is not exported because it the advanced version of Resolvers
32
+ } from './extensions/Resolvers'
33
+
34
+
14
35
  export declare type GraphQLBoolean = BrandGraphQLScalarType<'GraphQLBoolean', boolean>
15
36
  export declare type GraphQLDate = BrandGraphQLScalarType<'Date', string>
16
37
  export declare type GraphQLDateTime = BrandGraphQLScalarType<'DateTime', string>
@@ -35,14 +56,7 @@ export declare interface GraphQL {
35
56
  Json: GraphQLJson
36
57
  LocalDateTime: GraphQLLocalDateTime
37
58
  LocalTime: GraphQLLocalTime
38
- createDataFetcherResult: <
39
- In extends LocalContextRecord = LocalContext,
40
- Out extends LocalContextRecord = LocalContext
41
- > () => {
42
- data: ScriptValue // NOTE: ScriptValue type is expected to exist in global scope
43
- localContext?: LocalContext<Out>
44
- parentLocalContext?: LocalContext<In>
45
- }
59
+ createDataFetcherResult: CreateDataFetcherResult
46
60
  nonNull: (type: GraphQLType) => GraphQLType
47
61
  list: (type: GraphQLType) => GraphQLType[]
48
62
  reference: (typeName: string) => GraphQLType
@@ -71,33 +85,6 @@ export declare interface Enum {
71
85
  values: Record<string, string>
72
86
  }
73
87
 
74
- export declare type LocalContextRecord = Record<string,string|number|boolean|null>
75
-
76
- export declare type LocalContext<
77
- T extends LocalContextRecord = LocalContextRecord
78
- > = {
79
- branch: string
80
- project: string
81
- siteKey?: string
82
- } & T
83
-
84
- export declare interface DataFetchingEnvironment<
85
- Args extends Record<string, any> = Record<string, any>,
86
- Source extends unknown = unknown,
87
- > {
88
- args: Args
89
- localContext: LocalContext
90
- source: Source
91
- }
92
-
93
- export declare interface Resolver<
94
- Args extends Record<string, any> = Record<string, any>,
95
- Source extends unknown = unknown,
96
- Return = any
97
- > {
98
- (env: DataFetchingEnvironment<Args,Source>): Return
99
- }
100
-
101
88
  export declare interface Extensions {
102
89
  creationCallbacks?: Record<string, CreationCallback>
103
90
  enums?: Record<
@@ -142,6 +129,13 @@ export declare interface Extensions {
142
129
  }
143
130
 
144
131
 
132
+ export type {
133
+ BaseFolderContent,
134
+ MediaImageContent,
135
+ PortalSiteContent,
136
+ } from './xp'
137
+
138
+
145
139
  export {
146
140
  EnumTypeName,
147
141
  FormItemType,
package/package.json CHANGED
@@ -42,8 +42,9 @@
42
42
  },
43
43
  "scripts": {
44
44
  "check": "npx tsc --noEmit",
45
+ "prepublishOnly": "node setversion.js",
45
46
  "test": "tsd ./"
46
47
  },
47
48
  "types": "index.ts",
48
- "version": "0.0.1"
49
+ "version": "7.1.0-B1"
49
50
  }
package/xp/index.d.ts CHANGED
@@ -2,6 +2,8 @@ import type {Content} from '@enonic-types/core';
2
2
  import type {Site} from '@enonic-types/lib-content';
3
3
 
4
4
 
5
+ export declare type BaseFolderContent = Content<{}, 'base:folder'>;
6
+
5
7
  export declare type MediaImageContent = Content<{
6
8
  altText?: string
7
9
  artist?: string[]