diff --git a/.vscode/settings.json b/.vscode/settings.json index 6ceb4c8e..51325d3d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,6 +29,7 @@ "thumbhash", "uncomputed", "untarget", + "vars", "vuedraggable", "vuetify", "Vuex", diff --git a/app/imports/api/creature/creatureProperties/CreatureProperties.ts b/app/imports/api/creature/creatureProperties/CreatureProperties.ts index 2dfcec5f..b0bbf1cf 100644 --- a/app/imports/api/creature/creatureProperties/CreatureProperties.ts +++ b/app/imports/api/creature/creatureProperties/CreatureProperties.ts @@ -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; + +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 + > & Simplify< + Exclude, 'type'> + & InferType + & InferType + & InferType + > +} + +export type CreatureProperty = ConvertToUnion; + const CreatureProperties = new Mongo.Collection('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 = - ComputedProperty - & InferType - & InferType - & InferType - & InferType - -type ConvertToUnion = T[keyof T]; -export type CreatureProperty = ConvertToUnion<{ [key in keyof ComputedPropertyTypeMap]: CreaturePropertyByType }>; - export default CreatureProperties; export { DenormalisedOnlyCreaturePropertySchema, diff --git a/app/imports/api/icons/Icons.ts b/app/imports/api/icons/Icons.ts index 5a85af7a..d7efd84b 100644 --- a/app/imports/api/icons/Icons.ts +++ b/app/imports/api/icons/Icons.ts @@ -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, }, diff --git a/app/imports/api/library/LibraryNodes.js b/app/imports/api/library/LibraryNodes.js index 574ea464..c3e4f91d 100644 --- a/app/imports/api/library/LibraryNodes.js +++ b/app/imports/api/library/LibraryNodes.js @@ -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 } diff --git a/app/imports/api/parenting/ChildSchema.ts b/app/imports/api/parenting/ChildSchema.ts index cac212ab..ccf5a829 100644 --- a/app/imports/api/parenting/ChildSchema.ts +++ b/app/imports/api/parenting/ChildSchema.ts @@ -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, }, diff --git a/app/imports/api/parenting/SoftRemovableSchema.js b/app/imports/api/parenting/SoftRemovableSchema.js index 82cd7e49..09a64f24 100644 --- a/app/imports/api/parenting/SoftRemovableSchema.js +++ b/app/imports/api/parenting/SoftRemovableSchema.js @@ -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, diff --git a/app/imports/api/properties/Actions.ts b/app/imports/api/properties/Actions.ts index d3916d7e..7d73bb41 100644 --- a/app/imports/api/properties/Actions.ts +++ b/app/imports/api/properties/Actions.ts @@ -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; -export type ComputedOnlyAction = InferType; -export type ComputedAction = Expand & InferType>; - export { ActionSchema, ComputedOnlyActionSchema, ComputedActionSchema }; diff --git a/app/imports/api/properties/Adjustments.ts b/app/imports/api/properties/Adjustments.ts index f011a06d..8bc9315d 100644 --- a/app/imports/api/properties/Adjustments.ts +++ b/app/imports/api/properties/Adjustments.ts @@ -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; -export type ComputedOnlyAdjustment = InferType; -export type ComputedAdjustment = Expand & InferType>; - export { AdjustmentSchema, ComputedAdjustmentSchema, ComputedOnlyAdjustmentSchema }; diff --git a/app/imports/api/properties/Attributes.ts b/app/imports/api/properties/Attributes.ts index 0b3987aa..318c1f47 100644 --- a/app/imports/api/properties/Attributes.ts +++ b/app/imports/api/properties/Attributes.ts @@ -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; -export type ComputedOnlyAttribute = InferType; -export type ComputedAttribute = Expand & InferType>; - export { AttributeSchema, ComputedOnlyAttributeSchema, ComputedAttributeSchema }; diff --git a/app/imports/api/properties/Branches.ts b/app/imports/api/properties/Branches.ts index 36c63817..ffc4e68b 100644 --- a/app/imports/api/properties/Branches.ts +++ b/app/imports/api/properties/Branches.ts @@ -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; -export type ComputedOnlyBranch = InferType; -export type ComputedBranch = Expand & InferType>; - export { BranchSchema, ComputedBranchSchema, ComputedOnlyBranchSchema } diff --git a/app/imports/api/properties/BuffRemovers.ts b/app/imports/api/properties/BuffRemovers.ts index ee37e979..19891d7f 100644 --- a/app/imports/api/properties/BuffRemovers.ts +++ b/app/imports/api/properties/BuffRemovers.ts @@ -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; -export type ComputedOnlyBuffRemover = InferType; -export type ComputedBuffRemover = Expand & InferType>; - export { BuffRemoverSchema, ComputedOnlyBuffRemoverSchema, ComputedBuffRemoverSchema }; diff --git a/app/imports/api/properties/Buffs.ts b/app/imports/api/properties/Buffs.ts index 0d8a1389..0e2ba08a 100644 --- a/app/imports/api/properties/Buffs.ts +++ b/app/imports/api/properties/Buffs.ts @@ -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; -export type ComputedOnlyBuff = InferType; -export type ComputedBuff = Expand & InferType>; - export { BuffSchema, ComputedOnlyBuffSchema, ComputedBuffSchema }; diff --git a/app/imports/api/properties/ClassLevels.ts b/app/imports/api/properties/ClassLevels.ts index f80a658a..03619211 100644 --- a/app/imports/api/properties/ClassLevels.ts +++ b/app/imports/api/properties/ClassLevels.ts @@ -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; -export type ComputedOnlyClassLevel = InferType; -export type ComputedClassLevel = Expand & InferType>; - export { ClassLevelSchema, ComputedOnlyClassLevelSchema, ComputedClassLevelSchema }; diff --git a/app/imports/api/properties/Classes.ts b/app/imports/api/properties/Classes.ts index 9d8701fd..7596ee3c 100644 --- a/app/imports/api/properties/Classes.ts +++ b/app/imports/api/properties/Classes.ts @@ -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; -export type ComputedOnlyClass = InferType; -export type ComputedClass = Expand & InferType>; - export { ClassSchema, ComputedOnlyClassSchema, ComputedClassSchema }; diff --git a/app/imports/api/properties/Constants.ts b/app/imports/api/properties/Constants.ts index e6ecee61..407020a8 100644 --- a/app/imports/api/properties/Constants.ts +++ b/app/imports/api/properties/Constants.ts @@ -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; -export type ComputedOnlyConstant = InferType; -export type ComputedConstant = Expand & InferType>; +const ComputedConstantSchema = TypedSimpleSchema.from({}) + .extend(ConstantSchema) + .extend(ComputedOnlyConstantSchema); -export { ConstantSchema, ComputedOnlyConstantSchema }; +export { ConstantSchema, ComputedOnlyConstantSchema, ComputedConstantSchema }; diff --git a/app/imports/api/properties/Containers.ts b/app/imports/api/properties/Containers.ts index 69242679..49dca779 100644 --- a/app/imports/api/properties/Containers.ts +++ b/app/imports/api/properties/Containers.ts @@ -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; -export type ComputedOnlyContainer = InferType; -export type ComputedContainer = Expand & InferType>; - export { ContainerSchema, ComputedOnlyContainerSchema, ComputedContainerSchema }; diff --git a/app/imports/api/properties/CreatureTemplates.ts b/app/imports/api/properties/CreatureTemplates.ts index 29e5668c..20d0da72 100644 --- a/app/imports/api/properties/CreatureTemplates.ts +++ b/app/imports/api/properties/CreatureTemplates.ts @@ -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; -export type ComputedOnlyCreatureTemplate = InferType; -export type ComputedCreatureTemplate = Expand & InferType>; - export { CreatureTemplateSchema, ComputedCreatureTemplateSchema, ComputedOnlyCreatureTemplateSchema }; diff --git a/app/imports/api/properties/DamageMultipliers.ts b/app/imports/api/properties/DamageMultipliers.ts index 8ffe18bf..a79b6cde 100644 --- a/app/imports/api/properties/DamageMultipliers.ts +++ b/app/imports/api/properties/DamageMultipliers.ts @@ -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; -export type ComputedOnlyDamageMultiplier = InferType; -export type ComputedDamageMultiplier = Expand & InferType>; +const ComputedDamageMultiplierSchema = TypedSimpleSchema.from({}) + .extend(DamageMultiplierSchema) + .extend(ComputedOnlyDamageMultiplierSchema); -export { DamageMultiplierSchema, ComputedOnlyDamageMultiplierSchema }; +export { DamageMultiplierSchema, ComputedOnlyDamageMultiplierSchema, ComputedDamageMultiplierSchema }; diff --git a/app/imports/api/properties/Damages.ts b/app/imports/api/properties/Damages.ts index f1670e0d..38d72066 100644 --- a/app/imports/api/properties/Damages.ts +++ b/app/imports/api/properties/Damages.ts @@ -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; -export type ComputedOnlyDamage = InferType; -export type ComputedDamage = Expand & InferType>; - export { DamageSchema, ComputedDamageSchema, ComputedOnlyDamageSchema }; diff --git a/app/imports/api/properties/Effects.ts b/app/imports/api/properties/Effects.ts index 2a14f450..b9b50225 100644 --- a/app/imports/api/properties/Effects.ts +++ b/app/imports/api/properties/Effects.ts @@ -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; -export type ComputedOnlyEffect = InferType; -export type ComputedEffect = Expand & InferType>; - export { EffectSchema, ComputedEffectSchema, ComputedOnlyEffectSchema }; diff --git a/app/imports/api/properties/Features.ts b/app/imports/api/properties/Features.ts index 99f1a7c9..5311c4d0 100644 --- a/app/imports/api/properties/Features.ts +++ b/app/imports/api/properties/Features.ts @@ -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; -export type ComputedOnlyFeature = InferType; -export type ComputedFeature = Expand & InferType>; - export { FeatureSchema, ComputedFeatureSchema, ComputedOnlyFeatureSchema } diff --git a/app/imports/api/properties/Folders.ts b/app/imports/api/properties/Folders.ts index b24272c3..14039997 100644 --- a/app/imports/api/properties/Folders.ts +++ b/app/imports/api/properties/Folders.ts @@ -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; -export type ComputedOnlyFolder = InferType; -export type ComputedFolder = Expand & InferType>; - export { FolderSchema, ComputedFolderSchema, ComputedOnlyFolderSchema }; diff --git a/app/imports/api/properties/Items.ts b/app/imports/api/properties/Items.ts index 33566359..4cdc7dfe 100644 --- a/app/imports/api/properties/Items.ts +++ b/app/imports/api/properties/Items.ts @@ -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; -export type ComputedOnlyItem = InferType; -export type ComputedItem = Expand & InferType>; - export { ItemSchema, ComputedItemSchema, ComputedOnlyItemSchema }; diff --git a/app/imports/api/properties/Notes.ts b/app/imports/api/properties/Notes.ts index 607918c9..ccd1e79f 100644 --- a/app/imports/api/properties/Notes.ts +++ b/app/imports/api/properties/Notes.ts @@ -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; -export type ComputedOnlyNote = InferType; -export type ComputedNote = Expand & InferType>; - export { NoteSchema, ComputedNoteSchema, ComputedOnlyNoteSchema, }; diff --git a/app/imports/api/properties/PointBuys.ts b/app/imports/api/properties/PointBuys.ts index 04834421..04bb02c4 100644 --- a/app/imports/api/properties/PointBuys.ts +++ b/app/imports/api/properties/PointBuys.ts @@ -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; -export type ComputedOnlyPointBuy = InferType; -export type ComputedPointBuy = Expand & InferType>; - export { PointBuySchema, ComputedPointBuySchema, ComputedOnlyPointBuySchema }; diff --git a/app/imports/api/properties/Proficiencies.ts b/app/imports/api/properties/Proficiencies.ts index a5be59d5..84b40834 100644 --- a/app/imports/api/properties/Proficiencies.ts +++ b/app/imports/api/properties/Proficiencies.ts @@ -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; -export type ComputedOnlyProficiency = InferType; -export type ComputedProficiency = Expand & InferType>; - export { ProficiencySchema, ComputedOnlyProficiencySchema }; diff --git a/app/imports/api/properties/Property.type.ts b/app/imports/api/properties/Property.type.ts deleted file mode 100644 index 6896f76f..00000000 --- a/app/imports/api/properties/Property.type.ts +++ /dev/null @@ -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 = 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 = 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 = ComputedOnlyPropertyTypeMap[T] diff --git a/app/imports/api/properties/References.ts b/app/imports/api/properties/References.ts index 80ffd784..387ebae0 100644 --- a/app/imports/api/properties/References.ts +++ b/app/imports/api/properties/References.ts @@ -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; -export type ComputedOnlyReference = InferType; -export type ComputedReference = Expand & InferType>; - export { ReferenceSchema, ComputedOnlyReferenceSchema }; diff --git a/app/imports/api/properties/Rolls.ts b/app/imports/api/properties/Rolls.ts index 5caac4c3..c540cbe1 100644 --- a/app/imports/api/properties/Rolls.ts +++ b/app/imports/api/properties/Rolls.ts @@ -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; -export type ComputedOnlyRoll = InferType; -export type ComputedRoll = Expand & InferType>; - export { RollSchema, ComputedRollSchema, ComputedOnlyRollSchema }; diff --git a/app/imports/api/properties/SavingThrows.ts b/app/imports/api/properties/SavingThrows.ts index 80777970..40f45756 100644 --- a/app/imports/api/properties/SavingThrows.ts +++ b/app/imports/api/properties/SavingThrows.ts @@ -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; -export type ComputedOnlySavingThrow = InferType; -export type ComputedSavingThrow = Expand & InferType>; - export { SavingThrowSchema, ComputedOnlySavingThrowSchema, ComputedSavingThrowSchema }; diff --git a/app/imports/api/properties/Skills.ts b/app/imports/api/properties/Skills.ts index 7d486773..0e015956 100644 --- a/app/imports/api/properties/Skills.ts +++ b/app/imports/api/properties/Skills.ts @@ -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; -export type ComputedOnlySkill = InferType; -export type ComputedSkill = Expand & InferType>; - export { SkillSchema, ComputedSkillSchema, ComputedOnlySkillSchema }; diff --git a/app/imports/api/properties/Slots.ts b/app/imports/api/properties/Slots.ts index 0c47357f..a61485bf 100644 --- a/app/imports/api/properties/Slots.ts +++ b/app/imports/api/properties/Slots.ts @@ -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; -export type ComputedOnlySlot = InferType; -export type ComputedSlot = Expand & InferType>; - export { SlotSchema, ComputedSlotSchema, ComputedOnlySlotSchema }; diff --git a/app/imports/api/properties/SpellLists.ts b/app/imports/api/properties/SpellLists.ts index 94354a54..4ba70148 100644 --- a/app/imports/api/properties/SpellLists.ts +++ b/app/imports/api/properties/SpellLists.ts @@ -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; -export type ComputedOnlySpellList = InferType; -export type ComputedSpellList = Expand & InferType>; - export { SpellListSchema, ComputedOnlySpellListSchema, ComputedSpellListSchema }; diff --git a/app/imports/api/properties/Spells.ts b/app/imports/api/properties/Spells.ts index 0e44a7e6..71fb3ac3 100644 --- a/app/imports/api/properties/Spells.ts +++ b/app/imports/api/properties/Spells.ts @@ -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; -export type ComputedOnlySpell = InferType; -export type ComputedSpell = Expand & InferType>; - export { SpellSchema, ComputedOnlySpellSchema, ComputedSpellSchema }; diff --git a/app/imports/api/properties/Toggles.ts b/app/imports/api/properties/Toggles.ts index ca339413..dc68af54 100644 --- a/app/imports/api/properties/Toggles.ts +++ b/app/imports/api/properties/Toggles.ts @@ -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; -export type ComputedOnlyToggle = InferType; -export type ComputedToggle = Expand & InferType>; - -const ComputedToggleSchema = new SimpleSchema({}) +const ComputedToggleSchema = TypedSimpleSchema.from({}) .extend(ComputedOnlyToggleSchema) .extend(ToggleSchema); diff --git a/app/imports/api/properties/Triggers.ts b/app/imports/api/properties/Triggers.ts index 89f43e33..633a66ad 100644 --- a/app/imports/api/properties/Triggers.ts +++ b/app/imports/api/properties/Triggers.ts @@ -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, 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, optional: true, }, timing: { type: String, - allowedValues: [ - 'before', - 'after', - 'afterChildren', - ] as const, + allowedValues: Object.keys(timingOptions) as UnionToTuple, 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; -export type ComputedOnlyTrigger = InferType; -export type ComputedTrigger = Expand & InferType>; - export { TriggerSchema, ComputedOnlyTriggerSchema, ComputedTriggerSchema, eventOptions, timingOptions, actionPropertyTypeOptions diff --git a/app/imports/api/properties/computedOnlyPropertySchemasIndex.js b/app/imports/api/properties/computedOnlyPropertySchemasIndex.js index 3017d84a..ed007821 100644 --- a/app/imports/api/properties/computedOnlyPropertySchemasIndex.js +++ b/app/imports/api/properties/computedOnlyPropertySchemasIndex.js @@ -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; diff --git a/app/imports/api/properties/computedPropertySchemasIndex.js b/app/imports/api/properties/computedPropertySchemasIndex.js index 86fba824..66bbd9cd 100644 --- a/app/imports/api/properties/computedPropertySchemasIndex.js +++ b/app/imports/api/properties/computedPropertySchemasIndex.js @@ -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; diff --git a/app/imports/api/properties/propertySchemasIndex.js b/app/imports/api/properties/propertySchemasIndex.js index 2dcf8e41..ce7657d4 100644 --- a/app/imports/api/properties/propertySchemasIndex.js +++ b/app/imports/api/properties/propertySchemasIndex.js @@ -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; diff --git a/app/imports/api/properties/subSchemas/AdjustmentSchema.ts b/app/imports/api/properties/subSchemas/AdjustmentSchema.ts index 4f43b034..78f92a01 100644 --- a/app/imports/api/properties/subSchemas/AdjustmentSchema.ts +++ b/app/imports/api/properties/subSchemas/AdjustmentSchema.ts @@ -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; - export default AdjustmentSchema; diff --git a/app/imports/api/properties/subSchemas/ColorSchema.ts b/app/imports/api/properties/subSchemas/ColorSchema.ts index 70753fa8..71e68e1b 100644 --- a/app/imports/api/properties/subSchemas/ColorSchema.ts +++ b/app/imports/api/properties/subSchemas/ColorSchema.ts @@ -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 diff --git a/app/imports/api/properties/subSchemas/ErrorSchema.ts b/app/imports/api/properties/subSchemas/ErrorSchema.ts index d0086f38..9a509918 100644 --- a/app/imports/api/properties/subSchemas/ErrorSchema.ts +++ b/app/imports/api/properties/subSchemas/ErrorSchema.ts @@ -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, diff --git a/app/imports/api/properties/subSchemas/RollDetailsSchema.js b/app/imports/api/properties/subSchemas/RollDetailsSchema.js index 9ea3f279..3ed767bf 100644 --- a/app/imports/api/properties/subSchemas/RollDetailsSchema.js +++ b/app/imports/api/properties/subSchemas/RollDetailsSchema.js @@ -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, }, diff --git a/app/imports/api/properties/subSchemas/RollResultsSchema.js b/app/imports/api/properties/subSchemas/RollResultsSchema.js deleted file mode 100644 index b15746f3..00000000 --- a/app/imports/api/properties/subSchemas/RollResultsSchema.js +++ /dev/null @@ -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; diff --git a/app/imports/api/properties/subSchemas/TagTargetingSchema.ts b/app/imports/api/properties/subSchemas/TagTargetingSchema.ts index bdf9efa7..4c7b940f 100644 --- a/app/imports/api/properties/subSchemas/TagTargetingSchema.ts +++ b/app/imports/api/properties/subSchemas/TagTargetingSchema.ts @@ -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, diff --git a/app/imports/api/properties/subSchemas/createPropertySchema.ts b/app/imports/api/properties/subSchemas/createPropertySchema.ts index 801443ca..5a0ef1fe 100644 --- a/app/imports/api/properties/subSchemas/createPropertySchema.ts +++ b/app/imports/api/properties/subSchemas/createPropertySchema.ts @@ -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(definition: T): TypedSimpleSchema { +export default function createPropertySchema(definition: D): TypedSimpleSchema> { const computationFields = { inlineCalculationFieldToCompute: [], computedOnlyInlineCalculationField: [], @@ -41,7 +41,7 @@ export default function createPropertySchema(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 => { diff --git a/app/imports/api/utility/TypedSimpleSchema.ts b/app/imports/api/utility/TypedSimpleSchema.ts index 0f6e65e8..d0c7e540 100644 --- a/app/imports/api/utility/TypedSimpleSchema.ts +++ b/app/imports/api/utility/TypedSimpleSchema.ts @@ -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; // This is a no-op wrapper, effectively implementing a phantom type. -export class TypedSimpleSchema extends SimpleSchema { - constructor(definition: T) { +export class TypedSimpleSchema extends SimpleSchema { + private constructor(definition: Definition) { super(definition); } + static from(definition: D): TypedSimpleSchema> { + return new TypedSimpleSchema(definition); + } // Extending the schema with another schema &'s their definitions - extend(otherSchema: TypedSimpleSchema): TypedSimpleSchema { + // In some cases, this is not strictly accurate, use with caution + extend(otherSchema: TypedSimpleSchema): TypedSimpleSchema> { return super.extend(otherSchema); } } // It cannot be a method due to https://github.com/microsoft/TypeScript/issues/36931. -export function validate(schema: TypedSimpleSchema, value: unknown): asserts value is InferSchema { +export function validate(schema: TypedSimpleSchema, 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 = Expand>>; +export type InferType = T extends TypedSimpleSchema ? X : never; // Infer TypeScript type from SimpleSchema type. type InferTypeInner = @@ -47,7 +52,7 @@ type InferTypeInner = T extends typeof String ? string : T extends typeof Date ? Date : T extends RegExp ? string : - T extends TypedSimpleSchema ? InferSchema : + T extends TypedSimpleSchema ? U : NotImplementedMarker; // Infer TypeScript type from a single field definition. @@ -57,7 +62,7 @@ export type InferField = ? ArrayMarker extends InferTypeInner ? Array> : ObjectMarker extends InferTypeInner - ? { [L in keyof Def as L extends `${Key}.${infer SubKey}` ? SubKey extends `${string}.${string}` ? never : SubKey : never]: InferField } + ? { [L in keyof Def as L extends `${Key}.${infer SubKey}` ? SubKey extends `${string}.${string}` ? never : SubKey : never]: InferOptional> } : Def[Key] extends { allowedValues: infer Allowed extends string[] } ? InferOptional> : Def[Key] extends { type: 'fieldToCompute' } ? FieldToCalculate : Def[Key] extends { type: 'computedOnlyField' } ? CalculatedOnlyField @@ -73,18 +78,16 @@ type InferEnum = T[number]; // Infer optional from optional field type InferOptional = Def[Key] extends { optional: true } ? U | undefined : U; -type MakeUndefinedOptional = { [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 = 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 = InferField< +export type InferSchema = MakeUndefinedOptional; +>>; -// expands object types recursively -export type ExpandRecursively = T extends object - ? T extends infer O ? { [K in keyof O]: ExpandRecursively } : never - : T; - -export type Expand = T extends infer O ? { [K in keyof O]: O[K] } : never; +export type ConvertToUnion = T[keyof T]; diff --git a/app/imports/parser/resolve.ts b/app/imports/parser/resolve.ts index 10638c0f..2d89d81a 100644 --- a/app/imports/parser/resolve.ts +++ b/app/imports/parser/resolve.ts @@ -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; + }, } diff --git a/app/package-lock.json b/app/package-lock.json index 7c536713..7d99a336 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -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", diff --git a/app/package.json b/app/package.json index 65a82bac..ddedf3f4 100644 --- a/app/package.json +++ b/app/package.json @@ -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",