tinacms 0.0.0-d94de9b-20250707010010 → 0.0.0-d9ccf29-20251222052725
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 +4 -1
- package/dist/auth/AuthModal.d.ts +1 -4
- package/dist/auth/TinaCloudProvider.d.ts +0 -1
- package/dist/cache/node-cache.d.ts +6 -2
- package/dist/client.js +240 -181
- package/dist/index.js +122235 -34368
- package/dist/internalClient/index.d.ts +20 -1
- package/dist/react.js +297 -206
- package/dist/rich-text/index.d.ts +6 -0
- package/dist/rich-text/index.js +234 -224
- package/dist/rich-text/prism.js +16 -18
- package/dist/rich-text/static.d.ts +6 -0
- package/dist/rich-text/static.js +229 -225
- package/dist/tina-cms.d.ts +1 -1
- package/dist/toolkit/components/ProgressBar.d.ts +11 -0
- package/dist/toolkit/components/active-field-indicator.d.ts +1 -0
- package/dist/toolkit/components/media/media-item.d.ts +10 -0
- 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/components/password-field.d.ts +1 -1
- package/dist/toolkit/fields/components/reference/components/button.d.ts +1 -1
- package/dist/toolkit/fields/components/reference/components/command.d.ts +21 -33
- package/dist/toolkit/fields/components/select.d.ts +1 -1
- package/dist/toolkit/fields/components/text-field.d.ts +1 -1
- 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/dnd-kit-wrapper.d.ts +49 -0
- package/dist/toolkit/fields/plugins/group-list-field-plugin.d.ts +3 -1
- package/dist/toolkit/fields/plugins/list-field-plugin.d.ts +3 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/editor.d.ts +20 -18
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/blockquote-element.d.ts +14 -10
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/button.d.ts +5 -5
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/code-block-element.d.ts +17 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/error-message.d.ts +6 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-combobox.d.ts +6 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-toolbar-button.d.ts +6 -6
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-leaf.d.ts +2 -11
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-line-element.d.ts +14 -10
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-syntax-leaf.d.ts +2 -11
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/command.d.ts +112 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/dialog.d.ts +12 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/dropdown-menu.d.ts +10 -10
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/floating-toolbar.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/hr-element.d.ts +3 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/hr-toolbar-button.d.ts +18 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/icons.d.ts +2 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/image-toolbar-button.d.ts +6 -6
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/indent-list-toolbar-button.d.ts +6 -19
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/inline-combobox.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/input.d.ts +3 -3
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-element.d.ts +4 -11
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-floating-toolbar.d.ts +4 -5
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-toolbar-button.d.ts +4 -4
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/list-element.d.ts +28 -11
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mermaid-element.d.ts +3 -10
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mermaid-toolbar-button.d.ts +6 -8
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/paragraph-element.d.ts +15 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/popover.d.ts +7 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/quote-toolbar-button.d.ts +6 -6
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/raw-markdown-toolbar-button.d.ts +6 -6
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/resizable.d.ts +24 -21
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/separator.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/slash-input-element.d.ts +15 -11
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/block-selection.d.ts +6 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-cell-element.d.ts +33 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/{table-dropdown-menu.d.ts → table/table-dropdown-menu.d.ts} +1 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-element.d.ts +20 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-row-element.d.ts +15 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/toolbar.d.ts +7 -7
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-hook.d.ts +10 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-state.d.ts +22 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/hooks/use-create-editor.d.ts +6 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-block.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-lists.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-marks.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-utils.d.ts +3 -5
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/common.d.ts +11 -6
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/formatting.d.ts +18 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/index.d.ts +0 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-html-block/index.d.ts +6 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-img-plugin/index.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-invalid-markdown-plugin/index.d.ts +5 -5
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-mdx-plugins/component.d.ts +7 -4
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-mdx-plugins/index.d.ts +3 -5
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/editor-plugins.d.ts +520 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/components.d.ts +262 -207
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/floating-toolbar-plugin.d.ts +1 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/toolbar/toolbar-overrides.d.ts +1 -1
- 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/fields/plugins/wrap-field-with-meta.d.ts +6 -2
- package/dist/toolkit/form-builder/create-branch-modal.d.ts +13 -0
- package/dist/toolkit/form-builder/editorial-workflow-constants.d.ts +17 -0
- package/dist/toolkit/form-builder/fields-builder.d.ts +2 -1
- package/dist/toolkit/form-builder/form-builder.d.ts +1 -11
- package/dist/toolkit/form-builder/index.d.ts +1 -0
- package/dist/toolkit/forms/field.d.ts +3 -2
- package/dist/toolkit/icons/TinaExtended.d.ts +4 -0
- package/dist/toolkit/icons/index.d.ts +1 -0
- package/dist/toolkit/index.d.ts +1 -1
- package/dist/toolkit/plugin-branch-switcher/branch-button.d.ts +3 -1
- package/dist/toolkit/react-modals/modal/modal-actions.d.ts +2 -1
- package/dist/toolkit/react-modals/modal/modal-header.d.ts +1 -1
- package/dist/toolkit/react-sidebar/components/NavMenuTrigger.d.ts +11 -0
- package/dist/toolkit/react-sidebar/components/badge.d.ts +6 -0
- package/dist/toolkit/react-sidebar/components/callout.d.ts +5 -0
- package/dist/toolkit/react-sidebar/components/local-warning.d.ts +3 -1
- 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 -2
- package/dist/toolkit/react-sidebar/components/sidebar-body.d.ts +26 -1
- package/dist/toolkit/react-sidebar/index.d.ts +3 -0
- package/dist/toolkit/styles/button.d.ts +1 -1
- package/dist/toolkit/styles/dropdown-button.d.ts +75 -0
- package/dist/toolkit/styles/index.d.ts +1 -0
- package/dist/toolkit/tina-state.d.ts +42 -16
- package/dist/unifiedClient/index.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/package.json +56 -87
- package/dist/admin/pages/IndexingPage.d.ts +0 -2
- package/dist/client.mjs +0 -132
- package/dist/index.mjs +0 -35827
- package/dist/node-cache-5e8db9f0.mjs +0 -63
- package/dist/react.mjs +0 -254
- package/dist/rich-text/index.mjs +0 -243
- package/dist/rich-text/prism.mjs +0 -16
- package/dist/rich-text/static.mjs +0 -236
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-element.d.ts +0 -11
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-cell-element.d.ts +0 -27
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-element.d.ts +0 -14
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-row-element.d.ts +0 -13
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/with-correct-void-behavior.d.ts +0 -8
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-code-block/index.d.ts +0 -3
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-link-plugin/index.d.ts +0 -15
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/custom/mermaid-plugin.d.ts +0 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/create-soft-break-plugin.d.ts +0 -7
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/index.d.ts +0 -6
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/on-key-down-soft-break.d.ts +0 -5
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/types.d.ts +0 -11
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/code-block/index.d.ts +0 -11
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/transforms/insert-empty-block.d.ts +0 -2
- package/dist/toolkit/react-datetime/DateTime.d.ts +0 -135
- package/dist/toolkit/react-sidebar/components/alert.d.ts +0 -5
- /package/dist/admin/components/{Sidebar.d.ts → AdminNav.d.ts} +0 -0
package/dist/admin/api.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import type { TinaCMS } from '@tinacms/toolkit';
|
|
|
2
2
|
import type { Collection, TinaSchema } from '@tinacms/schema-tools';
|
|
3
3
|
import type { Client } from '../internalClient';
|
|
4
4
|
import type { CollectionResponse, DocumentForm } from './types';
|
|
5
|
-
import { SearchClient } from '@tinacms/search/
|
|
5
|
+
import { SearchClient } from '@tinacms/search/index-client';
|
|
6
|
+
export declare const CREATE_DOCUMENT_GQL = "#graphql\nmutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {\n createDocument(\n collection: $collection,\n relativePath: $relativePath,\n params: $params\n ){__typename}\n}";
|
|
7
|
+
export declare const UPDATE_DOCUMENT_GQL = "#graphql\nmutation($collection: String!, $relativePath: String!, $params: DocumentUpdateMutation!) {\n updateDocument(\n collection: $collection,\n relativePath: $relativePath,\n params: $params\n ){__typename}\n}";
|
|
8
|
+
export declare const DELETE_DOCUMENT_GQL = "#graphql\nmutation DeleteDocument($collection: String!, $relativePath: String!){\n deleteDocument(collection: $collection, relativePath: $relativePath){\n __typename\n }\n}";
|
|
6
9
|
export interface FilterArgs {
|
|
7
10
|
filterField: string;
|
|
8
11
|
collection?: string;
|
package/dist/auth/AuthModal.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ export interface TinaCloudAuthWallProps {
|
|
|
18
18
|
}[];
|
|
19
19
|
mediaStore?: TinaCloudMediaStoreClass | (() => Promise<TinaCloudMediaStoreClass>);
|
|
20
20
|
}
|
|
21
|
-
export declare const AuthWallInner: ({ children, cms, getModalActions, }: TinaCloudAuthWallProps) => React.JSX.Element;
|
|
22
21
|
/**
|
|
23
22
|
* Provides the ability to setup your CMS and media while also providing an authentication wall so Tina is not enabled without a valid user session.
|
|
24
23
|
*
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { Cache } from './index';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type FsModule = typeof import('node:fs');
|
|
3
|
+
type PathModule = typeof import('node:path');
|
|
4
|
+
type OsModule = typeof import('node:os');
|
|
5
|
+
export declare const makeCacheDir: (dir: string, fsArg: FsModule, pathArg: PathModule, osArg: OsModule) => string | null;
|
|
6
|
+
export declare const NodeCache: (dir: string) => Promise<Cache | null>;
|
|
7
|
+
export {};
|
package/dist/client.js
CHANGED
|
@@ -1,199 +1,258 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/cache/node-cache.ts
|
|
12
|
+
var node_cache_exports = {};
|
|
13
|
+
__export(node_cache_exports, {
|
|
14
|
+
NodeCache: () => NodeCache,
|
|
15
|
+
makeCacheDir: () => makeCacheDir
|
|
16
|
+
});
|
|
17
|
+
var resolveModule, getRootPath, makeCacheDir, NodeCache;
|
|
18
|
+
var init_node_cache = __esm({
|
|
19
|
+
"src/cache/node-cache.ts"() {
|
|
20
|
+
resolveModule = (mod) => {
|
|
21
|
+
if (mod && typeof mod === "object" && "default" in mod && mod.default) {
|
|
22
|
+
return mod.default;
|
|
23
|
+
}
|
|
24
|
+
return mod;
|
|
25
|
+
};
|
|
26
|
+
getRootPath = (pathParts, pathArg) => {
|
|
27
|
+
if (pathParts.length === 0) return null;
|
|
28
|
+
const isWindows = pathArg.sep === "\\";
|
|
29
|
+
const root = pathParts[0];
|
|
30
|
+
return isWindows ? `${root}${pathArg.sep}` : `${pathArg.sep}${root}`;
|
|
31
|
+
};
|
|
32
|
+
makeCacheDir = (dir, fsArg, pathArg, osArg) => {
|
|
33
|
+
const normalizedDir = pathArg.normalize(dir);
|
|
34
|
+
const pathParts = normalizedDir.split(pathArg.sep).filter(Boolean);
|
|
35
|
+
const cacheHash = pathParts[pathParts.length - 1];
|
|
36
|
+
const rootPath = getRootPath(pathParts, pathArg);
|
|
37
|
+
const rootExists = rootPath && fsArg.existsSync(rootPath);
|
|
38
|
+
const cacheDir = rootExists ? normalizedDir : pathArg.join(osArg.tmpdir(), cacheHash);
|
|
39
|
+
try {
|
|
40
|
+
fsArg.mkdirSync(cacheDir, { recursive: true });
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn(
|
|
43
|
+
`Warning: Failed to create cache directory: ${error.message}. Caching will be disabled.`
|
|
44
|
+
);
|
|
45
|
+
return null;
|
|
32
46
|
}
|
|
47
|
+
return cacheDir;
|
|
48
|
+
};
|
|
49
|
+
NodeCache = async (dir) => {
|
|
33
50
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
const [fsModule, pathModule, osModule, cryptoModule] = await Promise.all([
|
|
52
|
+
import("node:fs"),
|
|
53
|
+
import("node:path"),
|
|
54
|
+
import("node:os"),
|
|
55
|
+
import("node:crypto")
|
|
56
|
+
]);
|
|
57
|
+
const fs = resolveModule(fsModule);
|
|
58
|
+
const path = resolveModule(pathModule);
|
|
59
|
+
const os = resolveModule(osModule);
|
|
60
|
+
const crypto = resolveModule(cryptoModule);
|
|
61
|
+
if (typeof path?.join !== "function") {
|
|
62
|
+
console.warn(
|
|
63
|
+
"Warning: Node.js path module not available. Caching will be disabled."
|
|
64
|
+
);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const cacheDir = makeCacheDir(dir, fs, path, os);
|
|
68
|
+
if (cacheDir === null) {
|
|
69
|
+
return null;
|
|
38
70
|
}
|
|
71
|
+
return {
|
|
72
|
+
makeKey: (key) => {
|
|
73
|
+
const input = key && key instanceof Object ? JSON.stringify(key) : key || "";
|
|
74
|
+
return crypto.createHash("sha256").update(input).digest("hex");
|
|
75
|
+
},
|
|
76
|
+
get: async (key) => {
|
|
77
|
+
let readValue;
|
|
78
|
+
const cacheFilename = path.join(cacheDir, key);
|
|
79
|
+
try {
|
|
80
|
+
const data = await fs.promises.readFile(cacheFilename, "utf-8");
|
|
81
|
+
readValue = JSON.parse(data);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
if (e.code !== "ENOENT") {
|
|
84
|
+
console.warn(
|
|
85
|
+
`Warning: Failed to read cache file ${cacheFilename}: ${e.message}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return readValue;
|
|
90
|
+
},
|
|
91
|
+
set: async (key, value) => {
|
|
92
|
+
const cacheFilename = path.join(cacheDir, key);
|
|
93
|
+
try {
|
|
94
|
+
await fs.promises.writeFile(cacheFilename, JSON.stringify(value), {
|
|
95
|
+
encoding: "utf-8",
|
|
96
|
+
flag: "wx"
|
|
97
|
+
});
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (e.code !== "EEXIST") {
|
|
100
|
+
console.warn(
|
|
101
|
+
`Warning: Failed to write cache file ${cacheFilename}: ${e.message}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
39
107
|
} catch (e) {
|
|
40
|
-
console.
|
|
108
|
+
console.warn(
|
|
109
|
+
"Warning: Failed to initialize cache. Caching will be disabled.",
|
|
110
|
+
e.message
|
|
111
|
+
);
|
|
112
|
+
return null;
|
|
41
113
|
}
|
|
42
|
-
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// src/unifiedClient/index.ts
|
|
119
|
+
import AsyncLock from "async-lock";
|
|
120
|
+
var TINA_HOST = "content.tinajs.io";
|
|
121
|
+
function replaceGithubPathSplit(url, replacement) {
|
|
122
|
+
const parts = url.split("github/");
|
|
123
|
+
if (parts.length > 1 && replacement) {
|
|
124
|
+
return parts[0] + "github/" + replacement;
|
|
125
|
+
} else {
|
|
126
|
+
return url;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
var TinaClient = class {
|
|
130
|
+
apiUrl;
|
|
131
|
+
readonlyToken;
|
|
132
|
+
queries;
|
|
133
|
+
errorPolicy;
|
|
134
|
+
initialized = false;
|
|
135
|
+
cacheLock;
|
|
136
|
+
cacheDir;
|
|
137
|
+
cache;
|
|
138
|
+
constructor({
|
|
139
|
+
token,
|
|
140
|
+
url,
|
|
141
|
+
queries,
|
|
142
|
+
errorPolicy,
|
|
143
|
+
cacheDir
|
|
144
|
+
}) {
|
|
145
|
+
this.apiUrl = url;
|
|
146
|
+
this.readonlyToken = token?.trim();
|
|
147
|
+
this.queries = queries(this);
|
|
148
|
+
this.errorPolicy = errorPolicy || "throw";
|
|
149
|
+
this.cacheDir = cacheDir || "";
|
|
150
|
+
}
|
|
151
|
+
async init() {
|
|
152
|
+
if (this.initialized) {
|
|
153
|
+
return;
|
|
43
154
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
headers.append("X-API-KEY", this.readonlyToken);
|
|
51
|
-
}
|
|
52
|
-
headers.append("Content-Type", "application/json");
|
|
53
|
-
if (options == null ? void 0 : options.fetchOptions) {
|
|
54
|
-
if ((_a = options == null ? void 0 : options.fetchOptions) == null ? void 0 : _a.headers) {
|
|
55
|
-
Object.entries(options.fetchOptions.headers).forEach(([key2, value]) => {
|
|
56
|
-
headers.append(key2, value);
|
|
57
|
-
});
|
|
155
|
+
try {
|
|
156
|
+
if (this.cacheDir && typeof window === "undefined") {
|
|
157
|
+
const { NodeCache: NodeCache2 } = await Promise.resolve().then(() => (init_node_cache(), node_cache_exports));
|
|
158
|
+
this.cache = await NodeCache2(this.cacheDir);
|
|
159
|
+
if (this.cache) {
|
|
160
|
+
this.cacheLock = new AsyncLock();
|
|
58
161
|
}
|
|
59
162
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
query: args.query,
|
|
63
|
-
variables: (args == null ? void 0 : args.variables) || {}
|
|
64
|
-
});
|
|
65
|
-
const optionsObject = {
|
|
66
|
-
method: "POST",
|
|
67
|
-
headers,
|
|
68
|
-
body: bodyString,
|
|
69
|
-
redirect: "follow",
|
|
70
|
-
...providedFetchOptions
|
|
71
|
-
};
|
|
72
|
-
const draftBranch = headers.get("x-branch");
|
|
73
|
-
const url = replaceGithubPathSplit((args == null ? void 0 : args.url) || this.apiUrl, draftBranch);
|
|
74
|
-
let key = "";
|
|
75
|
-
let result;
|
|
76
|
-
if (this.cache) {
|
|
77
|
-
key = this.cache.makeKey(bodyString);
|
|
78
|
-
await this.cacheLock.acquire(key, async () => {
|
|
79
|
-
result = await this.cache.get(key);
|
|
80
|
-
if (!result) {
|
|
81
|
-
result = await requestFromServer(
|
|
82
|
-
url,
|
|
83
|
-
args.query,
|
|
84
|
-
optionsObject,
|
|
85
|
-
errorPolicyDefined
|
|
86
|
-
);
|
|
87
|
-
await this.cache.set(key, result);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
} else {
|
|
91
|
-
result = await requestFromServer(
|
|
92
|
-
url,
|
|
93
|
-
args.query,
|
|
94
|
-
optionsObject,
|
|
95
|
-
errorPolicyDefined
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
return result;
|
|
163
|
+
} catch (e) {
|
|
164
|
+
console.error(e);
|
|
99
165
|
}
|
|
166
|
+
this.initialized = true;
|
|
100
167
|
}
|
|
101
|
-
async
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
168
|
+
async request({ errorPolicy, ...args }, options) {
|
|
169
|
+
await this.init();
|
|
170
|
+
const errorPolicyDefined = errorPolicy || this.errorPolicy;
|
|
171
|
+
const headers = new Headers();
|
|
172
|
+
if (this.readonlyToken) {
|
|
173
|
+
headers.append("X-API-KEY", this.readonlyToken);
|
|
174
|
+
}
|
|
175
|
+
headers.append("Content-Type", "application/json");
|
|
176
|
+
if (options?.fetchOptions) {
|
|
177
|
+
if (options?.fetchOptions?.headers) {
|
|
178
|
+
Object.entries(options.fetchOptions.headers).forEach(([key2, value]) => {
|
|
179
|
+
headers.append(key2, value);
|
|
180
|
+
});
|
|
107
181
|
}
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
|
|
110
|
-
);
|
|
111
182
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
183
|
+
const { headers: _, ...providedFetchOptions } = options?.fetchOptions || {};
|
|
184
|
+
const bodyString = JSON.stringify({
|
|
185
|
+
query: args.query,
|
|
186
|
+
variables: args?.variables || {}
|
|
187
|
+
});
|
|
188
|
+
const optionsObject = {
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers,
|
|
191
|
+
body: bodyString,
|
|
192
|
+
redirect: "follow",
|
|
193
|
+
...providedFetchOptions
|
|
194
|
+
};
|
|
195
|
+
const draftBranch = headers.get("x-branch");
|
|
196
|
+
const url = replaceGithubPathSplit(args?.url || this.apiUrl, draftBranch);
|
|
197
|
+
let key = "";
|
|
198
|
+
let result;
|
|
199
|
+
if (this.cache) {
|
|
200
|
+
key = this.cache.makeKey(bodyString);
|
|
201
|
+
await this.cacheLock.acquire(key, async () => {
|
|
202
|
+
result = await this.cache.get(key);
|
|
203
|
+
if (!result) {
|
|
204
|
+
result = await requestFromServer(
|
|
205
|
+
url,
|
|
206
|
+
args.query,
|
|
207
|
+
optionsObject,
|
|
208
|
+
errorPolicyDefined
|
|
209
|
+
);
|
|
210
|
+
await this.cache.set(key, result);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
} else {
|
|
214
|
+
result = await requestFromServer(
|
|
215
|
+
url,
|
|
216
|
+
args.query,
|
|
217
|
+
optionsObject,
|
|
218
|
+
errorPolicyDefined
|
|
118
219
|
);
|
|
119
220
|
}
|
|
120
|
-
const result = {
|
|
121
|
-
data: json == null ? void 0 : json.data,
|
|
122
|
-
errors: (json == null ? void 0 : json.errors) || null,
|
|
123
|
-
query
|
|
124
|
-
};
|
|
125
221
|
return result;
|
|
126
222
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const rootUser = pathParts[0];
|
|
135
|
-
let cacheDir = dir;
|
|
136
|
-
if (!fs.existsSync(path.join(path.sep, rootUser))) {
|
|
137
|
-
cacheDir = path.join(os.tmpdir(), cacheHash);
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
141
|
-
} catch (error) {
|
|
142
|
-
throw new Error(`Failed to create cache directory: ${error.message}`);
|
|
223
|
+
};
|
|
224
|
+
async function requestFromServer(url, query, optionsObject, errorPolicyDefined) {
|
|
225
|
+
const res = await fetch(url, optionsObject);
|
|
226
|
+
if (!res.ok) {
|
|
227
|
+
let additionalInfo = "";
|
|
228
|
+
if (res.status === 401) {
|
|
229
|
+
additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
|
|
143
230
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
const data = await fs.promises.readFile(cacheFilename, "utf-8");
|
|
162
|
-
readValue = JSON.parse(data);
|
|
163
|
-
} catch (e) {
|
|
164
|
-
if (e.code !== "ENOENT") {
|
|
165
|
-
console.error(
|
|
166
|
-
`Failed to read cache file to ${cacheFilename}: ${e.message}`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return readValue;
|
|
171
|
-
},
|
|
172
|
-
set: async (key, value) => {
|
|
173
|
-
const cacheFilename = `${cacheDir}/${key}`;
|
|
174
|
-
try {
|
|
175
|
-
await fs.promises.writeFile(cacheFilename, JSON.stringify(value), {
|
|
176
|
-
encoding: "utf-8",
|
|
177
|
-
flag: "wx"
|
|
178
|
-
// Don't overwrite existing caches
|
|
179
|
-
});
|
|
180
|
-
} catch (e) {
|
|
181
|
-
if (e.code !== "EEXIST") {
|
|
182
|
-
console.error(
|
|
183
|
-
`Failed to write cache file to ${cacheFilename}: ${e.message}`
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
};
|
|
231
|
+
throw new Error(
|
|
232
|
+
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/r/FAQ/`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const json = await res.json();
|
|
236
|
+
if (json.errors && errorPolicyDefined === "throw") {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`Unable to fetch, please see our FAQ for more information: https://tina.io/docs/r/FAQ/
|
|
239
|
+
Errors:
|
|
240
|
+
${json.errors.map((error) => error.message).join("\n")}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
const result = {
|
|
244
|
+
data: json?.data,
|
|
245
|
+
errors: json?.errors || null,
|
|
246
|
+
query
|
|
189
247
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
function createClient(args) {
|
|
251
|
+
const client = new TinaClient(args);
|
|
252
|
+
return client;
|
|
253
|
+
}
|
|
254
|
+
export {
|
|
255
|
+
TINA_HOST,
|
|
256
|
+
TinaClient,
|
|
257
|
+
createClient
|
|
258
|
+
};
|