@tinacms/datalayer 0.0.2 → 0.2.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 CHANGED
@@ -1,5 +1,59 @@
1
1
  # tina-graphql
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4daf15b36: Updated matching logic to only return the correct extension.
8
+
9
+ This means if you are using any other files besides `.md` the format must be provided in the schema.
10
+
11
+ ```ts
12
+ // .tina/schema.ts
13
+
14
+ import { defineSchema } from 'tinacms'
15
+
16
+ const schema = defineSchema({
17
+ collections: [
18
+ {
19
+ name: 'page',
20
+ path: 'content/page',
21
+ label: 'Page',
22
+ // Need to provide the format if the file being used (default is `.md`)
23
+ format: 'mdx',
24
+ fields: [
25
+ //...
26
+ ],
27
+ },
28
+ ],
29
+ })
30
+ //...
31
+
32
+ export default schema
33
+ ```
34
+
35
+ ### Patch Changes
36
+
37
+ - b348f8b6b: Experimental isomorphic git bridge implementation
38
+
39
+ ## 0.1.1
40
+
41
+ ### Patch Changes
42
+
43
+ - a2906d6fe: Fix datetime filtering to handle both indexed and non-indexed queries
44
+ - 3e2d9e43a: Adds new GraphQL `deleteDocument` mutation and logic
45
+
46
+ ## 0.1.0
47
+
48
+ ### Minor Changes
49
+
50
+ - a87e1e6fa: Enable query filtering, pagination, sorting
51
+
52
+ ### Patch Changes
53
+
54
+ - 8b3be903f: Escape index field separator in input strings
55
+ - b01f2e382: Fixed an issue where `0` as a numerical operand was being evaluated as falsy.
56
+
3
57
  ## 0.0.2
4
58
 
5
59
  ### Patch Changes
@@ -19,8 +19,9 @@ import type { Bridge } from './index';
19
19
  export declare class FilesystemBridge implements Bridge {
20
20
  rootPath: string;
21
21
  constructor(rootPath: string);
22
- glob(pattern: string): Promise<string[]>;
22
+ glob(pattern: string, extension: 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>;
@@ -12,7 +12,8 @@ limitations under the License.
12
12
  */
13
13
  export interface Bridge {
14
14
  rootPath: string;
15
- glob(pattern: string): Promise<string[]>;
15
+ glob(pattern: string, extension: string): Promise<string[]>;
16
+ delete(filepath: string): Promise<void>;
16
17
  get(filepath: string): Promise<string>;
17
18
  put(filepath: string, data: string): Promise<void>;
18
19
  /**
@@ -0,0 +1,108 @@
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 { CallbackFsClient, PromiseFsClient } from 'isomorphic-git';
14
+ import type { Bridge } from './index';
15
+ export declare type IsomorphicGitBridgeOptions = {
16
+ gitRoot: string;
17
+ fsModule?: CallbackFsClient | PromiseFsClient;
18
+ commitMessage?: string;
19
+ author: {
20
+ name: string;
21
+ email: string;
22
+ };
23
+ committer?: {
24
+ name: string;
25
+ email: string;
26
+ };
27
+ ref?: string;
28
+ onPut?: (filepath: string, data: string) => Promise<void>;
29
+ onDelete?: (filepath: string) => Promise<void>;
30
+ };
31
+ /**
32
+ * Bridge backed by isomorphic-git
33
+ */
34
+ export declare class IsomorphicBridge implements Bridge {
35
+ rootPath: string;
36
+ relativePath: string;
37
+ gitRoot: string;
38
+ fsModule: CallbackFsClient | PromiseFsClient;
39
+ isomorphicConfig: {
40
+ fs: CallbackFsClient | PromiseFsClient;
41
+ dir: string;
42
+ };
43
+ commitMessage: string;
44
+ author: {
45
+ name: string;
46
+ email: string;
47
+ };
48
+ committer: {
49
+ name: string;
50
+ email: string;
51
+ };
52
+ ref: string | undefined;
53
+ private readonly onPut;
54
+ private readonly onDelete;
55
+ private cache;
56
+ constructor(rootPath: string, { gitRoot, author, committer, fsModule, commitMessage, ref, onPut, onDelete, }: IsomorphicGitBridgeOptions);
57
+ private getAuthor;
58
+ private getCommitter;
59
+ /**
60
+ * Recursively populate paths matching `pattern` for the given `entry`
61
+ *
62
+ * @param pattern - pattern to filter paths by
63
+ * @param entry - TreeEntry to start building list from
64
+ * @param path - base path
65
+ * @param results
66
+ * @private
67
+ */
68
+ private listEntries;
69
+ /**
70
+ * For the specified path, returns an object with an array containing the parts of the path (pathParts)
71
+ * and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
72
+ * pathEntries are placeholders for non-existent entries.
73
+ *
74
+ * @param path - path being resolved
75
+ * @param ref - ref to resolve path entries for
76
+ * @private
77
+ */
78
+ private resolvePathEntries;
79
+ /**
80
+ * Updates tree entry and associated parent tree entries
81
+ *
82
+ * @param existingOid - the existing OID
83
+ * @param updatedOid - the updated OID
84
+ * @param path - the path of the entry being updated
85
+ * @param type - the type of the entry being updated (blob or tree)
86
+ * @param pathEntries - parent path entries
87
+ * @param pathParts - parent path parts
88
+ * @private
89
+ */
90
+ private updateTreeHierarchy;
91
+ /**
92
+ * Creates a commit for the specified tree and updates the specified ref to point to the commit
93
+ *
94
+ * @param treeSha - sha of the new tree
95
+ * @param ref - the ref that should be updated
96
+ * @private
97
+ */
98
+ private commitTree;
99
+ private getRef;
100
+ glob(pattern: string, extension: string): Promise<string[]>;
101
+ supportsBuilding(): boolean;
102
+ delete(filepath: string): Promise<void>;
103
+ private qualifyPath;
104
+ private unqualifyPath;
105
+ get(filepath: string): Promise<string>;
106
+ putConfig(filepath: string, data: string): Promise<void>;
107
+ put(filepath: string, data: string): Promise<void>;
108
+ }
@@ -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,13 +18,16 @@ 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
- glob(pattern: string, callback: any): Promise<any[]>;
27
- put(filepath: string, data: object, keepTemplateKey: boolean): Promise<void>;
26
+ glob(pattern: string, callback: any, extension: any): Promise<any[]>;
27
+ put(filepath: string, data: object, options?: PutOptions): Promise<void>;
28
+ open(): Promise<void>;
29
+ close(): Promise<void>;
30
+ delete(filepath: any): Promise<void>;
28
31
  }
29
32
  export declare class AuditFilesystemStore extends FilesystemStore {
30
33
  put(_filepath: string, _data: object): Promise<void>;
@@ -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
- glob(pattern: string, hydrator?: (fullPath: string) => Promise<object>): Promise<string[]>;
92
+ glob(pattern: string, hydrator?: (fullPath: string) => Promise<object>, extension?: string): 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,5 +121,24 @@ export interface Store {
68
121
  * user's repo.
69
122
  */
70
123
  supportsIndexing(): boolean;
71
- put(filepath: string, data: object, keepTemplateKey: boolean): Promise<void>;
124
+ put(filepath: string, data: object, options?: PutOptions): Promise<void>;
72
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 {};
@@ -1,29 +1,32 @@
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
- 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 type { Store } from './index';
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 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
@@ -11,6 +11,10 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  export { FilesystemBridge, AuditFileSystemBridge, } from './database/bridge/filesystem';
14
+ export { IsomorphicBridge } from './database/bridge/isomorphic';
14
15
  export { FilesystemStore, AuditFilesystemStore, } from './database/store/filesystem';
15
- export { MemoryStore } from './database/store/memory';
16
16
  export { LevelStore } from './database/store/level';
17
+ export { coerceFilterChainOperands, DEFAULT_COLLECTION_SORT_KEY, DEFAULT_NUMERIC_LPAD, INDEX_KEY_FIELD_SEPARATOR, makeFilter, makeFilterChain, makeFilterSuffixes, makeKeyForField, makeStringEscaper, OP, } from './database/store';
18
+ export type { BinaryFilter, FilterCondition, IndexDefinition, PadDefinition, StoreQueryOptions, StoreQueryResponse, PageInfo, PutOptions, DeleteOptions, SeedOptions, Store, TernaryFilter, } from './database/store';
19
+ export declare type FilterOperand = string | number | boolean | string[] | number[];
20
+ export { atob, btoa } from './util';