Skip to content

Commit

Permalink
Preserve legacy 'meaning' of properties
Browse files Browse the repository at this point in the history
NDB sets this for compressed blobs.
  • Loading branch information
remko committed Aug 18, 2021
1 parent c4f8c72 commit be1fa12
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
6 changes: 6 additions & 0 deletions bin/initialize-dev-db.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ await call("commit", {
"eyJuYW1lIjoiZHNhZG1pbiIsInZlcnNpb24iOiIwLjExLjIiLCJzY3JpcHRzIjp7InN0YXJ0Ijoic25vd3BhY2sgZGV2IiwiYnVpbGQiOiJzbm93cGFjayBidWlsZCIsImZvcm1hdCI6InByZXR0aWVyIC0td3JpdGUgXCJzcmMvKiovKi57anMsanN4LHRzLHRzeH1cIiIsImxpbnQiOiJwcmV0dGllciAtLWxvZ2xldmVsIHdhcm4gLS1jaGVjayBcInNyYy8qKi8qLntqcyxqc3gsdHMsdHN4fVwiICYmIHRzYyAtLW5vRW1pdCAmJiBlc2xpbnQgLiIsInRlc3QiOiJqZXN0IiwidGVzdC1jb3ZlcmFnZSI6Implc3QgLS1jb3ZlcmFnZSIsInN0YXJ0LWVtdWxhdG9yIjoiZ2Nsb3VkIC0tcHJvamVjdD1kc2FkbWluLWRldiBiZXRhIGVtdWxhdG9ycyBkYXRhc3RvcmUgc3RhcnQgLS1ob3N0LXBvcnQ9bG9jYWxob3N0OjgwODEgLS1kYXRhLWRpcj1lbXVsYXRvci1kYXRhIiwicHJlcGFyZSI6InNub3dwYWNrIGJ1aWxkIn0sInJlcG9zaXRvcnkiOiJnaXRodWI6cmVta28vZHNhZG1pbiIsImRlcGVuZGVuY2llcyI6eyJodHRwMi1wcm94eSI6Il41LjAuNTMiLCJqc2VzYyI6Il4zLjAuMiIsIm5vZGUtc3RhdGljIjoiXjAuNy4xMSIsInlhcmdzIjoiMTQuMi4zIn0sImRldkRlcGVuZGVuY2llcyI6eyJAYmFiZWwvY29yZSI6Il43LjE0LjY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6aYZAGU3p9BZFASsNfr9h5JVnLm4zx0nxMFDb87ODk7WXz2v2YGc0OxmErJgPPLdlpvn0ZPvbgzpoo3hb87eDTz6lZwRXnMuWo2F+YcD2mqNxdmlsMLHwW0uzq6CxYYUYFpCfNxK6jo+Dm53HDiv2SU9R3Vxif54S/xP7ufnWs/wzMkpYgxqx2J5L7ZWVpa44t/34OGSb2y68kNLg/FgX9Gq5pWBa25tMh/ot6rP5hrOvLs2ozDhcLn5k8xuM4zYwwqd2PMlyo4d2HOmq6pEkMJYtr2NmFRuJMWrYu3YeBvfzurJBdLeE49ljxWQBGUnlhJ5rZO7W7HEXf8DzM/5INDZdUIvnztxRHZ8TDOua3snehCZylDJeDm9c2B39JuH9UPA2XE90rckfh6ALTS4s9o1QQqttLT9//MLnDRx2UlUuXC3ty8EpAW9ke9GF69auLNzYE1L3nPz5+PIPAhEwVw==",
excludeFromIndexes: true,
},
geoPointProp: {
geoPointValue: {
latitude: 50.8798,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test": "jest",
"test-coverage": "jest --coverage",
"start-emulator": "gcloud --project=dsadmin-dev beta emulators datastore start --host-port=localhost:8081 --data-dir=emulator-data",
"initialize-dev-db": "./bin/initialize-dev-db.mjs",
"prepare": "snowpack build"
},
"repository": "github:remko/dsadmin",
Expand Down
5 changes: 4 additions & 1 deletion src/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export type GeoPointValue = {
};
};

export type PropertyValue = { excludeFromIndexes?: boolean } & (
export type PropertyValue = {
excludeFromIndexes?: boolean;
meaning?: number;
} & (
| NullPropertyValue
| BooleanPropertyValue
| IntegerValue
Expand Down
68 changes: 32 additions & 36 deletions src/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function valueType(v: PropertyValue): ValueType {

export type PropertyEditValue = {
type: ValueType;
meaning?: number;
excludeFromIndexes?: boolean;
stringValue: string;
booleanValue: boolean;
Expand Down Expand Up @@ -182,82 +183,75 @@ export function valueToEditValue(
project: string,
namespace: string | null,
): PropertyEditValue {
const excludeFromIndexes =
v.excludeFromIndexes != null
const baseValue = {
...EMPTY_VALUE,
...(v.excludeFromIndexes != null
? { excludeFromIndexes: v.excludeFromIndexes }
: {};
: {}),
...(v.meaning != null ? { meaning: v.meaning } : {}),
};
if ("timestampValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.Timestamp,
...excludeFromIndexes,
stringValue: v.timestampValue,
};
} else if ("stringValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.String,
...excludeFromIndexes,
stringValue: v.stringValue,
};
} else if ("keyValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.Key,
...excludeFromIndexes,
stringValue: keyToString(v.keyValue, project, namespace),
};
} else if ("nullValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.Null,
...excludeFromIndexes,
};
} else if ("booleanValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.Boolean,
...excludeFromIndexes,
booleanValue: v.booleanValue,
};
} else if ("integerValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.Integer,
...excludeFromIndexes,
stringValue: v.integerValue,
};
} else if ("doubleValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.Double,
...excludeFromIndexes,
stringValue: v.doubleValue + "",
};
} else if ("geoPointValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.GeoPoint,
...excludeFromIndexes,
geoPointValue: {
latitude: (v.geoPointValue.latitude ?? 0) + "",
longitude: (v.geoPointValue.longitude ?? 0) + "",
},
};
} else if ("arrayValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.Array,
...excludeFromIndexes,
arrayValue: (v.arrayValue.values || []).map((v) =>
valueToEditValue(v, project, namespace),
),
};
} else if ("blobValue" in v) {
return {
...EMPTY_VALUE,
...baseValue,
type: ValueType.Blob,
...excludeFromIndexes,
stringValue: v.blobValue,
};
}
Expand All @@ -270,10 +264,12 @@ export function valueFromEditValue(
namespace: string | null,
): PropertyValue | null {
try {
const excludeFromIndexes =
value.excludeFromIndexes != null
const baseValue = {
...(value.excludeFromIndexes != null
? { excludeFromIndexes: value.excludeFromIndexes }
: {};
: {}),
...(value.meaning != null ? { meaning: value.meaning } : {}),
};
switch (value.type) {
case ValueType.Timestamp:
try {
Expand All @@ -282,55 +278,55 @@ export function valueFromEditValue(
return null;
}
return {
...excludeFromIndexes,
...baseValue,
timestampValue: value.stringValue,
};
case ValueType.String:
return {
...excludeFromIndexes,
...baseValue,
stringValue: value.stringValue,
};
case ValueType.Key:
return {
...excludeFromIndexes,
...baseValue,
keyValue: keyFromString(value.stringValue, project, namespace),
};
case ValueType.Integer:
return {
...excludeFromIndexes,
...baseValue,
integerValue: parseInteger(value.stringValue),
};
case ValueType.Double: {
return {
...excludeFromIndexes,
...baseValue,
doubleValue: parseDouble(value.stringValue),
};
}
case ValueType.Blob:
try {
b64decode(value.stringValue);
return {
...excludeFromIndexes,
...baseValue,
blobValue: value.stringValue,
};
} catch (e) {
return null;
}
case ValueType.Null:
return {
...excludeFromIndexes,
...baseValue,
nullValue: null,
};
case ValueType.Boolean:
return {
...excludeFromIndexes,
...baseValue,
booleanValue: value.booleanValue,
};
case ValueType.GeoPoint: {
const latitude = parseDouble(value.geoPointValue.latitude);
const longitude = parseDouble(value.geoPointValue.longitude);
return {
...excludeFromIndexes,
...baseValue,
geoPointValue: {
...(latitude === 0 ? {} : { latitude }),
...(longitude === 0 ? {} : { longitude }),
Expand All @@ -345,7 +341,7 @@ export function valueFromEditValue(
return null;
}
return {
...excludeFromIndexes,
...baseValue,
arrayValue:
values.length === 0
? {}
Expand Down

0 comments on commit be1fa12

Please sign in to comment.