@snowtop/ent 0.1.0-alpha147 → 0.1.0-alpha149
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/action/orchestrator.js +10 -2
- package/package.json +1 -1
- package/parse_schema/parse.js +2 -1
- package/schema/base_schema.d.ts +4 -2
- package/schema/base_schema.js +4 -2
- package/schema/schema.d.ts +4 -1
- package/schema/schema.js +23 -13
package/action/orchestrator.js
CHANGED
|
@@ -75,7 +75,7 @@ class EntCannotEditEntError extends Error {
|
|
|
75
75
|
}
|
|
76
76
|
class EntCannotEditEntFieldError extends Error {
|
|
77
77
|
constructor(privacyPolicy, viewer, field, ent) {
|
|
78
|
-
let msg = `${getViewer(viewer)} does not have permission to edit field ${field} ${ent.constructor.name}`;
|
|
78
|
+
let msg = `${getViewer(viewer)} does not have permission to edit field ${field} in ${ent.constructor.name}`;
|
|
79
79
|
super(msg);
|
|
80
80
|
this.privacyPolicy = privacyPolicy;
|
|
81
81
|
}
|
|
@@ -422,7 +422,15 @@ class Orchestrator {
|
|
|
422
422
|
// future optimization: can get schemaFields to memoize based on different values
|
|
423
423
|
const schemaFields = (0, schema_1.getFields)(this.options.schema);
|
|
424
424
|
// also future optimization, no need to go through the list of fields multiple times
|
|
425
|
-
|
|
425
|
+
let editPrivacyFields = new Map();
|
|
426
|
+
switch (this.actualOperation) {
|
|
427
|
+
case action_1.WriteOperation.Edit:
|
|
428
|
+
editPrivacyFields = (0, schema_1.getFieldsWithEditPrivacy)(this.options.schema, this.options.fieldInfo);
|
|
429
|
+
break;
|
|
430
|
+
case action_1.WriteOperation.Insert:
|
|
431
|
+
editPrivacyFields = (0, schema_1.getFieldsForCreateAction)(this.options.schema, this.options.fieldInfo);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
426
434
|
const editedFields = await this.options.editedFields();
|
|
427
435
|
let { data: editedData, userDefinedKeys } = await this.getFieldsWithDefaultValues(builder, schemaFields, editedFields, action);
|
|
428
436
|
return {
|
package/package.json
CHANGED
package/parse_schema/parse.js
CHANGED
|
@@ -275,7 +275,8 @@ async function parseSchema(potentialSchemas, globalSchema) {
|
|
|
275
275
|
assocEdgeGroups: [],
|
|
276
276
|
customGraphQLInterfaces: schema.customGraphQLInterfaces,
|
|
277
277
|
supportUpsert: schema.supportUpsert,
|
|
278
|
-
|
|
278
|
+
showCanViewerSee: schema.showCanViewerSee,
|
|
279
|
+
showCanViewerEdit: schema.showCanViewerEdit,
|
|
279
280
|
};
|
|
280
281
|
// let's put patterns first just so we have id, created_at, updated_at first
|
|
281
282
|
// ¯\_(ツ)_/¯
|
package/schema/base_schema.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export declare class EntSchema implements Schema {
|
|
|
21
21
|
hideFromGraphQL?: boolean;
|
|
22
22
|
customGraphQLInterfaces?: string[] | undefined;
|
|
23
23
|
supportUpsert?: boolean | undefined;
|
|
24
|
-
|
|
24
|
+
showCanViewerSee?: boolean | undefined;
|
|
25
|
+
showCanViewerEdit?: boolean | undefined;
|
|
25
26
|
constructor(cfg: SchemaConfig);
|
|
26
27
|
}
|
|
27
28
|
export declare class EntSchemaWithTZ implements Schema {
|
|
@@ -41,7 +42,8 @@ export declare class EntSchemaWithTZ implements Schema {
|
|
|
41
42
|
hideFromGraphQL?: boolean;
|
|
42
43
|
customGraphQLInterfaces?: string[] | undefined;
|
|
43
44
|
supportUpsert?: boolean | undefined;
|
|
44
|
-
|
|
45
|
+
showCanViewerSee?: boolean | undefined;
|
|
46
|
+
showCanViewerEdit?: boolean | undefined;
|
|
45
47
|
constructor(cfg: SchemaConfig);
|
|
46
48
|
}
|
|
47
49
|
export declare abstract class BaseEntSchema {
|
package/schema/base_schema.js
CHANGED
|
@@ -91,7 +91,8 @@ class EntSchema {
|
|
|
91
91
|
// TODO annoying that have to list these...
|
|
92
92
|
this.customGraphQLInterfaces = cfg.customGraphQLInterfaces;
|
|
93
93
|
this.supportUpsert = cfg.supportUpsert;
|
|
94
|
-
this.
|
|
94
|
+
this.showCanViewerSee = cfg.showCanViewerSee;
|
|
95
|
+
this.showCanViewerEdit = cfg.showCanViewerEdit;
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
exports.EntSchema = EntSchema;
|
|
@@ -122,7 +123,8 @@ class EntSchemaWithTZ {
|
|
|
122
123
|
// TODO annoying that have to list these...
|
|
123
124
|
this.customGraphQLInterfaces = cfg.customGraphQLInterfaces;
|
|
124
125
|
this.supportUpsert = cfg.supportUpsert;
|
|
125
|
-
this.
|
|
126
|
+
this.showCanViewerSee = cfg.showCanViewerSee;
|
|
127
|
+
this.showCanViewerEdit = cfg.showCanViewerEdit;
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
exports.EntSchemaWithTZ = EntSchemaWithTZ;
|
package/schema/schema.d.ts
CHANGED
|
@@ -40,7 +40,8 @@ export default interface Schema {
|
|
|
40
40
|
hideFromGraphQL?: boolean;
|
|
41
41
|
customGraphQLInterfaces?: string[];
|
|
42
42
|
supportUpsert?: boolean;
|
|
43
|
-
|
|
43
|
+
showCanViewerSee?: boolean;
|
|
44
|
+
showCanViewerEdit?: boolean;
|
|
44
45
|
}
|
|
45
46
|
export interface AssocEdge {
|
|
46
47
|
name: string;
|
|
@@ -237,6 +238,7 @@ export interface FieldOptions {
|
|
|
237
238
|
polymorphic?: boolean | PolymorphicOptions;
|
|
238
239
|
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
239
240
|
editPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
241
|
+
createOnlyOverrideEditPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
240
242
|
getDerivedFields?(name: string): FieldMap;
|
|
241
243
|
convert?: ConvertType;
|
|
242
244
|
fetchOnDemand?: boolean;
|
|
@@ -270,6 +272,7 @@ export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
|
270
272
|
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
271
273
|
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
272
274
|
export declare function getFieldsWithEditPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
275
|
+
export declare function getFieldsForCreateAction(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
273
276
|
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
274
277
|
interface objectLoaderOptions {
|
|
275
278
|
clause?: () => Clause | undefined;
|
package/schema/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsWithEditPrivacy = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
|
|
3
|
+
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsForCreateAction = exports.getFieldsWithEditPrivacy = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
|
|
4
4
|
const snake_case_1 = require("snake-case");
|
|
5
5
|
// we also want this transformation to exist on a per-action basis
|
|
6
6
|
// if it exists on an action, we don't do the global schema transformation
|
|
@@ -86,14 +86,21 @@ function getStorageKey(field, fieldName) {
|
|
|
86
86
|
exports.getStorageKey = getStorageKey;
|
|
87
87
|
// returns a mapping of storage key to field privacy
|
|
88
88
|
function getFieldsWithPrivacy(value, fieldInfoMap) {
|
|
89
|
-
return getFieldsWithPrivacyImpl(value, fieldInfoMap, "privacyPolicy");
|
|
89
|
+
return getFieldsWithPrivacyImpl(value, fieldInfoMap, ["privacyPolicy"]);
|
|
90
90
|
}
|
|
91
91
|
exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
|
|
92
92
|
function getFieldsWithEditPrivacy(value, fieldInfoMap) {
|
|
93
|
-
return getFieldsWithPrivacyImpl(value, fieldInfoMap, "editPrivacyPolicy");
|
|
93
|
+
return getFieldsWithPrivacyImpl(value, fieldInfoMap, ["editPrivacyPolicy"]);
|
|
94
94
|
}
|
|
95
95
|
exports.getFieldsWithEditPrivacy = getFieldsWithEditPrivacy;
|
|
96
|
-
function
|
|
96
|
+
function getFieldsForCreateAction(value, fieldInfoMap) {
|
|
97
|
+
return getFieldsWithPrivacyImpl(value, fieldInfoMap, [
|
|
98
|
+
"createOnlyOverrideEditPrivacyPolicy",
|
|
99
|
+
"editPrivacyPolicy",
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
exports.getFieldsForCreateAction = getFieldsForCreateAction;
|
|
103
|
+
function getFieldsWithPrivacyImpl(value, fieldInfoMap, keys) {
|
|
97
104
|
const schema = getSchema(value);
|
|
98
105
|
function addFields(fields) {
|
|
99
106
|
for (const name in fields) {
|
|
@@ -104,16 +111,19 @@ function getFieldsWithPrivacyImpl(value, fieldInfoMap, key) {
|
|
|
104
111
|
if (field.getDerivedFields !== undefined) {
|
|
105
112
|
addFields(field.getDerivedFields(name));
|
|
106
113
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
privacyPolicy
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
for (const key of keys) {
|
|
115
|
+
let privacyPolicy = field[key];
|
|
116
|
+
if (privacyPolicy) {
|
|
117
|
+
if (typeof privacyPolicy === "function") {
|
|
118
|
+
privacyPolicy = privacyPolicy();
|
|
119
|
+
}
|
|
120
|
+
const info = fieldInfoMap[name];
|
|
121
|
+
if (!info) {
|
|
122
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
123
|
+
}
|
|
124
|
+
m.set(info.dbCol, privacyPolicy);
|
|
125
|
+
break;
|
|
115
126
|
}
|
|
116
|
-
m.set(info.dbCol, privacyPolicy);
|
|
117
127
|
}
|
|
118
128
|
}
|
|
119
129
|
}
|