@tinacms/datalayer 0.1.1 → 0.2.2
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/LICENSE +176 -0
- package/dist/database/bridge/filesystem.d.ts +2 -2
- package/dist/database/bridge/index.d.ts +2 -1
- package/dist/database/bridge/isomorphic.d.ts +108 -0
- package/dist/database/store/filesystem.d.ts +2 -2
- package/dist/database/store/index.d.ts +2 -2
- package/dist/database/store/level.d.ts +11 -11
- package/dist/index.d.ts +1 -0
- package/dist/index.js +352 -25
- package/package.json +10 -8
- package/CHANGELOG.md +0 -828
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
|
-
//
|
|
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
|
-
//
|
|
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, "**",
|
|
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);
|
|
@@ -108,23 +109,347 @@ var FilesystemBridge = class {
|
|
|
108
109
|
}
|
|
109
110
|
};
|
|
110
111
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|
|
111
|
-
async put(
|
|
112
|
+
async put(filepath, data) {
|
|
113
|
+
if ([
|
|
114
|
+
".tina/__generated__/_lookup.json",
|
|
115
|
+
".tina/__generated__/_schema.json",
|
|
116
|
+
".tina/__generated__/_graphql.json"
|
|
117
|
+
].includes(filepath)) {
|
|
118
|
+
return super.put(filepath, data);
|
|
119
|
+
}
|
|
112
120
|
return;
|
|
113
121
|
}
|
|
114
122
|
};
|
|
115
123
|
|
|
116
|
-
//
|
|
124
|
+
// src/database/bridge/isomorphic.ts
|
|
125
|
+
var import_isomorphic_git = __toModule(require("isomorphic-git"));
|
|
117
126
|
var import_fs_extra2 = __toModule(require("fs-extra"));
|
|
127
|
+
var import_glob_parent = __toModule(require("glob-parent"));
|
|
128
|
+
var import_normalize_path2 = __toModule(require("normalize-path"));
|
|
129
|
+
var import_graphql = __toModule(require("graphql"));
|
|
130
|
+
var flat = typeof Array.prototype.flat === "undefined" ? (entries) => entries.reduce((acc, x) => acc.concat(x), []) : (entries) => entries.flat();
|
|
131
|
+
var toUint8Array = (buf) => {
|
|
132
|
+
const ab = new ArrayBuffer(buf.length);
|
|
133
|
+
const view = new Uint8Array(ab);
|
|
134
|
+
for (let i = 0; i < buf.length; ++i) {
|
|
135
|
+
view[i] = buf[i];
|
|
136
|
+
}
|
|
137
|
+
return view;
|
|
138
|
+
};
|
|
139
|
+
var IsomorphicBridge = class {
|
|
140
|
+
constructor(rootPath, {
|
|
141
|
+
gitRoot,
|
|
142
|
+
author,
|
|
143
|
+
committer,
|
|
144
|
+
fsModule = import_fs_extra2.default,
|
|
145
|
+
commitMessage = "Update from GraphQL client",
|
|
146
|
+
ref,
|
|
147
|
+
onPut,
|
|
148
|
+
onDelete
|
|
149
|
+
}) {
|
|
150
|
+
this.cache = {};
|
|
151
|
+
this.rootPath = rootPath;
|
|
152
|
+
this.gitRoot = gitRoot;
|
|
153
|
+
this.relativePath = rootPath.slice(this.gitRoot.length).replace(/\\/g, "/");
|
|
154
|
+
if (this.relativePath.startsWith("/")) {
|
|
155
|
+
this.relativePath = this.relativePath.slice(1);
|
|
156
|
+
}
|
|
157
|
+
this.fsModule = fsModule;
|
|
158
|
+
this.author = author;
|
|
159
|
+
this.committer = committer || author;
|
|
160
|
+
this.isomorphicConfig = {
|
|
161
|
+
dir: (0, import_normalize_path2.default)(this.gitRoot),
|
|
162
|
+
fs: this.fsModule
|
|
163
|
+
};
|
|
164
|
+
this.ref = ref;
|
|
165
|
+
this.commitMessage = commitMessage;
|
|
166
|
+
this.onPut = onPut || (() => {
|
|
167
|
+
});
|
|
168
|
+
this.onDelete = onDelete || (() => {
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
getAuthor() {
|
|
172
|
+
return __spreadProps(__spreadValues({}, this.author), {
|
|
173
|
+
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
174
|
+
timezoneOffset: 0
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
getCommitter() {
|
|
178
|
+
return __spreadProps(__spreadValues({}, this.committer), {
|
|
179
|
+
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
180
|
+
timezoneOffset: 0
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async listEntries({
|
|
184
|
+
pattern,
|
|
185
|
+
entry,
|
|
186
|
+
path: path4,
|
|
187
|
+
results
|
|
188
|
+
}) {
|
|
189
|
+
const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
190
|
+
oid: entry.oid,
|
|
191
|
+
cache: this.cache
|
|
192
|
+
}));
|
|
193
|
+
const children = [];
|
|
194
|
+
for (const childEntry of treeResult.tree) {
|
|
195
|
+
const childPath = path4 ? `${path4}/${childEntry.path}` : childEntry.path;
|
|
196
|
+
if (childEntry.type === "tree") {
|
|
197
|
+
children.push(childEntry);
|
|
198
|
+
} else {
|
|
199
|
+
if (childPath.startsWith(pattern)) {
|
|
200
|
+
results.push(childPath);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const childEntry of children) {
|
|
205
|
+
const childPath = path4 ? `${path4}/${childEntry.path}` : childEntry.path;
|
|
206
|
+
await this.listEntries({
|
|
207
|
+
pattern,
|
|
208
|
+
entry: childEntry,
|
|
209
|
+
path: childPath,
|
|
210
|
+
results
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
async resolvePathEntries(path4, ref) {
|
|
215
|
+
let pathParts = path4.split("/");
|
|
216
|
+
const result = await import_isomorphic_git.default.walk(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
217
|
+
map: async (filepath, [head]) => {
|
|
218
|
+
if (head._fullpath === "." || path4.startsWith(filepath)) {
|
|
219
|
+
return head;
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
cache: this.cache,
|
|
223
|
+
trees: [import_isomorphic_git.default.TREE({ ref })]
|
|
224
|
+
}));
|
|
225
|
+
const pathEntries = flat(result);
|
|
226
|
+
if (pathParts.indexOf(".") === -1) {
|
|
227
|
+
pathParts = [".", ...pathParts];
|
|
228
|
+
}
|
|
229
|
+
while (pathParts.length > pathEntries.length) {
|
|
230
|
+
pathEntries.push(null);
|
|
231
|
+
}
|
|
232
|
+
return { pathParts, pathEntries };
|
|
233
|
+
}
|
|
234
|
+
async updateTreeHierarchy(existingOid, updatedOid, path4, type, pathEntries, pathParts) {
|
|
235
|
+
const lastIdx = pathEntries.length - 1;
|
|
236
|
+
const parentEntry = pathEntries[lastIdx];
|
|
237
|
+
const parentPath = pathParts[lastIdx];
|
|
238
|
+
let parentOid;
|
|
239
|
+
let tree;
|
|
240
|
+
const mode = type === "blob" ? "100644" : "040000";
|
|
241
|
+
if (parentEntry) {
|
|
242
|
+
parentOid = await parentEntry.oid();
|
|
243
|
+
const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
244
|
+
oid: parentOid,
|
|
245
|
+
cache: this.cache
|
|
246
|
+
}));
|
|
247
|
+
tree = existingOid ? treeResult.tree.map((entry) => {
|
|
248
|
+
if (entry.path === path4) {
|
|
249
|
+
entry.oid = updatedOid;
|
|
250
|
+
}
|
|
251
|
+
return entry;
|
|
252
|
+
}) : [
|
|
253
|
+
...treeResult.tree,
|
|
254
|
+
{
|
|
255
|
+
oid: updatedOid,
|
|
256
|
+
type,
|
|
257
|
+
path: path4,
|
|
258
|
+
mode
|
|
259
|
+
}
|
|
260
|
+
];
|
|
261
|
+
} else {
|
|
262
|
+
tree = [
|
|
263
|
+
{
|
|
264
|
+
oid: updatedOid,
|
|
265
|
+
type,
|
|
266
|
+
path: path4,
|
|
267
|
+
mode
|
|
268
|
+
}
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
const updatedParentOid = await import_isomorphic_git.default.writeTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
272
|
+
tree
|
|
273
|
+
}));
|
|
274
|
+
if (lastIdx === 0) {
|
|
275
|
+
return updatedParentOid;
|
|
276
|
+
} else {
|
|
277
|
+
return await this.updateTreeHierarchy(parentOid, updatedParentOid, parentPath, "tree", pathEntries.slice(0, lastIdx), pathParts.slice(0, lastIdx));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
async commitTree(treeSha, ref) {
|
|
281
|
+
const commitSha = await import_isomorphic_git.default.writeCommit(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
282
|
+
commit: {
|
|
283
|
+
tree: treeSha,
|
|
284
|
+
parent: [
|
|
285
|
+
await import_isomorphic_git.default.resolveRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
286
|
+
ref
|
|
287
|
+
}))
|
|
288
|
+
],
|
|
289
|
+
message: this.commitMessage,
|
|
290
|
+
author: this.getAuthor(),
|
|
291
|
+
committer: this.getCommitter()
|
|
292
|
+
}
|
|
293
|
+
}));
|
|
294
|
+
await import_isomorphic_git.default.writeRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
295
|
+
ref,
|
|
296
|
+
value: commitSha,
|
|
297
|
+
force: true
|
|
298
|
+
}));
|
|
299
|
+
}
|
|
300
|
+
async getRef() {
|
|
301
|
+
if (this.ref) {
|
|
302
|
+
return this.ref;
|
|
303
|
+
}
|
|
304
|
+
const ref = await import_isomorphic_git.default.currentBranch(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
305
|
+
fullname: true
|
|
306
|
+
}));
|
|
307
|
+
if (!ref) {
|
|
308
|
+
throw new import_graphql.GraphQLError(`Unable to determine current branch from HEAD`, null, null, null, null, null, {});
|
|
309
|
+
}
|
|
310
|
+
this.ref = ref;
|
|
311
|
+
return ref;
|
|
312
|
+
}
|
|
313
|
+
async glob(pattern, extension) {
|
|
314
|
+
const ref = await this.getRef();
|
|
315
|
+
const parent = (0, import_glob_parent.default)(this.qualifyPath(pattern));
|
|
316
|
+
const { pathParts, pathEntries } = await this.resolvePathEntries(parent, ref);
|
|
317
|
+
const leafEntry = pathEntries[pathEntries.length - 1];
|
|
318
|
+
const entryPath = pathParts[pathParts.length - 1];
|
|
319
|
+
const parentEntry = pathEntries[pathEntries.length - 2];
|
|
320
|
+
let treeEntry;
|
|
321
|
+
let parentPath;
|
|
322
|
+
if (parentEntry) {
|
|
323
|
+
const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
324
|
+
oid: await parentEntry.oid(),
|
|
325
|
+
cache: this.cache
|
|
326
|
+
}));
|
|
327
|
+
treeEntry = treeResult.tree.find((entry) => entry.path === entryPath);
|
|
328
|
+
parentPath = pathParts.slice(1, pathParts.length).join("/");
|
|
329
|
+
} else {
|
|
330
|
+
treeEntry = {
|
|
331
|
+
type: "tree",
|
|
332
|
+
oid: await leafEntry.oid()
|
|
333
|
+
};
|
|
334
|
+
parentPath = "";
|
|
335
|
+
}
|
|
336
|
+
const results = [];
|
|
337
|
+
await this.listEntries({
|
|
338
|
+
pattern: this.qualifyPath(pattern),
|
|
339
|
+
entry: treeEntry,
|
|
340
|
+
path: parentPath,
|
|
341
|
+
results
|
|
342
|
+
});
|
|
343
|
+
return results.map((path4) => this.unqualifyPath(path4)).filter((path4) => path4.endsWith(extension));
|
|
344
|
+
}
|
|
345
|
+
supportsBuilding() {
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
async delete(filepath) {
|
|
349
|
+
const ref = await this.getRef();
|
|
350
|
+
const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
|
|
351
|
+
let oidToRemove;
|
|
352
|
+
let ptr = pathEntries.length - 1;
|
|
353
|
+
while (ptr >= 1) {
|
|
354
|
+
const leafEntry = pathEntries[ptr];
|
|
355
|
+
const nodePath = pathParts[ptr];
|
|
356
|
+
if (leafEntry) {
|
|
357
|
+
oidToRemove = oidToRemove || await leafEntry.oid();
|
|
358
|
+
const parentEntry = pathEntries[ptr - 1];
|
|
359
|
+
const existingOid = await parentEntry.oid();
|
|
360
|
+
const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
361
|
+
oid: existingOid,
|
|
362
|
+
cache: this.cache
|
|
363
|
+
}));
|
|
364
|
+
const updatedTree = treeResult.tree.filter((value) => value.path !== nodePath);
|
|
365
|
+
if (updatedTree.length === 0) {
|
|
366
|
+
ptr -= 1;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
const updatedTreeOid = await import_isomorphic_git.default.writeTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
370
|
+
tree: updatedTree
|
|
371
|
+
}));
|
|
372
|
+
const updatedRootTreeOid = await this.updateTreeHierarchy(existingOid, updatedTreeOid, pathParts[ptr - 1], "tree", pathEntries.slice(0, ptr - 1), pathParts.slice(0, ptr - 1));
|
|
373
|
+
await this.commitTree(updatedRootTreeOid, ref);
|
|
374
|
+
break;
|
|
375
|
+
} else {
|
|
376
|
+
throw new import_graphql.GraphQLError(`Unable to resolve path: ${filepath}`, null, null, null, null, null, { status: 404 });
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (oidToRemove) {
|
|
380
|
+
await import_isomorphic_git.default.updateIndex(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
381
|
+
filepath: this.qualifyPath(filepath),
|
|
382
|
+
force: true,
|
|
383
|
+
remove: true,
|
|
384
|
+
oid: oidToRemove,
|
|
385
|
+
cache: this.cache
|
|
386
|
+
}));
|
|
387
|
+
}
|
|
388
|
+
await this.onDelete(filepath);
|
|
389
|
+
}
|
|
390
|
+
qualifyPath(filepath) {
|
|
391
|
+
return this.relativePath ? `${this.relativePath}/${filepath}` : filepath;
|
|
392
|
+
}
|
|
393
|
+
unqualifyPath(filepath) {
|
|
394
|
+
return this.relativePath ? filepath.slice(this.relativePath.length + 1) : filepath;
|
|
395
|
+
}
|
|
396
|
+
async get(filepath) {
|
|
397
|
+
const ref = await this.getRef();
|
|
398
|
+
const oid = await import_isomorphic_git.default.resolveRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
399
|
+
ref
|
|
400
|
+
}));
|
|
401
|
+
const { blob } = await import_isomorphic_git.default.readBlob(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
402
|
+
oid,
|
|
403
|
+
filepath: this.qualifyPath(filepath),
|
|
404
|
+
cache: this.cache
|
|
405
|
+
}));
|
|
406
|
+
return Buffer.from(blob).toString("utf8");
|
|
407
|
+
}
|
|
408
|
+
async putConfig(filepath, data) {
|
|
409
|
+
await this.put(filepath, data);
|
|
410
|
+
}
|
|
411
|
+
async put(filepath, data) {
|
|
412
|
+
const ref = await this.getRef();
|
|
413
|
+
const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
|
|
414
|
+
const blobUpdate = toUint8Array(Buffer.from(data));
|
|
415
|
+
let existingOid;
|
|
416
|
+
const leafEntry = pathEntries[pathEntries.length - 1];
|
|
417
|
+
const nodePath = pathParts[pathParts.length - 1];
|
|
418
|
+
if (leafEntry) {
|
|
419
|
+
existingOid = await leafEntry.oid();
|
|
420
|
+
const hash = await import_isomorphic_git.default.hashBlob({ object: blobUpdate });
|
|
421
|
+
if (hash.oid === existingOid) {
|
|
422
|
+
await this.onPut(filepath, data);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
const updatedOid = await import_isomorphic_git.default.writeBlob(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
427
|
+
blob: blobUpdate
|
|
428
|
+
}));
|
|
429
|
+
const updatedRootSha = await this.updateTreeHierarchy(existingOid, updatedOid, nodePath, "blob", pathEntries.slice(0, pathEntries.length - 1), pathParts.slice(0, pathParts.length - 1));
|
|
430
|
+
await this.commitTree(updatedRootSha, ref);
|
|
431
|
+
await import_isomorphic_git.default.updateIndex(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
|
|
432
|
+
filepath: this.qualifyPath(filepath),
|
|
433
|
+
add: true,
|
|
434
|
+
oid: updatedOid,
|
|
435
|
+
cache: this.cache
|
|
436
|
+
}));
|
|
437
|
+
await this.onPut(filepath, data);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// src/database/store/filesystem.ts
|
|
442
|
+
var import_fs_extra3 = __toModule(require("fs-extra"));
|
|
118
443
|
var import_fast_glob2 = __toModule(require("fast-glob"));
|
|
119
444
|
var import_path2 = __toModule(require("path"));
|
|
120
|
-
var
|
|
445
|
+
var import_normalize_path3 = __toModule(require("normalize-path"));
|
|
121
446
|
|
|
122
|
-
//
|
|
447
|
+
// src/database/util.ts
|
|
123
448
|
var import_gray_matter = __toModule(require("gray-matter"));
|
|
124
449
|
|
|
125
|
-
//
|
|
450
|
+
// src/util.ts
|
|
126
451
|
var yup = __toModule(require("yup"));
|
|
127
|
-
var
|
|
452
|
+
var import_graphql2 = __toModule(require("graphql"));
|
|
128
453
|
var sequential = async (items, callback) => {
|
|
129
454
|
const accum = [];
|
|
130
455
|
if (!items) {
|
|
@@ -149,7 +474,7 @@ function assertShape(value, yupSchema, errorMessage) {
|
|
|
149
474
|
shape.validateSync(value);
|
|
150
475
|
} catch (e) {
|
|
151
476
|
const message = errorMessage || `Failed to assertShape - ${e.message}`;
|
|
152
|
-
throw new
|
|
477
|
+
throw new import_graphql2.GraphQLError(message, null, null, null, null, null, {
|
|
153
478
|
stack: e.stack
|
|
154
479
|
});
|
|
155
480
|
}
|
|
@@ -161,7 +486,7 @@ var btoa = (string) => {
|
|
|
161
486
|
return Buffer.from(string).toString("base64");
|
|
162
487
|
};
|
|
163
488
|
|
|
164
|
-
//
|
|
489
|
+
// src/database/util.ts
|
|
165
490
|
var stringifyFile = (content, format, keepTemplateKey) => {
|
|
166
491
|
switch (format) {
|
|
167
492
|
case ".markdown":
|
|
@@ -216,7 +541,7 @@ var parseFile = (content, format, yupSchema) => {
|
|
|
216
541
|
}
|
|
217
542
|
};
|
|
218
543
|
|
|
219
|
-
//
|
|
544
|
+
// src/database/store/filesystem.ts
|
|
220
545
|
var FilesystemStore = class {
|
|
221
546
|
async clear() {
|
|
222
547
|
}
|
|
@@ -225,14 +550,14 @@ var FilesystemStore = class {
|
|
|
225
550
|
constructor({ rootPath }) {
|
|
226
551
|
this.rootPath = rootPath || "";
|
|
227
552
|
}
|
|
228
|
-
async query(
|
|
553
|
+
async query(_queryOptions) {
|
|
229
554
|
throw new Error(`Unable to perform query for Filesystem store`);
|
|
230
555
|
}
|
|
231
556
|
async seed() {
|
|
232
557
|
throw new Error(`Seeding data is not possible for Filesystem store`);
|
|
233
558
|
}
|
|
234
559
|
async get(filepath) {
|
|
235
|
-
return parseFile(await
|
|
560
|
+
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
561
|
}
|
|
237
562
|
supportsSeeding() {
|
|
238
563
|
return false;
|
|
@@ -240,12 +565,12 @@ var FilesystemStore = class {
|
|
|
240
565
|
supportsIndexing() {
|
|
241
566
|
return false;
|
|
242
567
|
}
|
|
243
|
-
async glob(pattern, callback) {
|
|
568
|
+
async glob(pattern, callback, extension) {
|
|
244
569
|
const basePath = import_path2.default.join(this.rootPath, ...pattern.split("/"));
|
|
245
|
-
const itemsRaw = await (0, import_fast_glob2.default)(import_path2.default.join(basePath, "**",
|
|
570
|
+
const itemsRaw = await (0, import_fast_glob2.default)(import_path2.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"), {
|
|
246
571
|
dot: true
|
|
247
572
|
});
|
|
248
|
-
const posixRootPath = (0,
|
|
573
|
+
const posixRootPath = (0, import_normalize_path3.default)(this.rootPath);
|
|
249
574
|
const items = itemsRaw.map((item) => {
|
|
250
575
|
return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
|
|
251
576
|
});
|
|
@@ -258,14 +583,14 @@ var FilesystemStore = class {
|
|
|
258
583
|
}
|
|
259
584
|
}
|
|
260
585
|
async put(filepath, data, options) {
|
|
261
|
-
await
|
|
586
|
+
await import_fs_extra3.default.outputFileSync(import_path2.default.join(this.rootPath, filepath), stringifyFile(data, import_path2.default.extname(filepath), options.keepTemplateKey));
|
|
262
587
|
}
|
|
263
588
|
async open() {
|
|
264
589
|
}
|
|
265
590
|
async close() {
|
|
266
591
|
}
|
|
267
592
|
async delete(filepath) {
|
|
268
|
-
await
|
|
593
|
+
await import_fs_extra3.default.remove(import_path2.default.join(this.rootPath, filepath));
|
|
269
594
|
}
|
|
270
595
|
};
|
|
271
596
|
var AuditFilesystemStore = class extends FilesystemStore {
|
|
@@ -274,7 +599,7 @@ var AuditFilesystemStore = class extends FilesystemStore {
|
|
|
274
599
|
}
|
|
275
600
|
};
|
|
276
601
|
|
|
277
|
-
//
|
|
602
|
+
// src/database/store/index.ts
|
|
278
603
|
var import_jsonpath_plus = __toModule(require("jsonpath-plus"));
|
|
279
604
|
var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
|
|
280
605
|
var INDEX_KEY_FIELD_SEPARATOR = "#";
|
|
@@ -603,11 +928,12 @@ var makeFilterSuffixes = (filterChain, index) => {
|
|
|
603
928
|
return {};
|
|
604
929
|
}
|
|
605
930
|
};
|
|
606
|
-
var makeKeyForField = (definition, data, stringEscaper) => {
|
|
931
|
+
var makeKeyForField = (definition, data, stringEscaper, maxStringLength = 100) => {
|
|
607
932
|
const valueParts = [];
|
|
608
933
|
for (const field of definition.fields) {
|
|
609
|
-
if (field.name in data) {
|
|
610
|
-
const
|
|
934
|
+
if (field.name in data && data[field.name] !== void 0 && data[field.name] !== null) {
|
|
935
|
+
const rawValue = data[field.name];
|
|
936
|
+
const resolvedValue = String(field.type === "datetime" ? new Date(rawValue).getTime() : field.type === "string" ? stringEscaper(rawValue) : rawValue).substring(0, maxStringLength);
|
|
611
937
|
valueParts.push(applyPadding(resolvedValue, field.pad));
|
|
612
938
|
} else {
|
|
613
939
|
return null;
|
|
@@ -616,7 +942,7 @@ var makeKeyForField = (definition, data, stringEscaper) => {
|
|
|
616
942
|
return valueParts.join(INDEX_KEY_FIELD_SEPARATOR);
|
|
617
943
|
};
|
|
618
944
|
|
|
619
|
-
//
|
|
945
|
+
// src/database/store/level.ts
|
|
620
946
|
var import_path3 = __toModule(require("path"));
|
|
621
947
|
var import_level = __toModule(require("level"));
|
|
622
948
|
var import_levelup = __toModule(require("levelup"));
|
|
@@ -825,6 +1151,7 @@ var LevelStore = class {
|
|
|
825
1151
|
FilesystemBridge,
|
|
826
1152
|
FilesystemStore,
|
|
827
1153
|
INDEX_KEY_FIELD_SEPARATOR,
|
|
1154
|
+
IsomorphicBridge,
|
|
828
1155
|
LevelStore,
|
|
829
1156
|
OP,
|
|
830
1157
|
atob,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/datalayer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
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.
|
|
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": "
|
|
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
|
}
|