@tinacms/datalayer 0.0.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/dist/index.js ADDED
@@ -0,0 +1,609 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ __markAsModule(target);
39
+ for (var name in all)
40
+ __defProp(target, name, { get: all[name], enumerable: true });
41
+ };
42
+ var __reExport = (target, module2, desc) => {
43
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
44
+ for (let key of __getOwnPropNames(module2))
45
+ if (!__hasOwnProp.call(target, key) && key !== "default")
46
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
47
+ }
48
+ return target;
49
+ };
50
+ var __toModule = (module2) => {
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
+ };
53
+
54
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/index.ts
55
+ __export(exports, {
56
+ FilesystemBridge: () => FilesystemBridge,
57
+ FilesystemStore: () => FilesystemStore,
58
+ GithubBridge: () => GithubBridge,
59
+ GithubStore: () => GithubStore,
60
+ LevelStore: () => LevelStore,
61
+ MemoryStore: () => MemoryStore
62
+ });
63
+
64
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/bridge/github.ts
65
+ var import_lodash = __toModule(require("lodash"));
66
+ var import_path = __toModule(require("path"));
67
+ var import_rest = __toModule(require("@octokit/rest"));
68
+ var import_graphql = __toModule(require("graphql"));
69
+ var GithubBridge = class {
70
+ constructor({ rootPath, accessToken, owner, repo, ref }) {
71
+ this.rootPath = rootPath;
72
+ this.repoConfig = {
73
+ owner,
74
+ repo,
75
+ ref
76
+ };
77
+ this.appOctoKit = new import_rest.Octokit({
78
+ auth: accessToken
79
+ });
80
+ }
81
+ async readDir(filepath) {
82
+ const fullPath = import_path.default.join(this.rootPath, filepath);
83
+ const repos = await this.appOctoKit.repos.getContent(__spreadProps(__spreadValues({}, this.repoConfig), {
84
+ path: fullPath
85
+ })).then(async (response) => {
86
+ if (Array.isArray(response.data)) {
87
+ return await Promise.all(await response.data.map(async (d) => {
88
+ if (d.type === "dir") {
89
+ const nestedItems = await this.readDir(d.path);
90
+ if (Array.isArray(nestedItems)) {
91
+ return nestedItems.map((nestedItem) => {
92
+ return import_path.default.join(d.path, nestedItem);
93
+ });
94
+ } else {
95
+ throw new Error(`Expected items to be an array of strings for readDir at ${d.path}`);
96
+ }
97
+ }
98
+ return d.path;
99
+ }));
100
+ }
101
+ throw new Error(`Expected to return an array from Github directory ${import_path.default}`);
102
+ });
103
+ return import_lodash.default.flatten(repos);
104
+ }
105
+ supportsBuilding() {
106
+ return false;
107
+ }
108
+ async glob(pattern) {
109
+ const results = await this.readDir(pattern);
110
+ return results.map((item) => item.replace(this.rootPath, "").replace(/^\/|\/$/g, ""));
111
+ }
112
+ async get(filepath) {
113
+ const realpath = import_path.default.join(this.rootPath, filepath);
114
+ return this.appOctoKit.repos.getContent(__spreadProps(__spreadValues({}, this.repoConfig), {
115
+ path: realpath
116
+ })).then((response) => {
117
+ return Buffer.from(response.data.content, "base64").toString();
118
+ }).catch((e) => {
119
+ if (e.status === 401) {
120
+ throw new import_graphql.GraphQLError(`Unauthorized request to Github Repository: '${this.repoConfig.owner}/${this.repoConfig.repo}', please ensure your access token is valid.`, null, null, null, null, e, { status: e.status });
121
+ }
122
+ throw new import_graphql.GraphQLError(`Unable to find record '${filepath}' in Github Repository: '${this.repoConfig.owner}/${this.repoConfig.repo}', Ref: '${this.repoConfig.ref}'`, null, null, null, null, e, { status: e.status });
123
+ });
124
+ }
125
+ async putConfig(filepath, data) {
126
+ throw new Error(`Config files cannot be changed by the Github bridge`);
127
+ }
128
+ async put(filepath, data) {
129
+ const realpath = import_path.default.join(this.rootPath, filepath);
130
+ let fileSha = void 0;
131
+ try {
132
+ const fileContent = await this.appOctoKit.repos.getContent(__spreadProps(__spreadValues({}, this.repoConfig), {
133
+ path: realpath
134
+ }));
135
+ fileSha = fileContent.data.sha;
136
+ } catch (e) {
137
+ console.log("No file exists, creating new one");
138
+ }
139
+ await this.appOctoKit.repos.createOrUpdateFileContents(__spreadProps(__spreadValues({}, this.repoConfig), {
140
+ branch: this.repoConfig.ref,
141
+ path: realpath,
142
+ message: "Update from GraphQL client",
143
+ content: new Buffer(data).toString("base64"),
144
+ sha: fileSha
145
+ }));
146
+ }
147
+ };
148
+
149
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/store/github.ts
150
+ var import_lodash2 = __toModule(require("lodash"));
151
+ var import_path2 = __toModule(require("path"));
152
+ var import_rest2 = __toModule(require("@octokit/rest"));
153
+
154
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/util.ts
155
+ var import_gray_matter = __toModule(require("gray-matter"));
156
+
157
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/util.ts
158
+ var yup = __toModule(require("yup"));
159
+ var import_graphql2 = __toModule(require("graphql"));
160
+ var sequential = async (items, callback) => {
161
+ const accum = [];
162
+ if (!items) {
163
+ return [];
164
+ }
165
+ const reducePromises = async (previous, endpoint) => {
166
+ const prev = await previous;
167
+ if (prev) {
168
+ accum.push(prev);
169
+ }
170
+ return callback(endpoint, accum.length);
171
+ };
172
+ const result = await items.reduce(reducePromises, Promise.resolve());
173
+ if (result) {
174
+ accum.push(result);
175
+ }
176
+ return accum;
177
+ };
178
+ function assertShape(value, yupSchema, errorMessage) {
179
+ const shape = yupSchema(yup);
180
+ try {
181
+ shape.validateSync(value);
182
+ } catch (e) {
183
+ const message = errorMessage || `Failed to assertShape - ${e.message}`;
184
+ throw new import_graphql2.GraphQLError(message, null, null, null, null, null, {
185
+ stack: e.stack
186
+ });
187
+ }
188
+ }
189
+
190
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/util.ts
191
+ var stringifyFile = (content, format, keepTemplateKey) => {
192
+ switch (format) {
193
+ case ".markdown":
194
+ case ".mdx":
195
+ case ".md":
196
+ const _a = content, {
197
+ _relativePath,
198
+ _keepTemplateKey,
199
+ _id,
200
+ _template,
201
+ _collection,
202
+ $_body
203
+ } = _a, rest = __objRest(_a, [
204
+ "_relativePath",
205
+ "_keepTemplateKey",
206
+ "_id",
207
+ "_template",
208
+ "_collection",
209
+ "$_body"
210
+ ]);
211
+ const extra = {};
212
+ if (keepTemplateKey) {
213
+ extra["_template"] = _template;
214
+ }
215
+ const ok = import_gray_matter.default.stringify(typeof $_body === "undefined" ? "" : `
216
+ ${$_body}`, __spreadValues(__spreadValues({}, rest), extra));
217
+ return ok;
218
+ case ".json":
219
+ return JSON.stringify(content, null, 2);
220
+ default:
221
+ throw new Error(`Must specify a valid format, got ${format}`);
222
+ }
223
+ };
224
+ var parseFile = (content, format, yupSchema) => {
225
+ switch (format) {
226
+ case ".markdown":
227
+ case ".mdx":
228
+ case ".md":
229
+ const contentJSON = (0, import_gray_matter.default)(content || "");
230
+ const markdownData = __spreadProps(__spreadValues({}, contentJSON.data), {
231
+ $_body: contentJSON.content
232
+ });
233
+ assertShape(markdownData, yupSchema);
234
+ return markdownData;
235
+ case ".json":
236
+ if (!content) {
237
+ return {};
238
+ }
239
+ return JSON.parse(content);
240
+ default:
241
+ throw new Error(`Must specify a valid format, got ${format}`);
242
+ }
243
+ };
244
+
245
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/store/github.ts
246
+ var import_graphql3 = __toModule(require("graphql"));
247
+ var GithubStore = class {
248
+ async clear() {
249
+ }
250
+ async print() {
251
+ }
252
+ constructor({ rootPath, accessToken, owner, repo, ref }) {
253
+ this.rootPath = rootPath;
254
+ this.repoConfig = {
255
+ owner,
256
+ repo,
257
+ ref
258
+ };
259
+ this.appOctoKit = new import_rest2.Octokit({
260
+ auth: accessToken
261
+ });
262
+ }
263
+ async query(queryStrings) {
264
+ throw new Error(`Unable to perform query for GithubStore`);
265
+ }
266
+ supportsSeeding() {
267
+ return false;
268
+ }
269
+ async seed() {
270
+ throw new Error(`Seeding data is not possible for Github data store`);
271
+ }
272
+ async readDir(filepath) {
273
+ const fullPath = import_path2.default.join(this.rootPath, filepath);
274
+ const repos = await this.appOctoKit.repos.getContent(__spreadProps(__spreadValues({}, this.repoConfig), {
275
+ path: fullPath
276
+ })).then(async (response) => {
277
+ if (Array.isArray(response.data)) {
278
+ return await Promise.all(await response.data.map(async (d) => {
279
+ if (d.type === "dir") {
280
+ const nestedItems = await this.readDir(d.path);
281
+ if (Array.isArray(nestedItems)) {
282
+ return nestedItems.map((nestedItem) => {
283
+ return import_path2.default.join(d.path, nestedItem);
284
+ });
285
+ } else {
286
+ throw new Error(`Expected items to be an array of strings for readDir at ${d.path}`);
287
+ }
288
+ }
289
+ return d.path;
290
+ }));
291
+ }
292
+ throw new Error(`Expected to return an array from Github directory ${import_path2.default}`);
293
+ });
294
+ return import_lodash2.default.flatten(repos);
295
+ }
296
+ async glob(pattern, callback) {
297
+ const results = await this.readDir(pattern);
298
+ const items = results.map((item) => item.replace(this.rootPath, "").replace(/^\/|\/$/g, ""));
299
+ if (callback) {
300
+ return sequential(items, async (item) => {
301
+ return callback(item);
302
+ });
303
+ } else {
304
+ return items;
305
+ }
306
+ }
307
+ async get(filepath) {
308
+ const realpath = import_path2.default.join(this.rootPath, filepath);
309
+ return this.appOctoKit.repos.getContent(__spreadProps(__spreadValues({}, this.repoConfig), {
310
+ path: realpath
311
+ })).then((response) => {
312
+ const responseString = Buffer.from(response.data.content, "base64").toString();
313
+ return parseFile(responseString, import_path2.default.extname(filepath), (yup2) => yup2.object());
314
+ }).catch((e) => {
315
+ if (e.status === 401) {
316
+ throw new import_graphql3.GraphQLError(`Unauthorized request to Github Repository: '${this.repoConfig.owner}/${this.repoConfig.repo}', please ensure your access token is valid.`, null, null, null, null, e, { status: e.status });
317
+ }
318
+ throw new import_graphql3.GraphQLError(`Unable to find record '${filepath}' in Github Repository: '${this.repoConfig.owner}/${this.repoConfig.repo}', Ref: '${this.repoConfig.ref}'`, null, null, null, null, e, { status: e.status });
319
+ });
320
+ }
321
+ supportsIndexing() {
322
+ return false;
323
+ }
324
+ async put(filepath, data) {
325
+ const realpath = import_path2.default.join(this.rootPath, filepath);
326
+ let fileSha = void 0;
327
+ try {
328
+ const fileContent = await this.appOctoKit.repos.getContent(__spreadProps(__spreadValues({}, this.repoConfig), {
329
+ path: realpath
330
+ }));
331
+ fileSha = fileContent.data.sha;
332
+ } catch (e) {
333
+ console.log("No file exists, creating new one");
334
+ }
335
+ await this.appOctoKit.repos.createOrUpdateFileContents(__spreadProps(__spreadValues({}, this.repoConfig), {
336
+ branch: this.repoConfig.ref,
337
+ path: realpath,
338
+ message: "Update from GraphQL client",
339
+ content: new Buffer(stringifyFile(data, import_path2.default.extname(filepath), false)).toString("base64"),
340
+ sha: fileSha
341
+ }));
342
+ }
343
+ };
344
+
345
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/bridge/filesystem.ts
346
+ var import_fs_extra = __toModule(require("fs-extra"));
347
+ var import_fast_glob = __toModule(require("fast-glob"));
348
+ var import_path3 = __toModule(require("path"));
349
+ var import_normalize_path = __toModule(require("normalize-path"));
350
+ var FilesystemBridge = class {
351
+ constructor(rootPath) {
352
+ this.rootPath = rootPath || "";
353
+ }
354
+ async glob(pattern) {
355
+ const basePath = import_path3.default.join(this.rootPath, ...pattern.split("/"));
356
+ const items = await (0, import_fast_glob.default)(import_path3.default.join(basePath, "**", "/*").replace(/\\/g, "/"), {
357
+ dot: true
358
+ });
359
+ const posixRootPath = (0, import_normalize_path.default)(this.rootPath);
360
+ return items.map((item) => {
361
+ return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
362
+ });
363
+ }
364
+ supportsBuilding() {
365
+ return true;
366
+ }
367
+ async get(filepath) {
368
+ return import_fs_extra.default.readFileSync(import_path3.default.join(this.rootPath, filepath)).toString();
369
+ }
370
+ async putConfig(filepath, data) {
371
+ await this.put(filepath, data);
372
+ }
373
+ async put(filepath, data) {
374
+ await import_fs_extra.default.outputFileSync(import_path3.default.join(this.rootPath, filepath), data);
375
+ }
376
+ };
377
+
378
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/store/filesystem.ts
379
+ var import_fs_extra2 = __toModule(require("fs-extra"));
380
+ var import_fast_glob2 = __toModule(require("fast-glob"));
381
+ var import_path4 = __toModule(require("path"));
382
+ var import_normalize_path2 = __toModule(require("normalize-path"));
383
+ var FilesystemStore = class {
384
+ async clear() {
385
+ }
386
+ async print() {
387
+ }
388
+ constructor({ rootPath }) {
389
+ this.rootPath = rootPath || "";
390
+ }
391
+ async query(queryStrings) {
392
+ throw new Error(`Unable to perform query for Filesystem store`);
393
+ }
394
+ async seed() {
395
+ throw new Error(`Seeding data is not possible for Filesystem store`);
396
+ }
397
+ async get(filepath) {
398
+ return parseFile(await import_fs_extra2.default.readFileSync(import_path4.default.join(this.rootPath, filepath)).toString(), import_path4.default.extname(filepath), (yup2) => yup2.object());
399
+ }
400
+ supportsSeeding() {
401
+ return false;
402
+ }
403
+ supportsIndexing() {
404
+ return false;
405
+ }
406
+ async glob(pattern, callback) {
407
+ const basePath = import_path4.default.join(this.rootPath, ...pattern.split("/"));
408
+ const itemsRaw = await (0, import_fast_glob2.default)(import_path4.default.join(basePath, "**", "/*").replace(/\\/g, "/"), {
409
+ dot: true
410
+ });
411
+ const posixRootPath = (0, import_normalize_path2.default)(this.rootPath);
412
+ const items = itemsRaw.map((item) => {
413
+ return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
414
+ });
415
+ if (callback) {
416
+ return sequential(items, async (item) => {
417
+ return callback(item);
418
+ });
419
+ } else {
420
+ return items;
421
+ }
422
+ }
423
+ async put(filepath, data) {
424
+ await import_fs_extra2.default.outputFileSync(import_path4.default.join(this.rootPath, filepath), stringifyFile(data, import_path4.default.extname(filepath), false));
425
+ }
426
+ };
427
+
428
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/store/memory.ts
429
+ var MemoryStore = class {
430
+ constructor(rootPath, object = {}) {
431
+ this.map = object;
432
+ this.rootPath = rootPath || "";
433
+ this.db = {
434
+ get: async (filepath) => {
435
+ return this.map[filepath];
436
+ },
437
+ put: async (filepath, content) => {
438
+ this.map[filepath] = content;
439
+ await this.print();
440
+ }
441
+ };
442
+ }
443
+ async query(queryStrings, hydrator) {
444
+ const resultSets = await sequential(queryStrings, async (queryString) => {
445
+ const res = await this.get(queryString);
446
+ return res || [];
447
+ });
448
+ let items = [];
449
+ if (resultSets.length > 0) {
450
+ items = resultSets.reduce((p, c) => p.filter((e) => c.includes(e)));
451
+ }
452
+ return sequential(items, async (documentString) => {
453
+ return hydrator(documentString);
454
+ });
455
+ }
456
+ async seed(filepath, data) {
457
+ await this.put(filepath, data);
458
+ }
459
+ supportsSeeding() {
460
+ return true;
461
+ }
462
+ supportsIndexing() {
463
+ return true;
464
+ }
465
+ async print() {
466
+ }
467
+ async clear() {
468
+ this.map = {};
469
+ }
470
+ async glob(pattern, callback) {
471
+ const strings = Object.keys(this.map).filter((key) => {
472
+ if (key.startsWith(pattern)) {
473
+ return true;
474
+ } else {
475
+ return false;
476
+ }
477
+ });
478
+ if (callback) {
479
+ return sequential(strings, async (item) => {
480
+ return callback(item);
481
+ });
482
+ } else {
483
+ return strings;
484
+ }
485
+ }
486
+ async get(filepath) {
487
+ const content = await this.db.get(filepath);
488
+ return content;
489
+ }
490
+ async put(filepath, data) {
491
+ await this.db.put(filepath, data);
492
+ }
493
+ };
494
+
495
+ // pnp:/Users/jeffsee/code/tinacms2/packages/@tinacms/datalayer/src/database/store/level.ts
496
+ var import_path5 = __toModule(require("path"));
497
+ var import_level = __toModule(require("level"));
498
+ var import_levelup = __toModule(require("levelup"));
499
+ var import_memdown = __toModule(require("memdown"));
500
+ var import_encoding_down = __toModule(require("encoding-down"));
501
+ var LevelStore = class {
502
+ constructor(rootPath, useMemory = false) {
503
+ this.rootPath = rootPath || "";
504
+ if (useMemory) {
505
+ const db = (0, import_levelup.default)((0, import_encoding_down.default)((0, import_memdown.default)(), { valueEncoding: "json" }));
506
+ this.db = db;
507
+ } else {
508
+ const db = (0, import_level.default)(import_path5.default.join(rootPath, ".tina/__generated__/db"), {
509
+ valueEncoding: "json"
510
+ });
511
+ this.db = db;
512
+ }
513
+ }
514
+ async query(queryStrings, hydrator) {
515
+ const resultSets = await sequential(queryStrings, async (queryString) => {
516
+ let strings = [];
517
+ const p = new Promise((resolve, reject) => {
518
+ this.db.createReadStream({
519
+ gte: queryString,
520
+ lte: queryString + "\xFF"
521
+ }).on("data", (data) => {
522
+ strings = [...strings, ...data.value];
523
+ }).on("error", (message) => {
524
+ reject(message);
525
+ }).on("end", function() {
526
+ resolve();
527
+ });
528
+ });
529
+ await p;
530
+ return strings || [];
531
+ });
532
+ let items = [];
533
+ if (resultSets.length > 0) {
534
+ items = resultSets.reduce((p, c) => p.filter((e) => c.includes(e)));
535
+ }
536
+ return sequential(items, async (documentString) => {
537
+ return hydrator(documentString);
538
+ });
539
+ }
540
+ async seed(filepath, data) {
541
+ await this.put(filepath, data);
542
+ }
543
+ supportsSeeding() {
544
+ return true;
545
+ }
546
+ supportsIndexing() {
547
+ return true;
548
+ }
549
+ async print() {
550
+ this.db.createReadStream().on("data", function(data) {
551
+ console.log(data.key, "=", data.value);
552
+ }).on("error", function(err) {
553
+ console.log("Oh my!", err);
554
+ }).on("close", function() {
555
+ console.log("Stream closed");
556
+ }).on("end", function() {
557
+ console.log("Stream ended");
558
+ });
559
+ }
560
+ async open() {
561
+ await this.db.open();
562
+ }
563
+ async clear() {
564
+ await this.db.clear();
565
+ }
566
+ async glob(pattern, callback) {
567
+ const strings = [];
568
+ const p = new Promise((resolve, reject) => {
569
+ this.db.createKeyStream({
570
+ gte: pattern,
571
+ lte: pattern + "\xFF"
572
+ }).on("data", (data) => {
573
+ strings.push(data);
574
+ }).on("error", (message) => {
575
+ reject(message);
576
+ }).on("end", function() {
577
+ resolve();
578
+ });
579
+ });
580
+ await p;
581
+ if (callback) {
582
+ return sequential(strings, async (item) => {
583
+ return callback(item);
584
+ });
585
+ } else {
586
+ return strings;
587
+ }
588
+ }
589
+ async get(filepath) {
590
+ try {
591
+ const content = await this.db.get(filepath);
592
+ return content;
593
+ } catch (e) {
594
+ return void 0;
595
+ }
596
+ }
597
+ async put(filepath, data) {
598
+ await this.db.put(filepath, data);
599
+ }
600
+ };
601
+ // Annotate the CommonJS export names for ESM import in node:
602
+ 0 && (module.exports = {
603
+ FilesystemBridge,
604
+ FilesystemStore,
605
+ GithubBridge,
606
+ GithubStore,
607
+ LevelStore,
608
+ MemoryStore
609
+ });
package/dist/util.d.ts ADDED
@@ -0,0 +1,28 @@
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 * as yup from 'yup';
14
+ /**
15
+ * Iterate through an array of promises sequentially, ensuring the order
16
+ * is preserved.
17
+ *
18
+ * ```js
19
+ * await sequential(templates, async (template) => {
20
+ * await doSomething(template)
21
+ * })
22
+ * ```
23
+ */
24
+ export declare const sequential: <A, B>(items: A[], callback: (args: A, idx: number) => Promise<B>) => Promise<B[]>;
25
+ export declare function assertShape<T extends unknown>(value: unknown, yupSchema: (args: typeof yup) => yup.AnySchema, errorMessage?: string): asserts value is T;
26
+ export declare const atob: (b64Encoded: string) => string;
27
+ export declare const btoa: (string: string) => string;
28
+ export declare const lastItem: (arr: (number | string)[]) => string | number;
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@tinacms/datalayer",
3
+ "version": "0.0.0",
4
+ "main": "dist/index.js",
5
+ "typings": "dist/index.d.ts",
6
+ "files": [
7
+ "package.json",
8
+ "dist"
9
+ ],
10
+ "license": "Apache-2.0",
11
+ "buildConfig": {
12
+ "entryPoints": [
13
+ {
14
+ "name": "src/index.ts",
15
+ "target": "node",
16
+ "bundle": []
17
+ }
18
+ ]
19
+ },
20
+ "scripts": {
21
+ "types": "yarn tsc",
22
+ "build": "echo \"Run `yarn build` from the root of the repository instead\"",
23
+ "test": "jest"
24
+ },
25
+ "dependencies": {
26
+ "@octokit/auth-app": "^2.6.0",
27
+ "@octokit/graphql": "^4.5.6",
28
+ "@octokit/rest": "18.0.6",
29
+ "encoding-down": "^7.1.0",
30
+ "fast-glob": "^3.2.5",
31
+ "fs-extra": "^9.0.1",
32
+ "graphql": "^15.3.0",
33
+ "gray-matter": "^4.0.2",
34
+ "js-yaml": "^3.14.0",
35
+ "level": "^7.0.1",
36
+ "levelup": "^5.1.1",
37
+ "lodash": "^4.17.20",
38
+ "memdown": "^6.1.1",
39
+ "normalize-path": "^3.0.0",
40
+ "prettier": "^2.2.1",
41
+ "yup": "^0.32.9"
42
+ },
43
+ "publishConfig": {
44
+ "registry": "https://registry.npmjs.org"
45
+ },
46
+ "repository": {
47
+ "url": "https://github.com/tinacms/tinacms.git",
48
+ "directory": "packages/@tinacms/datalayer"
49
+ },
50
+ "devDependencies": {
51
+ "@tinacms/scripts": "0.50.4",
52
+ "@types/fs-extra": "^9.0.2",
53
+ "@types/jest": "^26.0.4",
54
+ "@types/js-yaml": "^3.12.5",
55
+ "@types/level": "^6.0.0",
56
+ "@types/lodash": "^4.14.161",
57
+ "@types/lodash.camelcase": "^4.3.6",
58
+ "@types/lodash.upperfirst": "^4.3.6",
59
+ "@types/node": "^14.17.34",
60
+ "@types/normalize-path": "^3.0.0",
61
+ "@types/yup": "^0.29.7",
62
+ "jest": "27.0.6",
63
+ "jest-diff": "27.0.6",
64
+ "jest-file-snapshot": "^0.5.0",
65
+ "jest-matcher-utils": "27.0.6",
66
+ "typescript": "^4.3.5"
67
+ }
68
+ }