@tinacms/datalayer 0.0.1 → 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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # tina-graphql
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - a2906d6fe: Fix datetime filtering to handle both indexed and non-indexed queries
8
+ - 3e2d9e43a: Adds new GraphQL `deleteDocument` mutation and logic
9
+
10
+ ## 0.1.0
11
+
12
+ ### Minor Changes
13
+
14
+ - a87e1e6fa: Enable query filtering, pagination, sorting
15
+
16
+ ### Patch Changes
17
+
18
+ - 8b3be903f: Escape index field separator in input strings
19
+ - b01f2e382: Fixed an issue where `0` as a numerical operand was being evaluated as falsy.
20
+
21
+ ## 0.0.2
22
+
23
+ ### Patch Changes
24
+
25
+ - b399c734c: Fixes support for collection.templates in graphql
26
+
3
27
  ## 0.0.1
4
28
 
5
29
  ### Patch Changes
@@ -21,7 +21,14 @@ 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>;
27
28
  }
29
+ /**
30
+ * Same as the `FileSystemBridge` except it does not save files
31
+ */
32
+ export declare class AuditFileSystemBridge extends FilesystemBridge {
33
+ put(_filepath: string, _data: string): Promise<void>;
34
+ }
@@ -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 { 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,17 @@ export declare class FilesystemStore implements Store {
18
18
  constructor({ rootPath }: {
19
19
  rootPath?: string;
20
20
  });
21
- query(queryStrings: string[]): Promise<object[]>;
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
+ delete(filepath: any): Promise<void>;
31
+ }
32
+ export declare class AuditFilesystemStore extends FilesystemStore {
33
+ put(_filepath: string, _data: object): Promise<void>;
28
34
  }
@@ -10,42 +10,97 @@ 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
+ };
88
+ export declare type DeleteOptions = SeedOptions & {
89
+ seed?: boolean;
90
+ };
13
91
  export interface Store {
14
92
  glob(pattern: string, hydrator?: (fullPath: string) => Promise<object>): Promise<string[]>;
15
93
  get<T extends object>(filepath: string): Promise<T>;
94
+ delete(filepath: string, options?: DeleteOptions): Promise<void>;
16
95
  clear(): void;
96
+ close(): void;
97
+ open(): void;
17
98
  /**
18
- *
19
- * @param queryStrings
20
- * Queries are currently structured as prefixed keys where that last portion
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
99
+ * Executes a query against a collection
100
+ * @param queryOptions - options for the query
101
+ * @returns the results of the query
47
102
  */
48
- query(queryStrings: string[], hydrator?: (fullPath: string) => Promise<object>): Promise<object[]>;
103
+ query(queryOptions: StoreQueryOptions): Promise<StoreQueryResponse>;
49
104
  /**
50
105
  * In this context, seeding is the act of putting records and indexing data into an ephemeral
51
106
  * storage layer for use during the GraphQL runtime. What might seem suprising is that some stores
@@ -56,9 +111,7 @@ export interface Store {
56
111
  * At this time it seems that it would never make sense to be able to "query" without "seed"-ing, and
57
112
  * there'd be no value in "seeding" without "query"-ing.
58
113
  */
59
- seed(filepath: string, data: object, options?: {
60
- includeTemplate?: boolean;
61
- }): Promise<void>;
114
+ seed(filepath: string, data: object, options?: PutOptions): Promise<void>;
62
115
  supportsSeeding(): boolean;
63
116
  /**
64
117
  * Whether this store supports the ability to index data.
@@ -68,7 +121,24 @@ export interface Store {
68
121
  * user's repo.
69
122
  */
70
123
  supportsIndexing(): boolean;
71
- put(filepath: string, data: object, options?: {
72
- includeTemplate?: boolean;
73
- }): Promise<void>;
124
+ put(filepath: string, data: object, options?: PutOptions): Promise<void>;
74
125
  }
126
+ export declare type FilterCondition = {
127
+ filterExpression: Record<string, FilterOperand>;
128
+ filterPath: string;
129
+ };
130
+ export declare const makeFilterChain: ({ conditions, }: {
131
+ conditions: FilterCondition[];
132
+ }) => (BinaryFilter | TernaryFilter)[];
133
+ export declare const makeFilter: ({ filterChain, }: {
134
+ filterChain?: (BinaryFilter | TernaryFilter)[];
135
+ }) => (values: Record<string, object | FilterOperand>) => boolean;
136
+ declare type StringEscaper = <T extends string | string[]>(input: T) => T;
137
+ export declare const makeStringEscaper: (regex: RegExp, replacement: string) => StringEscaper;
138
+ export declare const coerceFilterChainOperands: (filterChain: (BinaryFilter | TernaryFilter)[], stringEscaper: StringEscaper) => (BinaryFilter | TernaryFilter)[];
139
+ export declare const makeFilterSuffixes: (filterChain: (BinaryFilter | TernaryFilter)[], index: IndexDefinition) => {
140
+ left?: string;
141
+ right?: string;
142
+ } | undefined;
143
+ export declare const makeKeyForField: (definition: IndexDefinition, data: object, stringEscaper: StringEscaper) => string | null;
144
+ export {};
@@ -10,20 +10,23 @@ 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, DeleteOptions, 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(queryStrings: string[], hydrator: any): Promise<any[]>;
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;
24
+ delete(filepath: string, options: DeleteOptions): Promise<void>;
23
25
  print(): Promise<void>;
24
26
  open(): Promise<void>;
25
27
  clear(): Promise<void>;
26
28
  glob(pattern: string, callback: any): Promise<any[]>;
27
29
  get(filepath: string): Promise<any>;
28
- put(filepath: string, data: object): Promise<void>;
30
+ close(): Promise<void>;
31
+ put(filepath: string, data: object, options?: PutOptions): Promise<void>;
29
32
  }
package/dist/index.d.ts CHANGED
@@ -10,10 +10,10 @@ 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
- export { GithubBridge } from './database/bridge/github';
14
- export { GithubStore } from './database/store/github';
15
- export { FilesystemBridge } from './database/bridge/filesystem';
16
- export { FilesystemStore } from './database/store/filesystem';
17
- export { MemoryStore } from './database/store/memory';
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 type { GithubManagerInit } from './database/bridge/github';
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, DeleteOptions, SeedOptions, Store, TernaryFilter, } from './database/store';
18
+ export declare type FilterOperand = string | number | boolean | string[] | number[];
19
+ export { atob, btoa } from './util';