@snowtop/ent 0.1.0-alpha146 → 0.1.0-alpha147

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha146",
3
+ "version": "0.1.0-alpha147",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
2
- import { ActionField, Type, GlobalSchema, TransformReadBetaResult } from "../schema/schema";
2
+ import { ActionField, Type, GlobalSchema, TransformReadBetaResult, CanViewerDo } from "../schema/schema";
3
3
  declare enum NullableResult {
4
4
  CONTENTS = "contents",
5
5
  CONTENTS_AND_LIST = "contentsAndList",
@@ -30,8 +30,9 @@ type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields
30
30
  type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
31
31
  edgeAction?: OutputAction;
32
32
  };
33
- type OutputAction = Omit<Action, "actionOnlyFields"> & {
33
+ type OutputAction = Omit<Action, "actionOnlyFields" | "canViewerDo"> & {
34
34
  actionOnlyFields?: ProcessedActionField[];
35
+ canViewerDo?: CanViewerDo;
35
36
  };
36
37
  interface schemasDict {
37
38
  [key: string]: ProcessedSchema;
@@ -202,34 +202,39 @@ var NullableResult;
202
202
  NullableResult["ITEM"] = "true";
203
203
  })(NullableResult || (NullableResult = {}));
204
204
  function processAction(action) {
205
- if (!action.actionOnlyFields) {
206
- return { ...action };
207
- }
208
- let ret = { ...action };
209
- let actionOnlyFields = action.actionOnlyFields.map((f) => {
210
- let f2 = f;
211
- if (!f.nullable) {
212
- delete f2.nullable;
213
- return f2;
214
- }
215
- if (typeof f.nullable === "boolean") {
216
- f2.nullable = NullableResult.ITEM;
217
- }
218
- else {
219
- if (f.nullable === "contentsAndList") {
220
- f2.nullable = NullableResult.CONTENTS_AND_LIST;
221
- }
222
- else if (f.nullable === "contents") {
223
- f2.nullable = NullableResult.CONTENTS;
205
+ const ret = { ...action };
206
+ if (action.actionOnlyFields !== undefined) {
207
+ let actionOnlyFields = action.actionOnlyFields.map((f) => {
208
+ let f2 = f;
209
+ if (!f.nullable) {
210
+ delete f2.nullable;
211
+ return f2;
224
212
  }
225
- else if (f.nullable === "true") {
226
- // shouldn't happen but ran into weirdness where it did...
213
+ if (typeof f.nullable === "boolean") {
227
214
  f2.nullable = NullableResult.ITEM;
228
215
  }
216
+ else {
217
+ if (f.nullable === "contentsAndList") {
218
+ f2.nullable = NullableResult.CONTENTS_AND_LIST;
219
+ }
220
+ else if (f.nullable === "contents") {
221
+ f2.nullable = NullableResult.CONTENTS;
222
+ }
223
+ else if (f.nullable === "true") {
224
+ // shouldn't happen but ran into weirdness where it did...
225
+ f2.nullable = NullableResult.ITEM;
226
+ }
227
+ }
228
+ return f2;
229
+ });
230
+ ret.actionOnlyFields = actionOnlyFields;
231
+ }
232
+ if (action.canViewerDo !== undefined) {
233
+ if (typeof action.canViewerDo !== "object") {
234
+ delete ret.canViewerDo;
235
+ ret.canViewerDo = {};
229
236
  }
230
- return f2;
231
- });
232
- ret.actionOnlyFields = actionOnlyFields;
237
+ }
233
238
  return ret;
234
239
  }
235
240
  async function parseSchema(potentialSchemas, globalSchema) {
@@ -59,6 +59,7 @@ export interface EdgeAction {
59
59
  hideFromGraphQL?: boolean;
60
60
  graphQLName?: string;
61
61
  actionOnlyFields?: ActionField[];
62
+ canViewerDo?: boolean | CanViewerDo;
62
63
  }
63
64
  export interface InverseAssocEdge {
64
65
  name: string;
@@ -70,6 +71,7 @@ export interface EdgeGroupAction {
70
71
  hideFromGraphQL?: boolean;
71
72
  graphQLName?: string;
72
73
  actionOnlyFields?: ActionField[];
74
+ canViewerDo?: boolean | CanViewerDo;
73
75
  }
74
76
  export interface AssocEdgeGroup {
75
77
  name: string;
@@ -309,8 +311,13 @@ export interface Action {
309
311
  optionalFields?: string[];
310
312
  requiredFields?: string[];
311
313
  noFields?: boolean;
314
+ canViewerDo?: boolean | CanViewerDo;
312
315
  [x: string]: any;
313
316
  }
317
+ export interface CanViewerDo {
318
+ addAllFields?: boolean;
319
+ inputFields?: string[];
320
+ }
314
321
  export declare const NoFields = "__NO_FIELDS__";
315
322
  export declare function requiredField(field: string): string;
316
323
  export declare function optionalField(field: string): string;
@@ -2,7 +2,7 @@ import { Express, RequestHandler } from "express";
2
2
  import { Viewer } from "../../core/base";
3
3
  import { GraphQLSchema } from "graphql";
4
4
  import supertest from "supertest";
5
- export type Option = [string, any];
5
+ export type Option = [string, any] | [string, any, string];
6
6
  interface queryConfig {
7
7
  viewer?: Viewer;
8
8
  init?: (app: Express) => void;
@@ -418,8 +418,9 @@ async function expectFromRoot(config, ...options) {
418
418
  }
419
419
  }
420
420
  await Promise.all(options.map(async (option) => {
421
- let path = option[0];
422
- let expected = option[1];
421
+ const path = option[0];
422
+ const expected = option[1];
423
+ const alias = option[2];
423
424
  let nullPath;
424
425
  let nullParts = [];
425
426
  let undefinedPath;
@@ -442,7 +443,7 @@ async function expectFromRoot(config, ...options) {
442
443
  }
443
444
  }
444
445
  }
445
- let parts = splitPath(path);
446
+ let parts = splitPath(alias ?? path);
446
447
  let current = result;
447
448
  // possible to make this smarter and better
448
449
  // e.g. when building up the tree above