tinacms 0.0.0-a63a1f5-20251124043708 → 0.0.0-a6b1b39-20251217041730
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/dist/admin/api.d.ts +1 -1
- package/dist/cache/node-cache.d.ts +6 -2
- package/dist/client.js +240 -181
- package/dist/index.js +118253 -117939
- package/dist/internalClient/index.d.ts +1 -1
- package/dist/react.js +210 -213
- package/dist/rich-text/index.js +234 -237
- package/dist/rich-text/prism.js +16 -18
- package/dist/rich-text/static.js +229 -232
- package/dist/toolkit/components/ui/button.d.ts +11 -0
- package/dist/toolkit/components/ui/calendar.d.ts +8 -0
- package/dist/toolkit/components/ui/date-time-picker.d.ts +111 -0
- package/dist/toolkit/components/ui/input.d.ts +3 -0
- package/dist/toolkit/components/ui/popover.d.ts +7 -0
- package/dist/toolkit/components/ui/select.d.ts +13 -0
- package/dist/toolkit/fields/components/color-picker/block-widget.d.ts +3 -0
- package/dist/toolkit/fields/components/color-picker/color-input.d.ts +35 -0
- package/dist/toolkit/fields/components/color-picker/color-picker.d.ts +6 -2
- package/dist/toolkit/fields/components/color-picker/color-utils.d.ts +37 -0
- package/dist/toolkit/fields/components/color-picker/sketch-widget.d.ts +3 -0
- package/dist/toolkit/fields/plugins/button-toggle-field-plugin.d.ts +2 -2
- package/dist/toolkit/fields/plugins/checkbox-group-field-plugin.d.ts +2 -2
- package/dist/toolkit/fields/plugins/color-field-plugin.d.ts +1 -0
- package/dist/toolkit/fields/plugins/date-field-plugin.d.ts +0 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/editor.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/blockquote-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/button.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/code-block-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-line-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/command.d.ts +7 -7
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/list-element.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/paragraph-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/slash-input-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-cell-element.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-row-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-hook.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/components.d.ts +18 -18
- package/dist/toolkit/fields/plugins/radio-group-field-plugin.d.ts +2 -2
- package/dist/toolkit/fields/plugins/select-field-plugin.d.ts +2 -2
- package/dist/toolkit/fields/plugins/toggle-field-plugin.d.ts +2 -2
- package/dist/toolkit/index.d.ts +1 -1
- package/dist/toolkit/react-sidebar/components/NavMenuTrigger.d.ts +11 -0
- package/dist/toolkit/react-sidebar/components/nav-components.d.ts +11 -0
- package/dist/toolkit/react-sidebar/components/nav-context.d.ts +15 -0
- package/dist/toolkit/react-sidebar/components/nav.d.ts +3 -3
- package/dist/toolkit/react-sidebar/components/sidebar-body.d.ts +26 -1
- package/dist/toolkit/react-sidebar/index.d.ts +3 -0
- package/dist/unifiedClient/index.d.ts +1 -1
- package/package.json +28 -61
- package/dist/client.mjs +0 -132
- package/dist/index.mjs +0 -123215
- package/dist/node-cache-5e8db9f0.mjs +0 -63
- package/dist/react.mjs +0 -254
- package/dist/rich-text/index.mjs +0 -256
- package/dist/rich-text/prism.mjs +0 -16
- package/dist/rich-text/static.mjs +0 -243
- package/dist/toolkit/react-datetime/DateTime.d.ts +0 -135
- /package/dist/admin/components/{Sidebar.d.ts → AdminNav.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const RadioGroupField: (props: import("./wrap-field-with-meta").InputFieldType<import("
|
|
1
|
+
export declare const RadioGroupField: (props: import("./wrap-field-with-meta").InputFieldType<import("..").RadioGroupProps, {}>) => import("react").JSX.Element;
|
|
2
2
|
export declare const RadioGroupFieldPlugin: {
|
|
3
3
|
name: string;
|
|
4
|
-
Component: (props: import("./wrap-field-with-meta").InputFieldType<import("
|
|
4
|
+
Component: (props: import("./wrap-field-with-meta").InputFieldType<import("..").RadioGroupProps, {}>) => import("react").JSX.Element;
|
|
5
5
|
validate(value: any, values: any, meta: any, field: any): string;
|
|
6
6
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare const SelectField: (props: import("./wrap-field-with-meta").InputFieldType<import("
|
|
1
|
+
export declare const SelectField: (props: import("./wrap-field-with-meta").InputFieldType<import("..").SelectProps, {}>) => import("react").JSX.Element;
|
|
2
2
|
export declare const SelectFieldPlugin: {
|
|
3
3
|
name: string;
|
|
4
4
|
type: string;
|
|
5
|
-
Component: (props: import("./wrap-field-with-meta").InputFieldType<import("
|
|
5
|
+
Component: (props: import("./wrap-field-with-meta").InputFieldType<import("..").SelectProps, {}>) => import("react").JSX.Element;
|
|
6
6
|
parse: (value?: string) => string;
|
|
7
7
|
validate(value: any, values: any, meta: any, field: any): string;
|
|
8
8
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare const ToggleField: (props: import("./wrap-field-with-meta").InputFieldType<import("
|
|
1
|
+
export declare const ToggleField: (props: import("./wrap-field-with-meta").InputFieldType<import("..").ToggleProps, {}>) => import("react").JSX.Element;
|
|
2
2
|
export declare const ToggleFieldPlugin: {
|
|
3
3
|
name: string;
|
|
4
4
|
type: string;
|
|
5
|
-
Component: (props: import("./wrap-field-with-meta").InputFieldType<import("
|
|
5
|
+
Component: (props: import("./wrap-field-with-meta").InputFieldType<import("..").ToggleProps, {}>) => import("react").JSX.Element;
|
|
6
6
|
validate(value: any, values: any, meta: any, field: any): string;
|
|
7
7
|
};
|
package/dist/toolkit/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type { TinaState } from './tina-state';
|
|
|
19
19
|
export * from './forms';
|
|
20
20
|
export * from './icons';
|
|
21
21
|
export * from './react-dismissible';
|
|
22
|
-
export { Nav, LocalWarning, BillingWarning, SyncStatusButton, } from './react-sidebar';
|
|
22
|
+
export { Nav, NavCloudLink, NavProvider, NavMenuTrigger, useNav, LocalWarning, BillingWarning, SyncStatusButton, } from './react-sidebar';
|
|
23
23
|
export { useCMS } from './react-core';
|
|
24
24
|
/**
|
|
25
25
|
* Custom `tinacms` things
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface NavMenuTriggerProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A button component that triggers the navigation menu
|
|
8
|
+
* Can be used anywhere within the NavProvider hierarchy
|
|
9
|
+
*/
|
|
10
|
+
export declare const NavMenuTrigger: React.FC<NavMenuTriggerProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CloudConfigPlugin } from '../../react-cloud-config';
|
|
3
|
+
interface NavCloudLinkProps {
|
|
4
|
+
config: CloudConfigPlugin;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Shared component for rendering cloud configuration links
|
|
8
|
+
* Used across both admin and sidebar navigation
|
|
9
|
+
*/
|
|
10
|
+
export declare const NavCloudLink: React.FC<NavCloudLinkProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
export interface NavContextValue {
|
|
3
|
+
menuIsOpen: boolean;
|
|
4
|
+
toggleMenu: () => void;
|
|
5
|
+
openMenu: () => void;
|
|
6
|
+
closeMenu: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const NavContext: React.Context<NavContextValue>;
|
|
9
|
+
export declare const useNav: () => NavContextValue;
|
|
10
|
+
interface NavProviderProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
defaultOpen?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const NavProvider: React.FC<NavProviderProps>;
|
|
15
|
+
export {};
|
|
@@ -9,8 +9,8 @@ interface NavCollection {
|
|
|
9
9
|
interface NavProps {
|
|
10
10
|
isLocalMode: boolean;
|
|
11
11
|
showHamburger?: boolean;
|
|
12
|
-
menuIsOpen
|
|
13
|
-
toggleMenu
|
|
12
|
+
menuIsOpen?: boolean;
|
|
13
|
+
toggleMenu?: () => void;
|
|
14
14
|
children?: any;
|
|
15
15
|
className?: string;
|
|
16
16
|
userName?: string;
|
|
@@ -41,5 +41,5 @@ interface NavProps {
|
|
|
41
41
|
};
|
|
42
42
|
}>;
|
|
43
43
|
}
|
|
44
|
-
export declare const Nav: ({ isLocalMode, showHamburger, menuIsOpen, toggleMenu, className, children, showCollections, collectionsInfo, screens, cloudConfigs, contentCreators, sidebarWidth, RenderNavSite, RenderNavCloud, RenderNavCollection, AuthRenderNavCollection, ...props }: NavProps) => React.JSX.Element;
|
|
44
|
+
export declare const Nav: ({ isLocalMode, showHamburger, menuIsOpen: menuIsOpenProp, toggleMenu: toggleMenuProp, className, children, showCollections, collectionsInfo, screens, cloudConfigs, contentCreators, sidebarWidth, RenderNavSite, RenderNavCloud, RenderNavCollection, AuthRenderNavCollection, ...props }: NavProps) => React.JSX.Element;
|
|
45
45
|
export {};
|
|
@@ -9,8 +9,33 @@ export interface FormHeaderProps {
|
|
|
9
9
|
activeFieldName?: string;
|
|
10
10
|
tinaForm: Form;
|
|
11
11
|
};
|
|
12
|
+
branch?: string;
|
|
13
|
+
isLocalMode?: boolean;
|
|
14
|
+
repoProvider?: {
|
|
15
|
+
defaultBranchName?: string;
|
|
16
|
+
historyUrl?: (context: {
|
|
17
|
+
relativePath: string;
|
|
18
|
+
branch: string;
|
|
19
|
+
}) => {
|
|
20
|
+
url: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare const FormHeader: ({ activeForm, repoProvider, branch, isLocalMode, }: FormHeaderProps) => React.JSX.Element;
|
|
25
|
+
interface RepositoryProviderProps {
|
|
26
|
+
contentRelativePath: string;
|
|
27
|
+
tinaBranch?: string;
|
|
28
|
+
isLocalMode?: boolean;
|
|
29
|
+
defaultBranchName?: string;
|
|
30
|
+
historyUrl?: (context: {
|
|
31
|
+
relativePath: string;
|
|
32
|
+
branch: string;
|
|
33
|
+
}) => {
|
|
34
|
+
url: string;
|
|
35
|
+
};
|
|
12
36
|
}
|
|
13
|
-
export declare const
|
|
37
|
+
export declare const FileHistoryProvider: ({ contentRelativePath, tinaBranch, defaultBranchName, historyUrl, isLocalMode, }: RepositoryProviderProps) => React.JSX.Element;
|
|
14
38
|
export declare const FormBreadcrumbs: ({ rootBreadcrumbName, ...props }: {
|
|
15
39
|
rootBreadcrumbName?: string;
|
|
16
40
|
} & React.HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
|
|
41
|
+
export {};
|
|
@@ -3,3 +3,6 @@ export { SidebarProvider } from './components/sidebar';
|
|
|
3
3
|
export { Nav } from './components/nav';
|
|
4
4
|
export { LocalWarning, BillingWarning } from './components/local-warning';
|
|
5
5
|
export { SyncStatusButton } from './components/sync-status';
|
|
6
|
+
export { NavCloudLink } from './components/nav-components';
|
|
7
|
+
export { NavProvider, useNav } from './components/nav-context';
|
|
8
|
+
export { NavMenuTrigger } from './components/NavMenuTrigger';
|
|
@@ -29,7 +29,7 @@ export declare class TinaClient<GenQueries> {
|
|
|
29
29
|
initialized: boolean;
|
|
30
30
|
cacheLock: AsyncLock | undefined;
|
|
31
31
|
cacheDir: string;
|
|
32
|
-
cache: Cache;
|
|
32
|
+
cache: Cache | null;
|
|
33
33
|
constructor({ token, url, queries, errorPolicy, cacheDir, }: TinaClientArgs<GenQueries>);
|
|
34
34
|
init(): Promise<void>;
|
|
35
35
|
request<DataType extends Record<string, any> = any>({ errorPolicy, ...args }: TinaClientRequestArgs, options: {
|
package/package.json
CHANGED
|
@@ -1,44 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinacms",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"typings": "dist/index.d.ts",
|
|
5
|
+
"version": "0.0.0-a6b1b39-20251217041730",
|
|
4
6
|
"main": "dist/index.js",
|
|
5
|
-
"module": "./dist/index.
|
|
7
|
+
"module": "./dist/index.js",
|
|
6
8
|
"exports": {
|
|
7
|
-
".":
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"./dist/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"require": "./dist/client.js"
|
|
16
|
-
},
|
|
17
|
-
"./dist/edit-state": {
|
|
18
|
-
"types": "./dist/edit-state.d.ts",
|
|
19
|
-
"import": "./dist/edit-state.mjs",
|
|
20
|
-
"require": "./dist/edit-state.js"
|
|
21
|
-
},
|
|
22
|
-
"./dist/react": {
|
|
23
|
-
"types": "./dist/react.d.ts",
|
|
24
|
-
"import": "./dist/react.mjs",
|
|
25
|
-
"require": "./dist/react.js"
|
|
26
|
-
},
|
|
27
|
-
"./dist/rich-text": {
|
|
28
|
-
"types": "./dist/rich-text/index.d.ts",
|
|
29
|
-
"import": "./dist/rich-text/index.mjs",
|
|
30
|
-
"require": "./dist/rich-text/index.js"
|
|
31
|
-
},
|
|
32
|
-
"./dist/rich-text/static": {
|
|
33
|
-
"types": "./dist/rich-text/static.d.ts",
|
|
34
|
-
"import": "./dist/rich-text/static.mjs",
|
|
35
|
-
"require": "./dist/rich-text/static.js"
|
|
36
|
-
},
|
|
37
|
-
"./dist/rich-text/prism": {
|
|
38
|
-
"types": "./dist/rich-text/prism.d.ts",
|
|
39
|
-
"import": "./dist/rich-text/prism.mjs",
|
|
40
|
-
"require": "./dist/rich-text/prism.js"
|
|
41
|
-
}
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./dist/client": "./dist/client.js",
|
|
11
|
+
"./dist/edit-state": "./dist/edit-state.js",
|
|
12
|
+
"./react": "./dist/react.js",
|
|
13
|
+
"./dist/react": "./dist/react.js",
|
|
14
|
+
"./dist/rich-text": "./dist/rich-text/index.js",
|
|
15
|
+
"./dist/rich-text/static": "./dist/rich-text/static.js",
|
|
16
|
+
"./dist/rich-text/prism": "./dist/rich-text/prism.js"
|
|
42
17
|
},
|
|
43
18
|
"files": [
|
|
44
19
|
"dist"
|
|
@@ -50,20 +25,12 @@
|
|
|
50
25
|
"src/rich-text/static.tsx",
|
|
51
26
|
"src/rich-text/prism.tsx",
|
|
52
27
|
"src/react.tsx",
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"rollupOptions": {
|
|
57
|
-
"external": [
|
|
58
|
-
"crypto",
|
|
59
|
-
"fs",
|
|
60
|
-
"path",
|
|
61
|
-
"os"
|
|
62
|
-
]
|
|
28
|
+
{
|
|
29
|
+
"name": "src/client.ts",
|
|
30
|
+
"target": "node"
|
|
63
31
|
}
|
|
64
|
-
|
|
32
|
+
]
|
|
65
33
|
},
|
|
66
|
-
"typings": "dist/index.d.ts",
|
|
67
34
|
"license": "Apache-2.0",
|
|
68
35
|
"dependencies": {
|
|
69
36
|
"@ariakit/react": "^0.4.15",
|
|
@@ -79,11 +46,12 @@
|
|
|
79
46
|
"@radix-ui/react-checkbox": "^1.1.4",
|
|
80
47
|
"@radix-ui/react-dialog": "^1.1.6",
|
|
81
48
|
"@radix-ui/react-dropdown-menu": "^2.1.6",
|
|
82
|
-
"@radix-ui/react-popover": "^1.1.
|
|
49
|
+
"@radix-ui/react-popover": "^1.1.15",
|
|
50
|
+
"@radix-ui/react-select": "^2.2.6",
|
|
83
51
|
"@radix-ui/react-separator": "^1.1.2",
|
|
84
52
|
"@radix-ui/react-slot": "^1.1.2",
|
|
85
53
|
"@radix-ui/react-toolbar": "^1.1.2",
|
|
86
|
-
"@radix-ui/react-tooltip": "^1.2.
|
|
54
|
+
"@radix-ui/react-tooltip": "^1.2.8",
|
|
87
55
|
"@react-hook/window-size": "^3.1.1",
|
|
88
56
|
"@udecode/cmdk": "^0.2.1",
|
|
89
57
|
"@udecode/cn": "^48.0.3",
|
|
@@ -126,11 +94,13 @@
|
|
|
126
94
|
"lucide-react": "^0.424.0",
|
|
127
95
|
"mermaid": "9.3.0",
|
|
128
96
|
"moment": "2.29.4",
|
|
97
|
+
"moment-timezone": "^0.6.0",
|
|
129
98
|
"monaco-editor": "0.31.0",
|
|
130
99
|
"prism-react-renderer": "^2.4.1",
|
|
131
100
|
"prop-types": "15.7.2",
|
|
132
|
-
"react-
|
|
101
|
+
"react-colorful": "^5.6.1",
|
|
133
102
|
"react-datetime": "^3.3.1",
|
|
103
|
+
"react-day-picker": "^9.11.1",
|
|
134
104
|
"react-dropzone": "14.2.3",
|
|
135
105
|
"react-final-form": "^6.5.9",
|
|
136
106
|
"react-icons": "^5.4.0",
|
|
@@ -140,14 +110,14 @@
|
|
|
140
110
|
"webfontloader": "1.6.28",
|
|
141
111
|
"yup": "^1.6.1",
|
|
142
112
|
"zod": "^3.24.2",
|
|
143
|
-
"@tinacms/mdx": "
|
|
144
|
-
"@tinacms/
|
|
145
|
-
"@tinacms/
|
|
113
|
+
"@tinacms/mdx": "2.0.1",
|
|
114
|
+
"@tinacms/search": "1.1.6",
|
|
115
|
+
"@tinacms/schema-tools": "2.1.0"
|
|
146
116
|
},
|
|
147
117
|
"devDependencies": {
|
|
148
118
|
"@graphql-tools/utils": "^10.8.1",
|
|
149
119
|
"@testing-library/dom": "^10.4.0",
|
|
150
|
-
"@testing-library/jest-dom": "^6.
|
|
120
|
+
"@testing-library/jest-dom": "^6.7.0",
|
|
151
121
|
"@testing-library/react": "^16.2.0",
|
|
152
122
|
"@testing-library/user-event": "^14.6.1",
|
|
153
123
|
"@types/atob": "^2.1.4",
|
|
@@ -156,15 +126,12 @@
|
|
|
156
126
|
"@types/node": "^22.13.1",
|
|
157
127
|
"@types/prop-types": "^15.7.14",
|
|
158
128
|
"@types/react": "^18.3.18",
|
|
159
|
-
"@types/react-color": "^3.0.13",
|
|
160
129
|
"@types/react-dom": "^18.3.5",
|
|
161
|
-
"@types/yup": "^0.32.0",
|
|
162
130
|
"happy-dom": "15.10.2",
|
|
163
131
|
"identity-obj-proxy": "^3.0.0",
|
|
164
|
-
"isomorphic-fetch": "^3.0.0",
|
|
165
132
|
"jest-file-snapshot": "^0.7.0",
|
|
166
133
|
"lowlight": "^3.3.0",
|
|
167
|
-
"next": "14.2.
|
|
134
|
+
"next": "14.2.35",
|
|
168
135
|
"react": "^18.3.1",
|
|
169
136
|
"react-dom": "^18.3.1",
|
|
170
137
|
"react-is": "^18.3.1",
|
|
@@ -173,7 +140,7 @@
|
|
|
173
140
|
"typescript": "^5.7.3",
|
|
174
141
|
"vite": "^5.4.14",
|
|
175
142
|
"vitest": "^2.1.9",
|
|
176
|
-
"@tinacms/scripts": "
|
|
143
|
+
"@tinacms/scripts": "1.4.2"
|
|
177
144
|
},
|
|
178
145
|
"peerDependencies": {
|
|
179
146
|
"react": ">=16.14.0",
|
package/dist/client.mjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import AsyncLock from "async-lock";
|
|
2
|
-
const TINA_HOST = "content.tinajs.io";
|
|
3
|
-
function replaceGithubPathSplit(url, replacement) {
|
|
4
|
-
const parts = url.split("github/");
|
|
5
|
-
if (parts.length > 1 && replacement) {
|
|
6
|
-
return parts[0] + "github/" + replacement;
|
|
7
|
-
} else {
|
|
8
|
-
return url;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
class TinaClient {
|
|
12
|
-
constructor({
|
|
13
|
-
token,
|
|
14
|
-
url,
|
|
15
|
-
queries,
|
|
16
|
-
errorPolicy,
|
|
17
|
-
cacheDir
|
|
18
|
-
}) {
|
|
19
|
-
this.initialized = false;
|
|
20
|
-
this.apiUrl = url;
|
|
21
|
-
this.readonlyToken = token == null ? void 0 : token.trim();
|
|
22
|
-
this.queries = queries(this);
|
|
23
|
-
this.errorPolicy = errorPolicy || "throw";
|
|
24
|
-
this.cacheDir = cacheDir || "";
|
|
25
|
-
}
|
|
26
|
-
async init() {
|
|
27
|
-
if (this.initialized) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
if (this.cacheDir && typeof window === "undefined" && typeof require !== "undefined") {
|
|
32
|
-
const { NodeCache } = await import("./node-cache-5e8db9f0.mjs");
|
|
33
|
-
this.cache = await NodeCache(this.cacheDir);
|
|
34
|
-
this.cacheLock = new AsyncLock();
|
|
35
|
-
}
|
|
36
|
-
} catch (e) {
|
|
37
|
-
console.error(e);
|
|
38
|
-
}
|
|
39
|
-
this.initialized = true;
|
|
40
|
-
}
|
|
41
|
-
async request({ errorPolicy, ...args }, options) {
|
|
42
|
-
var _a;
|
|
43
|
-
await this.init();
|
|
44
|
-
const errorPolicyDefined = errorPolicy || this.errorPolicy;
|
|
45
|
-
const headers = new Headers();
|
|
46
|
-
if (this.readonlyToken) {
|
|
47
|
-
headers.append("X-API-KEY", this.readonlyToken);
|
|
48
|
-
}
|
|
49
|
-
headers.append("Content-Type", "application/json");
|
|
50
|
-
if (options == null ? void 0 : options.fetchOptions) {
|
|
51
|
-
if ((_a = options == null ? void 0 : options.fetchOptions) == null ? void 0 : _a.headers) {
|
|
52
|
-
Object.entries(options.fetchOptions.headers).forEach(([key2, value]) => {
|
|
53
|
-
headers.append(key2, value);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const { headers: _, ...providedFetchOptions } = (options == null ? void 0 : options.fetchOptions) || {};
|
|
58
|
-
const bodyString = JSON.stringify({
|
|
59
|
-
query: args.query,
|
|
60
|
-
variables: (args == null ? void 0 : args.variables) || {}
|
|
61
|
-
});
|
|
62
|
-
const optionsObject = {
|
|
63
|
-
method: "POST",
|
|
64
|
-
headers,
|
|
65
|
-
body: bodyString,
|
|
66
|
-
redirect: "follow",
|
|
67
|
-
...providedFetchOptions
|
|
68
|
-
};
|
|
69
|
-
const draftBranch = headers.get("x-branch");
|
|
70
|
-
const url = replaceGithubPathSplit((args == null ? void 0 : args.url) || this.apiUrl, draftBranch);
|
|
71
|
-
let key = "";
|
|
72
|
-
let result;
|
|
73
|
-
if (this.cache) {
|
|
74
|
-
key = this.cache.makeKey(bodyString);
|
|
75
|
-
await this.cacheLock.acquire(key, async () => {
|
|
76
|
-
result = await this.cache.get(key);
|
|
77
|
-
if (!result) {
|
|
78
|
-
result = await requestFromServer(
|
|
79
|
-
url,
|
|
80
|
-
args.query,
|
|
81
|
-
optionsObject,
|
|
82
|
-
errorPolicyDefined
|
|
83
|
-
);
|
|
84
|
-
await this.cache.set(key, result);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
} else {
|
|
88
|
-
result = await requestFromServer(
|
|
89
|
-
url,
|
|
90
|
-
args.query,
|
|
91
|
-
optionsObject,
|
|
92
|
-
errorPolicyDefined
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async function requestFromServer(url, query, optionsObject, errorPolicyDefined) {
|
|
99
|
-
const res = await fetch(url, optionsObject);
|
|
100
|
-
if (!res.ok) {
|
|
101
|
-
let additionalInfo = "";
|
|
102
|
-
if (res.status === 401) {
|
|
103
|
-
additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
|
|
104
|
-
}
|
|
105
|
-
throw new Error(
|
|
106
|
-
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/r/FAQ/`
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
const json = await res.json();
|
|
110
|
-
if (json.errors && errorPolicyDefined === "throw") {
|
|
111
|
-
throw new Error(
|
|
112
|
-
`Unable to fetch, please see our FAQ for more information: https://tina.io/docs/r/FAQ/
|
|
113
|
-
Errors:
|
|
114
|
-
${json.errors.map((error) => error.message).join("\n")}`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
const result = {
|
|
118
|
-
data: json == null ? void 0 : json.data,
|
|
119
|
-
errors: (json == null ? void 0 : json.errors) || null,
|
|
120
|
-
query
|
|
121
|
-
};
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
function createClient(args) {
|
|
125
|
-
const client = new TinaClient(args);
|
|
126
|
-
return client;
|
|
127
|
-
}
|
|
128
|
-
export {
|
|
129
|
-
TINA_HOST,
|
|
130
|
-
TinaClient,
|
|
131
|
-
createClient
|
|
132
|
-
};
|