@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.
Files changed (134) hide show
  1. package/README.md +17 -0
  2. package/dist/cli/args.d.ts +3 -0
  3. package/dist/cli/args.d.ts.map +1 -0
  4. package/dist/cli/args.js +10 -0
  5. package/dist/cli/args.js.map +1 -0
  6. package/dist/cli/datasworn-build.d.ts +3 -0
  7. package/dist/cli/datasworn-build.d.ts.map +1 -0
  8. package/dist/cli/datasworn-build.js +33 -0
  9. package/dist/cli/datasworn-build.js.map +1 -0
  10. package/dist/cli/datasworn-migrate.d.ts +3 -0
  11. package/dist/cli/datasworn-migrate.d.ts.map +1 -0
  12. package/dist/cli/datasworn-migrate.js +26 -0
  13. package/dist/cli/datasworn-migrate.js.map +1 -0
  14. package/dist/config.d.ts +3 -0
  15. package/dist/config.d.ts.map +1 -0
  16. package/dist/config.js +10 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/index.d.ts +4 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +4 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/rules-package-builder.d.ts +22 -0
  23. package/dist/rules-package-builder.d.ts.map +1 -0
  24. package/dist/rules-package-builder.js +84 -0
  25. package/dist/rules-package-builder.js.map +1 -0
  26. package/dist/schema.d.ts +8 -0
  27. package/dist/schema.d.ts.map +1 -0
  28. package/dist/schema.js +18 -0
  29. package/dist/schema.js.map +1 -0
  30. package/dist/validators.d.ts +8 -0
  31. package/dist/validators.d.ts.map +1 -0
  32. package/dist/validators.js +35 -0
  33. package/dist/validators.js.map +1 -0
  34. package/package.json +60 -0
  35. package/schema-source/schema/Assets.ts +66 -0
  36. package/schema-source/schema/Atlas.ts +20 -0
  37. package/schema-source/schema/Defs.ts +126 -0
  38. package/schema-source/schema/DelveSites.ts +3 -0
  39. package/schema-source/schema/Entities.ts +1 -0
  40. package/schema-source/schema/Generic.ts +18 -0
  41. package/schema-source/schema/Moves.ts +1 -0
  42. package/schema-source/schema/Npcs.ts +80 -0
  43. package/schema-source/schema/Oracles.ts +20 -0
  44. package/schema-source/schema/Rarities.ts +36 -0
  45. package/schema-source/schema/Root.ts +94 -0
  46. package/schema-source/schema/Rules.ts +61 -0
  47. package/schema-source/schema/RulesPackages.ts +135 -0
  48. package/schema-source/schema/Symbols.ts +30 -0
  49. package/schema-source/schema/Truths.ts +53 -0
  50. package/schema-source/schema/Utils.ts +21 -0
  51. package/schema-source/schema/assets/Ability.ts +79 -0
  52. package/schema-source/schema/assets/Enhancement.ts +62 -0
  53. package/schema-source/schema/assets/Fields.ts +285 -0
  54. package/schema-source/schema/assets/common.ts +29 -0
  55. package/schema-source/schema/common/Fields.ts +327 -0
  56. package/schema-source/schema/common/Id.ts +64 -0
  57. package/schema-source/schema/common/Inputs.ts +374 -0
  58. package/schema-source/schema/common/Metadata.ts +142 -0
  59. package/schema-source/schema/common/Player.ts +17 -0
  60. package/schema-source/schema/common/Progress.ts +63 -0
  61. package/schema-source/schema/common/Range.ts +53 -0
  62. package/schema-source/schema/common/RollableValues.ts +152 -0
  63. package/schema-source/schema/common/Rolls.ts +108 -0
  64. package/schema-source/schema/common/Text.ts +95 -0
  65. package/schema-source/schema/common/index.ts +16 -0
  66. package/schema-source/schema/delve/DelveSite.ts +121 -0
  67. package/schema-source/schema/delve/DelveSiteDomain.ts +136 -0
  68. package/schema-source/schema/delve/DelveSiteTheme.ts +97 -0
  69. package/schema-source/schema/delve/common.ts +32 -0
  70. package/schema-source/schema/entities/EntityPrompt.ts +13 -0
  71. package/schema-source/schema/entities/index.ts +1 -0
  72. package/schema-source/schema/generic/CollectableNode.ts +75 -0
  73. package/schema-source/schema/generic/CollectionNode.ts +145 -0
  74. package/schema-source/schema/generic/Dictionary.ts +39 -0
  75. package/schema-source/schema/generic/EmbedOnlyNode.ts +19 -0
  76. package/schema-source/schema/generic/Enhance.ts +38 -0
  77. package/schema-source/schema/generic/IdNode.ts +40 -0
  78. package/schema-source/schema/generic/Mixin.ts +11 -0
  79. package/schema-source/schema/generic/NonCollectableNode.ts +38 -0
  80. package/schema-source/schema/generic/PrimaryTypeNode.ts +115 -0
  81. package/schema-source/schema/generic/SourcedNode.ts +51 -0
  82. package/schema-source/schema/index.ts +23 -0
  83. package/schema-source/schema/moves/ActionRoll.ts +152 -0
  84. package/schema-source/schema/moves/EmbeddedMove.ts +24 -0
  85. package/schema-source/schema/moves/Move.ts +26 -0
  86. package/schema-source/schema/moves/MoveCategory.ts +6 -0
  87. package/schema-source/schema/moves/MoveEnhancement.ts +29 -0
  88. package/schema-source/schema/moves/ProgressRoll.ts +184 -0
  89. package/schema-source/schema/moves/Trigger.ts +193 -0
  90. package/schema-source/schema/moves/common.ts +136 -0
  91. package/schema-source/schema/moves/index.ts +13 -0
  92. package/schema-source/schema/moves/utils.ts +132 -0
  93. package/schema-source/schema/object_type/ObjectType.ts +23 -0
  94. package/schema-source/schema/oracles/EmbeddedOracleRollable.ts +28 -0
  95. package/schema-source/schema/oracles/OracleCollection.ts +140 -0
  96. package/schema-source/schema/oracles/OracleRollable.ts +207 -0
  97. package/schema-source/schema/oracles/Table.ts +94 -0
  98. package/schema-source/schema/oracles/TableRow.ts +141 -0
  99. package/schema-source/schema/root/NiceSchema.ts +15 -0
  100. package/schema-source/schema/root/Root.ts +41 -0
  101. package/schema-source/schema/root/SchemaTransform.ts +89 -0
  102. package/schema-source/schema/root/SourceData.ts +151 -0
  103. package/schema-source/schema/rules/ConditionMeterRule.ts +25 -0
  104. package/schema-source/schema/rules/ImpactRule.ts +54 -0
  105. package/schema-source/schema/rules/SpecialTrackRule.ts +29 -0
  106. package/schema-source/schema/rules/StatRule.ts +23 -0
  107. package/schema-source/schema/rules/TagRule.ts +176 -0
  108. package/schema-source/schema/rules/TagSchema.ts +161 -0
  109. package/schema-source/schema/tags/canonicalTags.ts +29 -0
  110. package/schema-source/schema/tools/build/index.ts +48 -0
  111. package/schema-source/schema/tools/i18n/index.ts +9 -0
  112. package/schema-source/schema/utils/Computed.ts +82 -0
  113. package/schema-source/schema/utils/DiscriminatedUnion.ts +255 -0
  114. package/schema-source/schema/utils/EmbeddedNode.ts +172 -0
  115. package/schema-source/schema/utils/ExtractLiteralFromEnum.ts +22 -0
  116. package/schema-source/schema/utils/FlatIntersect.ts +107 -0
  117. package/schema-source/schema/utils/IfThen.ts +50 -0
  118. package/schema-source/schema/utils/MergeEnumSchemas.ts +16 -0
  119. package/schema-source/schema/utils/NonNullable.ts +6 -0
  120. package/schema-source/schema/utils/Nullable.ts +29 -0
  121. package/schema-source/schema/utils/ObjectLiteral.ts +16 -0
  122. package/schema-source/schema/utils/ObjectProperties.ts +4 -0
  123. package/schema-source/schema/utils/OmitMeta.ts +22 -0
  124. package/schema-source/schema/utils/OmitOptional.ts +27 -0
  125. package/schema-source/schema/utils/PartialExcept.ts +26 -0
  126. package/schema-source/schema/utils/SetNullable.ts +44 -0
  127. package/schema-source/schema/utils/SetOptional.ts +48 -0
  128. package/schema-source/schema/utils/UnionEnum.ts +82 -0
  129. package/schema-source/schema/utils/UnionEnumFromRecord.ts +36 -0
  130. package/schema-source/schema/utils/UnionOneOf.ts +80 -0
  131. package/schema-source/schema/utils/generateRulesetSchemas.ts +204 -0
  132. package/schema-source/schema/utils/string.ts +15 -0
  133. package/schema-source/schema/utils/typebox.ts +141 -0
  134. 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'