@tinacms/datalayer 0.1.1 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # tina-graphql
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4daf15b36: Updated matching logic to only return the correct extension.
8
+
9
+ This means if you are using any other files besides `.md` the format must be provided in the schema.
10
+
11
+ ```ts
12
+ // .tina/schema.ts
13
+
14
+ import { defineSchema } from 'tinacms'
15
+
16
+ const schema = defineSchema({
17
+ collections: [
18
+ {
19
+ name: 'page',
20
+ path: 'content/page',
21
+ label: 'Page',
22
+ // Need to provide the format if the file being used (default is `.md`)
23
+ format: 'mdx',
24
+ fields: [
25
+ //...
26
+ ],
27
+ },
28
+ ],
29
+ })
30
+ //...
31
+
32
+ export default schema
33
+ ```
34
+
35
+ ### Patch Changes
36
+
37
+ - b348f8b6b: Experimental isomorphic git bridge implementation
38
+
3
39
  ## 0.1.1
4
40
 
5
41
  ### Patch Changes
@@ -19,7 +19,7 @@ import type { Bridge } from './index';
19
19
  export declare class FilesystemBridge implements Bridge {
20
20
  rootPath: string;
21
21
  constructor(rootPath: string);
22
- glob(pattern: string): Promise<string[]>;
22
+ glob(pattern: string, extension: string): Promise<string[]>;
23
23
  supportsBuilding(): boolean;
24
24
  delete(filepath: string): Promise<void>;
25
25
  get(filepath: string): Promise<string>;
@@ -12,7 +12,8 @@ limitations under the License.
12
12
  */
13
13
  export interface Bridge {
14
14
  rootPath: string;
15
- glob(pattern: string): Promise<string[]>;
15
+ glob(pattern: string, extension: string): Promise<string[]>;
16
+ delete(filepath: string): Promise<void>;
16
17
  get(filepath: string): Promise<string>;
17
18
  put(filepath: string, data: string): Promise<void>;
18
19
  /**
@@ -0,0 +1,108 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ import { CallbackFsClient, PromiseFsClient } from 'isomorphic-git';
14
+ import type { Bridge } from './index';
15
+ export declare type IsomorphicGitBridgeOptions = {
16
+ gitRoot: string;
17
+ fsModule?: CallbackFsClient | PromiseFsClient;
18
+ commitMessage?: string;
19
+ author: {
20
+ name: string;
21
+ email: string;
22
+ };
23
+ committer?: {
24
+ name: string;
25
+ email: string;
26
+ };
27
+ ref?: string;
28
+ onPut?: (filepath: string, data: string) => Promise<void>;
29
+ onDelete?: (filepath: string) => Promise<void>;
30
+ };
31
+ /**
32
+ * Bridge backed by isomorphic-git
33
+ */
34
+ export declare class IsomorphicBridge implements Bridge {
35
+ rootPath: string;
36
+ relativePath: string;
37
+ gitRoot: string;
38
+ fsModule: CallbackFsClient | PromiseFsClient;
39
+ isomorphicConfig: {
40
+ fs: CallbackFsClient | PromiseFsClient;
41
+ dir: string;
42
+ };
43
+ commitMessage: string;
44
+ author: {
45
+ name: string;
46
+ email: string;
47
+ };
48
+ committer: {
49
+ name: string;
50
+ email: string;
51
+ };
52
+ ref: string | undefined;
53
+ private readonly onPut;
54
+ private readonly onDelete;
55
+ private cache;
56
+ constructor(rootPath: string, { gitRoot, author, committer, fsModule, commitMessage, ref, onPut, onDelete, }: IsomorphicGitBridgeOptions);
57
+ private getAuthor;
58
+ private getCommitter;
59
+ /**
60
+ * Recursively populate paths matching `pattern` for the given `entry`
61
+ *
62
+ * @param pattern - pattern to filter paths by
63
+ * @param entry - TreeEntry to start building list from
64
+ * @param path - base path
65
+ * @param results
66
+ * @private
67
+ */
68
+ private listEntries;
69
+ /**
70
+ * For the specified path, returns an object with an array containing the parts of the path (pathParts)
71
+ * and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
72
+ * pathEntries are placeholders for non-existent entries.
73
+ *
74
+ * @param path - path being resolved
75
+ * @param ref - ref to resolve path entries for
76
+ * @private
77
+ */
78
+ private resolvePathEntries;
79
+ /**
80
+ * Updates tree entry and associated parent tree entries
81
+ *
82
+ * @param existingOid - the existing OID
83
+ * @param updatedOid - the updated OID
84
+ * @param path - the path of the entry being updated
85
+ * @param type - the type of the entry being updated (blob or tree)
86
+ * @param pathEntries - parent path entries
87
+ * @param pathParts - parent path parts
88
+ * @private
89
+ */
90
+ private updateTreeHierarchy;
91
+ /**
92
+ * Creates a commit for the specified tree and updates the specified ref to point to the commit
93
+ *
94
+ * @param treeSha - sha of the new tree
95
+ * @param ref - the ref that should be updated
96
+ * @private
97
+ */
98
+ private commitTree;
99
+ private getRef;
100
+ glob(pattern: string, extension: string): Promise<string[]>;
101
+ supportsBuilding(): boolean;
102
+ delete(filepath: string): Promise<void>;
103
+ private qualifyPath;
104
+ private unqualifyPath;
105
+ get(filepath: string): Promise<string>;
106
+ putConfig(filepath: string, data: string): Promise<void>;
107
+ put(filepath: string, data: string): Promise<void>;
108
+ }
@@ -18,12 +18,12 @@ export declare class FilesystemStore implements Store {
18
18
  constructor({ rootPath }: {
19
19
  rootPath?: string;
20
20
  });
21
- query(queryOptions: StoreQueryOptions): Promise<StoreQueryResponse>;
21
+ query(_queryOptions: StoreQueryOptions): Promise<StoreQueryResponse>;
22
22
  seed(): Promise<void>;
23
23
  get<T extends object>(filepath: string): Promise<T>;
24
24
  supportsSeeding(): boolean;
25
25
  supportsIndexing(): boolean;
26
- glob(pattern: string, callback: any): Promise<any[]>;
26
+ glob(pattern: string, callback: any, extension: any): Promise<any[]>;
27
27
  put(filepath: string, data: object, options?: PutOptions): Promise<void>;
28
28
  open(): Promise<void>;
29
29
  close(): Promise<void>;
@@ -89,7 +89,7 @@ export declare type DeleteOptions = SeedOptions & {
89
89
  seed?: boolean;
90
90
  };
91
91
  export interface Store {
92
- glob(pattern: string, hydrator?: (fullPath: string) => Promise<object>): Promise<string[]>;
92
+ glob(pattern: string, hydrator?: (fullPath: string) => Promise<object>, extension?: string): Promise<string[]>;
93
93
  get<T extends object>(filepath: string): Promise<T>;
94
94
  delete(filepath: string, options?: DeleteOptions): Promise<void>;
95
95
  clear(): void;
@@ -1,15 +1,15 @@
1
1
  /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
13
  import type { StoreQueryOptions, StoreQueryResponse, PutOptions, DeleteOptions, SeedOptions, Store } from './index';
14
14
  import { LevelDB } from 'level';
15
15
  export declare class LevelStore implements Store {
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  export { FilesystemBridge, AuditFileSystemBridge, } from './database/bridge/filesystem';
14
+ export { IsomorphicBridge } from './database/bridge/isomorphic';
14
15
  export { FilesystemStore, AuditFilesystemStore, } from './database/store/filesystem';
15
16
  export { LevelStore } from './database/store/level';
16
17
  export { coerceFilterChainOperands, DEFAULT_COLLECTION_SORT_KEY, DEFAULT_NUMERIC_LPAD, INDEX_KEY_FIELD_SEPARATOR, makeFilter, makeFilterChain, makeFilterSuffixes, makeKeyForField, makeStringEscaper, OP, } from './database/store';
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ __export(exports, {
60
60
  FilesystemBridge: () => FilesystemBridge,
61
61
  FilesystemStore: () => FilesystemStore,
62
62
  INDEX_KEY_FIELD_SEPARATOR: () => INDEX_KEY_FIELD_SEPARATOR,
63
+ IsomorphicBridge: () => IsomorphicBridge,
63
64
  LevelStore: () => LevelStore,
64
65
  OP: () => OP,
65
66
  atob: () => atob,
@@ -81,9 +82,9 @@ var FilesystemBridge = class {
81
82
  constructor(rootPath) {
82
83
  this.rootPath = rootPath || "";
83
84
  }
84
- async glob(pattern) {
85
+ async glob(pattern, extension) {
85
86
  const basePath = import_path.default.join(this.rootPath, ...pattern.split("/"));
86
- const items = await (0, import_fast_glob.default)(import_path.default.join(basePath, "**", "/*").replace(/\\/g, "/"), {
87
+ const items = await (0, import_fast_glob.default)(import_path.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"), {
87
88
  dot: true
88
89
  });
89
90
  const posixRootPath = (0, import_normalize_path.default)(this.rootPath);
@@ -113,18 +114,335 @@ var AuditFileSystemBridge = class extends FilesystemBridge {
113
114
  }
114
115
  };
115
116
 
116
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/store/filesystem.ts
117
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/bridge/isomorphic.ts
118
+ var import_isomorphic_git = __toModule(require("isomorphic-git"));
117
119
  var import_fs_extra2 = __toModule(require("fs-extra"));
120
+ var import_glob_parent = __toModule(require("glob-parent"));
121
+ var import_normalize_path2 = __toModule(require("normalize-path"));
122
+ var import_graphql = __toModule(require("graphql"));
123
+ var flat = typeof Array.prototype.flat === "undefined" ? (entries) => entries.reduce((acc, x) => acc.concat(x), []) : (entries) => entries.flat();
124
+ var toUint8Array = (buf) => {
125
+ const ab = new ArrayBuffer(buf.length);
126
+ const view = new Uint8Array(ab);
127
+ for (let i = 0; i < buf.length; ++i) {
128
+ view[i] = buf[i];
129
+ }
130
+ return view;
131
+ };
132
+ var IsomorphicBridge = class {
133
+ constructor(rootPath, {
134
+ gitRoot,
135
+ author,
136
+ committer,
137
+ fsModule = import_fs_extra2.default,
138
+ commitMessage = "Update from GraphQL client",
139
+ ref,
140
+ onPut,
141
+ onDelete
142
+ }) {
143
+ this.cache = {};
144
+ this.rootPath = rootPath;
145
+ this.gitRoot = gitRoot;
146
+ this.relativePath = rootPath.slice(this.gitRoot.length).replace(/\\/g, "/");
147
+ if (this.relativePath.startsWith("/")) {
148
+ this.relativePath = this.relativePath.slice(1);
149
+ }
150
+ this.fsModule = fsModule;
151
+ this.author = author;
152
+ this.committer = committer || author;
153
+ this.isomorphicConfig = {
154
+ dir: (0, import_normalize_path2.default)(this.gitRoot),
155
+ fs: this.fsModule
156
+ };
157
+ this.ref = ref;
158
+ this.commitMessage = commitMessage;
159
+ this.onPut = onPut || (() => {
160
+ });
161
+ this.onDelete = onDelete || (() => {
162
+ });
163
+ }
164
+ getAuthor() {
165
+ return __spreadProps(__spreadValues({}, this.author), {
166
+ timestamp: Math.round(new Date().getTime() / 1e3),
167
+ timezoneOffset: 0
168
+ });
169
+ }
170
+ getCommitter() {
171
+ return __spreadProps(__spreadValues({}, this.committer), {
172
+ timestamp: Math.round(new Date().getTime() / 1e3),
173
+ timezoneOffset: 0
174
+ });
175
+ }
176
+ async listEntries({
177
+ pattern,
178
+ entry,
179
+ path: path4,
180
+ results
181
+ }) {
182
+ const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
183
+ oid: entry.oid,
184
+ cache: this.cache
185
+ }));
186
+ const children = [];
187
+ for (const childEntry of treeResult.tree) {
188
+ const childPath = path4 ? `${path4}/${childEntry.path}` : childEntry.path;
189
+ if (childEntry.type === "tree") {
190
+ children.push(childEntry);
191
+ } else {
192
+ if (childPath.startsWith(pattern)) {
193
+ results.push(childPath);
194
+ }
195
+ }
196
+ }
197
+ for (const childEntry of children) {
198
+ const childPath = path4 ? `${path4}/${childEntry.path}` : childEntry.path;
199
+ await this.listEntries({
200
+ pattern,
201
+ entry: childEntry,
202
+ path: childPath,
203
+ results
204
+ });
205
+ }
206
+ }
207
+ async resolvePathEntries(path4, ref) {
208
+ let pathParts = path4.split("/");
209
+ const result = await import_isomorphic_git.default.walk(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
210
+ map: async (filepath, [head]) => {
211
+ if (head._fullpath === "." || path4.startsWith(filepath)) {
212
+ return head;
213
+ }
214
+ },
215
+ cache: this.cache,
216
+ trees: [import_isomorphic_git.default.TREE({ ref })]
217
+ }));
218
+ const pathEntries = flat(result);
219
+ if (pathParts.indexOf(".") === -1) {
220
+ pathParts = [".", ...pathParts];
221
+ }
222
+ while (pathParts.length > pathEntries.length) {
223
+ pathEntries.push(null);
224
+ }
225
+ return { pathParts, pathEntries };
226
+ }
227
+ async updateTreeHierarchy(existingOid, updatedOid, path4, type, pathEntries, pathParts) {
228
+ const lastIdx = pathEntries.length - 1;
229
+ const parentEntry = pathEntries[lastIdx];
230
+ const parentPath = pathParts[lastIdx];
231
+ let parentOid;
232
+ let tree;
233
+ const mode = type === "blob" ? "100644" : "040000";
234
+ if (parentEntry) {
235
+ parentOid = await parentEntry.oid();
236
+ const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
237
+ oid: parentOid,
238
+ cache: this.cache
239
+ }));
240
+ tree = existingOid ? treeResult.tree.map((entry) => {
241
+ if (entry.path === path4) {
242
+ entry.oid = updatedOid;
243
+ }
244
+ return entry;
245
+ }) : [
246
+ ...treeResult.tree,
247
+ {
248
+ oid: updatedOid,
249
+ type,
250
+ path: path4,
251
+ mode
252
+ }
253
+ ];
254
+ } else {
255
+ tree = [
256
+ {
257
+ oid: updatedOid,
258
+ type,
259
+ path: path4,
260
+ mode
261
+ }
262
+ ];
263
+ }
264
+ const updatedParentOid = await import_isomorphic_git.default.writeTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
265
+ tree
266
+ }));
267
+ if (lastIdx === 0) {
268
+ return updatedParentOid;
269
+ } else {
270
+ return await this.updateTreeHierarchy(parentOid, updatedParentOid, parentPath, "tree", pathEntries.slice(0, lastIdx), pathParts.slice(0, lastIdx));
271
+ }
272
+ }
273
+ async commitTree(treeSha, ref) {
274
+ const commitSha = await import_isomorphic_git.default.writeCommit(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
275
+ commit: {
276
+ tree: treeSha,
277
+ parent: [
278
+ await import_isomorphic_git.default.resolveRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
279
+ ref
280
+ }))
281
+ ],
282
+ message: this.commitMessage,
283
+ author: this.getAuthor(),
284
+ committer: this.getCommitter()
285
+ }
286
+ }));
287
+ await import_isomorphic_git.default.writeRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
288
+ ref,
289
+ value: commitSha,
290
+ force: true
291
+ }));
292
+ }
293
+ async getRef() {
294
+ if (this.ref) {
295
+ return this.ref;
296
+ }
297
+ const ref = await import_isomorphic_git.default.currentBranch(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
298
+ fullname: true
299
+ }));
300
+ if (!ref) {
301
+ throw new import_graphql.GraphQLError(`Unable to determine current branch from HEAD`, null, null, null, null, null, {});
302
+ }
303
+ this.ref = ref;
304
+ return ref;
305
+ }
306
+ async glob(pattern, extension) {
307
+ const ref = await this.getRef();
308
+ const parent = (0, import_glob_parent.default)(this.qualifyPath(pattern));
309
+ const { pathParts, pathEntries } = await this.resolvePathEntries(parent, ref);
310
+ const leafEntry = pathEntries[pathEntries.length - 1];
311
+ const entryPath = pathParts[pathParts.length - 1];
312
+ const parentEntry = pathEntries[pathEntries.length - 2];
313
+ let treeEntry;
314
+ let parentPath;
315
+ if (parentEntry) {
316
+ const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
317
+ oid: await parentEntry.oid(),
318
+ cache: this.cache
319
+ }));
320
+ treeEntry = treeResult.tree.find((entry) => entry.path === entryPath);
321
+ parentPath = pathParts.slice(1, pathParts.length).join("/");
322
+ } else {
323
+ treeEntry = {
324
+ type: "tree",
325
+ oid: await leafEntry.oid()
326
+ };
327
+ parentPath = "";
328
+ }
329
+ const results = [];
330
+ await this.listEntries({
331
+ pattern: this.qualifyPath(pattern),
332
+ entry: treeEntry,
333
+ path: parentPath,
334
+ results
335
+ });
336
+ return results.map((path4) => this.unqualifyPath(path4)).filter((path4) => path4.endsWith(extension));
337
+ }
338
+ supportsBuilding() {
339
+ return true;
340
+ }
341
+ async delete(filepath) {
342
+ const ref = await this.getRef();
343
+ const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
344
+ let oidToRemove;
345
+ let ptr = pathEntries.length - 1;
346
+ while (ptr >= 1) {
347
+ const leafEntry = pathEntries[ptr];
348
+ const nodePath = pathParts[ptr];
349
+ if (leafEntry) {
350
+ oidToRemove = oidToRemove || await leafEntry.oid();
351
+ const parentEntry = pathEntries[ptr - 1];
352
+ const existingOid = await parentEntry.oid();
353
+ const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
354
+ oid: existingOid,
355
+ cache: this.cache
356
+ }));
357
+ const updatedTree = treeResult.tree.filter((value) => value.path !== nodePath);
358
+ if (updatedTree.length === 0) {
359
+ ptr -= 1;
360
+ continue;
361
+ }
362
+ const updatedTreeOid = await import_isomorphic_git.default.writeTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
363
+ tree: updatedTree
364
+ }));
365
+ const updatedRootTreeOid = await this.updateTreeHierarchy(existingOid, updatedTreeOid, pathParts[ptr - 1], "tree", pathEntries.slice(0, ptr - 1), pathParts.slice(0, ptr - 1));
366
+ await this.commitTree(updatedRootTreeOid, ref);
367
+ break;
368
+ } else {
369
+ throw new import_graphql.GraphQLError(`Unable to resolve path: ${filepath}`, null, null, null, null, null, { status: 404 });
370
+ }
371
+ }
372
+ if (oidToRemove) {
373
+ await import_isomorphic_git.default.updateIndex(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
374
+ filepath: this.qualifyPath(filepath),
375
+ force: true,
376
+ remove: true,
377
+ oid: oidToRemove,
378
+ cache: this.cache
379
+ }));
380
+ }
381
+ await this.onDelete(filepath);
382
+ }
383
+ qualifyPath(filepath) {
384
+ return this.relativePath ? `${this.relativePath}/${filepath}` : filepath;
385
+ }
386
+ unqualifyPath(filepath) {
387
+ return this.relativePath ? filepath.slice(this.relativePath.length + 1) : filepath;
388
+ }
389
+ async get(filepath) {
390
+ const ref = await this.getRef();
391
+ const oid = await import_isomorphic_git.default.resolveRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
392
+ ref
393
+ }));
394
+ const { blob } = await import_isomorphic_git.default.readBlob(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
395
+ oid,
396
+ filepath: this.qualifyPath(filepath),
397
+ cache: this.cache
398
+ }));
399
+ return Buffer.from(blob).toString("utf8");
400
+ }
401
+ async putConfig(filepath, data) {
402
+ await this.put(filepath, data);
403
+ }
404
+ async put(filepath, data) {
405
+ const ref = await this.getRef();
406
+ const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
407
+ const blobUpdate = toUint8Array(Buffer.from(data));
408
+ let existingOid;
409
+ const leafEntry = pathEntries[pathEntries.length - 1];
410
+ const nodePath = pathParts[pathParts.length - 1];
411
+ if (leafEntry) {
412
+ existingOid = await leafEntry.oid();
413
+ const hash = await import_isomorphic_git.default.hashBlob({ object: blobUpdate });
414
+ if (hash.oid === existingOid) {
415
+ await this.onPut(filepath, data);
416
+ return;
417
+ }
418
+ }
419
+ const updatedOid = await import_isomorphic_git.default.writeBlob(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
420
+ blob: blobUpdate
421
+ }));
422
+ const updatedRootSha = await this.updateTreeHierarchy(existingOid, updatedOid, nodePath, "blob", pathEntries.slice(0, pathEntries.length - 1), pathParts.slice(0, pathParts.length - 1));
423
+ await this.commitTree(updatedRootSha, ref);
424
+ await import_isomorphic_git.default.updateIndex(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
425
+ filepath: this.qualifyPath(filepath),
426
+ add: true,
427
+ oid: updatedOid,
428
+ cache: this.cache
429
+ }));
430
+ await this.onPut(filepath, data);
431
+ }
432
+ };
433
+
434
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/store/filesystem.ts
435
+ var import_fs_extra3 = __toModule(require("fs-extra"));
118
436
  var import_fast_glob2 = __toModule(require("fast-glob"));
119
437
  var import_path2 = __toModule(require("path"));
120
- var import_normalize_path2 = __toModule(require("normalize-path"));
438
+ var import_normalize_path3 = __toModule(require("normalize-path"));
121
439
 
122
440
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/util.ts
123
441
  var import_gray_matter = __toModule(require("gray-matter"));
124
442
 
125
443
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/util.ts
126
444
  var yup = __toModule(require("yup"));
127
- var import_graphql = __toModule(require("graphql"));
445
+ var import_graphql2 = __toModule(require("graphql"));
128
446
  var sequential = async (items, callback) => {
129
447
  const accum = [];
130
448
  if (!items) {
@@ -149,7 +467,7 @@ function assertShape(value, yupSchema, errorMessage) {
149
467
  shape.validateSync(value);
150
468
  } catch (e) {
151
469
  const message = errorMessage || `Failed to assertShape - ${e.message}`;
152
- throw new import_graphql.GraphQLError(message, null, null, null, null, null, {
470
+ throw new import_graphql2.GraphQLError(message, null, null, null, null, null, {
153
471
  stack: e.stack
154
472
  });
155
473
  }
@@ -225,14 +543,14 @@ var FilesystemStore = class {
225
543
  constructor({ rootPath }) {
226
544
  this.rootPath = rootPath || "";
227
545
  }
228
- async query(queryOptions) {
546
+ async query(_queryOptions) {
229
547
  throw new Error(`Unable to perform query for Filesystem store`);
230
548
  }
231
549
  async seed() {
232
550
  throw new Error(`Seeding data is not possible for Filesystem store`);
233
551
  }
234
552
  async get(filepath) {
235
- return parseFile(await import_fs_extra2.default.readFileSync(import_path2.default.join(this.rootPath, filepath)).toString(), import_path2.default.extname(filepath), (yup2) => yup2.object());
553
+ return parseFile(await import_fs_extra3.default.readFileSync(import_path2.default.join(this.rootPath, filepath)).toString(), import_path2.default.extname(filepath), (yup2) => yup2.object());
236
554
  }
237
555
  supportsSeeding() {
238
556
  return false;
@@ -240,12 +558,12 @@ var FilesystemStore = class {
240
558
  supportsIndexing() {
241
559
  return false;
242
560
  }
243
- async glob(pattern, callback) {
561
+ async glob(pattern, callback, extension) {
244
562
  const basePath = import_path2.default.join(this.rootPath, ...pattern.split("/"));
245
- const itemsRaw = await (0, import_fast_glob2.default)(import_path2.default.join(basePath, "**", "/*").replace(/\\/g, "/"), {
563
+ const itemsRaw = await (0, import_fast_glob2.default)(import_path2.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"), {
246
564
  dot: true
247
565
  });
248
- const posixRootPath = (0, import_normalize_path2.default)(this.rootPath);
566
+ const posixRootPath = (0, import_normalize_path3.default)(this.rootPath);
249
567
  const items = itemsRaw.map((item) => {
250
568
  return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
251
569
  });
@@ -258,14 +576,14 @@ var FilesystemStore = class {
258
576
  }
259
577
  }
260
578
  async put(filepath, data, options) {
261
- await import_fs_extra2.default.outputFileSync(import_path2.default.join(this.rootPath, filepath), stringifyFile(data, import_path2.default.extname(filepath), options.keepTemplateKey));
579
+ await import_fs_extra3.default.outputFileSync(import_path2.default.join(this.rootPath, filepath), stringifyFile(data, import_path2.default.extname(filepath), options.keepTemplateKey));
262
580
  }
263
581
  async open() {
264
582
  }
265
583
  async close() {
266
584
  }
267
585
  async delete(filepath) {
268
- await import_fs_extra2.default.remove(import_path2.default.join(this.rootPath, filepath));
586
+ await import_fs_extra3.default.remove(import_path2.default.join(this.rootPath, filepath));
269
587
  }
270
588
  };
271
589
  var AuditFilesystemStore = class extends FilesystemStore {
@@ -825,6 +1143,7 @@ var LevelStore = class {
825
1143
  FilesystemBridge,
826
1144
  FilesystemStore,
827
1145
  INDEX_KEY_FIELD_SEPARATOR,
1146
+ IsomorphicBridge,
828
1147
  LevelStore,
829
1148
  OP,
830
1149
  atob,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/datalayer",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -29,8 +29,10 @@
29
29
  "encoding-down": "^7.1.0",
30
30
  "fast-glob": "^3.2.5",
31
31
  "fs-extra": "^9.0.1",
32
+ "glob-parent": "^6.0.2",
32
33
  "graphql": "^15.3.0",
33
34
  "gray-matter": "^4.0.2",
35
+ "isomorphic-git": "^1.10.3",
34
36
  "js-yaml": "^3.14.0",
35
37
  "jsonpath-plus": "^6.0.1",
36
38
  "level": "^7.0.1",
@@ -50,7 +52,7 @@
50
52
  "directory": "packages/@tinacms/datalayer"
51
53
  },
52
54
  "devDependencies": {
53
- "@tinacms/scripts": "0.50.7",
55
+ "@tinacms/scripts": "0.50.9",
54
56
  "@types/fs-extra": "^9.0.2",
55
57
  "@types/jest": "^27.4.1",
56
58
  "@types/js-yaml": "^3.12.5",