aboutsummaryrefslogtreecommitdiff
path: root/src/fields/util.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-06-06 18:48:59 -0400
committerbobzel <zzzman@gmail.com>2023-06-06 18:48:59 -0400
commit562e965cbc3d7629014ad3902e1177d5cbefd57c (patch)
treed1d1c063fa3770f0388c23367262cb9f0e256a5d /src/fields/util.ts
parent3d30bdaf6dcf4972593f10b9b0f2fabd79c7062b (diff)
updated Symbol naming. fixed various compile errors related to type checking.
Diffstat (limited to 'src/fields/util.ts')
-rw-r--r--src/fields/util.ts80
1 files changed, 30 insertions, 50 deletions
diff --git a/src/fields/util.ts b/src/fields/util.ts
index a2b445d6c..62f27c7d2 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -7,28 +7,9 @@ import { SerializationHelper } from '../client/util/SerializationHelper';
import { UndoManager } from '../client/util/UndoManager';
import { returnZero } from '../Utils';
import CursorField from './CursorField';
-import {
- AclAdmin,
- AclEdit,
- aclLevel,
- AclPrivate,
- AclSelfEdit,
- AclSym,
- DataSym,
- Doc,
- DocListCast,
- DocListCastAsync,
- ForceServerWrite,
- HeightSym,
- HierarchyMapping,
- Initializing,
- LayoutSym,
- ReverseHierarchyMap,
- updateCachedAcls,
- UpdatingFromServer,
- WidthSym,
-} from './Doc';
-import { Id, OnUpdate, Parent, SelfProxy, ToValue, Update } from './FieldSymbols';
+import { aclLevel, Doc, DocListCast, DocListCastAsync, HierarchyMapping, ReverseHierarchyMap, updateCachedAcls } from './Doc';
+import { AclAdmin, AclEdit, AclPrivate, AclSelfEdit, DocAcl, DocData, DocLayout, FieldKeys, ForceServerWrite, Height, Initializing, SelfProxy, Update, UpdatingFromServer, Width } from './DocSymbols';
+import { Id, OnUpdate, Parent, ToValue } from './FieldSymbols';
import { List } from './List';
import { ObjectField } from './ObjectField';
import { PrefetchProxy, ProxyField } from './Proxy';
@@ -56,7 +37,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number
if (value !== undefined) {
value = value[SelfProxy] || value;
}
- const curValue = target.__fields[prop];
+ const curValue = target.__fieldTuples[prop];
if (curValue === value || (curValue instanceof ProxyField && value instanceof RefField && curValue.fieldId === value[Id])) {
// TODO This kind of checks correctly in the case that curValue is a ProxyField and value is a RefField, but technically
// curValue should get filled in with value if it isn't already filled in, in case we fetched the referenced field some other way
@@ -88,11 +69,11 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number
if (writeToDoc) {
if (value === undefined) {
- target.__fieldKeys && delete target.__fieldKeys[prop];
- delete target.__fields[prop];
+ delete target[FieldKeys][prop];
+ delete target.__fieldTuples[prop];
} else {
- target.__fieldKeys && (target.__fieldKeys[prop] = true);
- target.__fields[prop] = value;
+ target[FieldKeys][prop] = true;
+ target.__fieldTuples[prop] = value;
}
if (writeToServer) {
@@ -148,12 +129,12 @@ export function denormalizeEmail(email: string) {
*/
export function inheritParentAcls(parent: Doc, child: Doc) {
return;
- const dataDoc = parent[DataSym];
- for (const key of Object.keys(dataDoc)) {
- // if the default acl mode is private, then don't inherit the acl-Public permission, but set it to private.
- const permission = key === 'acl-Public' && Doc.defaultAclPrivate ? AclPrivate : dataDoc[key];
- key.startsWith('acl') && distributeAcls(key, permission, child);
- }
+ // const dataDoc = parent[DataSym];
+ // for (const key of Object.keys(dataDoc)) {
+ // // if the default acl mode is private, then don't inherit the acl-Public permission, but set it to private.
+ // const permission = key === 'acl-Public' && Doc.defaultAclPrivate ? AclPrivate : dataDoc[key];
+ // key.startsWith('acl') && distributeAcls(key, permission, child);
+ // }
}
/**
@@ -212,7 +193,7 @@ export function SetCachedGroups(groups: string[]) {
runInAction(() => cachedGroups.push(...groups));
}
function getEffectiveAcl(target: any, user?: string): symbol {
- const targetAcls = target[AclSym];
+ const targetAcls = target[DocAcl];
if (targetAcls?.['acl-Me'] === AclAdmin || GetCachedGroupByName('Admin')) return AclAdmin;
const userChecked = user || Doc.CurrentUserEmail; // if the current user is the author of the document / the current user is a member of the admin group
@@ -237,7 +218,7 @@ function getEffectiveAcl(target: any, user?: string): symbol {
return DocServer?.Control?.isReadOnly?.() && HierarchyMapping.get(effectiveAcl)!.level < aclLevel.editable ? AclEdit : effectiveAcl;
}
// authored documents are private until an ACL is set.
- const targetAuthor = target.__fields?.author || target.author; // target may be a Doc of Proxy, so check __fields.author and .author
+ const targetAuthor = target.__fieldTuples?.author || target.author; // target may be a Doc of Proxy, so check __fieldTuples.author and .author
if (targetAuthor && targetAuthor !== userChecked) return AclPrivate;
return AclAdmin;
}
@@ -277,7 +258,7 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc
}
let dataDocChanged = false;
- const dataDoc = target[DataSym];
+ const dataDoc = target[DocData];
if (dataDoc && (!inheritingFromCollection || !dataDoc[key] || ReverseHierarchyMap.get(StrCast(dataDoc[key]))! > ReverseHierarchyMap.get(acl)!)) {
if (GetEffectiveAcl(dataDoc) === AclAdmin) {
dataDoc[key] = acl;
@@ -290,13 +271,13 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc
// maps over the children of the document
DocListCast(dataDoc[Doc.LayoutFieldKey(dataDoc)]).forEach(d => {
distributeAcls(key, acl, d, inheritingFromCollection, visited);
- distributeAcls(key, acl, d[DataSym], inheritingFromCollection, visited);
+ distributeAcls(key, acl, d[DocData], inheritingFromCollection, visited);
});
// maps over the annotations of the document
DocListCast(dataDoc[Doc.LayoutFieldKey(dataDoc) + '_annotations']).forEach(d => {
distributeAcls(key, acl, d, inheritingFromCollection, visited);
- distributeAcls(key, acl, d[DataSym], inheritingFromCollection, visited);
+ distributeAcls(key, acl, d[DocData], inheritingFromCollection, visited);
});
}
@@ -311,16 +292,16 @@ export function setter(target: any, in_prop: string | symbol | number, value: an
// if you're trying to change an acl but don't have Admin access / you're trying to change it to something that isn't an acceptable acl, you can't
if (typeof prop === 'string' && prop.startsWith('acl') && (effectiveAcl !== AclAdmin || ![...Object.values(SharingPermissions), undefined].includes(value))) return true;
- if (typeof prop === 'string' && prop !== '__id' && prop !== '__fields' && prop.startsWith('_')) {
+ if (typeof prop === 'string' && prop !== '__id' && prop !== '__fieldTuples' && prop.startsWith('_')) {
if (!prop.startsWith('__')) prop = prop.substring(1);
if (target.__LAYOUT__) {
target.__LAYOUT__[prop] = value;
return true;
}
}
- if (target.__fields[prop] instanceof ComputedField) {
- if (target.__fields[prop].setterscript && value !== undefined && !(value instanceof ComputedField)) {
- return ScriptCast(target.__fields[prop])?.setterscript?.run({ self: target[SelfProxy], this: target[SelfProxy], value }).success ? true : false;
+ if (target.__fieldTuples[prop] instanceof ComputedField) {
+ if (target.__fieldTuples[prop].setterscript && value !== undefined && !(value instanceof ComputedField)) {
+ return ScriptCast(target.__fieldTuples[prop])?.setterscript?.run({ self: target[SelfProxy], this: target[SelfProxy], value }).success ? true : false;
}
}
return _setter(target, prop, value, receiver);
@@ -330,14 +311,13 @@ export function getter(target: any, prop: string | symbol, proxy: any): any {
// prettier-ignore
switch (prop) {
case 'then' : return undefined;
- case '__fields' : case '__id':
- case 'constructor': case 'toString': case 'valueOf':
- case 'factory': case 'serializeInfo':
+ case 'constructor': case 'toString': case 'valueOf':
+ case 'serializeInfo': case 'factory':
return target[prop];
- case AclSym : return target[AclSym];
- case $mobx: return target.__fields[prop];
- case LayoutSym: return target.__LAYOUT__;
- case HeightSym: case WidthSym: if (GetEffectiveAcl(target) === AclPrivate) return returnZero;
+ case DocAcl : return target[DocAcl];
+ case $mobx: return target.__fieldTuples[prop];
+ case DocLayout: return target.__LAYOUT__;
+ case Height: case Width: if (GetEffectiveAcl(target) === AclPrivate) return returnZero;
default :
if (typeof prop === 'symbol') return target[prop];
if (prop.startsWith('isMobX')) return target[prop];
@@ -351,7 +331,7 @@ export function getter(target: any, prop: string | symbol, proxy: any): any {
}
function getFieldImpl(target: any, prop: string | number, proxy: any, ignoreProto: boolean = false): any {
- const field = target.__fields[prop];
+ const field = target.__fieldTuples[prop];
const value = field?.[ToValue]?.(proxy); // converts ComputedFields to values, or unpacks ProxyFields into Proxys
if (value) return value.value;
if (field === undefined && !ignoreProto && prop !== 'proto') {