@tinacms/graphql 0.0.0-20222901756 → 0.0.0-202231073

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,9 +1,53 @@
1
1
  # tina-graphql
2
2
 
3
- ## 0.0.0-20222901756
3
+ ## 0.0.0-202231073
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - 82174ff50: Modify Database.indexContentByPaths to not require collection parameter
8
+ - a87e1e6fa: Enable query filtering, pagination, sorting
9
+ - abf25c673: The schema can now to used on the frontend (optional for now but will be the main path moving forward).
10
+
11
+ ### How to migrate.
12
+
13
+ If you gone though the `tinacms init` process there should be a file called `.tina/components/TinaProvider`. In that file you can import the schema from `schema.ts` and add it to the TinaCMS wrapper component.
14
+
15
+ ```tsx
16
+ import TinaCMS from 'tinacms'
17
+ import schema, { tinaConfig } from '../schema.ts'
18
+
19
+ // Importing the TinaProvider directly into your page will cause Tina to be added to the production bundle.
20
+ // Instead, import the tina/provider/index default export to have it dynamially imported in edit-moode
21
+ /**
22
+ *
23
+ * @private Do not import this directly, please import the dynamic provider instead
24
+ */
25
+ const TinaProvider = ({ children }) => {
26
+ return (
27
+ <TinaCMS {...tinaConfig} schema={schema}>
28
+ {children}
29
+ </TinaCMS>
30
+ )
31
+ }
32
+
33
+ export default TinaProvider
34
+ ```
35
+
36
+ - 591640db0: Fixes a bug with `breadcrumbs` to account for subfolders (instead of just the `filename`) and allows Documents to be created and updated within subfolders.
37
+
38
+ Before this fix, `breadcrumbs` was only the `basename` of the file minus the `extension`. So `my-folder-a/my-folder-b/my-file.md` would have `breadcrumbs` of `['my-file']`. With this change, `breadcrumbs` will be `['my-folder-a','my-folder-b','my-file']` (leaving out the `content/<collection>`).
39
+
40
+ - e8b0de1f7: Add `parentTypename` to fields to allow us to disambiguate between fields which have the same field names but different types. Example, an event from field name of `blocks.0.title` could belong to a `Cta` block or a `Hero` block, both of which have a `title` field.
41
+ - Updated dependencies [8b3be903f]
42
+ - Updated dependencies [a87e1e6fa]
43
+ - Updated dependencies [b01f2e382]
44
+ - @tinacms/datalayer@0.0.0-202231073
45
+
46
+ ## 0.59.8
47
+
48
+ ### Patch Changes
49
+
50
+ - e7b27ba3b: Fix issue where un-normalized rich-text fields which send `null` values to the server on save would cause a parsing error
7
51
  - 11d55f441: Add experimental useGraphQLForms hook
8
52
 
9
53
  ## 0.59.7
@@ -10,21 +10,32 @@ 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 { BinaryFilter, IndexDefinition, Store, TernaryFilter } from '@tinacms/datalayer';
13
14
  import type { DocumentNode } from 'graphql';
14
15
  import type { TinaSchema } from '../schema';
15
16
  import type { TinaCloudSchemaBase } from '../types';
16
- import type { Store } from './store';
17
17
  import type { Bridge } from './bridge';
18
18
  declare type CreateDatabase = {
19
19
  bridge: Bridge;
20
20
  store: Store;
21
21
  };
22
22
  export declare const createDatabase: (config: CreateDatabase) => Promise<Database>;
23
+ /** Options for {@link Database.query} **/
24
+ export declare type QueryOptions = {
25
+ collection: string;
26
+ filterChain?: (BinaryFilter | TernaryFilter)[];
27
+ sort?: string;
28
+ first?: number;
29
+ last?: number;
30
+ after?: string;
31
+ before?: string;
32
+ };
23
33
  export declare class Database {
24
34
  config: CreateDatabase;
25
35
  bridge: Bridge;
26
36
  store: Store;
27
37
  private tinaSchema;
38
+ private collectionIndexDefinitions;
28
39
  private _lookup;
29
40
  private _graphql;
30
41
  private _tinaSchema;
@@ -51,8 +62,20 @@ export declare class Database {
51
62
  getGraphQLSchemaFromBridge: () => Promise<DocumentNode>;
52
63
  getTinaSchema: () => Promise<TinaCloudSchemaBase>;
53
64
  getSchema: () => Promise<TinaSchema>;
65
+ getIndexDefinitions: () => Promise<Record<string, Record<string, IndexDefinition>>>;
54
66
  documentExists: (fullpath: unknown) => Promise<boolean>;
55
- query: (queryStrings: string[], hydrator: any) => Promise<object[]>;
67
+ query: (queryOptions: QueryOptions, hydrator: any) => Promise<{
68
+ edges: {
69
+ node: any;
70
+ cursor: string;
71
+ }[];
72
+ pageInfo: {
73
+ hasPreviousPage: boolean;
74
+ hasNextPage: boolean;
75
+ startCursor: string;
76
+ endCursor: string;
77
+ };
78
+ }>;
56
79
  putConfigFiles: ({ graphQLSchema, tinaSchema, }: {
57
80
  graphQLSchema: DocumentNode;
58
81
  tinaSchema: TinaSchema;
package/dist/index.d.ts CHANGED
@@ -13,9 +13,10 @@ limitations under the License.
13
13
  export { indexDB } from './build';
14
14
  export { resolve } from './resolve';
15
15
  export { createDatabase } from './database';
16
+ export type { QueryOptions } from './database';
16
17
  import type { Database } from './database';
17
18
  export type { Database } from './database';
18
- export type { Store } from './database/store';
19
+ export type { Store } from '@tinacms/datalayer';
19
20
  export type { Bridge } from './database/bridge';
20
21
  export { sequential, assertShape } from './util';
21
22
  export { stringifyFile, parseFile } from './database/util';
package/dist/index.js CHANGED
@@ -11902,6 +11902,11 @@ var Builder = class {
11902
11902
  astBuilder.InputValueDefinition({
11903
11903
  name: "exists",
11904
11904
  type: astBuilder.TYPES.Boolean
11905
+ }),
11906
+ astBuilder.InputValueDefinition({
11907
+ name: "in",
11908
+ type: astBuilder.TYPES.Number,
11909
+ list: true
11905
11910
  })
11906
11911
  ]
11907
11912
  })
@@ -11927,6 +11932,11 @@ var Builder = class {
11927
11932
  astBuilder.InputValueDefinition({
11928
11933
  name: "exists",
11929
11934
  type: astBuilder.TYPES.Boolean
11935
+ }),
11936
+ astBuilder.InputValueDefinition({
11937
+ name: "in",
11938
+ type: astBuilder.TYPES.String,
11939
+ list: true
11930
11940
  })
11931
11941
  ]
11932
11942
  })
@@ -11949,6 +11959,11 @@ var Builder = class {
11949
11959
  astBuilder.InputValueDefinition({
11950
11960
  name: "exists",
11951
11961
  type: astBuilder.TYPES.Boolean
11962
+ }),
11963
+ astBuilder.InputValueDefinition({
11964
+ name: "in",
11965
+ type: astBuilder.TYPES.String,
11966
+ list: true
11952
11967
  })
11953
11968
  ]
11954
11969
  })
@@ -12256,6 +12271,10 @@ var listArgs = [
12256
12271
  astBuilder.InputValueDefinition({
12257
12272
  name: "last",
12258
12273
  type: astBuilder.TYPES.Number
12274
+ }),
12275
+ astBuilder.InputValueDefinition({
12276
+ name: "sort",
12277
+ type: astBuilder.TYPES.String
12259
12278
  })
12260
12279
  ];
12261
12280
  var filterSelections = (arr) => {
@@ -12370,7 +12389,7 @@ var validateField = async (field) => {
12370
12389
 
12371
12390
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/package.json
12372
12391
  var name = "@tinacms/graphql";
12373
- var version = "0.59.7";
12392
+ var version = "0.59.8";
12374
12393
  var main = "dist/index.js";
12375
12394
  var typings = "dist/index.d.ts";
12376
12395
  var files = [
@@ -12416,6 +12435,7 @@ var scripts = {
12416
12435
  };
12417
12436
  var dependencies = {
12418
12437
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
12438
+ "@tinacms/datalayer": "workspace:*",
12419
12439
  "body-parser": "^1.19.0",
12420
12440
  cors: "^2.8.5",
12421
12441
  dataloader: "^2.0.0",
@@ -12431,6 +12451,7 @@ var dependencies = {
12431
12451
  "graphql-type-json": "^0.3.2",
12432
12452
  "gray-matter": "^4.0.2",
12433
12453
  "js-yaml": "^3.14.0",
12454
+ leveldown: "^6.1.0",
12434
12455
  lodash: "^4.17.20",
12435
12456
  mdast: "^3.0.0",
12436
12457
  "mdast-util-from-markdown": "^1.0.0",
@@ -12438,7 +12459,6 @@ var dependencies = {
12438
12459
  "mdast-util-mdx-expression": "^1.1.0",
12439
12460
  "mdast-util-to-markdown": "^1.2.1",
12440
12461
  "micromark-extension-mdxjs": "^1.0.0",
12441
- mocha: "^9.1.1",
12442
12462
  "normalize-path": "^3.0.0",
12443
12463
  prettier: "^2.2.1",
12444
12464
  "rehype-format": "^3.1.0",
@@ -12473,7 +12493,6 @@ var devDependencies = {
12473
12493
  "@types/fs-extra": "^9.0.2",
12474
12494
  "@types/jest": "^26.0.4",
12475
12495
  "@types/js-yaml": "^3.12.5",
12476
- "@types/level": "^6.0.0",
12477
12496
  "@types/lodash": "^4.14.161",
12478
12497
  "@types/lodash.camelcase": "^4.3.6",
12479
12498
  "@types/lodash.upperfirst": "^4.3.6",
@@ -20357,6 +20376,7 @@ var defaultNodeTypes = {
20357
20376
  delete_mark: plateElements.MARK_STRIKETHROUGH,
20358
20377
  inline_code_mark: plateElements.ELEMENT_CODE_LINE,
20359
20378
  thematic_break: plateElements.ELEMENT_HR,
20379
+ break: "break",
20360
20380
  image: plateElements.ELEMENT_IMAGE
20361
20381
  };
20362
20382
  function remarkToSlate(node) {
@@ -20454,6 +20474,8 @@ function remarkToSlate(node) {
20454
20474
  return __spreadProps(__spreadValues({}, node), {
20455
20475
  children: void 0
20456
20476
  });
20477
+ case "break":
20478
+ return { type: types.break, children: [{ type: "text", text: "" }] };
20457
20479
  default:
20458
20480
  console.log("unknown", node);
20459
20481
  return { type: "text", text: "" };
@@ -21895,6 +21917,9 @@ var allChildrenEmpty = (children) => {
21895
21917
  return false;
21896
21918
  };
21897
21919
  var stringifyChildren = (children, field) => {
21920
+ if (!children) {
21921
+ return [];
21922
+ }
21898
21923
  return children.map((child) => stringify(child, field)).filter(Boolean);
21899
21924
  };
21900
21925
  var stringify = (node, field) => {
@@ -22244,6 +22269,10 @@ ${out}
22244
22269
  } catch (e) {
22245
22270
  console.log(e);
22246
22271
  }
22272
+ case "break":
22273
+ return {
22274
+ type: "break"
22275
+ };
22247
22276
  case "text":
22248
22277
  if (node == null ? void 0 : node.code) {
22249
22278
  return {
@@ -22270,7 +22299,102 @@ ${out}
22270
22299
  };
22271
22300
 
22272
22301
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolver/index.ts
22273
- var import_flat = __toModule(require("flat"));
22302
+ var import_datalayer = __toModule(require("@tinacms/datalayer"));
22303
+
22304
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolver/filter-utils.ts
22305
+ var resolveReferences = async (filter, fields, resolver2) => {
22306
+ for (const fieldKey of Object.keys(filter)) {
22307
+ const fieldDefinition = fields.find((f) => f.name === fieldKey);
22308
+ if (fieldDefinition) {
22309
+ if (fieldDefinition.type === "reference") {
22310
+ const { edges, values } = await resolver2(filter, fieldDefinition);
22311
+ if (edges.length === 1) {
22312
+ filter[fieldKey] = {
22313
+ eq: values[0]
22314
+ };
22315
+ } else if (edges.length > 1) {
22316
+ filter[fieldKey] = {
22317
+ in: values
22318
+ };
22319
+ } else {
22320
+ filter[fieldKey] = {
22321
+ eq: "___null___"
22322
+ };
22323
+ }
22324
+ } else if (fieldDefinition.type === "object") {
22325
+ if (fieldDefinition.templates) {
22326
+ const globalTemplates = {};
22327
+ for (const template of fieldDefinition.templates) {
22328
+ if (typeof template === "string") {
22329
+ globalTemplates[template] = 1;
22330
+ }
22331
+ }
22332
+ for (const templateName of Object.keys(filter[fieldKey])) {
22333
+ if (templateName in globalTemplates) {
22334
+ throw new Error("Global templates not yet supported for queries");
22335
+ }
22336
+ const template = fieldDefinition.templates.find((template2) => !(typeof template2 === "string") && template2.name === templateName);
22337
+ if (template) {
22338
+ await resolveReferences(filter[fieldKey][templateName], template.fields, resolver2);
22339
+ } else {
22340
+ throw new Error(`Template ${templateName} not found`);
22341
+ }
22342
+ }
22343
+ } else {
22344
+ await resolveReferences(filter[fieldKey], fieldDefinition.fields, resolver2);
22345
+ }
22346
+ }
22347
+ } else {
22348
+ throw new Error(`Unable to find field ${fieldKey}`);
22349
+ }
22350
+ }
22351
+ };
22352
+ var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
22353
+ for (const childFieldName of Object.keys(filterNode)) {
22354
+ const childField = fields.find((field) => field.name === childFieldName);
22355
+ if (!childField) {
22356
+ throw new Error(`Unable to find type for field ${childFieldName}`);
22357
+ }
22358
+ collectConditionsForField(childFieldName, childField, filterNode[childFieldName], pathExpression, collectCondition);
22359
+ }
22360
+ };
22361
+ var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
22362
+ if (field.list && field.templates) {
22363
+ const globalTemplates = {};
22364
+ for (const template of field.templates) {
22365
+ if (typeof template === "string") {
22366
+ globalTemplates[template] = 1;
22367
+ }
22368
+ }
22369
+ for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
22370
+ if (filterKey in globalTemplates) {
22371
+ throw new Error("Global templates not yet supported for queries");
22372
+ }
22373
+ const template = field.templates.find((template2) => !(typeof template2 === "string") && template2.name === filterKey);
22374
+ const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
22375
+ const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
22376
+ collectConditionsForChildFields(childFilterNode, template.fields, filterPath, collectCondition);
22377
+ }
22378
+ } else {
22379
+ const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
22380
+ const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
22381
+ collectConditionsForChildFields(filterNode, field.fields, filterPath, collectCondition);
22382
+ }
22383
+ };
22384
+ var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
22385
+ if (field.type === "object") {
22386
+ collectConditionsForObjectField(fieldName, field, filterNode, pathExpression, collectCondition);
22387
+ } else {
22388
+ collectCondition({
22389
+ filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
22390
+ filterExpression: __spreadValues({
22391
+ _type: field.type
22392
+ }, filterNode)
22393
+ });
22394
+ }
22395
+ };
22396
+
22397
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolver/index.ts
22274
22398
  var createResolver2 = (args) => {
22275
22399
  return new Resolver(args);
22276
22400
  };
@@ -22299,11 +22423,13 @@ var Resolver = class {
22299
22423
  data: rawData,
22300
22424
  collection
22301
22425
  });
22302
- const basename = import_path3.default.basename(fullPath);
22303
- const extension2 = import_path3.default.extname(fullPath);
22304
- const filename = basename.replace(extension2, "");
22426
+ const {
22427
+ base: basename,
22428
+ ext: extension2,
22429
+ name: filename
22430
+ } = import_path3.default.parse(fullPath);
22305
22431
  const relativePath = fullPath.replace("\\", "/").replace(collection.path, "").replace(/^\/|\/$/g, "");
22306
- const breadcrumbs = filename.split("/");
22432
+ const breadcrumbs = relativePath.replace(extension2, "").split("/");
22307
22433
  const form = {
22308
22434
  label: collection.label,
22309
22435
  name: basename,
@@ -22568,46 +22694,76 @@ var Resolver = class {
22568
22694
  const collection = this.tinaSchema.getCollection(collectionName);
22569
22695
  return this.database.store.glob(collection.path, this.getDocument);
22570
22696
  };
22697
+ this.referenceResolver = async (filter, fieldDefinition) => {
22698
+ const referencedCollection = this.tinaSchema.getCollection(fieldDefinition.collections[0]);
22699
+ if (!referencedCollection) {
22700
+ throw new Error(`Unable to find collection for ${fieldDefinition.collections[0]} querying ${fieldDefinition.name}`);
22701
+ }
22702
+ const sortKeys = Object.keys(filter[fieldDefinition.name][referencedCollection.name]);
22703
+ const resolvedCollectionConnection = await this.resolveCollectionConnection({
22704
+ args: {
22705
+ sort: sortKeys.length === 1 ? sortKeys[0] : void 0,
22706
+ filter: __spreadValues({}, filter[fieldDefinition.name][referencedCollection.name]),
22707
+ first: -1
22708
+ },
22709
+ collection: referencedCollection,
22710
+ hydrator: (path6) => path6
22711
+ });
22712
+ const { edges } = resolvedCollectionConnection;
22713
+ const values = edges.map((edge) => edge.node);
22714
+ return { edges, values };
22715
+ };
22571
22716
  this.resolveCollectionConnection = async ({
22572
22717
  args,
22573
- lookup
22718
+ collection,
22719
+ hydrator
22574
22720
  }) => {
22575
- let documents;
22576
- if (args.filter) {
22577
- const queries = [];
22578
- const flattenedArgs = (0, import_flat.default)(args.filter, { delimiter: "#" });
22579
- Object.entries(flattenedArgs).map(([key2, value]) => {
22580
- const keys2 = key2.split("#");
22581
- const maybeTemplateName = keys2[0];
22582
- const realKey = keys2.slice(0, keys2.length - 1).join("#");
22583
- const collection = this.tinaSchema.getCollection(lookup.collection);
22584
- let templateName = collection.name;
22585
- if (collection.templates) {
22586
- const template = collection.templates.find((template2) => {
22587
- if (typeof template2 === "string") {
22588
- throw new Error("Global templates not yet supported for queries");
22721
+ let edges;
22722
+ let pageInfo;
22723
+ if (args.filter || args.sort) {
22724
+ let conditions;
22725
+ if (args.filter) {
22726
+ if (collection.fields) {
22727
+ conditions = await this.resolveFilterConditions(args.filter, collection.fields, collection.name);
22728
+ } else if (collection.templates) {
22729
+ for (const templateName of Object.keys(args.filter)) {
22730
+ const template = collection.templates.find((template2) => template2.name === templateName);
22731
+ if (template) {
22732
+ conditions = await this.resolveFilterConditions(args.filter[templateName], template.fields, `${collection.name}.${templateName}`);
22733
+ } else {
22734
+ throw new Error(`Error template not found: ${templateName} in collection ${collection.name}`);
22589
22735
  }
22590
- return template2.name === maybeTemplateName;
22591
- });
22592
- if (typeof template === "string") {
22593
- throw new Error("Global templates not yet supported for queries");
22594
- }
22595
- if (template) {
22596
- templateName = template.name;
22597
22736
  }
22598
22737
  }
22599
- queries.push(`__attribute__${lookup.collection}#${templateName}#${realKey}#${value}`);
22600
- });
22601
- documents = await this.database.query(queries, this.getDocument);
22738
+ }
22739
+ const queryOptions = {
22740
+ filterChain: (0, import_datalayer.makeFilterChain)({
22741
+ conditions: conditions || []
22742
+ }),
22743
+ collection: collection.name,
22744
+ sort: args.sort,
22745
+ first: args.first,
22746
+ last: args.last,
22747
+ before: args.before,
22748
+ after: args.after
22749
+ };
22750
+ const result = await this.database.query(queryOptions, hydrator ? hydrator : this.getDocument);
22751
+ edges = result.edges;
22752
+ pageInfo = result.pageInfo;
22602
22753
  } else {
22603
- const collection = await this.tinaSchema.getCollection(lookup.collection);
22604
- documents = await this.database.store.glob(collection.path, this.getDocument);
22754
+ edges = (await this.database.store.glob(collection.path, this.getDocument)).map((document3) => ({
22755
+ node: document3
22756
+ }));
22605
22757
  }
22606
22758
  return {
22607
- totalCount: documents.length,
22608
- edges: documents.map((document3) => {
22609
- return { node: document3 };
22610
- })
22759
+ totalCount: edges.length,
22760
+ edges,
22761
+ pageInfo: pageInfo || {
22762
+ hasPreviousPage: false,
22763
+ hasNextPage: false,
22764
+ startCursor: "",
22765
+ endCursor: ""
22766
+ }
22611
22767
  };
22612
22768
  };
22613
22769
  this.buildFieldMutations = (fieldParams, template) => {
@@ -22741,6 +22897,7 @@ var Resolver = class {
22741
22897
  } = _d, field = __objRest(_d, [
22742
22898
  "namespace"
22743
22899
  ]);
22900
+ field.parentTypename = NAMER.dataTypeName(namespace.filter((_6, i) => i < namespace.length - 1));
22744
22901
  const extraFields = field.ui || {};
22745
22902
  switch (field.type) {
22746
22903
  case "number":
@@ -22868,6 +23025,27 @@ var Resolver = class {
22868
23025
  this.database = init.database;
22869
23026
  this.tinaSchema = init.tinaSchema;
22870
23027
  }
23028
+ async resolveFilterConditions(filter, fields, collectionName) {
23029
+ const conditions = [];
23030
+ const conditionCollector = (condition) => {
23031
+ if (!condition.filterPath) {
23032
+ throw new Error("Error parsing filter - unable to generate filterPath");
23033
+ }
23034
+ if (!condition.filterExpression) {
23035
+ throw new Error(`Error parsing filter - missing expression for ${condition.filterPath}`);
23036
+ }
23037
+ conditions.push(condition);
23038
+ };
23039
+ await resolveReferences(filter, fields, this.referenceResolver);
23040
+ for (const fieldName of Object.keys(filter)) {
23041
+ const field = fields.find((field2) => field2.name === fieldName);
23042
+ if (!field) {
23043
+ throw new Error(`${fieldName} not found in collection ${collectionName}`);
23044
+ }
23045
+ collectConditionsForField(fieldName, field, filter[fieldName], "", conditionCollector);
23046
+ }
23047
+ return conditions;
23048
+ }
22871
23049
  };
22872
23050
  var resolveDateInput = (value) => {
22873
23051
  const date = new Date(value);
@@ -23066,7 +23244,10 @@ var resolve = async ({
23066
23244
  }
23067
23245
  return result;
23068
23246
  case "collectionDocumentList":
23069
- return resolver2.resolveCollectionConnection({ args, lookup });
23247
+ return resolver2.resolveCollectionConnection({
23248
+ args,
23249
+ collection: tinaSchema.getCollection(lookup.collection)
23250
+ });
23070
23251
  case "unionData":
23071
23252
  return value;
23072
23253
  default:
@@ -23375,7 +23556,7 @@ var parseFile = (content3, format, yupSchema) => {
23375
23556
  };
23376
23557
 
23377
23558
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/database/index.ts
23378
- var import_lodash7 = __toModule(require("lodash"));
23559
+ var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
23379
23560
  var createDatabase = async (config) => {
23380
23561
  return new Database(__spreadProps(__spreadValues({}, config), {
23381
23562
  bridge: config.bridge,
@@ -23426,27 +23607,42 @@ var Database = class {
23426
23607
  };
23427
23608
  this.addPendingDocument = async (filepath, data) => {
23428
23609
  const { stringifiedFile, payload, keepTemplateKey } = await this.stringifyFile(filepath, data);
23610
+ const tinaSchema = await this.getSchema();
23611
+ const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23612
+ let collectionIndexDefinitions;
23613
+ if (collection) {
23614
+ const indexDefinitions = await this.getIndexDefinitions();
23615
+ collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23616
+ }
23429
23617
  if (this.store.supportsSeeding()) {
23430
23618
  await this.bridge.put(filepath, stringifiedFile);
23431
23619
  }
23432
- await this.store.put(filepath, payload, keepTemplateKey);
23620
+ await this.store.put(filepath, payload, {
23621
+ keepTemplateKey,
23622
+ collection: collection.name,
23623
+ indexDefinitions: collectionIndexDefinitions
23624
+ });
23433
23625
  };
23434
23626
  this.put = async (filepath, data) => {
23435
23627
  if (SYSTEM_FILES.includes(filepath)) {
23436
23628
  throw new Error(`Unexpected put for config file ${filepath}`);
23437
23629
  } else {
23630
+ const tinaSchema = await this.getSchema();
23631
+ const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23632
+ let collectionIndexDefinitions;
23633
+ if (collection) {
23634
+ const indexDefinitions = await this.getIndexDefinitions();
23635
+ collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23636
+ }
23438
23637
  const { stringifiedFile, payload, keepTemplateKey } = await this.stringifyFile(filepath, data);
23439
23638
  if (this.store.supportsSeeding()) {
23440
23639
  await this.bridge.put(filepath, stringifiedFile);
23441
23640
  }
23442
- if (this.store.supportsIndexing()) {
23443
- await indexDocument({
23444
- filepath,
23445
- data,
23446
- database: this
23447
- });
23448
- }
23449
- await this.store.put(filepath, payload, keepTemplateKey);
23641
+ await this.store.put(filepath, payload, {
23642
+ keepTemplateKey,
23643
+ collection: collection.name,
23644
+ indexDefinitions: collectionIndexDefinitions
23645
+ });
23450
23646
  }
23451
23647
  return true;
23452
23648
  };
@@ -23533,6 +23729,56 @@ var Database = class {
23533
23729
  this.tinaSchema = await createSchema({ schema });
23534
23730
  return this.tinaSchema;
23535
23731
  };
23732
+ this.getIndexDefinitions = async () => {
23733
+ if (!this.collectionIndexDefinitions) {
23734
+ await new Promise(async (resolve2, reject) => {
23735
+ try {
23736
+ const schema = await this.getSchema();
23737
+ const collections = schema.getCollections();
23738
+ for (const collection of collections) {
23739
+ const indexDefinitions = {
23740
+ [import_datalayer2.DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
23741
+ };
23742
+ if (collection.fields) {
23743
+ for (const field of collection.fields) {
23744
+ if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
23745
+ continue;
23746
+ }
23747
+ indexDefinitions[field.name] = {
23748
+ fields: [
23749
+ {
23750
+ name: field.name,
23751
+ type: field.type,
23752
+ pad: field.type === "number" ? { fillString: "0", maxLength: import_datalayer2.DEFAULT_NUMERIC_LPAD } : void 0
23753
+ }
23754
+ ]
23755
+ };
23756
+ }
23757
+ }
23758
+ if (collection.indexes) {
23759
+ for (const index2 of collection.indexes) {
23760
+ indexDefinitions[index2.name] = {
23761
+ fields: index2.fields.map((indexField) => {
23762
+ var _a;
23763
+ return {
23764
+ name: indexField.name,
23765
+ type: (_a = collection.fields.find((field) => indexField.name === field.name)) == null ? void 0 : _a.type
23766
+ };
23767
+ })
23768
+ };
23769
+ }
23770
+ }
23771
+ this.collectionIndexDefinitions = this.collectionIndexDefinitions || {};
23772
+ this.collectionIndexDefinitions[collection.name] = indexDefinitions;
23773
+ }
23774
+ resolve2();
23775
+ } catch (err) {
23776
+ reject(err);
23777
+ }
23778
+ });
23779
+ }
23780
+ return this.collectionIndexDefinitions;
23781
+ };
23536
23782
  this.documentExists = async (fullpath) => {
23537
23783
  try {
23538
23784
  await this.get(fullpath);
@@ -23541,8 +23787,52 @@ var Database = class {
23541
23787
  }
23542
23788
  return true;
23543
23789
  };
23544
- this.query = async (queryStrings, hydrator) => {
23545
- return await this.store.query(queryStrings, hydrator);
23790
+ this.query = async (queryOptions, hydrator) => {
23791
+ const { first, after, last, before, sort, collection, filterChain } = queryOptions;
23792
+ const storeQueryOptions = {
23793
+ sort,
23794
+ collection,
23795
+ filterChain
23796
+ };
23797
+ if (first) {
23798
+ storeQueryOptions.limit = first;
23799
+ } else if (last) {
23800
+ storeQueryOptions.limit = last;
23801
+ } else {
23802
+ storeQueryOptions.limit = 10;
23803
+ }
23804
+ if (after) {
23805
+ storeQueryOptions.gt = (0, import_datalayer2.atob)(after);
23806
+ } else if (before) {
23807
+ storeQueryOptions.lt = (0, import_datalayer2.atob)(before);
23808
+ }
23809
+ if (last) {
23810
+ storeQueryOptions.reverse = true;
23811
+ }
23812
+ const indexDefinitions = await this.getIndexDefinitions();
23813
+ storeQueryOptions.indexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[queryOptions.collection];
23814
+ if (!storeQueryOptions.indexDefinitions) {
23815
+ throw new Error(`No indexDefinitions for collection ${queryOptions.collection}`);
23816
+ }
23817
+ const {
23818
+ edges,
23819
+ pageInfo: { hasPreviousPage, hasNextPage, startCursor, endCursor }
23820
+ } = await this.store.query(storeQueryOptions);
23821
+ return {
23822
+ edges: await sequential(edges, async (edge) => {
23823
+ const node = await hydrator(edge.path);
23824
+ return {
23825
+ node,
23826
+ cursor: (0, import_datalayer2.btoa)(edge.cursor)
23827
+ };
23828
+ }),
23829
+ pageInfo: {
23830
+ hasPreviousPage,
23831
+ hasNextPage,
23832
+ startCursor: (0, import_datalayer2.btoa)(startCursor),
23833
+ endCursor: (0, import_datalayer2.btoa)(endCursor)
23834
+ }
23835
+ };
23546
23836
  };
23547
23837
  this.putConfigFiles = async ({
23548
23838
  graphQLSchema,
@@ -23571,13 +23861,32 @@ var Database = class {
23571
23861
  }
23572
23862
  };
23573
23863
  this.indexContentByPaths = async (documentPaths) => {
23574
- await _indexContent(this, documentPaths);
23864
+ const pathsByCollection = {};
23865
+ const nonCollectionPaths = [];
23866
+ const collections = {};
23867
+ const tinaSchema = await this.getSchema();
23868
+ for (const documentPath of documentPaths) {
23869
+ const collection = tinaSchema.schema.collections.find((collection2) => documentPath.startsWith(collection2.path));
23870
+ if (collection) {
23871
+ if (!pathsByCollection[collection.name]) {
23872
+ pathsByCollection[collection.name] = [];
23873
+ }
23874
+ collections[collection.name] = collection;
23875
+ pathsByCollection[collection.name].push(documentPath);
23876
+ } else {
23877
+ nonCollectionPaths.push(documentPath);
23878
+ }
23879
+ }
23880
+ for (const collection of Object.keys(pathsByCollection)) {
23881
+ await _indexContent(this, pathsByCollection[collection], collections[collection]);
23882
+ }
23883
+ await _indexContent(this, nonCollectionPaths);
23575
23884
  };
23576
23885
  this._indexAllContent = async () => {
23577
23886
  const tinaSchema = await this.getSchema();
23578
23887
  await sequential(tinaSchema.getCollections(), async (collection) => {
23579
23888
  const documentPaths = await this.bridge.glob(collection.path);
23580
- await _indexContent(this, documentPaths);
23889
+ await _indexContent(this, documentPaths, collection);
23581
23890
  });
23582
23891
  };
23583
23892
  this.addToLookupMap = async (lookup) => {
@@ -23600,138 +23909,31 @@ var Database = class {
23600
23909
  function hasOwnProperty2(obj, prop) {
23601
23910
  return obj.hasOwnProperty(prop);
23602
23911
  }
23603
- var _indexContent = async (database, documentPaths) => {
23912
+ var _indexContent = async (database, documentPaths, collection) => {
23913
+ let seedOptions = void 0;
23914
+ if (collection) {
23915
+ const indexDefinitions = await database.getIndexDefinitions();
23916
+ const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23917
+ if (!collectionIndexDefinitions) {
23918
+ throw new Error(`No indexDefinitions for collection ${collection.name}`);
23919
+ }
23920
+ const numIndexes = Object.keys(collectionIndexDefinitions).length;
23921
+ if (numIndexes > 20) {
23922
+ throw new Error(`A maximum of 20 indexes are allowed per field. Currently collection ${collection.name} has ${numIndexes} indexes. Add 'indexed: false' to exclude a field from indexing.`);
23923
+ }
23924
+ seedOptions = {
23925
+ collection: collection.name,
23926
+ indexDefinitions: collectionIndexDefinitions
23927
+ };
23928
+ }
23604
23929
  await sequential(documentPaths, async (filepath) => {
23605
23930
  const dataString = await database.bridge.get(filepath);
23606
23931
  const data = parseFile(dataString, import_path4.default.extname(filepath), (yup3) => yup3.object({}));
23607
23932
  if (database.store.supportsSeeding()) {
23608
- await database.store.seed(filepath, data);
23609
- }
23610
- if (database.store.supportsIndexing()) {
23611
- return indexDocument({ filepath, data, database });
23933
+ await database.store.seed(filepath, data, seedOptions);
23612
23934
  }
23613
23935
  });
23614
23936
  };
23615
- var indexDocument = async ({
23616
- filepath,
23617
- data,
23618
- database
23619
- }) => {
23620
- var _a;
23621
- const schema = await database.getSchema();
23622
- const collection = await schema.getCollectionByFullPath(filepath);
23623
- let existingData;
23624
- try {
23625
- existingData = await database.get(filepath);
23626
- } catch (err) {
23627
- if (((_a = err.extensions) == null ? void 0 : _a["status"]) !== 404) {
23628
- throw err;
23629
- }
23630
- }
23631
- if (existingData) {
23632
- const attributesToFilterOut = await _indexCollectable({
23633
- record: filepath,
23634
- value: existingData,
23635
- field: collection,
23636
- prefix: collection.name,
23637
- database
23638
- });
23639
- await sequential(attributesToFilterOut, async (attribute) => {
23640
- const records = await database.store.get(attribute) || [];
23641
- await database.store.put(attribute, records.filter((item) => item !== filepath));
23642
- return true;
23643
- });
23644
- }
23645
- const attributes = await _indexCollectable({
23646
- record: filepath,
23647
- field: collection,
23648
- value: data,
23649
- prefix: `${lastItem(collection.namespace)}`,
23650
- database
23651
- });
23652
- await sequential(attributes, async (fieldName) => {
23653
- const existingRecords = await database.store.get(fieldName) || [];
23654
- const uniqueItems = [...new Set([...existingRecords, filepath])];
23655
- await database.store.put(fieldName, uniqueItems);
23656
- });
23657
- };
23658
- var _indexCollectable = async (_a) => {
23659
- var _b = _a, {
23660
- field,
23661
- value
23662
- } = _b, rest = __objRest(_b, [
23663
- "field",
23664
- "value"
23665
- ]);
23666
- let template;
23667
- let extra = "";
23668
- if (field.templates) {
23669
- template = field.templates.find((t) => {
23670
- if (typeof t === "string") {
23671
- throw new Error(`Global templates not yet supported`);
23672
- }
23673
- if (hasOwnProperty2(value, "_template")) {
23674
- return t.name === value._template;
23675
- } else {
23676
- throw new Error(`Expected value for collectable with multiple templates to have property _template`);
23677
- }
23678
- });
23679
- extra = `#${lastItem(template.namespace)}`;
23680
- } else {
23681
- template = field;
23682
- }
23683
- const atts = await _indexAttributes({
23684
- record: rest.record,
23685
- data: value,
23686
- prefix: `${rest.prefix}${extra}#${template.name}`,
23687
- fields: template.fields,
23688
- database: rest.database
23689
- });
23690
- return (0, import_lodash7.flatten)(atts).filter((item) => !(0, import_lodash7.isBoolean)(item));
23691
- };
23692
- var _indexAttributes = async (_a) => {
23693
- var _b = _a, {
23694
- data,
23695
- fields
23696
- } = _b, rest = __objRest(_b, [
23697
- "data",
23698
- "fields"
23699
- ]);
23700
- return sequential(fields, async (field) => {
23701
- const value = data[field.name];
23702
- if (!value) {
23703
- return true;
23704
- }
23705
- switch (field.type) {
23706
- case "boolean":
23707
- case "string":
23708
- case "number":
23709
- case "datetime":
23710
- return _indexAttribute(__spreadValues({ value, field }, rest));
23711
- case "object":
23712
- if (field.list) {
23713
- await sequential(value, async (item) => {
23714
- return _indexCollectable(__spreadValues({ field, value: item }, rest));
23715
- });
23716
- } else {
23717
- return _indexCollectable(__spreadValues({ field, value }, rest));
23718
- }
23719
- return true;
23720
- case "reference":
23721
- return _indexAttribute(__spreadValues({ value, field }, rest));
23722
- }
23723
- return true;
23724
- });
23725
- };
23726
- var _indexAttribute = async ({
23727
- value,
23728
- prefix,
23729
- field
23730
- }) => {
23731
- const stringValue = value.toString().substr(0, 100);
23732
- const fieldName = `__attribute__${prefix}#${field.name}#${stringValue}`;
23733
- return fieldName;
23734
- };
23735
23937
 
23736
23938
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/index.ts
23737
23939
  var buildSchema = async (rootPath, database) => {
@@ -96,6 +96,7 @@ export interface NodeTypes {
96
96
  delete_mark: string;
97
97
  inline_code_mark: string;
98
98
  thematic_break: string;
99
+ break: string;
99
100
  }
100
101
  export declare type SlateNodeType = {
101
102
  type: 'heading_one';
@@ -0,0 +1,22 @@
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 { ReferenceTypeInner, TinaFieldInner } from '../types';
14
+ import type { FilterCondition } from '@tinacms/datalayer';
15
+ export declare type ReferenceResolver = (filter: Record<string, object>, fieldDefinition: ReferenceTypeInner) => Promise<{
16
+ edges: {
17
+ node: any;
18
+ }[];
19
+ values: any[];
20
+ }>;
21
+ export declare const resolveReferences: (filter: any, fields: TinaFieldInner<false>[], resolver: ReferenceResolver) => Promise<void>;
22
+ export declare const collectConditionsForField: (fieldName: string, field: TinaFieldInner<false>, filterNode: Record<string, object>, pathExpression: string, collectCondition: (condition: FilterCondition) => void) => void;
@@ -11,8 +11,9 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import { TinaSchema } from '../schema';
14
- import { Database, CollectionDocumentListLookup } from '../database';
15
- import type { Collectable, TinaCloudCollection } from '../types';
14
+ import { Database } from '../database';
15
+ import type { Collectable, ReferenceTypeWithNamespace, TinaCloudCollection } from '../types';
16
+ import { TinaFieldInner } from '../types';
16
17
  interface ResolverConfig {
17
18
  database: Database;
18
19
  tinaSchema: TinaSchema;
@@ -28,32 +29,34 @@ export declare class Resolver {
28
29
  tinaSchema: TinaSchema;
29
30
  constructor(init: ResolverConfig);
30
31
  resolveCollection: (collectionName: string, hasDocuments?: boolean) => Promise<{
31
- fields: string | import("../types").TinaFieldInner<true>[];
32
+ fields: string | TinaFieldInner<true>[];
32
33
  templates?: undefined;
33
- references?: import("../types").ReferenceTypeWithNamespace[];
34
+ references?: ReferenceTypeWithNamespace[];
34
35
  namespace: string[];
35
36
  label?: string;
36
37
  name: string;
37
38
  path: string;
38
39
  format?: "json" | "md" | "markdown" | "mdx";
39
40
  match?: string;
41
+ indexes?: import("../types").TinaIndex[];
40
42
  documents: {};
41
43
  } | {
42
44
  templates: (string | {
43
45
  label: string;
44
46
  name: string;
45
- fields: import("../types").TinaFieldInner<true>[];
47
+ fields: TinaFieldInner<true>[];
46
48
  ui?: object;
47
49
  namespace: string[];
48
50
  })[];
49
51
  fields?: undefined;
50
- references?: import("../types").ReferenceTypeWithNamespace[];
52
+ references?: ReferenceTypeWithNamespace[];
51
53
  namespace: string[];
52
54
  label?: string;
53
55
  name: string;
54
56
  path: string;
55
57
  format?: "json" | "md" | "markdown" | "mdx";
56
58
  match?: string;
59
+ indexes?: import("../types").TinaIndex[];
57
60
  documents: {};
58
61
  }>;
59
62
  getDocument: (fullPath: unknown) => Promise<{
@@ -243,12 +246,16 @@ export declare class Resolver {
243
246
  }[];
244
247
  }>;
245
248
  getDocumentsForCollection: (collectionName: string) => Promise<string[]>;
246
- resolveCollectionConnection: ({ args, lookup, }: {
247
- args: Record<string, Record<string, object>>;
248
- lookup: CollectionDocumentListLookup;
249
+ private referenceResolver;
250
+ private resolveFilterConditions;
251
+ resolveCollectionConnection: ({ args, collection, hydrator, }: {
252
+ args: Record<string, Record<string, object> | string | number>;
253
+ collection: TinaCloudCollection<true>;
254
+ hydrator?: (string: any) => any;
249
255
  }) => Promise<{
250
256
  totalCount: any;
251
257
  edges: any;
258
+ pageInfo: any;
252
259
  }>;
253
260
  private buildFieldMutations;
254
261
  private resolveFieldData;
@@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import { Database } from '../database';
14
- import type { Store } from '../database/store';
14
+ import type { Store } from '@tinacms/datalayer';
15
15
  import type { TinaCloudSchema } from '../types';
16
16
  export declare const setup: (rootPath: string, schema: TinaCloudSchema<false>, store: Store) => Promise<{
17
17
  database: Database;
package/dist/types.d.ts CHANGED
@@ -36,6 +36,7 @@ interface BaseCollection {
36
36
  path: string;
37
37
  format?: FormatType;
38
38
  match?: string;
39
+ indexes?: TinaIndex[];
39
40
  }
40
41
  declare type CollectionTemplates<WithNamespace extends boolean> = WithNamespace extends true ? CollectionTemplatesWithNamespace<WithNamespace> : CollectionTemplatesInner<WithNamespace>;
41
42
  interface CollectionTemplatesInner<WithNamespace extends boolean> extends BaseCollection {
@@ -60,6 +61,12 @@ interface CollectionFieldsInner<WithNamespace extends boolean> extends BaseColle
60
61
  templates?: undefined;
61
62
  }
62
63
  export declare type TinaFieldInner<WithNamespace extends boolean> = ScalarType<WithNamespace> | ObjectType<WithNamespace> | ReferenceType<WithNamespace> | RichType<WithNamespace>;
64
+ export declare type TinaIndex = {
65
+ name: string;
66
+ fields: {
67
+ name: string;
68
+ }[];
69
+ };
63
70
  export declare type TinaFieldBase = TinaFieldInner<false>;
64
71
  export declare type TinaFieldEnriched = TinaFieldInner<true>;
65
72
  interface TinaField {
@@ -68,6 +75,7 @@ interface TinaField {
68
75
  description?: string;
69
76
  required?: boolean;
70
77
  list?: boolean;
78
+ indexed?: boolean;
71
79
  /**
72
80
  * Any items passed to the UI field will be passed to the underlying field.
73
81
  * NOTE: only serializable values are supported, so functions like `validate`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.0.0-20222901756",
3
+ "version": "0.0.0-202231073",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -46,6 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
49
+ "@tinacms/datalayer": "0.0.0-202231073",
49
50
  "body-parser": "^1.19.0",
50
51
  "cors": "^2.8.5",
51
52
  "dataloader": "^2.0.0",
@@ -61,6 +62,7 @@
61
62
  "graphql-type-json": "^0.3.2",
62
63
  "gray-matter": "^4.0.2",
63
64
  "js-yaml": "^3.14.0",
65
+ "leveldown": "^6.1.0",
64
66
  "lodash": "^4.17.20",
65
67
  "mdast": "^3.0.0",
66
68
  "mdast-util-from-markdown": "^1.0.0",
@@ -68,7 +70,6 @@
68
70
  "mdast-util-mdx-expression": "^1.1.0",
69
71
  "mdast-util-to-markdown": "^1.2.1",
70
72
  "micromark-extension-mdxjs": "^1.0.0",
71
- "mocha": "^9.1.1",
72
73
  "normalize-path": "^3.0.0",
73
74
  "prettier": "^2.2.1",
74
75
  "rehype-format": "^3.1.0",
@@ -95,7 +96,7 @@
95
96
  "directory": "packages/tina-graphql"
96
97
  },
97
98
  "devDependencies": {
98
- "@tinacms/datalayer": "0.0.2",
99
+ "@tinacms/datalayer": "0.0.0-202231073",
99
100
  "@tinacms/scripts": "0.50.7",
100
101
  "@types/cors": "^2.8.7",
101
102
  "@types/estree": "^0.0.50",
@@ -103,7 +104,6 @@
103
104
  "@types/fs-extra": "^9.0.2",
104
105
  "@types/jest": "^26.0.4",
105
106
  "@types/js-yaml": "^3.12.5",
106
- "@types/level": "^6.0.0",
107
107
  "@types/lodash": "^4.14.161",
108
108
  "@types/lodash.camelcase": "^4.3.6",
109
109
  "@types/lodash.upperfirst": "^4.3.6",
@@ -1,72 +0,0 @@
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
- export interface Store {
14
- glob(pattern: string, hydrator?: (fullPath: string) => Promise<object>): Promise<string[]>;
15
- get<T extends object>(filepath: string): Promise<T>;
16
- clear(): void;
17
- /**
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
47
- */
48
- query(queryStrings: string[], hydrator?: (fullPath: string) => Promise<object>): Promise<object[]>;
49
- /**
50
- * In this context, seeding is the act of putting records and indexing data into an ephemeral
51
- * storage layer for use during the GraphQL runtime. What might seem suprising is that some stores
52
- * don't support seeding, this is because they're behaving more like a "bridge" (GithubStore and FilesystemStore).
53
- * Currently they're acting as a way to swap out true data-layer behavior with a backwards-compatible
54
- * "store". In the future, all stores should be able to query and seed data.
55
- *
56
- * At this time it seems that it would never make sense to be able to "query" without "seed"-ing, and
57
- * there'd be no value in "seeding" without "query"-ing.
58
- */
59
- seed(filepath: string, data: object, options?: {
60
- includeTemplate?: boolean;
61
- }): Promise<void>;
62
- supportsSeeding(): boolean;
63
- /**
64
- * Whether this store supports the ability to index data.
65
- * Indexing data requires writing arbitrary keys/values to
66
- * the external service, so is not advisable to use for
67
- * something like Github, which would write commits to the
68
- * user's repo.
69
- */
70
- supportsIndexing(): boolean;
71
- put(filepath: string, data: object, keepTemplateKey?: boolean): Promise<void>;
72
- }