tinacms 0.0.0-9d5e351-20241023053720 → 0.0.0-9e83b99-20250316235714

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.
Files changed (27) hide show
  1. package/dist/admin/api.d.ts +1 -0
  2. package/dist/admin/types.d.ts +3 -0
  3. package/dist/auth/TinaCloudProvider.d.ts +1 -1
  4. package/dist/cache/node-cache.d.ts +1 -0
  5. package/dist/client.js +83 -63
  6. package/dist/client.mjs +49 -35
  7. package/dist/hooks/create-page-plugin.d.ts +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +1839 -635
  10. package/dist/index.mjs +1856 -652
  11. package/dist/node-cache-5e8db9f0.mjs +63 -0
  12. package/dist/react.d.ts +1 -0
  13. package/dist/react.js +10 -1
  14. package/dist/react.mjs +10 -1
  15. package/dist/toolkit/fields/components/reference/reference-select.d.ts +2 -2
  16. package/dist/toolkit/fields/plugins/mdx-field-plugin/index.d.ts +4 -1
  17. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/indent-list-toolbar-button.d.ts +17 -5
  18. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mark-toolbar-button.d.ts +4 -18
  19. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/index.d.ts +1 -1
  20. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/components.d.ts +6 -11
  21. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/toolbar/toolbar-overrides.d.ts +5 -1
  22. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/toolbar/toolbar-provider.d.ts +2 -2
  23. package/dist/toolkit/fields/plugins/wrap-field-with-meta.d.ts +8 -0
  24. package/dist/unifiedClient/index.d.ts +8 -1
  25. package/package.json +40 -40
  26. package/dist/__vite-browser-external-d06ac358.mjs +0 -4
  27. package/dist/node-cache-8f9e873e.mjs +0 -52
@@ -7,6 +7,7 @@ export interface FilterArgs {
7
7
  filterField: string;
8
8
  collection?: string;
9
9
  relativePath?: string;
10
+ relativePathWithoutExtension?: string;
10
11
  newRelativePath?: string;
11
12
  startsWith?: string;
12
13
  endsWith?: string;
@@ -25,6 +25,9 @@ export interface DocumentNode {
25
25
  }
26
26
  export interface DocumentForm {
27
27
  _values: Object;
28
+ _sys?: {
29
+ hasReferences?: boolean;
30
+ };
28
31
  }
29
32
  export interface DocumentSys {
30
33
  _sys: {
@@ -1,5 +1,5 @@
1
+ import { MediaStore, StaticMedia, TinaCMS } from '@tinacms/toolkit';
1
2
  import React from 'react';
2
- import { TinaCMS, MediaStore, StaticMedia } from '@tinacms/toolkit';
3
3
  import { Client, TinaIOConfig } from '../internalClient';
4
4
  import { CreateClientProps } from '../utils';
5
5
  export interface TinaCloudMediaStoreClass {
@@ -1,2 +1,3 @@
1
1
  import type { Cache } from './index';
2
+ export declare const makeCacheDir: (dir: string, fs: any, path: any, os: any) => Promise<string>;
2
3
  export declare const NodeCache: (dir: string) => Promise<Cache>;
package/dist/client.js CHANGED
@@ -1,10 +1,7 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("fetch-ponyfill")) : typeof define === "function" && define.amd ? define(["exports", "fetch-ponyfill"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}, global.NOOP));
3
- })(this, function(exports2, fetchPonyfill) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("async-lock")) : typeof define === "function" && define.amd ? define(["exports", "async-lock"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}, global.NOOP));
3
+ })(this, function(exports2, AsyncLock) {
4
4
  "use strict";
5
- const { fetch: fetchPonyfillFN, Headers: HeadersPonyfill } = fetchPonyfill();
6
- const fetchDefined = typeof fetch === "undefined" ? fetchPonyfillFN : fetch;
7
- const HeadersDefined = typeof Headers === "undefined" ? HeadersPonyfill : Headers;
8
5
  const TINA_HOST = "content.tinajs.io";
9
6
  class TinaClient {
10
7
  constructor({
@@ -29,6 +26,7 @@
29
26
  if (this.cacheDir && typeof window === "undefined" && typeof require !== "undefined") {
30
27
  const { NodeCache: NodeCache2 } = await Promise.resolve().then(() => nodeCache);
31
28
  this.cache = await NodeCache2(this.cacheDir);
29
+ this.cacheLock = new AsyncLock();
32
30
  }
33
31
  } catch (e) {
34
32
  console.error(e);
@@ -39,7 +37,7 @@
39
37
  var _a;
40
38
  await this.init();
41
39
  const errorPolicyDefined = errorPolicy || this.errorPolicy;
42
- const headers = new HeadersDefined();
40
+ const headers = new Headers();
43
41
  if (this.readonlyToken) {
44
42
  headers.append("X-API-KEY", this.readonlyToken);
45
43
  }
@@ -65,56 +63,68 @@
65
63
  ...providedFetchOptions
66
64
  };
67
65
  let key = "";
66
+ let result;
68
67
  if (this.cache) {
69
68
  key = this.cache.makeKey(bodyString);
70
- const value = await this.cache.get(key);
71
- if (value) {
72
- return value;
73
- }
74
- }
75
- const res = await fetchDefined(url, optionsObject);
76
- if (!res.ok) {
77
- let additionalInfo = "";
78
- if (res.status === 401) {
79
- additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
80
- }
81
- throw new Error(
82
- `Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
83
- );
84
- }
85
- const json = await res.json();
86
- if (json.errors && errorPolicyDefined === "throw") {
87
- throw new Error(
88
- `Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
89
- Errors:
90
- ${json.errors.map((error) => error.message).join("\n")}`
69
+ await this.cacheLock.acquire(key, async () => {
70
+ result = await this.cache.get(key);
71
+ if (!result) {
72
+ result = await requestFromServer(
73
+ url,
74
+ args.query,
75
+ optionsObject,
76
+ errorPolicyDefined
77
+ );
78
+ await this.cache.set(key, result);
79
+ }
80
+ });
81
+ } else {
82
+ result = await requestFromServer(
83
+ url,
84
+ args.query,
85
+ optionsObject,
86
+ errorPolicyDefined
91
87
  );
92
88
  }
93
- const result = {
94
- data: json == null ? void 0 : json.data,
95
- errors: (json == null ? void 0 : json.errors) || null,
96
- query: args.query
97
- };
98
- if (this.cache) {
99
- await this.cache.set(key, result);
100
- }
101
89
  return result;
102
90
  }
103
91
  }
92
+ async function requestFromServer(url, query, optionsObject, errorPolicyDefined) {
93
+ const res = await fetch(url, optionsObject);
94
+ if (!res.ok) {
95
+ let additionalInfo = "";
96
+ if (res.status === 401) {
97
+ additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
98
+ }
99
+ throw new Error(
100
+ `Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
101
+ );
102
+ }
103
+ const json = await res.json();
104
+ if (json.errors && errorPolicyDefined === "throw") {
105
+ throw new Error(
106
+ `Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
107
+ Errors:
108
+ ${json.errors.map((error) => error.message).join("\n")}`
109
+ );
110
+ }
111
+ const result = {
112
+ data: json == null ? void 0 : json.data,
113
+ errors: (json == null ? void 0 : json.errors) || null,
114
+ query
115
+ };
116
+ return result;
117
+ }
104
118
  function createClient(args) {
105
119
  const client = new TinaClient(args);
106
120
  return client;
107
121
  }
108
- const makeCacheDir = async (dir, fs) => {
109
- const path = await Promise.resolve().then(() => __viteBrowserExternal$1);
110
- const os = await Promise.resolve().then(() => __viteBrowserExternal$1);
111
- if (typeof dir !== "string" || !dir.trim()) {
112
- throw new Error("Invalid directory path");
113
- }
114
- const pathParts = dir.split(path.sep);
122
+ const makeCacheDir = async (dir, fs, path, os) => {
123
+ const pathParts = dir.split(path.sep).filter(Boolean);
115
124
  const cacheHash = pathParts[pathParts.length - 1];
125
+ const rootUser = pathParts[0];
116
126
  let cacheDir = dir;
117
- if (!fs.existsSync(dir)) {
127
+ if (!fs.existsSync(path.join(path.sep, rootUser))) {
118
128
  cacheDir = path.join(os.tmpdir(), cacheHash);
119
129
  }
120
130
  try {
@@ -125,43 +135,53 @@
125
135
  return cacheDir;
126
136
  };
127
137
  const NodeCache = async (dir) => {
128
- const fs = (await Promise.resolve().then(() => __viteBrowserExternal$1)).default;
129
- console.log("fs", JSON.stringify(fs));
130
- const { createHash } = await Promise.resolve().then(() => __viteBrowserExternal$1);
131
- const cacheDir = await makeCacheDir(dir, fs);
138
+ const fs = require("node:fs");
139
+ const path = require("node:path");
140
+ const os = require("node:os");
141
+ const { createHash } = require("node:crypto");
142
+ const cacheDir = await makeCacheDir(dir, fs, path, os);
132
143
  return {
133
144
  makeKey: (key) => {
134
145
  const input = key && key instanceof Object ? JSON.stringify(key) : key || "";
135
146
  return createHash("sha256").update(input).digest("hex");
136
147
  },
137
148
  get: async (key) => {
149
+ let readValue;
150
+ const cacheFilename = `${cacheDir}/${key}`;
138
151
  try {
139
- const data = await fs.promises.readFile(`${cacheDir}/${key}`, "utf-8");
140
- return JSON.parse(data);
152
+ const data = await fs.promises.readFile(cacheFilename, "utf-8");
153
+ readValue = JSON.parse(data);
141
154
  } catch (e) {
142
- if (e.code === "ENOENT") {
143
- return void 0;
155
+ if (e.code !== "ENOENT") {
156
+ console.error(
157
+ `Failed to read cache file to ${cacheFilename}: ${e.message}`
158
+ );
144
159
  }
145
- throw e;
146
160
  }
161
+ return readValue;
147
162
  },
148
163
  set: async (key, value) => {
149
- await fs.promises.writeFile(
150
- `${cacheDir}/${key}`,
151
- JSON.stringify(value),
152
- "utf-8"
153
- );
164
+ const cacheFilename = `${cacheDir}/${key}`;
165
+ try {
166
+ await fs.promises.writeFile(cacheFilename, JSON.stringify(value), {
167
+ encoding: "utf-8",
168
+ flag: "wx"
169
+ // Don't overwrite existing caches
170
+ });
171
+ } catch (e) {
172
+ if (e.code !== "EEXIST") {
173
+ console.error(
174
+ `Failed to write cache file to ${cacheFilename}: ${e.message}`
175
+ );
176
+ }
177
+ }
154
178
  }
155
179
  };
156
180
  };
157
181
  const nodeCache = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
158
182
  __proto__: null,
159
- NodeCache
160
- }, Symbol.toStringTag, { value: "Module" }));
161
- const __viteBrowserExternal = {};
162
- const __viteBrowserExternal$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
163
- __proto__: null,
164
- default: __viteBrowserExternal
183
+ NodeCache,
184
+ makeCacheDir
165
185
  }, Symbol.toStringTag, { value: "Module" }));
166
186
  exports2.TINA_HOST = TINA_HOST;
167
187
  exports2.TinaClient = TinaClient;
package/dist/client.mjs CHANGED
@@ -1,7 +1,4 @@
1
- import fetchPonyfill from "fetch-ponyfill";
2
- const { fetch: fetchPonyfillFN, Headers: HeadersPonyfill } = fetchPonyfill();
3
- const fetchDefined = typeof fetch === "undefined" ? fetchPonyfillFN : fetch;
4
- const HeadersDefined = typeof Headers === "undefined" ? HeadersPonyfill : Headers;
1
+ import AsyncLock from "async-lock";
5
2
  const TINA_HOST = "content.tinajs.io";
6
3
  class TinaClient {
7
4
  constructor({
@@ -24,8 +21,9 @@ class TinaClient {
24
21
  }
25
22
  try {
26
23
  if (this.cacheDir && typeof window === "undefined" && typeof require !== "undefined") {
27
- const { NodeCache } = await import("./node-cache-8f9e873e.mjs");
24
+ const { NodeCache } = await import("./node-cache-5e8db9f0.mjs");
28
25
  this.cache = await NodeCache(this.cacheDir);
26
+ this.cacheLock = new AsyncLock();
29
27
  }
30
28
  } catch (e) {
31
29
  console.error(e);
@@ -36,7 +34,7 @@ class TinaClient {
36
34
  var _a;
37
35
  await this.init();
38
36
  const errorPolicyDefined = errorPolicy || this.errorPolicy;
39
- const headers = new HeadersDefined();
37
+ const headers = new Headers();
40
38
  if (this.readonlyToken) {
41
39
  headers.append("X-API-KEY", this.readonlyToken);
42
40
  }
@@ -62,42 +60,58 @@ class TinaClient {
62
60
  ...providedFetchOptions
63
61
  };
64
62
  let key = "";
63
+ let result;
65
64
  if (this.cache) {
66
65
  key = this.cache.makeKey(bodyString);
67
- const value = await this.cache.get(key);
68
- if (value) {
69
- return value;
70
- }
71
- }
72
- const res = await fetchDefined(url, optionsObject);
73
- if (!res.ok) {
74
- let additionalInfo = "";
75
- if (res.status === 401) {
76
- additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
77
- }
78
- throw new Error(
79
- `Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
66
+ await this.cacheLock.acquire(key, async () => {
67
+ result = await this.cache.get(key);
68
+ if (!result) {
69
+ result = await requestFromServer(
70
+ url,
71
+ args.query,
72
+ optionsObject,
73
+ errorPolicyDefined
74
+ );
75
+ await this.cache.set(key, result);
76
+ }
77
+ });
78
+ } else {
79
+ result = await requestFromServer(
80
+ url,
81
+ args.query,
82
+ optionsObject,
83
+ errorPolicyDefined
80
84
  );
81
85
  }
82
- const json = await res.json();
83
- if (json.errors && errorPolicyDefined === "throw") {
84
- throw new Error(
85
- `Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
86
- Errors:
87
- ${json.errors.map((error) => error.message).join("\n")}`
88
- );
89
- }
90
- const result = {
91
- data: json == null ? void 0 : json.data,
92
- errors: (json == null ? void 0 : json.errors) || null,
93
- query: args.query
94
- };
95
- if (this.cache) {
96
- await this.cache.set(key, result);
97
- }
98
86
  return result;
99
87
  }
100
88
  }
89
+ async function requestFromServer(url, query, optionsObject, errorPolicyDefined) {
90
+ const res = await fetch(url, optionsObject);
91
+ if (!res.ok) {
92
+ let additionalInfo = "";
93
+ if (res.status === 401) {
94
+ additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
95
+ }
96
+ throw new Error(
97
+ `Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
98
+ );
99
+ }
100
+ const json = await res.json();
101
+ if (json.errors && errorPolicyDefined === "throw") {
102
+ throw new Error(
103
+ `Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
104
+ Errors:
105
+ ${json.errors.map((error) => error.message).join("\n")}`
106
+ );
107
+ }
108
+ const result = {
109
+ data: json == null ? void 0 : json.data,
110
+ errors: (json == null ? void 0 : json.errors) || null,
111
+ query
112
+ };
113
+ return result;
114
+ }
101
115
  function createClient(args) {
102
116
  const client = new TinaClient(args);
103
117
  return client;
@@ -29,7 +29,7 @@ export type OnNewDocument = (args: {
29
29
  path: string;
30
30
  }) => void;
31
31
  export declare class ContentCreatorPlugin implements AddContentPlugin<FormShape> {
32
- __type: 'content-creator';
32
+ __type: "content-creator";
33
33
  fields: AddContentPlugin<FormShape>['fields'];
34
34
  onNewDocument?: OnNewDocument;
35
35
  onChange: (values: any) => void;
package/dist/index.d.ts CHANGED
@@ -53,7 +53,7 @@ export type TinaCollection = Collection;
53
53
  export type TinaCloudSchema = Schema;
54
54
  export declare const defineSchema: (config: Schema) => Schema<false>;
55
55
  export declare const defineLegacyConfig: (config: Omit<TinaCMSProviderDefaultProps, "children">) => Omit<TinaCMSProviderDefaultProps, "children">;
56
- interface MediaStoreClass {
56
+ export interface MediaStoreClass {
57
57
  new (...args: any[]): MediaStore;
58
58
  }
59
59
  export declare const defineStaticConfig: (config: Config<(cms: TinaCMS) => TinaCMS, formifyCallback, DocumentCreatorCallback, MediaStoreClass>) => Config<(cms: TinaCMS) => TinaCMS, formifyCallback, import("./hooks/use-content-creator").DocumentCreatorArgs, MediaStoreClass, undefined>;