@tinacms/datalayer 0.1.0 → 0.1.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/CHANGELOG.md +7 -0
- package/dist/database/bridge/filesystem.d.ts +1 -0
- package/dist/database/store/filesystem.d.ts +2 -1
- package/dist/database/store/index.d.ts +4 -0
- package/dist/database/store/level.d.ts +2 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.js +33 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -21,6 +21,7 @@ export declare class FilesystemBridge implements Bridge {
|
|
|
21
21
|
constructor(rootPath: string);
|
|
22
22
|
glob(pattern: string): Promise<string[]>;
|
|
23
23
|
supportsBuilding(): boolean;
|
|
24
|
+
delete(filepath: string): Promise<void>;
|
|
24
25
|
get(filepath: string): Promise<string>;
|
|
25
26
|
putConfig(filepath: string, data: string): Promise<void>;
|
|
26
27
|
put(filepath: string, data: string): Promise<void>;
|
|
@@ -3,7 +3,7 @@ Copyright 2021 Forestry.io Holdings, Inc.
|
|
|
3
3
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
you may not use this file except in compliance with the License.
|
|
5
5
|
You may obtain a copy of the License at
|
|
6
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
7
|
Unless required by applicable law or agreed to in writing, software
|
|
8
8
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
9
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
@@ -27,6 +27,7 @@ export declare class FilesystemStore implements Store {
|
|
|
27
27
|
put(filepath: string, data: object, options?: PutOptions): Promise<void>;
|
|
28
28
|
open(): Promise<void>;
|
|
29
29
|
close(): Promise<void>;
|
|
30
|
+
delete(filepath: any): Promise<void>;
|
|
30
31
|
}
|
|
31
32
|
export declare class AuditFilesystemStore extends FilesystemStore {
|
|
32
33
|
put(_filepath: string, _data: object): Promise<void>;
|
|
@@ -85,9 +85,13 @@ export declare type SeedOptions = {
|
|
|
85
85
|
export declare type PutOptions = SeedOptions & {
|
|
86
86
|
seed?: boolean;
|
|
87
87
|
};
|
|
88
|
+
export declare type DeleteOptions = SeedOptions & {
|
|
89
|
+
seed?: boolean;
|
|
90
|
+
};
|
|
88
91
|
export interface Store {
|
|
89
92
|
glob(pattern: string, hydrator?: (fullPath: string) => Promise<object>): Promise<string[]>;
|
|
90
93
|
get<T extends object>(filepath: string): Promise<T>;
|
|
94
|
+
delete(filepath: string, options?: DeleteOptions): Promise<void>;
|
|
91
95
|
clear(): void;
|
|
92
96
|
close(): void;
|
|
93
97
|
open(): void;
|
|
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
10
10
|
See the License for the specific language governing permissions and
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import type { StoreQueryOptions, StoreQueryResponse, PutOptions, SeedOptions, Store } from './index';
|
|
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 {
|
|
16
16
|
rootPath: any;
|
|
@@ -21,6 +21,7 @@ export declare class LevelStore implements Store {
|
|
|
21
21
|
seed(filepath: string, data: object, options?: SeedOptions): Promise<void>;
|
|
22
22
|
supportsSeeding(): boolean;
|
|
23
23
|
supportsIndexing(): boolean;
|
|
24
|
+
delete(filepath: string, options: DeleteOptions): Promise<void>;
|
|
24
25
|
print(): Promise<void>;
|
|
25
26
|
open(): Promise<void>;
|
|
26
27
|
clear(): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
export { FilesystemBridge, AuditFileSystemBridge, } from './database/bridge/filesystem';
|
|
14
14
|
export { FilesystemStore, AuditFilesystemStore, } from './database/store/filesystem';
|
|
15
15
|
export { LevelStore } from './database/store/level';
|
|
16
16
|
export { coerceFilterChainOperands, DEFAULT_COLLECTION_SORT_KEY, DEFAULT_NUMERIC_LPAD, INDEX_KEY_FIELD_SEPARATOR, makeFilter, makeFilterChain, makeFilterSuffixes, makeKeyForField, makeStringEscaper, OP, } from './database/store';
|
|
17
|
-
export type { BinaryFilter, FilterCondition, IndexDefinition, PadDefinition, StoreQueryOptions, StoreQueryResponse, PageInfo, PutOptions, SeedOptions, Store, TernaryFilter, } from './database/store';
|
|
17
|
+
export type { BinaryFilter, FilterCondition, IndexDefinition, PadDefinition, StoreQueryOptions, StoreQueryResponse, PageInfo, PutOptions, DeleteOptions, SeedOptions, Store, TernaryFilter, } from './database/store';
|
|
18
18
|
export declare type FilterOperand = string | number | boolean | string[] | number[];
|
|
19
19
|
export { atob, btoa } from './util';
|
package/dist/index.js
CHANGED
|
@@ -94,6 +94,9 @@ var FilesystemBridge = class {
|
|
|
94
94
|
supportsBuilding() {
|
|
95
95
|
return true;
|
|
96
96
|
}
|
|
97
|
+
async delete(filepath) {
|
|
98
|
+
await import_fs_extra.default.remove(import_path.default.join(this.rootPath, filepath));
|
|
99
|
+
}
|
|
97
100
|
async get(filepath) {
|
|
98
101
|
return import_fs_extra.default.readFileSync(import_path.default.join(this.rootPath, filepath)).toString();
|
|
99
102
|
}
|
|
@@ -261,6 +264,9 @@ var FilesystemStore = class {
|
|
|
261
264
|
}
|
|
262
265
|
async close() {
|
|
263
266
|
}
|
|
267
|
+
async delete(filepath) {
|
|
268
|
+
await import_fs_extra2.default.remove(import_path2.default.join(this.rootPath, filepath));
|
|
269
|
+
}
|
|
264
270
|
};
|
|
265
271
|
var AuditFilesystemStore = class extends FilesystemStore {
|
|
266
272
|
async put(_filepath, _data) {
|
|
@@ -377,8 +383,13 @@ var makeFilter = ({
|
|
|
377
383
|
let operands;
|
|
378
384
|
if (dataType === "string" || dataType === "reference") {
|
|
379
385
|
operands = resolvedValues;
|
|
380
|
-
} else if (dataType === "number"
|
|
386
|
+
} else if (dataType === "number") {
|
|
381
387
|
operands = resolvedValues.map((resolvedValue) => Number(resolvedValue));
|
|
388
|
+
} else if (dataType === "datetime") {
|
|
389
|
+
operands = resolvedValues.map((resolvedValue) => {
|
|
390
|
+
const coerced = new Date(resolvedValue).getTime();
|
|
391
|
+
return isNaN(coerced) ? Number(resolvedValue) : coerced;
|
|
392
|
+
});
|
|
382
393
|
} else if (dataType === "boolean") {
|
|
383
394
|
operands = resolvedValues.map((resolvedValue) => typeof resolvedValue === "boolean" && resolvedValue || resolvedValue === "true" || resolvedValue === "1");
|
|
384
395
|
} else {
|
|
@@ -701,6 +712,27 @@ var LevelStore = class {
|
|
|
701
712
|
supportsIndexing() {
|
|
702
713
|
return true;
|
|
703
714
|
}
|
|
715
|
+
async delete(filepath, options) {
|
|
716
|
+
const data = await this.db.get(`${defaultPrefix}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`);
|
|
717
|
+
if (!data) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (options == null ? void 0 : options.indexDefinitions) {
|
|
721
|
+
for (const [sort, definition] of Object.entries(options.indexDefinitions)) {
|
|
722
|
+
const indexedValue = makeKeyForField(definition, data, escapeStr);
|
|
723
|
+
let indexKey;
|
|
724
|
+
if (sort === DEFAULT_COLLECTION_SORT_KEY) {
|
|
725
|
+
indexKey = `${options.collection}${INDEX_KEY_FIELD_SEPARATOR}${sort}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`;
|
|
726
|
+
} else {
|
|
727
|
+
indexKey = indexedValue ? `${options.collection}${INDEX_KEY_FIELD_SEPARATOR}${sort}${INDEX_KEY_FIELD_SEPARATOR}${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}` : null;
|
|
728
|
+
}
|
|
729
|
+
if (indexKey) {
|
|
730
|
+
await this.db.del(indexKey);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
await this.db.del(`${defaultPrefix}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`);
|
|
735
|
+
}
|
|
704
736
|
async print() {
|
|
705
737
|
this.db.createReadStream().on("data", function(data) {
|
|
706
738
|
console.log(data.key, "=", data.value);
|