@tinacms/datalayer 0.1.0 → 0.2.1

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/index.js CHANGED
@@ -51,7 +51,7 @@ var __toModule = (module2) => {
51
51
  return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
52
52
  };
53
53
 
54
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/index.ts
54
+ // src/index.ts
55
55
  __export(exports, {
56
56
  AuditFileSystemBridge: () => AuditFileSystemBridge,
57
57
  AuditFilesystemStore: () => AuditFilesystemStore,
@@ -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,
@@ -72,7 +73,7 @@ __export(exports, {
72
73
  makeStringEscaper: () => makeStringEscaper
73
74
  });
74
75
 
75
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/bridge/filesystem.ts
76
+ // src/database/bridge/filesystem.ts
76
77
  var import_fs_extra = __toModule(require("fs-extra"));
77
78
  var import_fast_glob = __toModule(require("fast-glob"));
78
79
  var import_path = __toModule(require("path"));
@@ -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);
@@ -94,6 +95,9 @@ var FilesystemBridge = class {
94
95
  supportsBuilding() {
95
96
  return true;
96
97
  }
98
+ async delete(filepath) {
99
+ await import_fs_extra.default.remove(import_path.default.join(this.rootPath, filepath));
100
+ }
97
101
  async get(filepath) {
98
102
  return import_fs_extra.default.readFileSync(import_path.default.join(this.rootPath, filepath)).toString();
99
103
  }
@@ -110,18 +114,335 @@ var AuditFileSystemBridge = class extends FilesystemBridge {
110
114
  }
111
115
  };
112
116
 
113
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/store/filesystem.ts
117
+ // src/database/bridge/isomorphic.ts
118
+ var import_isomorphic_git = __toModule(require("isomorphic-git"));
114
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
+ // src/database/store/filesystem.ts
435
+ var import_fs_extra3 = __toModule(require("fs-extra"));
115
436
  var import_fast_glob2 = __toModule(require("fast-glob"));
116
437
  var import_path2 = __toModule(require("path"));
117
- var import_normalize_path2 = __toModule(require("normalize-path"));
438
+ var import_normalize_path3 = __toModule(require("normalize-path"));
118
439
 
119
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/util.ts
440
+ // src/database/util.ts
120
441
  var import_gray_matter = __toModule(require("gray-matter"));
121
442
 
122
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/util.ts
443
+ // src/util.ts
123
444
  var yup = __toModule(require("yup"));
124
- var import_graphql = __toModule(require("graphql"));
445
+ var import_graphql2 = __toModule(require("graphql"));
125
446
  var sequential = async (items, callback) => {
126
447
  const accum = [];
127
448
  if (!items) {
@@ -146,7 +467,7 @@ function assertShape(value, yupSchema, errorMessage) {
146
467
  shape.validateSync(value);
147
468
  } catch (e) {
148
469
  const message = errorMessage || `Failed to assertShape - ${e.message}`;
149
- throw new import_graphql.GraphQLError(message, null, null, null, null, null, {
470
+ throw new import_graphql2.GraphQLError(message, null, null, null, null, null, {
150
471
  stack: e.stack
151
472
  });
152
473
  }
@@ -158,7 +479,7 @@ var btoa = (string) => {
158
479
  return Buffer.from(string).toString("base64");
159
480
  };
160
481
 
161
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/util.ts
482
+ // src/database/util.ts
162
483
  var stringifyFile = (content, format, keepTemplateKey) => {
163
484
  switch (format) {
164
485
  case ".markdown":
@@ -213,7 +534,7 @@ var parseFile = (content, format, yupSchema) => {
213
534
  }
214
535
  };
215
536
 
216
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/store/filesystem.ts
537
+ // src/database/store/filesystem.ts
217
538
  var FilesystemStore = class {
218
539
  async clear() {
219
540
  }
@@ -222,14 +543,14 @@ var FilesystemStore = class {
222
543
  constructor({ rootPath }) {
223
544
  this.rootPath = rootPath || "";
224
545
  }
225
- async query(queryOptions) {
546
+ async query(_queryOptions) {
226
547
  throw new Error(`Unable to perform query for Filesystem store`);
227
548
  }
228
549
  async seed() {
229
550
  throw new Error(`Seeding data is not possible for Filesystem store`);
230
551
  }
231
552
  async get(filepath) {
232
- 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());
233
554
  }
234
555
  supportsSeeding() {
235
556
  return false;
@@ -237,12 +558,12 @@ var FilesystemStore = class {
237
558
  supportsIndexing() {
238
559
  return false;
239
560
  }
240
- async glob(pattern, callback) {
561
+ async glob(pattern, callback, extension) {
241
562
  const basePath = import_path2.default.join(this.rootPath, ...pattern.split("/"));
242
- 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, "/"), {
243
564
  dot: true
244
565
  });
245
- const posixRootPath = (0, import_normalize_path2.default)(this.rootPath);
566
+ const posixRootPath = (0, import_normalize_path3.default)(this.rootPath);
246
567
  const items = itemsRaw.map((item) => {
247
568
  return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
248
569
  });
@@ -255,12 +576,15 @@ var FilesystemStore = class {
255
576
  }
256
577
  }
257
578
  async put(filepath, data, options) {
258
- 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));
259
580
  }
260
581
  async open() {
261
582
  }
262
583
  async close() {
263
584
  }
585
+ async delete(filepath) {
586
+ await import_fs_extra3.default.remove(import_path2.default.join(this.rootPath, filepath));
587
+ }
264
588
  };
265
589
  var AuditFilesystemStore = class extends FilesystemStore {
266
590
  async put(_filepath, _data) {
@@ -268,7 +592,7 @@ var AuditFilesystemStore = class extends FilesystemStore {
268
592
  }
269
593
  };
270
594
 
271
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/store/index.ts
595
+ // src/database/store/index.ts
272
596
  var import_jsonpath_plus = __toModule(require("jsonpath-plus"));
273
597
  var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
274
598
  var INDEX_KEY_FIELD_SEPARATOR = "#";
@@ -377,8 +701,13 @@ var makeFilter = ({
377
701
  let operands;
378
702
  if (dataType === "string" || dataType === "reference") {
379
703
  operands = resolvedValues;
380
- } else if (dataType === "number" || dataType === "datetime") {
704
+ } else if (dataType === "number") {
381
705
  operands = resolvedValues.map((resolvedValue) => Number(resolvedValue));
706
+ } else if (dataType === "datetime") {
707
+ operands = resolvedValues.map((resolvedValue) => {
708
+ const coerced = new Date(resolvedValue).getTime();
709
+ return isNaN(coerced) ? Number(resolvedValue) : coerced;
710
+ });
382
711
  } else if (dataType === "boolean") {
383
712
  operands = resolvedValues.map((resolvedValue) => typeof resolvedValue === "boolean" && resolvedValue || resolvedValue === "true" || resolvedValue === "1");
384
713
  } else {
@@ -592,11 +921,11 @@ var makeFilterSuffixes = (filterChain, index) => {
592
921
  return {};
593
922
  }
594
923
  };
595
- var makeKeyForField = (definition, data, stringEscaper) => {
924
+ var makeKeyForField = (definition, data, stringEscaper, maxStringLength = 100) => {
596
925
  const valueParts = [];
597
926
  for (const field of definition.fields) {
598
927
  if (field.name in data) {
599
- const resolvedValue = String(field.type === "datetime" ? new Date(data[field.name]).getTime() : field.type === "string" ? stringEscaper(data[field.name]) : data[field.name]);
928
+ const resolvedValue = String(field.type === "datetime" ? new Date(data[field.name]).getTime() : field.type === "string" ? stringEscaper(data[field.name]) : data[field.name]).substring(0, maxStringLength);
600
929
  valueParts.push(applyPadding(resolvedValue, field.pad));
601
930
  } else {
602
931
  return null;
@@ -605,7 +934,7 @@ var makeKeyForField = (definition, data, stringEscaper) => {
605
934
  return valueParts.join(INDEX_KEY_FIELD_SEPARATOR);
606
935
  };
607
936
 
608
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/datalayer/src/database/store/level.ts
937
+ // src/database/store/level.ts
609
938
  var import_path3 = __toModule(require("path"));
610
939
  var import_level = __toModule(require("level"));
611
940
  var import_levelup = __toModule(require("levelup"));
@@ -701,6 +1030,27 @@ var LevelStore = class {
701
1030
  supportsIndexing() {
702
1031
  return true;
703
1032
  }
1033
+ async delete(filepath, options) {
1034
+ const data = await this.db.get(`${defaultPrefix}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`);
1035
+ if (!data) {
1036
+ return;
1037
+ }
1038
+ if (options == null ? void 0 : options.indexDefinitions) {
1039
+ for (const [sort, definition] of Object.entries(options.indexDefinitions)) {
1040
+ const indexedValue = makeKeyForField(definition, data, escapeStr);
1041
+ let indexKey;
1042
+ if (sort === DEFAULT_COLLECTION_SORT_KEY) {
1043
+ indexKey = `${options.collection}${INDEX_KEY_FIELD_SEPARATOR}${sort}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`;
1044
+ } else {
1045
+ indexKey = indexedValue ? `${options.collection}${INDEX_KEY_FIELD_SEPARATOR}${sort}${INDEX_KEY_FIELD_SEPARATOR}${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}` : null;
1046
+ }
1047
+ if (indexKey) {
1048
+ await this.db.del(indexKey);
1049
+ }
1050
+ }
1051
+ }
1052
+ await this.db.del(`${defaultPrefix}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`);
1053
+ }
704
1054
  async print() {
705
1055
  this.db.createReadStream().on("data", function(data) {
706
1056
  console.log(data.key, "=", data.value);
@@ -793,6 +1143,7 @@ var LevelStore = class {
793
1143
  FilesystemBridge,
794
1144
  FilesystemStore,
795
1145
  INDEX_KEY_FIELD_SEPARATOR,
1146
+ IsomorphicBridge,
796
1147
  LevelStore,
797
1148
  OP,
798
1149
  atob,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/datalayer",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -17,11 +17,6 @@
17
17
  }
18
18
  ]
19
19
  },
20
- "scripts": {
21
- "types": "yarn tsc",
22
- "build": "echo \"Run `yarn build` from the root of the repository instead\"",
23
- "test": "jest --passWithNoTests"
24
- },
25
20
  "dependencies": {
26
21
  "@octokit/auth-app": "^2.6.0",
27
22
  "@octokit/graphql": "^4.5.6",
@@ -29,8 +24,10 @@
29
24
  "encoding-down": "^7.1.0",
30
25
  "fast-glob": "^3.2.5",
31
26
  "fs-extra": "^9.0.1",
27
+ "glob-parent": "^6.0.2",
32
28
  "graphql": "^15.3.0",
33
29
  "gray-matter": "^4.0.2",
30
+ "isomorphic-git": "^1.10.3",
34
31
  "js-yaml": "^3.14.0",
35
32
  "jsonpath-plus": "^6.0.1",
36
33
  "level": "^7.0.1",
@@ -50,7 +47,7 @@
50
47
  "directory": "packages/@tinacms/datalayer"
51
48
  },
52
49
  "devDependencies": {
53
- "@tinacms/scripts": "0.50.7",
50
+ "@tinacms/scripts": "0.50.9",
54
51
  "@types/fs-extra": "^9.0.2",
55
52
  "@types/jest": "^27.4.1",
56
53
  "@types/js-yaml": "^3.12.5",
@@ -65,6 +62,11 @@
65
62
  "jest-diff": "27.0.6",
66
63
  "jest-file-snapshot": "^0.5.0",
67
64
  "jest-matcher-utils": "27.0.6",
68
- "typescript": "^4.3.5"
65
+ "typescript": "4.3.5"
66
+ },
67
+ "scripts": {
68
+ "types": "pnpm tsc",
69
+ "build": "tinacms-scripts build",
70
+ "test": "jest --passWithNoTests"
69
71
  }
70
72
  }