@tinacms/datalayer 0.0.0 → 0.1.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 +23 -0
- package/dist/database/bridge/filesystem.d.ts +6 -0
- package/dist/database/store/filesystem.d.ts +9 -4
- package/dist/database/store/index.d.ts +102 -36
- package/dist/database/store/level.d.ts +6 -4
- package/dist/index.d.ts +17 -17
- package/dist/index.js +520 -323
- package/package.json +6 -4
- package/dist/database/bridge/github.d.ts +0 -33
- package/dist/database/store/github.d.ts +0 -37
- package/dist/database/store/memory.d.ts +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# tina-graphql
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a87e1e6fa: Enable query filtering, pagination, sorting
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 8b3be903f: Escape index field separator in input strings
|
|
12
|
+
- b01f2e382: Fixed an issue where `0` as a numerical operand was being evaluated as falsy.
|
|
13
|
+
|
|
14
|
+
## 0.0.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- b399c734c: Fixes support for collection.templates in graphql
|
|
19
|
+
|
|
20
|
+
## 0.0.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 80732bd97: Create a @tinacms/datalayer package which houses the logic for data management for the GraphQL API. This simplifies the @tinacms/graphql package and allows for a clearer separation.
|
|
25
|
+
|
|
3
26
|
## 0.59.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -25,3 +25,9 @@ export declare class FilesystemBridge implements Bridge {
|
|
|
25
25
|
putConfig(filepath: string, data: string): Promise<void>;
|
|
26
26
|
put(filepath: string, data: string): Promise<void>;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Same as the `FileSystemBridge` except it does not save files
|
|
30
|
+
*/
|
|
31
|
+
export declare class AuditFileSystemBridge extends FilesystemBridge {
|
|
32
|
+
put(_filepath: string, _data: string): Promise<void>;
|
|
33
|
+
}
|
|
@@ -3,14 +3,14 @@ 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
|
-
|
|
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.
|
|
10
10
|
See the License for the specific language governing permissions and
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import { Store } from '.';
|
|
13
|
+
import { StoreQueryOptions, PutOptions, Store, StoreQueryResponse } from '.';
|
|
14
14
|
export declare class FilesystemStore implements Store {
|
|
15
15
|
rootPath: string;
|
|
16
16
|
clear(): Promise<void>;
|
|
@@ -18,11 +18,16 @@ export declare class FilesystemStore implements Store {
|
|
|
18
18
|
constructor({ rootPath }: {
|
|
19
19
|
rootPath?: string;
|
|
20
20
|
});
|
|
21
|
-
query(
|
|
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
26
|
glob(pattern: string, callback: any): Promise<any[]>;
|
|
27
|
-
put(filepath: string, data: object): Promise<void>;
|
|
27
|
+
put(filepath: string, data: object, options?: PutOptions): Promise<void>;
|
|
28
|
+
open(): Promise<void>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export declare class AuditFilesystemStore extends FilesystemStore {
|
|
32
|
+
put(_filepath: string, _data: object): Promise<void>;
|
|
28
33
|
}
|
|
@@ -10,42 +10,93 @@ 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 { FilterOperand } from '../../index';
|
|
14
|
+
export declare const DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
|
|
15
|
+
export declare const INDEX_KEY_FIELD_SEPARATOR = "#";
|
|
16
|
+
export declare const DEFAULT_NUMERIC_LPAD = 4;
|
|
17
|
+
export declare enum OP {
|
|
18
|
+
EQ = "eq",
|
|
19
|
+
GT = "gt",
|
|
20
|
+
LT = "lt",
|
|
21
|
+
GTE = "gte",
|
|
22
|
+
LTE = "lte",
|
|
23
|
+
STARTS_WITH = "startsWith",
|
|
24
|
+
IN = "in"
|
|
25
|
+
}
|
|
26
|
+
export declare type PadDefinition = {
|
|
27
|
+
fillString: string;
|
|
28
|
+
maxLength: number;
|
|
29
|
+
};
|
|
30
|
+
export declare type BinaryFilter = {
|
|
31
|
+
pathExpression: string;
|
|
32
|
+
rightOperand: FilterOperand;
|
|
33
|
+
operator: OP.EQ | OP.GT | OP.LT | OP.GTE | OP.LTE | OP.STARTS_WITH | OP.IN;
|
|
34
|
+
type: string;
|
|
35
|
+
pad?: PadDefinition;
|
|
36
|
+
};
|
|
37
|
+
export declare type TernaryFilter = {
|
|
38
|
+
pathExpression: string;
|
|
39
|
+
leftOperand: FilterOperand;
|
|
40
|
+
rightOperand: FilterOperand;
|
|
41
|
+
leftOperator: OP.GTE | OP.GT;
|
|
42
|
+
rightOperator: OP.LT | OP.LTE;
|
|
43
|
+
type: string;
|
|
44
|
+
pad?: PadDefinition;
|
|
45
|
+
};
|
|
46
|
+
/** Options for {@link Store.query} */
|
|
47
|
+
export declare type StoreQueryOptions = {
|
|
48
|
+
collection: string;
|
|
49
|
+
indexDefinitions?: Record<string, IndexDefinition>;
|
|
50
|
+
filterChain: (BinaryFilter | TernaryFilter)[];
|
|
51
|
+
sort?: string;
|
|
52
|
+
gt?: string;
|
|
53
|
+
gte?: string;
|
|
54
|
+
lt?: string;
|
|
55
|
+
lte?: string;
|
|
56
|
+
reverse?: boolean;
|
|
57
|
+
limit?: number;
|
|
58
|
+
};
|
|
59
|
+
export declare type PageInfo = {
|
|
60
|
+
hasPreviousPage: boolean;
|
|
61
|
+
hasNextPage: boolean;
|
|
62
|
+
startCursor: string;
|
|
63
|
+
endCursor: string;
|
|
64
|
+
};
|
|
65
|
+
export declare type StoreQueryResponse = {
|
|
66
|
+
edges: {
|
|
67
|
+
cursor: string;
|
|
68
|
+
path: string;
|
|
69
|
+
}[];
|
|
70
|
+
pageInfo: PageInfo;
|
|
71
|
+
};
|
|
72
|
+
export declare type IndexDefinition = {
|
|
73
|
+
fields: {
|
|
74
|
+
name: string;
|
|
75
|
+
type?: string;
|
|
76
|
+
pad?: PadDefinition;
|
|
77
|
+
}[];
|
|
78
|
+
};
|
|
79
|
+
export declare type SeedOptions = {
|
|
80
|
+
collection?: string;
|
|
81
|
+
indexDefinitions?: Record<string, IndexDefinition>;
|
|
82
|
+
includeTemplate?: boolean;
|
|
83
|
+
keepTemplateKey?: boolean;
|
|
84
|
+
};
|
|
85
|
+
export declare type PutOptions = SeedOptions & {
|
|
86
|
+
seed?: boolean;
|
|
87
|
+
};
|
|
13
88
|
export interface Store {
|
|
14
89
|
glob(pattern: string, hydrator?: (fullPath: string) => Promise<object>): Promise<string[]>;
|
|
15
90
|
get<T extends object>(filepath: string): Promise<T>;
|
|
16
91
|
clear(): void;
|
|
92
|
+
close(): void;
|
|
93
|
+
open(): void;
|
|
17
94
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param
|
|
20
|
-
*
|
|
21
|
-
* of the key is the value provided by the query
|
|
22
|
-
* ```graphql
|
|
23
|
-
* {
|
|
24
|
-
* getPostsList(filter: {
|
|
25
|
-
* title: {
|
|
26
|
-
* eq: "Hello, World"
|
|
27
|
-
* }
|
|
28
|
-
* }) {
|
|
29
|
-
* ...
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
* Would equate to a query string of:
|
|
34
|
-
* ```
|
|
35
|
-
* __attribute__#posts#posts#title#Hello, World
|
|
36
|
-
* ```
|
|
37
|
-
* This can be used by a data store as a secondary index of sorts
|
|
38
|
-
*
|
|
39
|
-
* It's important to note that for now each query string acts as an "AND" clause,
|
|
40
|
-
* meaning the resulting records need to be present in _each_ query string.
|
|
41
|
-
*
|
|
42
|
-
* @param hydrator
|
|
43
|
-
* hydrator is an optional callback, which may be useful depending on the storage mechanism.
|
|
44
|
-
* For example, the in-memory storage only stores the path to its records as its value,
|
|
45
|
-
* but in something like DynamoDB the query strings may be used to look up the full record,
|
|
46
|
-
* meaning there's no need to "hydrate" the return value
|
|
95
|
+
* Executes a query against a collection
|
|
96
|
+
* @param queryOptions - options for the query
|
|
97
|
+
* @returns the results of the query
|
|
47
98
|
*/
|
|
48
|
-
query(
|
|
99
|
+
query(queryOptions: StoreQueryOptions): Promise<StoreQueryResponse>;
|
|
49
100
|
/**
|
|
50
101
|
* In this context, seeding is the act of putting records and indexing data into an ephemeral
|
|
51
102
|
* storage layer for use during the GraphQL runtime. What might seem suprising is that some stores
|
|
@@ -56,9 +107,7 @@ export interface Store {
|
|
|
56
107
|
* At this time it seems that it would never make sense to be able to "query" without "seed"-ing, and
|
|
57
108
|
* there'd be no value in "seeding" without "query"-ing.
|
|
58
109
|
*/
|
|
59
|
-
seed(filepath: string, data: object, options?:
|
|
60
|
-
includeTemplate?: boolean;
|
|
61
|
-
}): Promise<void>;
|
|
110
|
+
seed(filepath: string, data: object, options?: PutOptions): Promise<void>;
|
|
62
111
|
supportsSeeding(): boolean;
|
|
63
112
|
/**
|
|
64
113
|
* Whether this store supports the ability to index data.
|
|
@@ -68,7 +117,24 @@ export interface Store {
|
|
|
68
117
|
* user's repo.
|
|
69
118
|
*/
|
|
70
119
|
supportsIndexing(): boolean;
|
|
71
|
-
put(filepath: string, data: object, options?:
|
|
72
|
-
includeTemplate?: boolean;
|
|
73
|
-
}): Promise<void>;
|
|
120
|
+
put(filepath: string, data: object, options?: PutOptions): Promise<void>;
|
|
74
121
|
}
|
|
122
|
+
export declare type FilterCondition = {
|
|
123
|
+
filterExpression: Record<string, FilterOperand>;
|
|
124
|
+
filterPath: string;
|
|
125
|
+
};
|
|
126
|
+
export declare const makeFilterChain: ({ conditions, }: {
|
|
127
|
+
conditions: FilterCondition[];
|
|
128
|
+
}) => (BinaryFilter | TernaryFilter)[];
|
|
129
|
+
export declare const makeFilter: ({ filterChain, }: {
|
|
130
|
+
filterChain?: (BinaryFilter | TernaryFilter)[];
|
|
131
|
+
}) => (values: Record<string, object | FilterOperand>) => boolean;
|
|
132
|
+
declare type StringEscaper = <T extends string | string[]>(input: T) => T;
|
|
133
|
+
export declare const makeStringEscaper: (regex: RegExp, replacement: string) => StringEscaper;
|
|
134
|
+
export declare const coerceFilterChainOperands: (filterChain: (BinaryFilter | TernaryFilter)[], stringEscaper: StringEscaper) => (BinaryFilter | TernaryFilter)[];
|
|
135
|
+
export declare const makeFilterSuffixes: (filterChain: (BinaryFilter | TernaryFilter)[], index: IndexDefinition) => {
|
|
136
|
+
left?: string;
|
|
137
|
+
right?: string;
|
|
138
|
+
} | undefined;
|
|
139
|
+
export declare const makeKeyForField: (definition: IndexDefinition, data: object, stringEscaper: StringEscaper) => string | null;
|
|
140
|
+
export {};
|
|
@@ -10,14 +10,15 @@ 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 { Store } from './index';
|
|
13
|
+
import type { StoreQueryOptions, StoreQueryResponse, PutOptions, SeedOptions, Store } from './index';
|
|
14
14
|
import { LevelDB } from 'level';
|
|
15
15
|
export declare class LevelStore implements Store {
|
|
16
16
|
rootPath: any;
|
|
17
17
|
db: LevelDB;
|
|
18
|
+
useMemory: boolean;
|
|
18
19
|
constructor(rootPath: string, useMemory?: boolean);
|
|
19
|
-
query(
|
|
20
|
-
seed(filepath: string, data: object): Promise<void>;
|
|
20
|
+
query(queryOptions: StoreQueryOptions): Promise<StoreQueryResponse>;
|
|
21
|
+
seed(filepath: string, data: object, options?: SeedOptions): Promise<void>;
|
|
21
22
|
supportsSeeding(): boolean;
|
|
22
23
|
supportsIndexing(): boolean;
|
|
23
24
|
print(): Promise<void>;
|
|
@@ -25,5 +26,6 @@ export declare class LevelStore implements Store {
|
|
|
25
26
|
clear(): Promise<void>;
|
|
26
27
|
glob(pattern: string, callback: any): Promise<any[]>;
|
|
27
28
|
get(filepath: string): Promise<any>;
|
|
28
|
-
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
put(filepath: string, data: object, options?: PutOptions): Promise<void>;
|
|
29
31
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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
|
-
|
|
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
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export { FilesystemBridge } from './database/bridge/filesystem';
|
|
16
|
-
export { FilesystemStore } from './database/store/filesystem';
|
|
17
|
-
export { MemoryStore } from './database/store/memory';
|
|
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
|
+
export { FilesystemBridge, AuditFileSystemBridge, } from './database/bridge/filesystem';
|
|
14
|
+
export { FilesystemStore, AuditFilesystemStore, } from './database/store/filesystem';
|
|
18
15
|
export { LevelStore } from './database/store/level';
|
|
19
|
-
export
|
|
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';
|
|
18
|
+
export declare type FilterOperand = string | number | boolean | string[] | number[];
|
|
19
|
+
export { atob, btoa } from './util';
|