@platecms/delta-client 0.1.0
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 +148 -0
- package/package.json +58 -0
- package/src/__generated__/fragment-masking.d.ts +19 -0
- package/src/__generated__/fragment-masking.js +22 -0
- package/src/__generated__/fragment-masking.js.map +1 -0
- package/src/__generated__/gql.d.ts +3 -0
- package/src/__generated__/gql.js +8 -0
- package/src/__generated__/gql.js.map +1 -0
- package/src/__generated__/graphql.d.ts +1821 -0
- package/src/__generated__/graphql.js +57 -0
- package/src/__generated__/graphql.js.map +1 -0
- package/src/__generated__/index.d.ts +2 -0
- package/src/__generated__/index.js +6 -0
- package/src/__generated__/index.js.map +1 -0
- package/src/api/index.d.ts +2 -0
- package/src/api/index.js +4 -0
- package/src/api/index.js.map +1 -0
- package/src/apollo/index.d.ts +7 -0
- package/src/apollo/index.js +35 -0
- package/src/apollo/index.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -0
- package/src/index.js.map +1 -0
- package/src/schema/index.d.ts +2 -0
- package/src/schema/index.js +8 -0
- package/src/schema/index.js.map +1 -0
- package/src/schema/lib/nodes.d.ts +46 -0
- package/src/schema/lib/nodes.js +14 -0
- package/src/schema/lib/nodes.js.map +1 -0
- package/src/schema/lib/parser.d.ts +12 -0
- package/src/schema/lib/parser.js +49 -0
- package/src/schema/lib/parser.js.map +1 -0
- package/src/schema/lib/schema.d.ts +17 -0
- package/src/schema/lib/schema.js +65 -0
- package/src/schema/lib/schema.js.map +1 -0
- package/src/schema/lib/utils.d.ts +12 -0
- package/src/schema/lib/utils.js +61 -0
- package/src/schema/lib/utils.js.map +1 -0
- package/src/slate/index.d.ts +55 -0
- package/src/slate/index.js +3 -0
- package/src/slate/index.js.map +1 -0
- package/src/utils/index.d.ts +6 -0
- package/src/utils/index.js +6 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/lib/connectors/BaseConnector.d.ts +16 -0
- package/src/utils/lib/connectors/BaseConnector.js +17 -0
- package/src/utils/lib/connectors/BaseConnector.js.map +1 -0
- package/src/utils/lib/connectors/WindowConnector.d.ts +10 -0
- package/src/utils/lib/connectors/WindowConnector.js +53 -0
- package/src/utils/lib/connectors/WindowConnector.js.map +1 -0
- package/src/utils/lib/events/ConnectorEvents.d.ts +63 -0
- package/src/utils/lib/events/ConnectorEvents.js +24 -0
- package/src/utils/lib/events/ConnectorEvents.js.map +1 -0
- package/src/utils/lib/events/EventEmitter.d.ts +7 -0
- package/src/utils/lib/events/EventEmitter.js +21 -0
- package/src/utils/lib/events/EventEmitter.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# delta-client-schema
|
|
2
|
+
|
|
3
|
+
This library is part of the [Delta Client]() utility packages.
|
|
4
|
+
It provides a utility to convert abstract building blocks and their values to usable data structures.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
Defining a schema looks as follows consists of a root object and nested fields.
|
|
9
|
+
For example for a building block that has a welcome message, the schema would look like this:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { s } from "@platecms/delta-client/schema";
|
|
13
|
+
|
|
14
|
+
const heroBuildingBlock = s.object({
|
|
15
|
+
title: s.primitive(c('root', 'title')),
|
|
16
|
+
description: s.cast(c('root', 'description')),
|
|
17
|
+
images: s.array(s.asset())
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The schema can then be used to convert the abstract building block to a usable data structure:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { p as parser } from "@platecms/delta-client/schema";
|
|
26
|
+
|
|
27
|
+
const heroBuildingBlock = parser.parse(schema, buildingBlockFieldFulfillments);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Yields:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
const heroBuildingBlock = {
|
|
34
|
+
title: "Hero Title",
|
|
35
|
+
description: {
|
|
36
|
+
type: 'root',
|
|
37
|
+
children: [
|
|
38
|
+
{
|
|
39
|
+
type: 'text',
|
|
40
|
+
value: 'Welcome to our website'
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
images: [
|
|
45
|
+
{
|
|
46
|
+
fileName: "first image",
|
|
47
|
+
url: 'https://example.com/image.jpg',
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
### Object
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
s.object({
|
|
59
|
+
// shape of the object
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Array
|
|
64
|
+
|
|
65
|
+
Default array with one placeholder
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
s.array(
|
|
69
|
+
s.primitive('value')
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Array with a limit of the maximum number of items to display
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
s.array(
|
|
77
|
+
s.primitive('value'), 5 // limit to 5 items
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Array with an array of placeholders, also uses this a minimum number of items to display
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
s.array(
|
|
85
|
+
[
|
|
86
|
+
s.primitive('value'),
|
|
87
|
+
s.primitive('value'),
|
|
88
|
+
// other fields
|
|
89
|
+
]
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Primitive
|
|
94
|
+
|
|
95
|
+
#### string
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
s.primitive('value')
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### number
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
s.primitive(23)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Asset
|
|
108
|
+
|
|
109
|
+
Accepts a partial Asset object as a placeholder
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
s.asset({
|
|
113
|
+
fileName: 'first',
|
|
114
|
+
url: 'https://example.com/image.jpg'
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### PathPart
|
|
119
|
+
|
|
120
|
+
Accepts a partial PathPart object as a placeholder
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
s.pathPart({
|
|
124
|
+
path: '/blogs',
|
|
125
|
+
})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### GridPlacement
|
|
129
|
+
|
|
130
|
+
Accepts a partial GridPlacement object as a placeholder
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
s.gridPlacement({
|
|
134
|
+
prn: 'prn:grid:123',
|
|
135
|
+
row: 1
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Cast
|
|
140
|
+
|
|
141
|
+
Accepts a correct root object to cast the schema to a usable data structure
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
s.cast({
|
|
145
|
+
type: 'root',
|
|
146
|
+
children: []
|
|
147
|
+
})
|
|
148
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@platecms/delta-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Utilities and functions to interact with the Delta CMS.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://bitbucket.org/startmetplate/delta.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://bitbucket.org/startmetplate/delta/src/dev/packages/delta-client",
|
|
14
|
+
"type": "commonjs",
|
|
15
|
+
"main": "./src/index.cjs.js",
|
|
16
|
+
"types": "./src/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"src/**/*"
|
|
19
|
+
],
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@platecms/delta-cast": "*",
|
|
22
|
+
"@graphql-typed-document-node/core": "3.2.0",
|
|
23
|
+
"graphql": "16.10.0",
|
|
24
|
+
"lodash": "4.17.21",
|
|
25
|
+
"slate": "0.112.0",
|
|
26
|
+
"slate-react": "0.112.1",
|
|
27
|
+
"tslib": "2.8.1",
|
|
28
|
+
"class-transformer": "0.5.1",
|
|
29
|
+
"reflect-metadata": "0.2.2",
|
|
30
|
+
"@apollo/client": "3.13.1",
|
|
31
|
+
"defu": "^6.1.4"
|
|
32
|
+
},
|
|
33
|
+
"exports": {
|
|
34
|
+
"./package.json": "./package.json",
|
|
35
|
+
".": {
|
|
36
|
+
"import": "./index.esm.js",
|
|
37
|
+
"default": "./index.cjs.js",
|
|
38
|
+
"types": "./src/index.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./slate": {
|
|
41
|
+
"import": "./src/slate/index.esm.js",
|
|
42
|
+
"default": "./src/slate/index.cjs.js",
|
|
43
|
+
"types": "./src/slate/index.d.ts"
|
|
44
|
+
},
|
|
45
|
+
"./schema": {
|
|
46
|
+
"import": "./src/schema/index.esm.js",
|
|
47
|
+
"default": "./src/schema/index.cjs.js",
|
|
48
|
+
"types": "./src/schema/index.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./apollo": {
|
|
51
|
+
"import": "./src/apollo/index.esm.js",
|
|
52
|
+
"default": "./src/apollo/index.cjs.js",
|
|
53
|
+
"types": "./src/apollo/index.d.ts"
|
|
54
|
+
},
|
|
55
|
+
"./slate/index": "./src/slate/index.js"
|
|
56
|
+
},
|
|
57
|
+
"module": "./index.esm.js"
|
|
58
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import type { Incremental } from './graphql';
|
|
3
|
+
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<infer TType, any> ? [TType] extends [{
|
|
4
|
+
' $fragmentName'?: infer TKey;
|
|
5
|
+
}] ? TKey extends string ? {
|
|
6
|
+
' $fragmentRefs'?: {
|
|
7
|
+
[key in TKey]: TType;
|
|
8
|
+
};
|
|
9
|
+
} : never : never : never;
|
|
10
|
+
export declare function useFragment<TType>(_documentNode: DocumentTypeDecoration<TType, any>, fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>): TType;
|
|
11
|
+
export declare function useFragment<TType>(_documentNode: DocumentTypeDecoration<TType, any>, fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined): TType | undefined;
|
|
12
|
+
export declare function useFragment<TType>(_documentNode: DocumentTypeDecoration<TType, any>, fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null): TType | null;
|
|
13
|
+
export declare function useFragment<TType>(_documentNode: DocumentTypeDecoration<TType, any>, fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined): TType | null | undefined;
|
|
14
|
+
export declare function useFragment<TType>(_documentNode: DocumentTypeDecoration<TType, any>, fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>): Array<TType>;
|
|
15
|
+
export declare function useFragment<TType>(_documentNode: DocumentTypeDecoration<TType, any>, fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined): Array<TType> | null | undefined;
|
|
16
|
+
export declare function useFragment<TType>(_documentNode: DocumentTypeDecoration<TType, any>, fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>): ReadonlyArray<TType>;
|
|
17
|
+
export declare function useFragment<TType>(_documentNode: DocumentTypeDecoration<TType, any>, fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined): ReadonlyArray<TType> | null | undefined;
|
|
18
|
+
export declare function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>(data: FT, _fragment: F): FragmentType<F>;
|
|
19
|
+
export declare function isFragmentReady<TQuery, TFrag>(queryNode: DocumentTypeDecoration<TQuery, any>, fragmentNode: TypedDocumentNode<TFrag>, data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined): data is FragmentType<typeof fragmentNode>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFragment = useFragment;
|
|
4
|
+
exports.makeFragmentData = makeFragmentData;
|
|
5
|
+
exports.isFragmentReady = isFragmentReady;
|
|
6
|
+
function useFragment(_documentNode, fragmentType) {
|
|
7
|
+
return fragmentType;
|
|
8
|
+
}
|
|
9
|
+
function makeFragmentData(data, _fragment) {
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
function isFragmentReady(queryNode, fragmentNode, data) {
|
|
13
|
+
const deferredFields = queryNode.__meta__
|
|
14
|
+
?.deferredFields;
|
|
15
|
+
if (!deferredFields)
|
|
16
|
+
return true;
|
|
17
|
+
const fragDef = fragmentNode.definitions[0];
|
|
18
|
+
const fragName = fragDef?.name?.value;
|
|
19
|
+
const fields = (fragName && deferredFields[fragName]) || [];
|
|
20
|
+
return fields.length > 0 && fields.every(field => data && field in data);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=fragment-masking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragment-masking.js","sourceRoot":"","sources":["../../../../../../packages/delta-client/src/__generated__/fragment-masking.ts"],"names":[],"mappings":";;AAyDA,kCAKC;AAGD,4CAKC;AACD,0CAeC;AA7BD,SAAgB,WAAW,CACzB,aAAiD,EACjD,YAA6M;IAE7M,OAAO,YAAmB,CAAC;AAC7B,CAAC;AAGD,SAAgB,gBAAgB,CAG9B,IAAQ,EAAE,SAAY;IACtB,OAAO,IAAuB,CAAC;AACjC,CAAC;AACD,SAAgB,eAAe,CAC7B,SAA8C,EAC9C,YAAsC,EACtC,IAAiF;IAEjF,MAAM,cAAc,GAAI,SAAgF,CAAC,QAAQ;QAC/G,EAAE,cAAc,CAAC;IAEnB,IAAI,CAAC,cAAc;QAAE,OAAO,IAAI,CAAC;IAEjC,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC,CAAuC,CAAC;IAClF,MAAM,QAAQ,GAAG,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC;IAEtC,MAAM,MAAM,GAAG,CAAC,QAAQ,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5D,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
export declare function graphql(source: string): unknown;
|
|
3
|
+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gql.js","sourceRoot":"","sources":["../../../../../../packages/delta-client/src/__generated__/gql.ts"],"names":[],"mappings":";;AAmBA,0BAEC;AAjBD,MAAM,SAAS,GAAY,EAAE,CAAC;AAe9B,SAAgB,OAAO,CAAC,MAAc;IACpC,OAAQ,SAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AAC1C,CAAC"}
|