Improved typing of Creature Properties

This commit is contained in:
ThaumRystra
2025-01-14 13:21:43 +02:00
parent 1b05b8d3bf
commit c0d1412463
50 changed files with 158 additions and 449 deletions

View File

@@ -29,6 +29,7 @@
"thumbhash",
"uncomputed",
"untarget",
"vars",
"vuedraggable",
"vuetify",
"Vuex",

View File

@@ -6,10 +6,12 @@ import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema';
import propertySchemasIndex from '/imports/api/properties/computedPropertySchemasIndex';
import { storedIconsSchema } from '/imports/api/icons/Icons';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import type { ComputedProperty, ComputedPropertyTypeMap } from '/imports/api/properties/Property.type';
import { ConvertToUnion, InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { Simplify } from 'type-fest';
const PreComputeCreaturePropertySchema = new TypedSimpleSchema({
type PropertyType = Exclude<keyof typeof propertySchemasIndex, 'any'>;
const PreComputeCreaturePropertySchema = TypedSimpleSchema.from({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id,
@@ -54,7 +56,7 @@ const PreComputeCreaturePropertySchema = new TypedSimpleSchema({
},
});
const DenormalisedOnlyCreaturePropertySchema = new TypedSimpleSchema({
const DenormalisedOnlyCreaturePropertySchema = TypedSimpleSchema.from({
// Denormalised flag if this property is inactive on the sheet for any reason
// Including being disabled, or a descendant of a disabled property
inactive: {
@@ -131,6 +133,20 @@ const DenormalisedOnlyCreaturePropertySchema = new TypedSimpleSchema({
const CreaturePropertySchema = PreComputeCreaturePropertySchema.extend(DenormalisedOnlyCreaturePropertySchema);
export type CreaturePropertyTypes = {
[T in PropertyType]: Simplify<
{ type: T }
& InferType<typeof propertySchemasIndex[T]>
> & Simplify<
Exclude<InferType<typeof CreaturePropertySchema>, 'type'>
& InferType<typeof ColorSchema>
& InferType<typeof ChildSchema>
& InferType<typeof SoftRemovableSchema>
>
}
export type CreatureProperty = ConvertToUnion<CreaturePropertyTypes>;
const CreatureProperties = new Mongo.Collection<CreatureProperty>('creatureProperties');
let key: keyof typeof propertySchemasIndex;
@@ -141,29 +157,12 @@ for (key in propertySchemasIndex) {
schema.extend(ColorSchema);
schema.extend(ChildSchema);
schema.extend(SoftRemovableSchema);
// Use the any schema as a default schema for the collection
if (key === 'any') {
// @ts-expect-error don't have types for .attachSchema
CreatureProperties.attachSchema(schema);
} else {
// TODO remove all {selector: {type: any}} options
// @ts-expect-error don't have types for .attachSchema
CreatureProperties.attachSchema(schema, {
selector: { type: key }
});
}
// @ts-expect-error don't have types for .attachSchema
CreatureProperties.attachSchema(schema, {
selector: { type: key }
});
}
export type CreaturePropertyByType<T extends keyof ComputedPropertyTypeMap> =
ComputedProperty<T>
& InferType<typeof CreaturePropertySchema>
& InferType<typeof ColorSchema>
& InferType<typeof ChildSchema>
& InferType<typeof SoftRemovableSchema>
type ConvertToUnion<T> = T[keyof T];
export type CreatureProperty = ConvertToUnion<{ [key in keyof ComputedPropertyTypeMap]: CreaturePropertyByType<key> }>;
export default CreatureProperties;
export {
DenormalisedOnlyCreaturePropertySchema,

View File

@@ -5,7 +5,7 @@ import { assertAdmin } from '/imports/api/sharing/sharingPermissions';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const iconsSchema = new TypedSimpleSchema({
const iconsSchema = TypedSimpleSchema.from({
name: {
type: String,
unique: true,
@@ -47,7 +47,7 @@ if (Meteor.isServer) {
});
}
const storedIconsSchema = new TypedSimpleSchema({
const storedIconsSchema = TypedSimpleSchema.from({
name: {
type: String,
},

View File

@@ -115,12 +115,6 @@ for (let key in propertySchemasIndex) {
schema.extend(propertySchemasIndex[key]);
schema.extend(ChildSchema);
schema.extend(SoftRemovableSchema);
// Use the any schema as a default schema for the collection
if (key === 'any') {
// @ts-expect-error don't have types for .attachSchema
LibraryNodes.attachSchema(schema);
}
// TODO make this an else branch and remove all {selector: {type: any}} options
// @ts-expect-error don't have types for .attachSchema
LibraryNodes.attachSchema(schema, {
selector: { type: key }

View File

@@ -16,7 +16,7 @@ export interface TreeDoc {
removed?: true,
}
const RefSchema = new TypedSimpleSchema({
const RefSchema = TypedSimpleSchema.from({
id: {
type: String,
regEx: SimpleSchema.RegEx.Id,
@@ -27,7 +27,7 @@ const RefSchema = new TypedSimpleSchema({
},
});
const ChildSchema = new TypedSimpleSchema({
const ChildSchema = TypedSimpleSchema.from({
root: {
type: Object,
},

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
let SoftRemovableSchema = new TypedSimpleSchema({
let SoftRemovableSchema = TypedSimpleSchema.from({
'removed': {
type: Boolean,
optional: true,

View File

@@ -3,7 +3,7 @@ import createPropertySchema from '/imports/api/properties/subSchemas/createPrope
import { storedIconsSchema } from '/imports/api/icons/Icons';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import { Expand, InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
/*
* Actions are things a character can do
@@ -258,12 +258,8 @@ const ComputedOnlyActionSchema = createPropertySchema({
},
});
const ComputedActionSchema = new TypedSimpleSchema({})
const ComputedActionSchema = TypedSimpleSchema.from({})
.extend(ActionSchema)
.extend(ComputedOnlyActionSchema);
export type Action = InferType<typeof ActionSchema>;
export type ComputedOnlyAction = InferType<typeof ComputedOnlyActionSchema>;
export type ComputedAction = Expand<InferType<typeof ActionSchema> & InferType<typeof ComputedOnlyActionSchema>>;
export { ActionSchema, ComputedOnlyActionSchema, ComputedActionSchema };

View File

@@ -1,6 +1,6 @@
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const AdjustmentSchema = createPropertySchema({
// The roll that determines how much to change the attribute
@@ -46,12 +46,8 @@ const ComputedOnlyAdjustmentSchema = createPropertySchema({
},
});
const ComputedAdjustmentSchema = new TypedSimpleSchema({})
const ComputedAdjustmentSchema = TypedSimpleSchema.from({})
.extend(AdjustmentSchema)
.extend(ComputedOnlyAdjustmentSchema);
export type Adjustment = InferType<typeof AdjustmentSchema>;
export type ComputedOnlyAdjustment = InferType<typeof ComputedOnlyAdjustmentSchema>;
export type ComputedAdjustment = Expand<InferType<typeof AdjustmentSchema> & InferType<typeof ComputedOnlyAdjustmentSchema>>;
export { AdjustmentSchema, ComputedAdjustmentSchema, ComputedOnlyAdjustmentSchema };

View File

@@ -2,7 +2,7 @@ import SimpleSchema from 'simpl-schema';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
/*
* Attributes are numbered stats of a character
@@ -297,12 +297,8 @@ const ComputedOnlyAttributeSchema = createPropertySchema({
},
});
const ComputedAttributeSchema = new TypedSimpleSchema({})
const ComputedAttributeSchema = TypedSimpleSchema.from({})
.extend(ComputedOnlyAttributeSchema)
.extend(AttributeSchema);
export type Attribute = InferType<typeof AttributeSchema>;
export type ComputedOnlyAttribute = InferType<typeof ComputedOnlyAttributeSchema>;
export type ComputedAttribute = Expand<InferType<typeof AttributeSchema> & InferType<typeof ComputedOnlyAttributeSchema>>;
export { AttributeSchema, ComputedOnlyAttributeSchema, ComputedAttributeSchema };

View File

@@ -1,6 +1,6 @@
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const BranchSchema = createPropertySchema({
branchType: {
@@ -52,12 +52,8 @@ const ComputedOnlyBranchSchema = createPropertySchema({
},
});
const ComputedBranchSchema = new TypedSimpleSchema({})
const ComputedBranchSchema = TypedSimpleSchema.from({})
.extend(BranchSchema)
.extend(ComputedOnlyBranchSchema);
export type Branch = InferType<typeof BranchSchema>;
export type ComputedOnlyBranch = InferType<typeof ComputedOnlyBranchSchema>;
export type ComputedBranch = Expand<InferType<typeof BranchSchema> & InferType<typeof ComputedBranchSchema>>;
export { BranchSchema, ComputedBranchSchema, ComputedOnlyBranchSchema }

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const BuffRemoverSchema = createPropertySchema({
name: {
@@ -50,7 +49,6 @@ const BuffRemoverSchema = createPropertySchema({
},
'extraTags.$._id': {
type: String,
regEx: SimpleSchema.RegEx.Id,
autoValue() {
if (!this.isSet) return Random.id();
}
@@ -78,12 +76,8 @@ const BuffRemoverSchema = createPropertySchema({
const ComputedOnlyBuffRemoverSchema = createPropertySchema({});
const ComputedBuffRemoverSchema = new SimpleSchema({})
const ComputedBuffRemoverSchema = TypedSimpleSchema.from({})
.extend(BuffRemoverSchema)
.extend(ComputedOnlyBuffRemoverSchema);
export type BuffRemover = InferType<typeof BuffRemoverSchema>;
export type ComputedOnlyBuffRemover = InferType<typeof ComputedOnlyBuffRemoverSchema>;
export type ComputedBuffRemover = Expand<InferType<typeof BuffRemoverSchema> & InferType<typeof ComputedOnlyBuffRemoverSchema>>;
export { BuffRemoverSchema, ComputedOnlyBuffRemoverSchema, ComputedBuffRemoverSchema };

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const BuffSchema = createPropertySchema({
name: {
@@ -75,12 +75,8 @@ const ComputedOnlyBuffSchema = createPropertySchema({
},
});
const ComputedBuffSchema = new TypedSimpleSchema({})
const ComputedBuffSchema = TypedSimpleSchema.from({})
.extend(BuffSchema)
.extend(ComputedOnlyBuffSchema);
export type Buff = InferType<typeof BuffSchema>;
export type ComputedOnlyBuff = InferType<typeof ComputedOnlyBuffSchema>;
export type ComputedBuff = Expand<InferType<typeof BuffSchema> & InferType<typeof ComputedOnlyBuffSchema>>;
export { BuffSchema, ComputedOnlyBuffSchema, ComputedBuffSchema };

View File

@@ -2,7 +2,7 @@ import SimpleSchema from 'simpl-schema';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const ClassLevelSchema = createPropertySchema({
name: {
@@ -36,12 +36,8 @@ const ComputedOnlyClassLevelSchema = createPropertySchema({
},
});
const ComputedClassLevelSchema = new SimpleSchema({})
const ComputedClassLevelSchema = TypedSimpleSchema.from({})
.extend(ComputedOnlyClassLevelSchema)
.extend(ClassLevelSchema);
export type ClassLevel = InferType<typeof ClassLevelSchema>;
export type ComputedOnlyClassLevel = InferType<typeof ComputedOnlyClassLevelSchema>;
export type ComputedClassLevel = Expand<InferType<typeof ClassLevelSchema> & InferType<typeof ComputedOnlyClassLevelSchema>>;
export { ClassLevelSchema, ComputedOnlyClassLevelSchema, ComputedClassLevelSchema };

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
// Classes are like slots, except they only take class levels and enforce that
// lower levels are taken before higher levels
@@ -92,12 +92,8 @@ const ComputedOnlyClassSchema = createPropertySchema({
},
});
const ComputedClassSchema = new SimpleSchema({})
const ComputedClassSchema = TypedSimpleSchema.from({})
.extend(ClassSchema)
.extend(ComputedOnlyClassSchema);
export type Class = InferType<typeof ClassSchema>;
export type ComputedOnlyClass = InferType<typeof ComputedOnlyClassSchema>;
export type ComputedClass = Expand<InferType<typeof ClassSchema> & InferType<typeof ComputedOnlyClassSchema>>;
export { ClassSchema, ComputedOnlyClassSchema, ComputedClassSchema };

View File

@@ -6,11 +6,8 @@ import {
} from '/imports/parser/parser';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import resolve from '/imports/parser/resolve';
import Context from '/imports/parser/types/Context';
import traverse from '/imports/parser/traverse';
import type ResolveLevel from '/imports/parser/types/ResolveLevel';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
/*
* Constants are primitive values that can be used elsewhere in computations
@@ -39,7 +36,7 @@ const ConstantSchema = createPropertySchema({
errors: {
type: Array,
maxCount: STORAGE_LIMITS.errorCount,
async autoValue() {
autoValue() {
const calc = this.field('calculation');
if (!calc.isSet && this.isModifier) {
this.unset()
@@ -48,15 +45,7 @@ const ConstantSchema = createPropertySchema({
const string = calc.value;
if (!string) return [];
// Evaluate the calculation with no scope
const { result, context } = await parseString(string);
// Any existing errors will result in an early failure
if (context && context.errors.length) return context.errors;
// Ban variables in constants if necessary
result && traverse(result, node => {
if (node.parseType === 'symbol' || node.parseType === 'accessor') {
context.error('Variables can\'t be used to define a constant');
}
});
const { context } = parseString(string);
return context && context.errors || [];
}
},
@@ -65,30 +54,27 @@ const ConstantSchema = createPropertySchema({
},
});
async function parseString(string, fn: ResolveLevel = 'compile') {
function parseString(string) {
const context = new Context();
if (!string) {
return { result: string, context };
}
// Parse the string using mathjs
let node;
try {
node = parse(string);
parse(string);
} catch (e) {
const message = prettifyParseError(e as Error);
context.error(message);
return { context };
return { context, result: undefined };
}
if (!node) return { context };
const { result } = await resolve(fn, node, {/*empty scope*/ }, context);
return { result, context }
return { context, result: undefined };
}
const ComputedOnlyConstantSchema = createPropertySchema({});
export type Constant = InferType<typeof ConstantSchema>;
export type ComputedOnlyConstant = InferType<typeof ComputedOnlyConstantSchema>;
export type ComputedConstant = Expand<InferType<typeof ConstantSchema> & InferType<typeof ComputedOnlyConstantSchema>>;
const ComputedConstantSchema = TypedSimpleSchema.from({})
.extend(ConstantSchema)
.extend(ComputedOnlyConstantSchema);
export { ConstantSchema, ComputedOnlyConstantSchema };
export { ConstantSchema, ComputedOnlyConstantSchema, ComputedConstantSchema };

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const ContainerSchema = createPropertySchema({
name: {
@@ -65,12 +64,8 @@ const ComputedOnlyContainerSchema = createPropertySchema({
},
});
const ComputedContainerSchema = new SimpleSchema({})
const ComputedContainerSchema = TypedSimpleSchema.from({})
.extend(ComputedOnlyContainerSchema)
.extend(ContainerSchema);
export type Container = InferType<typeof ContainerSchema>;
export type ComputedOnlyContainer = InferType<typeof ComputedOnlyContainerSchema>;
export type ComputedContainer = Expand<InferType<typeof ContainerSchema> & InferType<typeof ComputedOnlyContainerSchema>>;
export { ContainerSchema, ComputedOnlyContainerSchema, ComputedContainerSchema };

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
// Creature templates represent creatures that don't yet exist
// Used to store creatures in the library, or as templates for another creature to summon
@@ -34,12 +33,8 @@ const ComputedOnlyCreatureTemplateSchema = createPropertySchema({
},
});
const ComputedCreatureTemplateSchema = new SimpleSchema({})
const ComputedCreatureTemplateSchema = TypedSimpleSchema.from({})
.extend(CreatureTemplateSchema)
.extend(ComputedOnlyCreatureTemplateSchema);
export type CreatureTemplate = InferType<typeof CreatureTemplateSchema>;
export type ComputedOnlyCreatureTemplate = InferType<typeof ComputedOnlyCreatureTemplateSchema>;
export type ComputedCreatureTemplate = Expand<InferType<typeof CreatureTemplateSchema> & InferType<typeof ComputedOnlyCreatureTemplateSchema>>;
export { CreatureTemplateSchema, ComputedCreatureTemplateSchema, ComputedOnlyCreatureTemplateSchema };

View File

@@ -1,7 +1,7 @@
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
/*
* DamageMultipliers are multipliers that affect how much damage is taken from
@@ -54,8 +54,8 @@ const DamageMultiplierSchema = createPropertySchema({
const ComputedOnlyDamageMultiplierSchema = createPropertySchema({});
export type DamageMultiplier = InferType<typeof DamageMultiplierSchema>;
export type ComputedOnlyDamageMultiplier = InferType<typeof ComputedOnlyDamageMultiplierSchema>;
export type ComputedDamageMultiplier = Expand<InferType<typeof DamageMultiplierSchema> & InferType<typeof ComputedOnlyDamageMultiplierSchema>>;
const ComputedDamageMultiplierSchema = TypedSimpleSchema.from({})
.extend(DamageMultiplierSchema)
.extend(ComputedOnlyDamageMultiplierSchema);
export { DamageMultiplierSchema, ComputedOnlyDamageMultiplierSchema };
export { DamageMultiplierSchema, ComputedOnlyDamageMultiplierSchema, ComputedDamageMultiplierSchema };

View File

@@ -1,8 +1,7 @@
import SimpleSchema from 'simpl-schema';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const DamageSchema = createPropertySchema({
// The roll that determines how much to damage the attribute
@@ -79,12 +78,8 @@ const ComputedOnlyDamageSchema = createPropertySchema({
},
});
const ComputedDamageSchema = new SimpleSchema({})
const ComputedDamageSchema = TypedSimpleSchema.from({})
.extend(DamageSchema)
.extend(ComputedOnlyDamageSchema);
export type Damage = InferType<typeof DamageSchema>;
export type ComputedOnlyDamage = InferType<typeof ComputedOnlyDamageSchema>;
export type ComputedDamage = Expand<InferType<typeof DamageSchema> & InferType<typeof ComputedOnlyDamageSchema>>;
export { DamageSchema, ComputedDamageSchema, ComputedOnlyDamageSchema };

View File

@@ -1,8 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import TagTargetingSchema from '/imports/api/properties/subSchemas/TagTargetingSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
/*
* Effects are reason-value attached to skills and abilities
@@ -61,12 +60,8 @@ const ComputedOnlyEffectSchema = createPropertySchema({
},
});
const ComputedEffectSchema = new SimpleSchema({})
const ComputedEffectSchema = TypedSimpleSchema.from({})
.extend(ComputedOnlyEffectSchema)
.extend(EffectSchema);
export type Effect = InferType<typeof EffectSchema>;
export type ComputedOnlyEffect = InferType<typeof ComputedOnlyEffectSchema>;
export type ComputedEffect = Expand<InferType<typeof EffectSchema> & InferType<typeof ComputedOnlyEffectSchema>>;
export { EffectSchema, ComputedEffectSchema, ComputedOnlyEffectSchema };

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const FeatureSchema = createPropertySchema({
name: {
@@ -30,12 +29,8 @@ const ComputedOnlyFeatureSchema = createPropertySchema({
},
});
const ComputedFeatureSchema = new SimpleSchema({})
const ComputedFeatureSchema = TypedSimpleSchema.from({})
.extend(FeatureSchema)
.extend(ComputedOnlyFeatureSchema);
export type Feature = InferType<typeof FeatureSchema>;
export type ComputedOnlyFeature = InferType<typeof ComputedOnlyFeatureSchema>;
export type ComputedFeature = Expand<InferType<typeof FeatureSchema> & InferType<typeof ComputedOnlyFeatureSchema>>;
export { FeatureSchema, ComputedFeatureSchema, ComputedOnlyFeatureSchema }

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
// Folders organize a character sheet into a tree, particularly to group things
// like 'race' and 'background'
@@ -46,12 +45,8 @@ const ComputedOnlyFolderSchema = createPropertySchema({
},
});
const ComputedFolderSchema = new SimpleSchema({})
const ComputedFolderSchema = TypedSimpleSchema.from({})
.extend(FolderSchema)
.extend(ComputedOnlyFolderSchema);
export type Folder = InferType<typeof FolderSchema>;
export type ComputedOnlyFolder = InferType<typeof ComputedOnlyFolderSchema>;
export type ComputedFolder = Expand<InferType<typeof FolderSchema> & InferType<typeof ComputedOnlyFolderSchema>>;
export { FolderSchema, ComputedFolderSchema, ComputedOnlyFolderSchema };

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const ItemSchema = createPropertySchema({
name: {
@@ -100,12 +100,8 @@ const ComputedOnlyItemSchema = createPropertySchema({
},
});
const ComputedItemSchema = new SimpleSchema({})
const ComputedItemSchema = TypedSimpleSchema.from({})
.extend(ItemSchema)
.extend(ComputedOnlyItemSchema);
export type Item = InferType<typeof ItemSchema>;
export type ComputedOnlyItem = InferType<typeof ComputedOnlyItemSchema>;
export type ComputedItem = Expand<InferType<typeof ItemSchema> & InferType<typeof ComputedOnlyItemSchema>>;
export { ItemSchema, ComputedItemSchema, ComputedOnlyItemSchema };

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const NoteSchema = createPropertySchema({
name: {
@@ -35,12 +34,8 @@ const ComputedOnlyNoteSchema = createPropertySchema({
},
});
const ComputedNoteSchema = new SimpleSchema({})
const ComputedNoteSchema = TypedSimpleSchema.from({})
.extend(NoteSchema)
.extend(ComputedOnlyNoteSchema);
export type Note = InferType<typeof NoteSchema>;
export type ComputedOnlyNote = InferType<typeof ComputedOnlyNoteSchema>;
export type ComputedNote = Expand<InferType<typeof NoteSchema> & InferType<typeof ComputedOnlyNoteSchema>>;
export { NoteSchema, ComputedNoteSchema, ComputedOnlyNoteSchema, };

View File

@@ -3,7 +3,7 @@ import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
/*
* PointBuys are reason-value attached to skills and abilities
@@ -128,12 +128,8 @@ const ComputedOnlyPointBuySchema = createPropertySchema({
},
});
const ComputedPointBuySchema = new SimpleSchema({})
const ComputedPointBuySchema = TypedSimpleSchema.from({})
.extend(ComputedOnlyPointBuySchema)
.extend(PointBuySchema);
export type PointBuy = InferType<typeof PointBuySchema>;
export type ComputedOnlyPointBuy = InferType<typeof ComputedOnlyPointBuySchema>;
export type ComputedPointBuy = Expand<InferType<typeof PointBuySchema> & InferType<typeof ComputedOnlyPointBuySchema>>;
export { PointBuySchema, ComputedPointBuySchema, ComputedOnlyPointBuySchema };

View File

@@ -1,7 +1,6 @@
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import TagTargetingSchema from '/imports/api/properties/subSchemas/TagTargetingSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
const ProficiencySchema = createPropertySchema({
name: {
@@ -30,8 +29,4 @@ const ProficiencySchema = createPropertySchema({
const ComputedOnlyProficiencySchema = createPropertySchema({});
export type Proficiency = InferType<typeof ProficiencySchema>;
export type ComputedOnlyProficiency = InferType<typeof ComputedOnlyProficiencySchema>;
export type ComputedProficiency = Expand<InferType<typeof ProficiencySchema> & InferType<typeof ComputedOnlyProficiencySchema>>;
export { ProficiencySchema, ComputedOnlyProficiencySchema };

View File

@@ -1,115 +0,0 @@
import { Attribute, ComputedAttribute, ComputedOnlyAttribute } from './Attributes';
import { Branch, ComputedBranch, ComputedOnlyBranch } from './Branches';
import { Buff, ComputedBuff, ComputedOnlyBuff } from './Buffs';
import { Class, ComputedClass, ComputedOnlyClass } from './Classes';
import { Constant, ComputedConstant, ComputedOnlyConstant } from './Constants';
import { Container, ComputedContainer, ComputedOnlyContainer } from './Containers';
import { CreatureTemplate, ComputedCreatureTemplate, ComputedOnlyCreatureTemplate } from './CreatureTemplates';
import { Damage, ComputedDamage, ComputedOnlyDamage } from './Damages';
import { DamageMultiplier, ComputedDamageMultiplier, ComputedOnlyDamageMultiplier } from './DamageMultipliers';
import { Effect, ComputedEffect, ComputedOnlyEffect } from './Effects';
import { Feature, ComputedFeature, ComputedOnlyFeature } from './Features';
import { Folder, ComputedFolder, ComputedOnlyFolder } from './Folders';
import { Item, ComputedItem, ComputedOnlyItem } from './Items';
import { Note, ComputedNote, ComputedOnlyNote } from './Notes';
import { PointBuy, ComputedPointBuy, ComputedOnlyPointBuy } from './PointBuys';
import { Proficiency, ComputedProficiency, ComputedOnlyProficiency } from './Proficiencies';
import { Reference, ComputedReference, ComputedOnlyReference } from './References';
import { Roll, ComputedRoll, ComputedOnlyRoll } from './Rolls';
import { SavingThrow, ComputedSavingThrow, ComputedOnlySavingThrow } from './SavingThrows';
import { Skill, ComputedSkill, ComputedOnlySkill } from './Skills';
import { Slot, ComputedSlot, ComputedOnlySlot } from './Slots';
import { SpellList, ComputedSpellList, ComputedOnlySpellList } from './SpellLists';
import { Spell, ComputedSpell, ComputedOnlySpell } from './Spells';
import { Toggle, ComputedToggle, ComputedOnlyToggle } from './Toggles';
import { Trigger, ComputedTrigger, ComputedOnlyTrigger } from './Triggers';
export type PropertyTypeMap = {
'attribute': Attribute,
'branch': Branch,
'buff': Buff,
'class': Class,
'constant': Constant,
'container': Container,
'creatureTemplate': CreatureTemplate,
'damage': Damage,
'damageMultiplier': DamageMultiplier,
'effect': Effect,
'feature': Feature,
'folder': Folder,
'item': Item,
'note': Note,
'pointBuy': PointBuy,
'proficiency': Proficiency,
'reference': Reference,
'roll': Roll,
'savingThrow': SavingThrow,
'skill': Skill,
'slot': Slot,
'spellList': SpellList,
'spell': Spell,
'toggle': Toggle,
'trigger': Trigger,
}
export type Property<T extends keyof PropertyTypeMap> = PropertyTypeMap[T]
export type ComputedPropertyTypeMap = {
'attribute': ComputedAttribute,
'branch': ComputedBranch,
'buff': ComputedBuff,
'class': ComputedClass,
'constant': ComputedConstant,
'container': ComputedContainer,
'creatureTemplate': ComputedCreatureTemplate,
'damage': ComputedDamage,
'damageMultiplier': ComputedDamageMultiplier,
'effect': ComputedEffect,
'feature': ComputedFeature,
'folder': ComputedFolder,
'item': ComputedItem,
'note': ComputedNote,
'pointBuy': ComputedPointBuy,
'proficiency': ComputedProficiency,
'reference': ComputedReference,
'roll': ComputedRoll,
'savingThrow': ComputedSavingThrow,
'skill': ComputedSkill,
'slot': ComputedSlot,
'spellList': ComputedSpellList,
'spell': ComputedSpell,
'toggle': ComputedToggle,
'trigger': ComputedTrigger,
}
export type ComputedProperty<T extends keyof ComputedPropertyTypeMap> = ComputedPropertyTypeMap[T]
export type ComputedOnlyPropertyTypeMap = {
'attribute': ComputedOnlyAttribute,
'branch': ComputedOnlyBranch,
'buff': ComputedOnlyBuff,
'class': ComputedOnlyClass,
'constant': ComputedOnlyConstant,
'container': ComputedOnlyContainer,
'creatureTemplate': ComputedOnlyCreatureTemplate,
'damage': ComputedOnlyDamage,
'damageMultiplier': ComputedOnlyDamageMultiplier,
'effect': ComputedOnlyEffect,
'feature': ComputedOnlyFeature,
'folder': ComputedOnlyFolder,
'item': ComputedOnlyItem,
'note': ComputedOnlyNote,
'pointBuy': ComputedOnlyPointBuy,
'proficiency': ComputedOnlyProficiency,
'reference': ComputedOnlyReference,
'roll': ComputedOnlyRoll,
'savingThrow': ComputedOnlySavingThrow,
'skill': ComputedOnlySkill,
'slot': ComputedOnlySlot,
'spellList': ComputedOnlySpellList,
'spell': ComputedOnlySpell,
'toggle': ComputedOnlyToggle,
'trigger': ComputedOnlyTrigger,
}
export type ComputedOnlyProperty<T extends keyof ComputedOnlyPropertyTypeMap> = ComputedOnlyPropertyTypeMap[T]

View File

@@ -1,6 +1,5 @@
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
const ReferenceSchema = createPropertySchema({
ref: {
@@ -64,8 +63,4 @@ const ReferenceSchema = createPropertySchema({
const ComputedOnlyReferenceSchema = createPropertySchema({});
export type Reference = InferType<typeof ReferenceSchema>;
export type ComputedOnlyReference = InferType<typeof ComputedOnlyReferenceSchema>;
export type ComputedReference = Expand<InferType<typeof ReferenceSchema> & InferType<typeof ComputedOnlyReferenceSchema>>;
export { ReferenceSchema, ComputedOnlyReferenceSchema };

View File

@@ -1,8 +1,7 @@
import SimpleSchema from 'simpl-schema';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
/**
* Rolls are children to actions or other rolls, they are triggered with 0 or
@@ -57,12 +56,8 @@ const ComputedOnlyRollSchema = createPropertySchema({
},
});
const ComputedRollSchema = new SimpleSchema({})
const ComputedRollSchema = TypedSimpleSchema.from({})
.extend(RollSchema)
.extend(ComputedOnlyRollSchema);
export type Roll = InferType<typeof RollSchema>;
export type ComputedOnlyRoll = InferType<typeof ComputedOnlyRollSchema>;
export type ComputedRoll = Expand<InferType<typeof RollSchema> & InferType<typeof ComputedOnlyRollSchema>>;
export { RollSchema, ComputedRollSchema, ComputedOnlyRollSchema };

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
// These are the rolls made when saves are called for
// For the saving throw bonus or proficiency, see ./Skills.js
@@ -46,12 +45,8 @@ const ComputedOnlySavingThrowSchema = createPropertySchema({
},
});
const ComputedSavingThrowSchema = new SimpleSchema({})
const ComputedSavingThrowSchema = TypedSimpleSchema.from({})
.extend(SavingThrowSchema)
.extend(ComputedOnlySavingThrowSchema);
export type SavingThrow = InferType<typeof SavingThrowSchema>;
export type ComputedOnlySavingThrow = InferType<typeof ComputedOnlySavingThrowSchema>;
export type ComputedSavingThrow = Expand<InferType<typeof SavingThrowSchema> & InferType<typeof ComputedOnlySavingThrowSchema>>;
export { SavingThrowSchema, ComputedOnlySavingThrowSchema, ComputedSavingThrowSchema };

View File

@@ -3,7 +3,7 @@ import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import TagTargetingSchema from '/imports/api/properties/subSchemas/TagTargetingSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
/*
* Skills are anything that results in a modifier to be added to a D20
@@ -171,12 +171,8 @@ const ComputedOnlySkillSchema = createPropertySchema({
},
})
const ComputedSkillSchema = new SimpleSchema({})
const ComputedSkillSchema = TypedSimpleSchema.from({})
.extend(ComputedOnlySkillSchema)
.extend(SkillSchema);
export type Skill = InferType<typeof SkillSchema>;
export type ComputedOnlySkill = InferType<typeof ComputedOnlySkillSchema>;
export type ComputedSkill = Expand<InferType<typeof SkillSchema> & InferType<typeof ComputedOnlySkillSchema>>;
export { SkillSchema, ComputedSkillSchema, ComputedOnlySkillSchema };

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const SlotSchema = createPropertySchema({
name: {
@@ -115,12 +115,8 @@ const ComputedOnlySlotSchema = createPropertySchema({
},
});
const ComputedSlotSchema = new SimpleSchema({})
const ComputedSlotSchema = TypedSimpleSchema.from({})
.extend(ComputedOnlySlotSchema)
.extend(SlotSchema);
export type Slot = InferType<typeof SlotSchema>;
export type ComputedOnlySlot = InferType<typeof ComputedOnlySlotSchema>;
export type ComputedSlot = Expand<InferType<typeof SlotSchema> & InferType<typeof ComputedOnlySlotSchema>>;
export { SlotSchema, ComputedSlotSchema, ComputedOnlySlotSchema };

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const SpellListSchema = createPropertySchema({
name: {
@@ -61,12 +61,8 @@ const ComputedOnlySpellListSchema = createPropertySchema({
},
});
const ComputedSpellListSchema = new SimpleSchema({})
const ComputedSpellListSchema = TypedSimpleSchema.from({})
.extend(SpellListSchema)
.extend(ComputedOnlySpellListSchema);
export type SpellList = InferType<typeof SpellListSchema>;
export type ComputedOnlySpellList = InferType<typeof ComputedOnlySpellListSchema>;
export type ComputedSpellList = Expand<InferType<typeof SpellListSchema> & InferType<typeof ComputedOnlySpellListSchema>>;
export { SpellListSchema, ComputedOnlySpellListSchema, ComputedSpellListSchema };

View File

@@ -2,12 +2,11 @@ import { ActionSchema, ComputedOnlyActionSchema } from '/imports/api/properties/
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { TypedSimpleSchema } from '../utility/TypedSimpleSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const SpellSchema = createPropertySchema({})
.extend(ActionSchema)
.extend(new TypedSimpleSchema({
.extend(TypedSimpleSchema.from({
name: {
type: String,
optional: true,
@@ -95,12 +94,8 @@ const SpellSchema = createPropertySchema({})
const ComputedOnlySpellSchema = createPropertySchema({})
.extend(ComputedOnlyActionSchema);
const ComputedSpellSchema = new SimpleSchema({})
const ComputedSpellSchema = TypedSimpleSchema.from({})
.extend(SpellSchema)
.extend(ComputedOnlySpellSchema);
export type Spell = InferType<typeof SpellSchema>;
export type ComputedOnlySpell = InferType<typeof ComputedOnlySpellSchema>;
export type ComputedSpell = Expand<InferType<typeof SpellSchema> & InferType<typeof ComputedOnlySpellSchema>>;
export { SpellSchema, ComputedOnlySpellSchema, ComputedSpellSchema };

View File

@@ -1,8 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import TagTargetingSchema from '/imports/api/properties/subSchemas/TagTargetingSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const ToggleSchema = createPropertySchema({
name: {
@@ -47,11 +46,7 @@ const ComputedOnlyToggleSchema = createPropertySchema({
},
});
export type Toggle = InferType<typeof ToggleSchema>;
export type ComputedOnlyToggle = InferType<typeof ComputedOnlyToggleSchema>;
export type ComputedToggle = Expand<InferType<typeof ToggleSchema> & InferType<typeof ComputedOnlyToggleSchema>>;
const ComputedToggleSchema = new SimpleSchema({})
const ComputedToggleSchema = TypedSimpleSchema.from({})
.extend(ComputedOnlyToggleSchema)
.extend(ToggleSchema);

View File

@@ -1,7 +1,8 @@
import SimpleSchema from 'simpl-schema';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { UnionToTuple } from 'type-fest';
const eventOptions = {
doActionProperty: 'Do action',
@@ -54,42 +55,18 @@ const TriggerSchema = createPropertySchema({
},
event: {
type: String,
allowedValues: [
'doActionProperty',
'check',
'damageProperty',
'anyRest',
'longRest',
'shortRest',
] as const,
allowedValues: Object.keys(eventOptions) as UnionToTuple<keyof typeof eventOptions>,
defaultValue: 'doActionProperty',
},
// Action type
actionPropertyType: {
type: String,
allowedValues: [
'action',
'ammo',
'adjustment',
'branch',
'buff',
'buffRemover',
'damage',
'note',
'roll',
'savingThrow',
'spell',
'toggle',
] as const,
allowedValues: Object.keys(actionPropertyTypeOptions) as UnionToTuple<keyof typeof actionPropertyTypeOptions>,
optional: true,
},
timing: {
type: String,
allowedValues: [
'before',
'after',
'afterChildren',
] as const,
allowedValues: Object.keys(timingOptions) as UnionToTuple<keyof typeof timingOptions>,
defaultValue: 'after',
},
condition: {
@@ -159,14 +136,10 @@ const ComputedOnlyTriggerSchema = createPropertySchema({
},
});
const ComputedTriggerSchema = new SimpleSchema({})
const ComputedTriggerSchema = TypedSimpleSchema.from({})
.extend(TriggerSchema)
.extend(ComputedOnlyTriggerSchema);
export type Trigger = InferType<typeof TriggerSchema>;
export type ComputedOnlyTrigger = InferType<typeof ComputedOnlyTriggerSchema>;
export type ComputedTrigger = Expand<InferType<typeof TriggerSchema> & InferType<typeof ComputedOnlyTriggerSchema>>;
export {
TriggerSchema, ComputedOnlyTriggerSchema, ComputedTriggerSchema,
eventOptions, timingOptions, actionPropertyTypeOptions

View File

@@ -1,4 +1,3 @@
import SimpleSchema from 'simpl-schema';
import { ComputedOnlyActionSchema } from '/imports/api/properties/Actions';
import { ComputedOnlyAdjustmentSchema } from '/imports/api/properties/Adjustments';
import { ComputedOnlyAttributeSchema } from '/imports/api/properties/Attributes';
@@ -59,7 +58,6 @@ const propertySchemasIndex = {
spellList: ComputedOnlySpellListSchema,
toggle: ComputedOnlyToggleSchema,
trigger: ComputedOnlyTriggerSchema,
any: new SimpleSchema({}),
};
export default propertySchemasIndex;

View File

@@ -1,5 +1,4 @@
import '/imports/api/simpleSchemaConfig';
import SimpleSchema from 'simpl-schema';
import { ComputedActionSchema } from '/imports/api/properties/Actions';
import { ComputedAdjustmentSchema } from '/imports/api/properties/Adjustments';
import { ComputedAttributeSchema } from '/imports/api/properties/Attributes';
@@ -60,7 +59,6 @@ const propertySchemasIndex = {
spellList: ComputedSpellListSchema,
toggle: ComputedToggleSchema,
trigger: ComputedTriggerSchema,
any: new SimpleSchema({}),
};
export default propertySchemasIndex;

View File

@@ -1,4 +1,3 @@
import SimpleSchema from 'simpl-schema';
import { ActionSchema } from '/imports/api/properties/Actions';
import { AdjustmentSchema } from '/imports/api/properties/Adjustments';
import { AttributeSchema } from '/imports/api/properties/Attributes';
@@ -59,7 +58,6 @@ const propertySchemasIndex = {
spellList: SpellListSchema,
toggle: ToggleSchema,
trigger: TriggerSchema,
any: new SimpleSchema({}),
};
export default propertySchemasIndex;

View File

@@ -1,7 +1,7 @@
import { Random } from 'meteor/random';
import { InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const AdjustmentSchema = new TypedSimpleSchema({
const AdjustmentSchema = TypedSimpleSchema.from({
_id: {
type: String,
max: 17,
@@ -32,6 +32,4 @@ const AdjustmentSchema = new TypedSimpleSchema({
},
});
export type Adjustment = InferType<typeof AdjustmentSchema>;
export default AdjustmentSchema;

View File

@@ -1,6 +1,6 @@
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const ColorSchema = new TypedSimpleSchema({
const ColorSchema = TypedSimpleSchema.from({
color: {
type: String,
// match hex colors of the form #A23 or #A23f56

View File

@@ -1,7 +1,7 @@
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const ErrorSchema = new TypedSimpleSchema({
const ErrorSchema = TypedSimpleSchema.from({
message: {
type: String,
max: STORAGE_LIMITS.errorMessage,

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const RollDetailsSchema = new SimpleSchema({
const RollDetailsSchema = TypedSimpleSchema.from({
number: {
type: Number,
},

View File

@@ -1,25 +0,0 @@
import SimpleSchema from 'simpl-schema';
import ResultsSchema from '/imports/api/properties/subSchemas/ResultsSchema';
let RollResultsSchema = new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id,
autoValue() {
if (!this.isSet) return Random.id();
}
},
// Expression of whether or not to apply the roll
// Evaluates to an expression which gets compared to the roll
// or a number which the roll must equal
comparison: {
type: String,
optional: true,
},
results: {
type: ResultsSchema,
defaultValue: {},
},
});
export default RollResultsSchema;

View File

@@ -2,7 +2,7 @@ import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
const TagTargetingSchema = new TypedSimpleSchema({
const TagTargetingSchema = TypedSimpleSchema.from({
// True when targeting by tags instead of stats
targetByTags: {
type: Boolean,

View File

@@ -6,12 +6,12 @@ import {
fieldToCompute,
computedOnlyField,
} from '/imports/api/properties/subSchemas/computedField';
import { Definition, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
import { Definition, InferSchema, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
// Search through the schema for keys whose type is 'fieldToCompute' etc.
// replace the type with Object and attach extend the schema with
// the required fields to make the computation work
export default function createPropertySchema<T extends Definition>(definition: T): TypedSimpleSchema<T> {
export default function createPropertySchema<D extends Definition>(definition: D): TypedSimpleSchema<InferSchema<D>> {
const computationFields = {
inlineCalculationFieldToCompute: [],
computedOnlyInlineCalculationField: [],
@@ -41,7 +41,7 @@ export default function createPropertySchema<T extends Definition>(definition: T
}
// Create a schema with the edited definition
const schema = new TypedSimpleSchema(definition);
const schema = TypedSimpleSchema.from(definition);
// Extend the schema with all the computation fields
computationFields.inlineCalculationFieldToCompute.forEach(key => {

View File

@@ -5,23 +5,28 @@ import type {
import type {
InlineCalculationFieldToCompute, ComputedOnlyInlineCalculationField
} from '/imports/api/properties/subSchemas/inlineCalculationField';
import type { Simplify } from 'type-fest';
// It DOES NOT support a constructor with multiple schemas.
export type Definition = Exclude<SimpleSchemaDefinition, any[]>;
// This is a no-op wrapper, effectively implementing a phantom type.
export class TypedSimpleSchema<T extends Definition> extends SimpleSchema {
constructor(definition: T) {
export class TypedSimpleSchema<T> extends SimpleSchema {
private constructor(definition: Definition) {
super(definition);
}
static from<D extends Definition>(definition: D): TypedSimpleSchema<InferSchema<D>> {
return new TypedSimpleSchema(definition);
}
// Extending the schema with another schema &'s their definitions
extend<U extends Definition>(otherSchema: TypedSimpleSchema<U>): TypedSimpleSchema<T & U> {
// In some cases, this is not strictly accurate, use with caution
extend<U>(otherSchema: TypedSimpleSchema<U>): TypedSimpleSchema<Simplify<T & U>> {
return super.extend(otherSchema);
}
}
// It cannot be a method due to https://github.com/microsoft/TypeScript/issues/36931.
export function validate<T extends Definition>(schema: TypedSimpleSchema<T>, value: unknown): asserts value is InferSchema<T> {
export function validate<T extends Definition>(schema: TypedSimpleSchema<T>, value: unknown): asserts value is T {
schema.validate(value);
}
@@ -33,7 +38,7 @@ type NotImplementedMarker = { readonly NotImplementedMarker: unique symbol };
type ArrayMarker = { readonly ArrayMarker: unique symbol };
type ObjectMarker = { readonly ObjectMarker: unique symbol };
export type InferType<T> = Expand<MakeUndefinedOptional<InferTypeInner<T>>>;
export type InferType<T> = T extends TypedSimpleSchema<infer X> ? X : never;
// Infer TypeScript type from SimpleSchema type.
type InferTypeInner<T> =
@@ -47,7 +52,7 @@ type InferTypeInner<T> =
T extends typeof String ? string :
T extends typeof Date ? Date :
T extends RegExp ? string :
T extends TypedSimpleSchema<infer U> ? InferSchema<U> :
T extends TypedSimpleSchema<infer U> ? U :
NotImplementedMarker;
// Infer TypeScript type from a single field definition.
@@ -57,7 +62,7 @@ export type InferField<Def extends Definition, Key extends keyof Def> =
? ArrayMarker extends InferTypeInner<Typ>
? Array<InferField<Def, `${Key}.$`>>
: ObjectMarker extends InferTypeInner<Typ>
? { [L in keyof Def as L extends `${Key}.${infer SubKey}` ? SubKey extends `${string}.${string}` ? never : SubKey : never]: InferField<Def, L> }
? { [L in keyof Def as L extends `${Key}.${infer SubKey}` ? SubKey extends `${string}.${string}` ? never : SubKey : never]: InferOptional<Def, L, InferField<Def, L>> }
: Def[Key] extends { allowedValues: infer Allowed extends string[] } ? InferOptional<Def, Key, InferEnum<Allowed>>
: Def[Key] extends { type: 'fieldToCompute' } ? FieldToCalculate
: Def[Key] extends { type: 'computedOnlyField' } ? CalculatedOnlyField
@@ -73,18 +78,16 @@ type InferEnum<T extends string[]> = T[number];
// Infer optional from optional field
type InferOptional<Def, Key extends keyof Def, U> = Def[Key] extends { optional: true } ? U | undefined : U;
type MakeUndefinedOptional<Type> = { [Property in keyof Type as undefined extends Type[Property] ? never : Property]: Type[Property]; }
& { [Property in keyof Type as undefined extends Type[Property] ? Property : never]+?: Type[Property]; };
type MakeUndefinedOptional<Type> = Simplify<{
[Property in keyof Type as undefined extends Type[Property] ? never : Property]: Type[Property];
} & {
[Property in keyof Type as undefined extends Type[Property] ? Property : never]?: Type[Property];
}>;
// Infer TypeScript type from a schema definition.
export type InferSchema<Def extends Definition> = InferField<
export type InferSchema<Def extends Definition> = MakeUndefinedOptional<InferField<
{ '': { type: typeof Object } }
& { [Key in keyof Def as Key extends string ? `.${Key}` : never]: Def[Key] }, ''
>;
>>;
// expands object types recursively
export type ExpandRecursively<T> = T extends object
? T extends infer O ? { [K in keyof O]: ExpandRecursively<O[K]> } : never
: T;
export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
export type ConvertToUnion<T> = T[keyof T];

View File

@@ -1,6 +1,6 @@
import '/imports/parser/parseTree/array';
import factories from '/imports/parser/parseTree';
import InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
import InputProvider, { CastSpellParams, CheckParams } from '/imports/api/engine/action/functions/userInput/InputProvider';
import ParseNode from '/imports/parser/parseTree/ParseNode';
import rollDice from '/imports/parser/rollDice';
import ResolveLevel from './types/ResolveLevel';
@@ -53,5 +53,17 @@ const computationInputProvider: InputProvider = {
chosen.push(choices[i]._id);
}
return chosen;
}
},
async targetIds() {
return [];
},
async advantage() {
return 0;
},
async check(input: CheckParams) {
return input;
},
async castSpell(input: CastSpellParams) {
return input;
},
}

15
app/package-lock.json generated
View File

@@ -5851,6 +5851,14 @@
"dev": true,
"requires": {
"type-fest": "^0.20.2"
},
"dependencies": {
"type-fest": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz",
"integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==",
"dev": true
}
}
},
"globby": {
@@ -8020,10 +8028,9 @@
"dev": true
},
"type-fest": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz",
"integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==",
"dev": true
"version": "4.32.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.32.0.tgz",
"integrity": "sha512-rfgpoi08xagF3JSdtJlCwMq9DGNDE0IMh3Mkpc1wUypg9vPi786AiqeBBKcqvIkq42azsBM85N490fyZjeUftw=="
},
"typescript": {
"version": "5.3.3",

View File

@@ -57,6 +57,7 @@
"source-map-support": "^0.5.21",
"speakingurl": "^14.0.1",
"thumbhash": "^0.1.1",
"type-fest": "^4.32.0",
"vivagraphjs": "^0.12.0",
"vue": "2.6.14",
"vue-meteor-tracker": "^2.0.0",