@snowtop/ent 0.1.0-alpha148 → 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/schema/schema.d.ts +2 -0
- 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/schema/schema.d.ts
CHANGED
|
@@ -238,6 +238,7 @@ export interface FieldOptions {
|
|
|
238
238
|
polymorphic?: boolean | PolymorphicOptions;
|
|
239
239
|
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
240
240
|
editPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
241
|
+
createOnlyOverrideEditPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
241
242
|
getDerivedFields?(name: string): FieldMap;
|
|
242
243
|
convert?: ConvertType;
|
|
243
244
|
fetchOnDemand?: boolean;
|
|
@@ -271,6 +272,7 @@ export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
|
271
272
|
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
272
273
|
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
273
274
|
export declare function getFieldsWithEditPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
275
|
+
export declare function getFieldsForCreateAction(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
274
276
|
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
275
277
|
interface objectLoaderOptions {
|
|
276
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
|
}
|