@datasworn-community/build-tools 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/cli/args.d.ts +3 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +10 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/datasworn-build.d.ts +3 -0
- package/dist/cli/datasworn-build.d.ts.map +1 -0
- package/dist/cli/datasworn-build.js +33 -0
- package/dist/cli/datasworn-build.js.map +1 -0
- package/dist/cli/datasworn-migrate.d.ts +3 -0
- package/dist/cli/datasworn-migrate.d.ts.map +1 -0
- package/dist/cli/datasworn-migrate.js +26 -0
- package/dist/cli/datasworn-migrate.js.map +1 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +10 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/rules-package-builder.d.ts +22 -0
- package/dist/rules-package-builder.d.ts.map +1 -0
- package/dist/rules-package-builder.js +84 -0
- package/dist/rules-package-builder.js.map +1 -0
- package/dist/schema.d.ts +8 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +18 -0
- package/dist/schema.js.map +1 -0
- package/dist/validators.d.ts +8 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +35 -0
- package/dist/validators.js.map +1 -0
- package/package.json +60 -0
- package/schema-source/schema/Assets.ts +66 -0
- package/schema-source/schema/Atlas.ts +20 -0
- package/schema-source/schema/Defs.ts +126 -0
- package/schema-source/schema/DelveSites.ts +3 -0
- package/schema-source/schema/Entities.ts +1 -0
- package/schema-source/schema/Generic.ts +18 -0
- package/schema-source/schema/Moves.ts +1 -0
- package/schema-source/schema/Npcs.ts +80 -0
- package/schema-source/schema/Oracles.ts +20 -0
- package/schema-source/schema/Rarities.ts +36 -0
- package/schema-source/schema/Root.ts +94 -0
- package/schema-source/schema/Rules.ts +61 -0
- package/schema-source/schema/RulesPackages.ts +135 -0
- package/schema-source/schema/Symbols.ts +30 -0
- package/schema-source/schema/Truths.ts +53 -0
- package/schema-source/schema/Utils.ts +21 -0
- package/schema-source/schema/assets/Ability.ts +79 -0
- package/schema-source/schema/assets/Enhancement.ts +62 -0
- package/schema-source/schema/assets/Fields.ts +285 -0
- package/schema-source/schema/assets/common.ts +29 -0
- package/schema-source/schema/common/Fields.ts +327 -0
- package/schema-source/schema/common/Id.ts +64 -0
- package/schema-source/schema/common/Inputs.ts +374 -0
- package/schema-source/schema/common/Metadata.ts +142 -0
- package/schema-source/schema/common/Player.ts +17 -0
- package/schema-source/schema/common/Progress.ts +63 -0
- package/schema-source/schema/common/Range.ts +53 -0
- package/schema-source/schema/common/RollableValues.ts +152 -0
- package/schema-source/schema/common/Rolls.ts +108 -0
- package/schema-source/schema/common/Text.ts +95 -0
- package/schema-source/schema/common/index.ts +16 -0
- package/schema-source/schema/delve/DelveSite.ts +121 -0
- package/schema-source/schema/delve/DelveSiteDomain.ts +136 -0
- package/schema-source/schema/delve/DelveSiteTheme.ts +97 -0
- package/schema-source/schema/delve/common.ts +32 -0
- package/schema-source/schema/entities/EntityPrompt.ts +13 -0
- package/schema-source/schema/entities/index.ts +1 -0
- package/schema-source/schema/generic/CollectableNode.ts +75 -0
- package/schema-source/schema/generic/CollectionNode.ts +145 -0
- package/schema-source/schema/generic/Dictionary.ts +39 -0
- package/schema-source/schema/generic/EmbedOnlyNode.ts +19 -0
- package/schema-source/schema/generic/Enhance.ts +38 -0
- package/schema-source/schema/generic/IdNode.ts +40 -0
- package/schema-source/schema/generic/Mixin.ts +11 -0
- package/schema-source/schema/generic/NonCollectableNode.ts +38 -0
- package/schema-source/schema/generic/PrimaryTypeNode.ts +115 -0
- package/schema-source/schema/generic/SourcedNode.ts +51 -0
- package/schema-source/schema/index.ts +23 -0
- package/schema-source/schema/moves/ActionRoll.ts +152 -0
- package/schema-source/schema/moves/EmbeddedMove.ts +24 -0
- package/schema-source/schema/moves/Move.ts +26 -0
- package/schema-source/schema/moves/MoveCategory.ts +6 -0
- package/schema-source/schema/moves/MoveEnhancement.ts +29 -0
- package/schema-source/schema/moves/ProgressRoll.ts +184 -0
- package/schema-source/schema/moves/Trigger.ts +193 -0
- package/schema-source/schema/moves/common.ts +136 -0
- package/schema-source/schema/moves/index.ts +13 -0
- package/schema-source/schema/moves/utils.ts +132 -0
- package/schema-source/schema/object_type/ObjectType.ts +23 -0
- package/schema-source/schema/oracles/EmbeddedOracleRollable.ts +28 -0
- package/schema-source/schema/oracles/OracleCollection.ts +140 -0
- package/schema-source/schema/oracles/OracleRollable.ts +207 -0
- package/schema-source/schema/oracles/Table.ts +94 -0
- package/schema-source/schema/oracles/TableRow.ts +141 -0
- package/schema-source/schema/root/NiceSchema.ts +15 -0
- package/schema-source/schema/root/Root.ts +41 -0
- package/schema-source/schema/root/SchemaTransform.ts +89 -0
- package/schema-source/schema/root/SourceData.ts +151 -0
- package/schema-source/schema/rules/ConditionMeterRule.ts +25 -0
- package/schema-source/schema/rules/ImpactRule.ts +54 -0
- package/schema-source/schema/rules/SpecialTrackRule.ts +29 -0
- package/schema-source/schema/rules/StatRule.ts +23 -0
- package/schema-source/schema/rules/TagRule.ts +176 -0
- package/schema-source/schema/rules/TagSchema.ts +161 -0
- package/schema-source/schema/tags/canonicalTags.ts +29 -0
- package/schema-source/schema/tools/build/index.ts +48 -0
- package/schema-source/schema/tools/i18n/index.ts +9 -0
- package/schema-source/schema/utils/Computed.ts +82 -0
- package/schema-source/schema/utils/DiscriminatedUnion.ts +255 -0
- package/schema-source/schema/utils/EmbeddedNode.ts +172 -0
- package/schema-source/schema/utils/ExtractLiteralFromEnum.ts +22 -0
- package/schema-source/schema/utils/FlatIntersect.ts +107 -0
- package/schema-source/schema/utils/IfThen.ts +50 -0
- package/schema-source/schema/utils/MergeEnumSchemas.ts +16 -0
- package/schema-source/schema/utils/NonNullable.ts +6 -0
- package/schema-source/schema/utils/Nullable.ts +29 -0
- package/schema-source/schema/utils/ObjectLiteral.ts +16 -0
- package/schema-source/schema/utils/ObjectProperties.ts +4 -0
- package/schema-source/schema/utils/OmitMeta.ts +22 -0
- package/schema-source/schema/utils/OmitOptional.ts +27 -0
- package/schema-source/schema/utils/PartialExcept.ts +26 -0
- package/schema-source/schema/utils/SetNullable.ts +44 -0
- package/schema-source/schema/utils/SetOptional.ts +48 -0
- package/schema-source/schema/utils/UnionEnum.ts +82 -0
- package/schema-source/schema/utils/UnionEnumFromRecord.ts +36 -0
- package/schema-source/schema/utils/UnionOneOf.ts +80 -0
- package/schema-source/schema/utils/generateRulesetSchemas.ts +204 -0
- package/schema-source/schema/utils/string.ts +15 -0
- package/schema-source/schema/utils/typebox.ts +141 -0
- package/schema-source/scripts/const.ts +55 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** Utilities for manipulating TypeBox schemata. */
|
|
2
|
+
import {
|
|
3
|
+
CloneType,
|
|
4
|
+
type ObjectOptions,
|
|
5
|
+
type Static,
|
|
6
|
+
type TInteger,
|
|
7
|
+
type TLiteral,
|
|
8
|
+
type TNull,
|
|
9
|
+
type TNumber,
|
|
10
|
+
/** Transform an object of literal values into a schema representing the object. */
|
|
11
|
+
type TObject,
|
|
12
|
+
type TOptional,
|
|
13
|
+
type TProperties,
|
|
14
|
+
type TRef,
|
|
15
|
+
type TRefUnsafe,
|
|
16
|
+
type TSchema,
|
|
17
|
+
type TString,
|
|
18
|
+
Type,
|
|
19
|
+
TypeGuard
|
|
20
|
+
} from '@sinclair/typebox'
|
|
21
|
+
import { isEmpty, isUndefined } from 'lodash-es'
|
|
22
|
+
import JtdType from '../../scripts/json-typedef/typedef.js'
|
|
23
|
+
import { JsonTypeDef } from '../Symbols.js'
|
|
24
|
+
import type { TDiscriminatedUnion } from './DiscriminatedUnion.js'
|
|
25
|
+
import type { TNullable } from './Nullable.js'
|
|
26
|
+
import type { TUnionEnum } from './UnionEnum.js'
|
|
27
|
+
|
|
28
|
+
export type ExtractKeysOfValueType<ObjectType, ValueType> = {
|
|
29
|
+
[P in keyof ObjectType]: ObjectType[P] extends ValueType ? P : never
|
|
30
|
+
}[keyof ObjectType]
|
|
31
|
+
|
|
32
|
+
export type PickByType<ObjectType, ValueType> = {
|
|
33
|
+
[P in keyof ObjectType as ExtractKeysOfValueType<
|
|
34
|
+
ObjectType,
|
|
35
|
+
ValueType
|
|
36
|
+
>]: ObjectType[P]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function keysWithDefaults<T extends TObject>(schema: T) {
|
|
40
|
+
const keys: string[] = []
|
|
41
|
+
|
|
42
|
+
for (const [key, subschema] of Object.entries(schema.properties)) {
|
|
43
|
+
// skip if it's already optional
|
|
44
|
+
if (TypeGuard.IsOptional(subschema)) continue
|
|
45
|
+
if (isUndefined(subschema.default)) continue
|
|
46
|
+
|
|
47
|
+
keys.push(key)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return keys as Array<keyof Static<T>>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function NoDefaults<T extends TObject>(
|
|
54
|
+
schema: T,
|
|
55
|
+
options: ObjectOptions = {}
|
|
56
|
+
) {
|
|
57
|
+
const newSchema = CloneType(schema, options)
|
|
58
|
+
for (const key in newSchema.properties)
|
|
59
|
+
delete newSchema.properties[key]?.default
|
|
60
|
+
|
|
61
|
+
return newSchema
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function WithDefaults<T extends TObject>(
|
|
65
|
+
schema: T,
|
|
66
|
+
defaults: Partial<Static<T>>,
|
|
67
|
+
options: ObjectOptions = {}
|
|
68
|
+
) {
|
|
69
|
+
const newSchema = CloneType(schema, options)
|
|
70
|
+
|
|
71
|
+
for (const key in defaults) {
|
|
72
|
+
newSchema.properties[key] ||= {} as any
|
|
73
|
+
newSchema.properties[key].default = defaults[key]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return newSchema
|
|
77
|
+
}
|
|
78
|
+
/** Resolves to `{const: 0}` in JSON schema, and falls back to uint8 for JSON TypeDef */
|
|
79
|
+
|
|
80
|
+
export const LiteralZero = Type.Literal(0, {
|
|
81
|
+
default: 0,
|
|
82
|
+
[JsonTypeDef]: { schema: JtdType.Int8() }
|
|
83
|
+
})
|
|
84
|
+
// manually set to "integer" b/c Type.Literal defaults to "number"
|
|
85
|
+
LiteralZero.type = 'integer'
|
|
86
|
+
export type LiteralZero = 0
|
|
87
|
+
/**
|
|
88
|
+
* A schema that resolves to a given type.
|
|
89
|
+
* @template T - The static type of the schema.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
export type TSchemaOf<T> = TSchema & { static: T }
|
|
93
|
+
/**
|
|
94
|
+
* A schema that resolves to a type, which may be optional or nullable.
|
|
95
|
+
* @template T - The static type of the schema.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
export type TFuzzySchemaOf<T> =
|
|
99
|
+
| TSchemaOf<T>
|
|
100
|
+
| (TSchema & { static: T | undefined })
|
|
101
|
+
| (TSchema & { static: T | null })
|
|
102
|
+
/**
|
|
103
|
+
* Assigns descriptions to the properties of an object schema.
|
|
104
|
+
* @param schema - The object schema.
|
|
105
|
+
* @param descriptions - The descriptions to be set on each property.
|
|
106
|
+
* @param override - Should non-empty descriptions be overwritten? (default: true)
|
|
107
|
+
* @returns The mutated object schema.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
export function setDescriptions<T extends TObject>(
|
|
111
|
+
schema: T,
|
|
112
|
+
descriptions: { [P in keyof Static<TObject>]?: string | undefined },
|
|
113
|
+
override = true
|
|
114
|
+
) {
|
|
115
|
+
for (const property in descriptions) {
|
|
116
|
+
const description = descriptions[property]
|
|
117
|
+
if (!override && !isEmpty(schema.properties[property].description)) continue
|
|
118
|
+
if (typeof description !== 'string' && typeof description !== 'undefined')
|
|
119
|
+
continue
|
|
120
|
+
schema.properties[property].description = description
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return schema
|
|
124
|
+
}
|
|
125
|
+
export type TFuzzyRef<T extends TSchema> = T | TRefUnsafe<T> | TRef<string>
|
|
126
|
+
|
|
127
|
+
export type TFuzzyString = TFuzzyRef<
|
|
128
|
+
TString | TLiteral<string> | TUnionEnum<string[]>
|
|
129
|
+
>
|
|
130
|
+
export type TFuzzyObject<Props extends TProperties = TProperties> = TFuzzyRef<
|
|
131
|
+
| TObject<Props>
|
|
132
|
+
| (TDiscriminatedUnion<any, string> & {
|
|
133
|
+
static: Static<TObject<Props>>
|
|
134
|
+
})
|
|
135
|
+
>
|
|
136
|
+
export type TFuzzyNumber = TFuzzyRef<
|
|
137
|
+
TNumber | TInteger | TLiteral<number> | TUnionEnum<number[]>
|
|
138
|
+
>
|
|
139
|
+
export type TFuzzyOptional<T extends TSchema> = T | TOptional<T>
|
|
140
|
+
|
|
141
|
+
export type TFuzzyNull<T extends TSchema> = TFuzzyRef<T> | TNullable<T> | TNull
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { DATASWORN_SCHEMA_VERSION } from '@datasworn-community/core'
|
|
3
|
+
|
|
4
|
+
const root = process.cwd()
|
|
5
|
+
|
|
6
|
+
export const VERSION = DATASWORN_SCHEMA_VERSION
|
|
7
|
+
|
|
8
|
+
export const PKG_NAME = 'Datasworn'
|
|
9
|
+
export const SCHEMA_NAME = 'Datasworn'
|
|
10
|
+
export const SOURCE_SCHEMA_NAME = 'DataswornSource'
|
|
11
|
+
|
|
12
|
+
export const PKG_SCOPE_OFFICIAL = '@datasworn'
|
|
13
|
+
export const PKG_SCOPE_COMMUNITY = '@datasworn-community'
|
|
14
|
+
|
|
15
|
+
export const ROOT_OUTPUT = path.join(root, 'datasworn')
|
|
16
|
+
export const ROOT_SOURCE_DATA = path.join(root, 'source_data')
|
|
17
|
+
export const ROOT_HISTORY = path.join(root, 'packages/core/migration')
|
|
18
|
+
export const DIR_HISTORY_CURRENT = path.join(ROOT_HISTORY, VERSION)
|
|
19
|
+
export const ROOT_TYPES_OUT = path.join(root, 'packages/core/src')
|
|
20
|
+
export const CORE_COMMON = path.join(root, 'packages/core/src')
|
|
21
|
+
|
|
22
|
+
export const SCHEMA_PATH = path.join(
|
|
23
|
+
root,
|
|
24
|
+
'packages/core/json/datasworn.schema.json'
|
|
25
|
+
)
|
|
26
|
+
export const SOURCE_SCHEMA_PATH = path.join(
|
|
27
|
+
root,
|
|
28
|
+
'packages/core/json/datasworn-source.schema.json'
|
|
29
|
+
)
|
|
30
|
+
export const SOURCEDATA_SCHEMA_PATH = SOURCE_SCHEMA_PATH
|
|
31
|
+
|
|
32
|
+
export const SCHEMA_DELVE_OUT = path.join(
|
|
33
|
+
ROOT_OUTPUT,
|
|
34
|
+
'datasworn-delve.schema.json'
|
|
35
|
+
)
|
|
36
|
+
export const SCHEMA_DELVE_IN = path.join(
|
|
37
|
+
ROOT_OUTPUT,
|
|
38
|
+
'datasworn-delve-source.schema.json'
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
export const SCHEMA_ID = 'https://ironswornrpg.com/datasworn.schema.json'
|
|
42
|
+
export const SOURCE_SCHEMA_ID =
|
|
43
|
+
'https://ironswornrpg.com/datasworn-source.schema.json'
|
|
44
|
+
export const DELVE_SCHEMA_ID =
|
|
45
|
+
'https://ironswornrpg.com/datasworn-delve.schema.json'
|
|
46
|
+
export const DELVE_SOURCE_ID =
|
|
47
|
+
'https://ironswornrpg.com/datasworn-delve-source.schema.json'
|
|
48
|
+
|
|
49
|
+
/** JSON schema draft used by Datasworn. */
|
|
50
|
+
export const $schema = 'http://json-schema.org/draft-07/schema#' as const
|
|
51
|
+
/** The standard key for definitions in the JSON schema draft. */
|
|
52
|
+
export const DefsKey = 'definitions' as const
|
|
53
|
+
|
|
54
|
+
/** Identifier for the type at the root of a Datasworn JSON file. */
|
|
55
|
+
export const rootSchemaName = 'RulesPackage'
|