@power-plant/schema 0.0.2 → 0.0.3
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 +221 -1
- package/dist/codegen.cjs +1 -77
- package/dist/codegen.mjs +1 -78
- package/dist/{constants-Cx9_Shfk.d.cts → constants-u7ovYS9e.d.cts} +3 -4
- package/dist/constants-u7ovYS9e.d.cts.map +1 -0
- package/dist/{constants-Cx9_Shfk.d.mts → constants-u7ovYS9e.d.mts} +3 -4
- package/dist/constants-u7ovYS9e.d.mts.map +1 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.d.cts +2 -2
- package/dist/constants.d.mts +2 -2
- package/dist/constants.mjs +1 -1
- package/dist/extract.cjs +1 -1
- package/dist/extract.d.cts +22 -9
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +22 -9
- package/dist/extract.mjs +2 -1
- package/dist/extract.mjs.map +1 -0
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.d.cts +14 -3
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +14 -3
- package/dist/helpers.mjs +1 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -10
- package/dist/index.mjs +1 -1
- package/dist/metadata-CsY3HrP2.cjs +77 -0
- package/dist/metadata-DIEpQjbq.mjs +78 -0
- package/dist/metadata-DIEpQjbq.mjs.map +1 -0
- package/dist/metadata.cjs +1 -1
- package/dist/metadata.d.cts +65 -2
- package/dist/metadata.d.cts.map +1 -1
- package/dist/metadata.d.mts +65 -2
- package/dist/metadata.mjs +1 -2
- package/dist/type-checks.cjs +1 -1
- package/dist/type-checks.d.cts +10 -3
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +10 -3
- package/dist/type-checks.mjs +1 -1
- package/dist/types.d.cts +206 -37
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +206 -37
- package/package.json +19 -64
- package/dist/bundle.cjs +0 -1
- package/dist/bundle.d.cts +0 -18
- package/dist/bundle.d.cts.map +0 -1
- package/dist/bundle.d.mts +0 -18
- package/dist/bundle.d.mts.map +0 -1
- package/dist/bundle.mjs +0 -2
- package/dist/bundle.mjs.map +0 -1
- package/dist/codegen.mjs.map +0 -1
- package/dist/constants-Cx9_Shfk.d.cts.map +0 -1
- package/dist/constants-Cx9_Shfk.d.mts.map +0 -1
- package/dist/helpers.mjs.map +0 -1
- package/dist/metadata.mjs.map +0 -1
- package/dist/persistence-B9pzElsC.mjs +0 -2
- package/dist/persistence-B9pzElsC.mjs.map +0 -1
- package/dist/persistence-CLni2zCP.cjs +0 -1
- package/dist/persistence.cjs +0 -1
- package/dist/persistence.d.cts +0 -58
- package/dist/persistence.d.cts.map +0 -1
- package/dist/persistence.d.mts +0 -58
- package/dist/persistence.d.mts.map +0 -1
- package/dist/persistence.mjs +0 -1
- package/dist/resolve.cjs +0 -1
- package/dist/resolve.d.cts +0 -45
- package/dist/resolve.d.cts.map +0 -1
- package/dist/resolve.d.mts +0 -45
- package/dist/resolve.d.mts.map +0 -1
- package/dist/resolve.mjs +0 -2
- package/dist/resolve.mjs.map +0 -1
package/dist/types.d.mts
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
import { n as JSON_SCHEMA_PRIMITIVE_TYPES, r as JSON_SCHEMA_TYPES } from "./constants-
|
|
1
|
+
import { n as JSON_SCHEMA_PRIMITIVE_TYPES, r as JSON_SCHEMA_TYPES } from "./constants-u7ovYS9e.mjs";
|
|
2
2
|
import { StandardJSONSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
import {
|
|
3
|
+
import { InferLoadOptions, LoadInput } from "@stryke/resolve/types";
|
|
4
|
+
import { MaybePromise } from "@stryke/types/base";
|
|
4
5
|
import { InputObject, Schema as Schema$1 } from "untyped";
|
|
5
6
|
import { BaseIssue, BaseSchema } from "valibot";
|
|
6
7
|
import * as z3 from "zod/v3";
|
|
7
8
|
|
|
8
9
|
//#region src/types.d.ts
|
|
9
|
-
/**
|
|
10
|
-
* Alias for the Untyped object-input schema shape.
|
|
11
|
-
*/
|
|
12
|
-
type UntypedInputObject = InputObject;
|
|
13
|
-
/**
|
|
14
|
-
* Alias for the Untyped schema document shape.
|
|
15
|
-
*/
|
|
16
|
-
type UntypedSchema = Schema$1;
|
|
17
|
-
/**
|
|
18
|
-
* A Valibot schema instance.
|
|
19
|
-
*
|
|
20
|
-
* @template TInput - The raw input type accepted by the schema.
|
|
21
|
-
* @template TOutput - The parsed output type produced by the schema.
|
|
22
|
-
* @template TIssue - The issue type emitted for validation errors.
|
|
23
|
-
*/
|
|
24
|
-
type ValibotSchema<TInput = unknown, TOutput = unknown, TIssue extends BaseIssue<unknown> = BaseIssue<unknown>> = BaseSchema<TInput, TOutput, TIssue>;
|
|
25
10
|
/**
|
|
26
11
|
* Primitive JSON Schema `type` keyword values.
|
|
27
12
|
*
|
|
@@ -118,10 +103,14 @@ interface JsonSchemaMetadataKeywords {
|
|
|
118
103
|
* A name for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
119
104
|
*/
|
|
120
105
|
name?: string;
|
|
106
|
+
/**
|
|
107
|
+
* A version for the schema, which can be used by documentation tools or other libraries that support this feature to provide additional context or information about the schema's version. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
108
|
+
*/
|
|
109
|
+
version?: string | number;
|
|
121
110
|
/**
|
|
122
111
|
* A title for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
123
112
|
*/
|
|
124
|
-
|
|
113
|
+
displayName?: string;
|
|
125
114
|
/**
|
|
126
115
|
* A description for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable explanation or summary of the schema's purpose and usage. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
127
116
|
*/
|
|
@@ -133,7 +122,11 @@ interface JsonSchemaMetadataKeywords {
|
|
|
133
122
|
/**
|
|
134
123
|
* An array of example values that conform to the schema. This property can be used to provide sample data for documentation purposes or to assist developers in understanding the expected structure and content of the data that the schema represents. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
135
124
|
*/
|
|
136
|
-
examples?: unknown
|
|
125
|
+
examples?: (unknown | {
|
|
126
|
+
name?: string;
|
|
127
|
+
description?: string;
|
|
128
|
+
value: unknown;
|
|
129
|
+
})[];
|
|
137
130
|
/**
|
|
138
131
|
* An array of strings or an alias reference to indicate that the field is an alias for one or more other fields.
|
|
139
132
|
*/
|
|
@@ -1136,35 +1129,217 @@ type SchemaSourceVariant = "standard-schema" | "json-schema" | "zod3" | "untyped
|
|
|
1136
1129
|
* Accepted schema input variants, including raw type definitions.
|
|
1137
1130
|
*/
|
|
1138
1131
|
type SchemaInputVariant = SchemaSourceVariant | "file-reference";
|
|
1132
|
+
/**
|
|
1133
|
+
* Alias for the Untyped object-input schema shape.
|
|
1134
|
+
*/
|
|
1135
|
+
type UntypedInputObject = InputObject;
|
|
1136
|
+
/**
|
|
1137
|
+
* Alias for the Untyped schema document shape.
|
|
1138
|
+
*/
|
|
1139
|
+
type UntypedSchema = Schema$1;
|
|
1140
|
+
/**
|
|
1141
|
+
* A Valibot schema instance.
|
|
1142
|
+
*
|
|
1143
|
+
* @template TInput - The raw input type accepted by the schema.
|
|
1144
|
+
* @template TOutput - The parsed output type produced by the schema.
|
|
1145
|
+
* @template TIssue - The issue type emitted for validation errors.
|
|
1146
|
+
*/
|
|
1147
|
+
type ValibotSchema<TInput = unknown, TOutput = unknown, TIssue extends BaseIssue<unknown> = BaseIssue<unknown>> = BaseSchema<TInput, TOutput, TIssue>;
|
|
1139
1148
|
/**
|
|
1140
1149
|
* Raw schema source input union before normalization.
|
|
1141
1150
|
*/
|
|
1142
1151
|
type SchemaSourceInput<TSpec = any> = StandardJSONSchemaV1<TSpec> | JsonSchemaOf<TSpec> | z3.ZodType<TSpec, any, any> | UntypedInputObject | UntypedSchema | ValibotSchema<TSpec>;
|
|
1143
1152
|
/**
|
|
1144
1153
|
* Any accepted schema input, including normalized schemas and references.
|
|
1154
|
+
*
|
|
1155
|
+
* @remarks
|
|
1156
|
+
* The `SchemaInput` type can be one of the following variants:
|
|
1157
|
+
* - A file path string (for example: `"./src/types.ts"`).
|
|
1158
|
+
* - A URL string (for example: `"https://example.com/config.json"`).
|
|
1159
|
+
* - A {@link GitHubReference | GitHub repository reference string}, starting with either `"github:"` or `"gh:"`, an optional branch or tag, and optionally including a specific file path within the repository (for example: `"github:main:storm-software/stryke/packages/resolve/src/types.ts"`). It is also valid to provide the branch or tag after the file path (for example: `"github:storm-software/stryke/packages/resolve/src/types.ts@main"`).
|
|
1160
|
+
* - A {@link GitLabReference | GitLab repository reference string}, starting with either `"gitlab:"` or `"gl:"`, an optional branch or tag, and optionally including a specific file path within the repository (for example: `"gitlab:master:storm-software/stryke/packages/resolve/src/types.ts"`). It is also valid to provide the branch or tag after the file path (for example: `"gitlab:storm-software/stryke/packages/resolve/src/types.ts@master"`).
|
|
1161
|
+
* - A TypeScript module name string (for example: `"@stryke/resolve"`), and optionally a specific module export from the package (for example: `"@stryke/resolve/some-module"`).
|
|
1162
|
+
* - A file reference string (this value can include both a path to the TypeScript module and the name of the module export separated by a ":", "#", or ";" character - for example: `"./src/types.ts#ExampleExport"`).
|
|
1163
|
+
* - A {@link FileReference} object, which contains information about a file reference.
|
|
1164
|
+
* - A {@link URL} object, which represents a URL to fetch the file from.
|
|
1165
|
+
* - A {@link SchemaSourceInput} object, which represents a raw schema input in one of the supported formats (Standard Schema, JSON Schema, Zod v3, Untyped, or Valibot).
|
|
1166
|
+
*
|
|
1167
|
+
* @template TSpec - The original TypeScript type for which the schema is being extracted. This type parameter is used to derive the appropriate JSON Schema representation based on the structure and constraints of `T`.
|
|
1168
|
+
*
|
|
1169
|
+
* @see {@link SchemaSourceInput}
|
|
1170
|
+
* @see {@link Schema}
|
|
1171
|
+
* @see {@link SchemaInputWithMeta}
|
|
1145
1172
|
*/
|
|
1146
|
-
type SchemaInput<TSpec = any> = SchemaSourceInput<TSpec> | Schema<JsonSchemaOf<TSpec>> |
|
|
1173
|
+
type SchemaInput<TSpec = any> = LoadInput | SchemaSourceInput<TSpec> | Schema<JsonSchemaOf<TSpec>> | SchemaInputWithMeta<TSpec>;
|
|
1174
|
+
type InferExtractOptions<T extends SchemaInput> = T extends LoadInput ? InferLoadOptions<T> : {};
|
|
1175
|
+
type MetaValue<TSpec, TValue = any> = TValue | ((spec: TSpec) => MaybePromise<TValue>);
|
|
1176
|
+
type MetaDeprecated = true | string | {
|
|
1177
|
+
message?: string;
|
|
1178
|
+
since?: string;
|
|
1179
|
+
alternative?: string;
|
|
1180
|
+
};
|
|
1181
|
+
type MetaLink = string | {
|
|
1182
|
+
href: string;
|
|
1183
|
+
description?: string;
|
|
1184
|
+
};
|
|
1185
|
+
interface MetaInput<TSpec> {
|
|
1186
|
+
/**
|
|
1187
|
+
* A name for the schema, which can be used to identify or reference the schema in documentation, tooling, or other contexts. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1188
|
+
*
|
|
1189
|
+
* @remarks
|
|
1190
|
+
* The `name` property is a string that can be used to give the schema a human-readable identifier. It can be used in documentation, error messages, or other contexts where it is helpful to have a name associated with the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1191
|
+
*/
|
|
1192
|
+
name?: MetaValue<TSpec, string>;
|
|
1193
|
+
/**
|
|
1194
|
+
* A version string that indicates the version of the schema. This property can be used to track changes or updates to the schema over time, allowing consumers of the schema to determine which version they are working with. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1195
|
+
*
|
|
1196
|
+
* @remarks
|
|
1197
|
+
* The `version` property is a string that can follow any versioning scheme, such as semantic versioning (e.g., "1.0.0", "2.1.3"), date-based versioning (e.g., "2023-06-15"), or any other format that conveys the version of the schema. It is recommended to use a consistent versioning scheme across all schemas to facilitate easier tracking and management of schema versions.
|
|
1198
|
+
*
|
|
1199
|
+
* @defaultValue "1.0"
|
|
1200
|
+
*/
|
|
1201
|
+
version?: MetaValue<TSpec, string | Date | number>;
|
|
1202
|
+
/**
|
|
1203
|
+
* A string that describes the schema in some way.
|
|
1204
|
+
*/
|
|
1205
|
+
description?: MetaValue<TSpec, string>;
|
|
1206
|
+
/**
|
|
1207
|
+
* A string that provides a human-readable name for the schema, which can be used in documentation, tooling, or other contexts to identify or reference the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1208
|
+
*
|
|
1209
|
+
* @remarks
|
|
1210
|
+
* The `displayName` property is a string that can be used to give the schema a more user-friendly or descriptive name. It can be used in documentation, error messages, or other contexts where it is helpful to have a display name associated with the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1211
|
+
*/
|
|
1212
|
+
displayName?: MetaValue<TSpec, string>;
|
|
1213
|
+
/**
|
|
1214
|
+
* A string that describes when the schema is used.
|
|
1215
|
+
*/
|
|
1216
|
+
usage?: MetaValue<TSpec, string>;
|
|
1217
|
+
/**
|
|
1218
|
+
* Indicates whether the schema is deprecated, and optionally provides additional information about the deprecation, such as a message, the version since which it is deprecated, and an alternative schema to use instead.
|
|
1219
|
+
*
|
|
1220
|
+
* @remarks
|
|
1221
|
+
* The `deprecated` property can be a boolean value, where `true` indicates that the schema is deprecated and `false` indicates that it is not. It can also be a string that provides a message explaining the deprecation, or an object that includes additional details such as a message, the version since which it is deprecated, and an alternative schema to use instead. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1222
|
+
*/
|
|
1223
|
+
deprecated?: MetaValue<TSpec, MetaDeprecated>;
|
|
1224
|
+
/**
|
|
1225
|
+
* An array of tags associated with the schema. Tags can be used to categorize or label schemas for organizational purposes, making it easier to search, filter, or group related schemas together. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1226
|
+
*
|
|
1227
|
+
* @remarks
|
|
1228
|
+
* Each tag in the array should be a string that represents a meaningful label or category for the schema. It is recommended to use consistent and descriptive tags across schemas to facilitate easier management and discovery of related schemas.
|
|
1229
|
+
*/
|
|
1230
|
+
tags?: MetaValue<TSpec, string[]>;
|
|
1231
|
+
/**
|
|
1232
|
+
* An array of links associated with the schema. Each link can be a string representing a URL or an object containing a `href` property and an optional `description` property.
|
|
1233
|
+
*/
|
|
1234
|
+
links?: MetaValue<TSpec, MetaLink[]>;
|
|
1235
|
+
}
|
|
1236
|
+
interface Meta<TSpec> {
|
|
1237
|
+
/**
|
|
1238
|
+
* A unique identifier for the schema, which can be used to reference or identify the schema in documentation, tooling, or other contexts. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1239
|
+
*
|
|
1240
|
+
* @remarks
|
|
1241
|
+
* The `id` property is a string that can be used to give the schema a unique identifier. It can be used in documentation, error messages, or other contexts where it is helpful to have an identifier associated with the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1242
|
+
*/
|
|
1243
|
+
id: MetaValue<TSpec, string>;
|
|
1244
|
+
/**
|
|
1245
|
+
* A name for the schema, which can be used to identify or reference the schema in documentation, tooling, or other contexts. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1246
|
+
*
|
|
1247
|
+
* @remarks
|
|
1248
|
+
* The `name` property is a string that can be used to give the schema a human-readable identifier. It can be used in documentation, error messages, or other contexts where it is helpful to have a name associated with the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1249
|
+
*/
|
|
1250
|
+
name: MetaValue<TSpec, string>;
|
|
1251
|
+
/**
|
|
1252
|
+
* A version string that indicates the version of the schema. This property can be used to track changes or updates to the schema over time, allowing consumers of the schema to determine which version they are working with. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1253
|
+
*
|
|
1254
|
+
* @remarks
|
|
1255
|
+
* The `version` property is a string that can follow any versioning scheme, such as semantic versioning (e.g., "1.0.0", "2.1.3"), date-based versioning (e.g., "2023-06-15"), or any other format that conveys the version of the schema. It is recommended to use a consistent versioning scheme across all schemas to facilitate easier tracking and management of schema versions.
|
|
1256
|
+
*
|
|
1257
|
+
* @defaultValue "1.0"
|
|
1258
|
+
*/
|
|
1259
|
+
version: MetaValue<TSpec, string | Date | number>;
|
|
1260
|
+
/**
|
|
1261
|
+
* A string that describes the schema in some way.
|
|
1262
|
+
*/
|
|
1263
|
+
description: MetaValue<TSpec, string>;
|
|
1264
|
+
/**
|
|
1265
|
+
* A string that provides a human-readable name for the schema, which can be used in documentation, tooling, or other contexts to identify or reference the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1266
|
+
*
|
|
1267
|
+
* @remarks
|
|
1268
|
+
* The `displayName` property is a string that can be used to give the schema a more user-friendly or descriptive name. It can be used in documentation, error messages, or other contexts where it is helpful to have a display name associated with the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1269
|
+
*/
|
|
1270
|
+
displayName: MetaValue<TSpec, string>;
|
|
1271
|
+
/**
|
|
1272
|
+
* A string that describes when the schema is used.
|
|
1273
|
+
*/
|
|
1274
|
+
usage?: MetaValue<TSpec, string>;
|
|
1275
|
+
/**
|
|
1276
|
+
* Indicates whether the schema is deprecated, and optionally provides additional information about the deprecation, such as a message, the version since which it is deprecated, and an alternative schema to use instead.
|
|
1277
|
+
*
|
|
1278
|
+
* @remarks
|
|
1279
|
+
* The `deprecated` property can be a boolean value, where `true` indicates that the schema is deprecated and `false` indicates that it is not. It can also be a string that provides a message explaining the deprecation, or an object that includes additional details such as a message, the version since which it is deprecated, and an alternative schema to use instead. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1280
|
+
*/
|
|
1281
|
+
deprecated?: MetaValue<TSpec, MetaDeprecated>;
|
|
1282
|
+
/**
|
|
1283
|
+
* An array of tags associated with the schema. Tags can be used to categorize or label schemas for organizational purposes, making it easier to search, filter, or group related schemas together. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
1284
|
+
*
|
|
1285
|
+
* @remarks
|
|
1286
|
+
* Each tag in the array should be a string that represents a meaningful label or category for the schema. It is recommended to use consistent and descriptive tags across schemas to facilitate easier management and discovery of related schemas.
|
|
1287
|
+
*/
|
|
1288
|
+
tags?: MetaValue<TSpec, string[]>;
|
|
1289
|
+
/**
|
|
1290
|
+
* An array of links associated with the schema. Each link can be a string representing a URL or an object containing a `href` property and an optional `description` property.
|
|
1291
|
+
*/
|
|
1292
|
+
links: MetaValue<TSpec, MetaLink[]>;
|
|
1293
|
+
}
|
|
1294
|
+
type SchemaMetaExample<TSpec> = TSpec | {
|
|
1295
|
+
description?: string;
|
|
1296
|
+
value: TSpec;
|
|
1297
|
+
};
|
|
1298
|
+
interface SchemaMetaInput<TSpec> extends MetaInput<TSpec> {
|
|
1299
|
+
/**
|
|
1300
|
+
* Examples of valid data for the schema. This can be a single example or an array of examples.
|
|
1301
|
+
*/
|
|
1302
|
+
examples?: SchemaMetaExample<TSpec> | MetaValue<TSpec, SchemaMetaExample<TSpec>[]>;
|
|
1303
|
+
}
|
|
1304
|
+
interface SchemaMeta<TSpec> extends Meta<TSpec> {
|
|
1305
|
+
/**
|
|
1306
|
+
* Examples of valid data for the schema.
|
|
1307
|
+
*/
|
|
1308
|
+
examples: MetaValue<TSpec, SchemaMetaExample<TSpec>[]>;
|
|
1309
|
+
}
|
|
1147
1310
|
/**
|
|
1148
1311
|
* Schema input wrapper that attaches optional contextual metadata.
|
|
1149
1312
|
*/
|
|
1150
1313
|
interface SchemaInputWithMeta<TSpec = any> {
|
|
1151
|
-
/**
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1314
|
+
/**
|
|
1315
|
+
* The underlying schema input payload.
|
|
1316
|
+
*/
|
|
1317
|
+
schema: SchemaSourceInput<TSpec> | Schema<JsonSchemaOf<TSpec>> | LoadInput;
|
|
1318
|
+
/**
|
|
1319
|
+
* Optional contextual metadata associated with this schema input.
|
|
1320
|
+
*/
|
|
1321
|
+
meta?: SchemaMetaInput<TSpec> | string;
|
|
1155
1322
|
}
|
|
1156
1323
|
/**
|
|
1157
1324
|
* A schema extracted from a source input, normalized to JSON Schema.
|
|
1158
1325
|
*/
|
|
1159
1326
|
interface Schema<TJsonSchema extends JsonSchema = JsonSchema> {
|
|
1160
|
-
/**
|
|
1327
|
+
/**
|
|
1328
|
+
* A stable content hash for the normalized schema.
|
|
1329
|
+
*/
|
|
1161
1330
|
hash: string;
|
|
1162
|
-
/**
|
|
1331
|
+
/**
|
|
1332
|
+
* The source variant used to derive the normalized {@link JsonSchema}.
|
|
1333
|
+
*/
|
|
1163
1334
|
variant: SchemaInputVariant;
|
|
1164
|
-
/**
|
|
1335
|
+
/**
|
|
1336
|
+
* The normalized schema definition.
|
|
1337
|
+
*/
|
|
1165
1338
|
schema: TJsonSchema;
|
|
1166
|
-
/**
|
|
1167
|
-
|
|
1339
|
+
/**
|
|
1340
|
+
* Optional contextual metadata associated with the schema.
|
|
1341
|
+
*/
|
|
1342
|
+
meta: SchemaMeta<SpecOf<TJsonSchema>>;
|
|
1168
1343
|
}
|
|
1169
1344
|
/**
|
|
1170
1345
|
* A normalized JSON Schema extracted from a source input of type `T`. This type represents the result of the schema extraction process, where a raw schema input (which could be in various formats such as Zod, Untyped, Valibot, or as a type definition in TypeScript source code) is transformed into a standardized JSON Schema format. The `SchemaOf<T>` type captures the normalized JSON Schema along with metadata about the source variant and a content hash for caching or identification purposes.
|
|
@@ -1174,12 +1349,6 @@ interface Schema<TJsonSchema extends JsonSchema = JsonSchema> {
|
|
|
1174
1349
|
* @see {@link Schema}
|
|
1175
1350
|
*/
|
|
1176
1351
|
type SchemaOf<TSpec> = Schema<JsonSchemaOf<TSpec>>;
|
|
1177
|
-
interface SchemaMeta<TSpec> {
|
|
1178
|
-
/**
|
|
1179
|
-
* A string description (or a function that returns a string) of the schema.
|
|
1180
|
-
*/
|
|
1181
|
-
description?: string | ((spec: TSpec) => string);
|
|
1182
|
-
}
|
|
1183
1352
|
/**
|
|
1184
1353
|
* Base metadata captured for schema source inputs.
|
|
1185
1354
|
*/
|
|
@@ -1250,5 +1419,5 @@ interface ExtractedSchema<TSpec = any> extends SchemaOf<TSpec> {
|
|
|
1250
1419
|
source: SchemaSource<TSpec>;
|
|
1251
1420
|
}
|
|
1252
1421
|
//#endregion
|
|
1253
|
-
export { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaOf, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, Schema, SchemaInput, SchemaInputVariant, SchemaInputWithMeta, SchemaMeta, SchemaOf, SchemaSource, SchemaSourceInput, SchemaSourceVariant, SpecOf, StandardSchemaSchemaSource, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource };
|
|
1422
|
+
export { BaseSchemaSource, ExtractedSchema, InferExtractOptions, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaOf, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, Meta, MetaDeprecated, MetaInput, MetaLink, MetaValue, Schema, SchemaInput, SchemaInputVariant, SchemaInputWithMeta, SchemaMeta, SchemaMetaExample, SchemaMetaInput, SchemaOf, SchemaSource, SchemaSourceInput, SchemaSourceVariant, SpecOf, StandardSchemaSchemaSource, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource };
|
|
1254
1423
|
//# sourceMappingURL=types.d.mts.map
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@power-plant/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "A
|
|
5
|
+
"description": "A Power Plant utility package to help managing schemas.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"zod",
|
|
8
8
|
"valibot",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "github",
|
|
23
23
|
"url": "https://github.com/storm-software/power-plant.git",
|
|
24
|
-
"directory": "packages/schema"
|
|
24
|
+
"directory": "packages/base/schema"
|
|
25
25
|
},
|
|
26
26
|
"funding": {
|
|
27
27
|
"type": "github",
|
|
@@ -63,20 +63,6 @@
|
|
|
63
63
|
"default": "./dist/index.mjs"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"./bundle": {
|
|
67
|
-
"require": {
|
|
68
|
-
"types": "./dist/bundle.d.cts",
|
|
69
|
-
"default": "./dist/bundle.cjs"
|
|
70
|
-
},
|
|
71
|
-
"import": {
|
|
72
|
-
"types": "./dist/bundle.d.mts",
|
|
73
|
-
"default": "./dist/bundle.mjs"
|
|
74
|
-
},
|
|
75
|
-
"default": {
|
|
76
|
-
"types": "./dist/bundle.d.mts",
|
|
77
|
-
"default": "./dist/bundle.mjs"
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
66
|
"./codegen": {
|
|
81
67
|
"require": {
|
|
82
68
|
"types": "./dist/codegen.d.cts",
|
|
@@ -148,34 +134,6 @@
|
|
|
148
134
|
}
|
|
149
135
|
},
|
|
150
136
|
"./package.json": "./package.json",
|
|
151
|
-
"./persistence": {
|
|
152
|
-
"require": {
|
|
153
|
-
"types": "./dist/persistence.d.cts",
|
|
154
|
-
"default": "./dist/persistence.cjs"
|
|
155
|
-
},
|
|
156
|
-
"import": {
|
|
157
|
-
"types": "./dist/persistence.d.mts",
|
|
158
|
-
"default": "./dist/persistence.mjs"
|
|
159
|
-
},
|
|
160
|
-
"default": {
|
|
161
|
-
"types": "./dist/persistence.d.mts",
|
|
162
|
-
"default": "./dist/persistence.mjs"
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
"./resolve": {
|
|
166
|
-
"require": {
|
|
167
|
-
"types": "./dist/resolve.d.cts",
|
|
168
|
-
"default": "./dist/resolve.cjs"
|
|
169
|
-
},
|
|
170
|
-
"import": {
|
|
171
|
-
"types": "./dist/resolve.d.mts",
|
|
172
|
-
"default": "./dist/resolve.mjs"
|
|
173
|
-
},
|
|
174
|
-
"default": {
|
|
175
|
-
"types": "./dist/resolve.d.mts",
|
|
176
|
-
"default": "./dist/resolve.mjs"
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
137
|
"./type-checks": {
|
|
180
138
|
"require": {
|
|
181
139
|
"types": "./dist/type-checks.d.cts",
|
|
@@ -211,33 +169,30 @@
|
|
|
211
169
|
"typings": "dist/index.d.mts",
|
|
212
170
|
"files": ["dist"],
|
|
213
171
|
"dependencies": {
|
|
214
|
-
"@msgpack/msgpack": "^3.1.3",
|
|
215
172
|
"@standard-schema/spec": "^1.1.0",
|
|
216
|
-
"@stryke/convert": "^0.7.
|
|
217
|
-
"@stryke/
|
|
218
|
-
"@stryke/hash": "^0.13.
|
|
219
|
-
"@stryke/helpers": "^0.10.
|
|
220
|
-
"@stryke/json": "^0.15.
|
|
221
|
-
"@stryke/path": "^0.29.
|
|
222
|
-
"@stryke/
|
|
223
|
-
"@stryke/
|
|
224
|
-
"@stryke/
|
|
225
|
-
"@stryke/
|
|
226
|
-
"@stryke/
|
|
173
|
+
"@stryke/convert": "^0.7.23",
|
|
174
|
+
"@stryke/date": "^0.0.4",
|
|
175
|
+
"@stryke/hash": "^0.13.46",
|
|
176
|
+
"@stryke/helpers": "^0.10.32",
|
|
177
|
+
"@stryke/json": "^0.15.16",
|
|
178
|
+
"@stryke/path": "^0.29.19",
|
|
179
|
+
"@stryke/resolve": "^0.0.8",
|
|
180
|
+
"@stryke/string-format": "^0.17.34",
|
|
181
|
+
"@stryke/type-checks": "^0.6.25",
|
|
182
|
+
"@stryke/types": "^0.12.20",
|
|
183
|
+
"@stryke/unique-id": "^0.3.104",
|
|
184
|
+
"@stryke/url": "^0.4.43",
|
|
185
|
+
"@stryke/zod": "^0.3.38",
|
|
227
186
|
"@valibot/to-json-schema": "^1.7.1",
|
|
228
187
|
"defu": "^6.1.7",
|
|
229
|
-
"esbuild": "^0.27.7",
|
|
230
|
-
"jiti": "^2.7.0",
|
|
231
|
-
"smol-toml": "^1.7.0",
|
|
232
188
|
"ts-json-schema-generator": "^2.9.0",
|
|
233
189
|
"typescript": "^6.0.3",
|
|
234
|
-
"untyped": "^1.5.2"
|
|
235
|
-
"yaml": "^2.9.0"
|
|
190
|
+
"untyped": "^1.5.2"
|
|
236
191
|
},
|
|
237
192
|
"devDependencies": {
|
|
238
193
|
"@powerlines/plugin-tsdown": "^0.1.540",
|
|
239
194
|
"@types/node": "^25.9.4",
|
|
240
|
-
"powerlines": "
|
|
195
|
+
"powerlines": "0.47.139",
|
|
241
196
|
"valibot": "^1.4.1",
|
|
242
197
|
"zod": "^4.4.3"
|
|
243
198
|
},
|
|
@@ -250,5 +205,5 @@
|
|
|
250
205
|
"zod": { "optional": true }
|
|
251
206
|
},
|
|
252
207
|
"publishConfig": { "access": "public" },
|
|
253
|
-
"gitHead": "
|
|
208
|
+
"gitHead": "43169e6b829afa991d5a0a3ea05a49b800aa9d44"
|
|
254
209
|
}
|
package/dist/bundle.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@stryke/helpers/omit"),t=require("esbuild"),n=require("node:fs");async function r(r,i={}){if(!r||!(0,n.existsSync)(r))throw Error(`Module not found: "${r}". Please check the path and try again.`);let a=await(0,t.build)({platform:`node`,format:`esm`,...(0,e.omit)(i,[`debug`]),logLevel:`silent`,entryPoints:[r],write:!1,sourcemap:!1,splitting:!1,treeShaking:!0,bundle:!0,packages:`bundle`,keepNames:!0,metafile:!1});if(a.errors.length>0)throw Error(`Failed to bundle ${r}: ${a.errors.map(e=>e.text).join(`, `)}`);if(!a.outputFiles||a.outputFiles.filter(Boolean).length===0)throw Error(`No output files generated for ${r}. Please check the configuration and try again.`);return a.outputFiles.filter(Boolean)[0]}exports.bundle=r;
|
package/dist/bundle.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { DeepPartial } from "@stryke/types/base";
|
|
2
|
-
import { BuildOptions, OutputFile } from "esbuild";
|
|
3
|
-
|
|
4
|
-
//#region src/bundle.d.ts
|
|
5
|
-
type BundleOptions = DeepPartial<BuildOptions> & {
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Bundle a type definition to a module.
|
|
10
|
-
*
|
|
11
|
-
* @param file - The file path to bundle.
|
|
12
|
-
* @param options - Optional overrides for the ESBuild configuration.
|
|
13
|
-
* @returns A promise that resolves to the bundled module.
|
|
14
|
-
*/
|
|
15
|
-
declare function bundle(file: string, options?: BundleOptions): Promise<OutputFile>;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { BundleOptions, bundle };
|
|
18
|
-
//# sourceMappingURL=bundle.d.cts.map
|
package/dist/bundle.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.cts","names":[],"sources":["../src/bundle.ts"],"mappings":";;;;KAwBY,aAAA,GAAgB,WAAW,CAAC,YAAA;EACtC,KAAA;AAAA;;;;;;;;iBAUoB,MAAA,CACpB,IAAA,UACA,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,UAAA"}
|
package/dist/bundle.d.mts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BuildOptions, OutputFile } from "esbuild";
|
|
2
|
-
import { DeepPartial } from "@stryke/types/base";
|
|
3
|
-
|
|
4
|
-
//#region src/bundle.d.ts
|
|
5
|
-
type BundleOptions = DeepPartial<BuildOptions> & {
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Bundle a type definition to a module.
|
|
10
|
-
*
|
|
11
|
-
* @param file - The file path to bundle.
|
|
12
|
-
* @param options - Optional overrides for the ESBuild configuration.
|
|
13
|
-
* @returns A promise that resolves to the bundled module.
|
|
14
|
-
*/
|
|
15
|
-
declare function bundle(file: string, options?: BundleOptions): Promise<OutputFile>;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { BundleOptions, bundle };
|
|
18
|
-
//# sourceMappingURL=bundle.d.mts.map
|
package/dist/bundle.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.mts","names":[],"sources":["../src/bundle.ts"],"mappings":""}
|
package/dist/bundle.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{omit as e}from"@stryke/helpers/omit";import{build as t}from"esbuild";import{existsSync as n}from"node:fs";async function r(r,i={}){if(!r||!n(r))throw Error(`Module not found: "${r}". Please check the path and try again.`);let a=await t({platform:`node`,format:`esm`,...e(i,[`debug`]),logLevel:`silent`,entryPoints:[r],write:!1,sourcemap:!1,splitting:!1,treeShaking:!0,bundle:!0,packages:`bundle`,keepNames:!0,metafile:!1});if(a.errors.length>0)throw Error(`Failed to bundle ${r}: ${a.errors.map(e=>e.text).join(`, `)}`);if(!a.outputFiles||a.outputFiles.filter(Boolean).length===0)throw Error(`No output files generated for ${r}. Please check the configuration and try again.`);return a.outputFiles.filter(Boolean)[0]}export{r as bundle};
|
|
2
|
-
//# sourceMappingURL=bundle.mjs.map
|
package/dist/bundle.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.mjs","names":[],"sources":[],"mappings":""}
|
package/dist/codegen.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants-Cx9_Shfk.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAoBa,4BAAA;AAAA,cAiBA,mBAAA;EAAA;;;;;;;;cAUA,2BAAA;AAAA,cAQA,iBAAA;AAAA,cAMA,yBAAA;;;;;cAoBA,sBAAA,EAAsB,GAAA;;AAlCnC;;;cA8Ca,sBAAA,EAAsB,GAAA;AAxCzB;AAEV;;;AAFU,cAyDG,4BAAA,EAA4B,GAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants-Cx9_Shfk.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":""}
|
package/dist/helpers.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":[],"mappings":""}
|
package/dist/metadata.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{VALID_SOURCE_FILE_EXTENSIONS as e}from"./constants.mjs";import{isFileReference as t,isJsonSchema as n,isJsonSchemaObject as r,isSchema as i,isSchemaWithSource as a,isUntypedInput as o,isUntypedInputStrict as s,isUntypedSchema as c,isUntypedSchemaStrict as l,isValibotSchema as u}from"./type-checks.mjs";import{resolveSafe as d,resolveTSType as f}from"./resolve.mjs";import{isSetString as p}from"@stryke/type-checks";import{extractFileReference as m}from"@stryke/convert/extract-file-reference";import{findFileExtensionSafe as h}from"@stryke/path/find";import{mkdir as g,readFile as _,writeFile as v}from"node:fs/promises";import{existsSync as y}from"node:fs";import{joinPaths as b}from"@stryke/path/join";import{getEnvPaths as ee}from"@stryke/env/get-env-paths";import{murmurhash as x}from"@stryke/hash";import{deepClone as S}from"@stryke/helpers/deep-clone";import{isStandardJsonSchema as C}from"@stryke/json";import{list as te}from"@stryke/string-format/list";import{isSetObject as w}from"@stryke/type-checks/is-set-object";import{extractJsonSchema as T,isZod3Type as E}from"@stryke/zod";import{toJsonSchema as D}from"@valibot/to-json-schema";const O=`https://powerlines.invalid/`;function ne(e){return!w(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e?!1:Object.keys(e).every(e=>e===`schema`||e===`meta`)}function k(e){return ne(e)?{input:e.schema,meta:e.meta}:{input:e}}function A(e){return e.endsWith(`#`)?e.slice(0,-1):e}function j(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function M(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function N(e){return e.length===0?``:`/${e.map(e=>M(e)).join(`/`)}`}function P(e,t){try{return A(new URL(e,t).toString())}catch{return A(e)}}function F(e,t,n,r,i){if(!w(e))return;let a=e,o=N(t),s=p(a.$id)?P(a.$id,n):n,c=j(s);if(r.set(s,o),r.set(c,o),p(a.$anchor)&&r.set(`${c}#${a.$anchor}`,o),p(a.$dynamicAnchor)){let e=`${c}#${a.$dynamicAnchor}`;r.set(e,o),i.set(e,`#${a.$dynamicAnchor}`)}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{F(n,[...t,e,String(a)],s,r,i)});continue}F(n,[...t,e],s,r,i)}}function I(e,t,n,r,i){if(!w(e))return;let a=e,o=p(a.$id)?P(a.$id,n):n;if(p(a.$ref)){let e=P(a.$ref,o),t=r.get(e)??r.get(j(e));t!==void 0&&(a.$ref=t.length>0?`#${t}`:`#`)}if(p(a.$dynamicRef)){let e=P(a.$dynamicRef,o),t=i.get(e);if(t)a.$dynamicRef=t;else{let t=r.get(e)??r.get(j(e));t!==void 0&&(a.$dynamicRef=t.length>0?`#${t}`:`#`)}}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{I(n,[...t,e,String(a)],o,r,i)});continue}I(n,[...t,e],o,r,i)}}function L(e){if(!w(e))return e;let t=S(e),n=p(t.$id)?P(t.$id,O):O,r=new Map,i=new Map;return F(t,[],n,r,i),I(t,[],n,r,i),t}function R(e){if(c(e))return V(e);if(w(e)){if(o(e))return H(e);let t=e;if(`$schema`in t&&c(t.$schema))return V(t.$schema)}return e}function z(e){return Array.isArray(e)?e.map(e=>R(e)):e}function B(e){return D(e,{target:`draft-2020-12`})}function V(e){let t=e,n={};for(let[e,r]of Object.entries(t))if(!(e===`tsType`||e===`markdownType`||e===`tags`||e===`args`||e===`resolve`)){if(e===`id`&&p(r)){n.$id=r;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!w(r)){n[e]=r;continue}n[e]=Object.fromEntries(Object.entries(r).map(([e,t])=>[e,R(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=R(r);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=z(r);continue}n[e]=r}return n}function H(e){let t=e,n=c(t.$schema)?V(t.$schema):{},i={};for(let[e,n]of Object.entries(t)){if(e.startsWith(`$`)||!w(n))continue;if(o(n)){i[e]=H(n);continue}let t=n;if(`$schema`in t&&c(t.$schema)){i[e]=V(t.$schema);continue}c(n)&&(i[e]=V(n))}if(!r(n))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let a={...w(n.properties)?n.properties:{},...i};return{...n,type:n.type??`object`,...Object.keys(a).length>0?{properties:a}:{}}}function U(e,t){let{input:r}=k(t);if(a(r)||i(r))return x({variant:e,input:r.schema});if(p(r)||typeof r==`boolean`)return x({variant:e,input:r});if(w(r)){if(E(r))return x({variant:e,input:r._def});if(C(r))return x({variant:e,input:r[`~standard`]});if(n(r))return x({variant:e,input:r});if(u(r))return x({variant:e,input:B(r)});if(o(r))return x({variant:e,input:H(r)});if(c(r))return x({variant:e,input:V(r)})}throw Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`)}function W(e){if(w(e)){if(E(e))return T(e,{target:`draft-2020-12`});if(s(e))return H(e);if(l(e))return V(e);if(C(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(u(e))return B(e);if(n(e))return e}}function G(e){if(w(e)){if(E(e))return`zod3`;if(s(e)||l(e))return`untyped`;if(C(e))return`standard-schema`;if(n(e))return`json-schema`;if(u(e))return`valibot`}throw Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`)}function K(e){let{input:n}=k(e);return a(n)||i(n)?n.variant:p(n)||t(n)?`file-reference`:G(n)}async function q(e,t){if(a(e))return e.schema;let n=t??G(e),r;if((n===`zod3`||n===`json-schema`||n===`standard-schema`||n===`untyped`||n===`valibot`)&&(r=W(e)),r)return L(r);throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`)}function J(e,t){if(e===`zod3`)return{hash:U(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:U(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:U(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:U(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:U(e,t),variant:`valibot`,schema:t};throw Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`)}async function Y(t,n={}){let{input:r,meta:o}=k(t);if(a(r))return o===void 0?r:{...r,meta:o};if(i(r))return{...r,...o===void 0?{}:{meta:o},source:{hash:U(`json-schema`,r.schema),variant:`json-schema`,schema:r.schema}};let s,c=K(r),l=U(c,r),u=o;if(c===`file-reference`){let t=m(r);if(!t)throw Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(r)}". Please ensure that the input is correctly formatted as a file reference (e.g. "./schema.ts#MySchema") and that the file exists at the specified path.`);let o=h(t.file);if(o&&!e.includes(o))throw Error(`The provided schema file input "${t.file}" has an invalid file extension (.${o}). Please ensure that the file has one of the following extensions: ${te(e,{conjunction:`or`})}.`);let c=await d(r,n);c??=await f(r,n);let{input:l,meta:p}=k(c);u===void 0&&p!==void 0&&(u=p),s=a(l)?l.source:i(l)?{hash:U(`json-schema`,l.schema),variant:`json-schema`,schema:l.schema}:J(G(l),l)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(c))s=J(c,r);else throw Error(`Invalid schema definition input "${c}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);let p={variant:c,source:s,schema:await q(s.schema,s.variant),hash:l};return u!==void 0&&(p.meta=u),p}async function re(e,t={}){let{input:n,meta:r}=k(e);if(a(n)||i(n))return r===void 0?n:{...n,meta:r};let o,s=K(n),c=U(s,n),l=t.cachePath??ee().cache,u={cachePath:l},d=b(X(u),`${c}.json`);if(t.skipCache!==!0&&y(d)){let e=await _(d,`utf8`);if(e){let t={variant:s,hash:c,schema:JSON.parse(e)};r!==void 0&&(t.meta=r),o=t}}if(o??=await Y(e,{...t,cachePath:l}),r!==void 0&&o&&(o.meta=r),!o?.schema)throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);return t.skipCache!==!0&&await Q(u,o),o}function X(e){return b(e.cachePath,`schemas`)}function Z(e,t){let n=U(K(t),t);return b(X(e),`${n}.json`)}async function Q(e,t){if(!i(t))throw Error(`The provided input is not a valid schema. A valid schema must have a "variant" property indicating the type of the input and a "schema" property containing the parsed JSON Schema object.`);let n=X(e),r=e.fs?.mkdir??g,a=e.fs?.write??v;!y(n)&&!e.fs?.mkdir?await g(n,{recursive:!0}):e.fs?.mkdir&&await r(n,{recursive:!0}),await a(Z(e,t),JSON.stringify(t.schema))}async function $(e,t){let n=Z(e,t),r=e.fs?.exists??(async e=>Promise.resolve(y(e))),a=e.fs?.read??_;if(!await r(n))return;let o=await a(n);if(!o)return;let s=JSON.parse(typeof o==`string`?o:o.toString());if(i(s))return s}async function ie(e,t){let n=await $(e,t);if(!n){let e=K(t),n=U(e,t);throw Error(`The ${e} schema with hash "${n}" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`)}return n}export{Q as a,U as c,q as d,Y as f,$ as i,W as l,K as m,Z as n,L as o,J as p,ie as r,re as s,X as t,G as u};
|
|
2
|
-
//# sourceMappingURL=persistence-B9pzElsC.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"persistence-B9pzElsC.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require("./constants.cjs"),t=require("./type-checks.cjs"),n=require("./resolve.cjs");let r=require("@stryke/type-checks"),i=require("@stryke/convert/extract-file-reference"),a=require("@stryke/path/find"),o=require("node:fs/promises"),s=require("node:fs"),c=require("@stryke/path/join"),l=require("@stryke/env/get-env-paths"),u=require("@stryke/hash"),d=require("@stryke/helpers/deep-clone"),f=require("@stryke/json"),p=require("@stryke/string-format/list"),m=require("@stryke/type-checks/is-set-object"),h=require("@stryke/zod"),g=require("@valibot/to-json-schema");const _=`https://powerlines.invalid/`;function v(e){return!(0,m.isSetObject)(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e?!1:Object.keys(e).every(e=>e===`schema`||e===`meta`)}function y(e){return v(e)?{input:e.schema,meta:e.meta}:{input:e}}function b(e){return e.endsWith(`#`)?e.slice(0,-1):e}function x(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function S(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function C(e){return e.length===0?``:`/${e.map(e=>S(e)).join(`/`)}`}function w(e,t){try{return b(new URL(e,t).toString())}catch{return b(e)}}function T(e,t,n,i,a){if(!(0,m.isSetObject)(e))return;let o=e,s=C(t),c=(0,r.isSetString)(o.$id)?w(o.$id,n):n,l=x(c);if(i.set(c,s),i.set(l,s),(0,r.isSetString)(o.$anchor)&&i.set(`${l}#${o.$anchor}`,s),(0,r.isSetString)(o.$dynamicAnchor)){let e=`${l}#${o.$dynamicAnchor}`;i.set(e,s),a.set(e,`#${o.$dynamicAnchor}`)}for(let[e,n]of Object.entries(o)){if(Array.isArray(n)){n.forEach((n,r)=>{T(n,[...t,e,String(r)],c,i,a)});continue}T(n,[...t,e],c,i,a)}}function E(e,t,n,i,a){if(!(0,m.isSetObject)(e))return;let o=e,s=(0,r.isSetString)(o.$id)?w(o.$id,n):n;if((0,r.isSetString)(o.$ref)){let e=w(o.$ref,s),t=i.get(e)??i.get(x(e));t!==void 0&&(o.$ref=t.length>0?`#${t}`:`#`)}if((0,r.isSetString)(o.$dynamicRef)){let e=w(o.$dynamicRef,s),t=a.get(e);if(t)o.$dynamicRef=t;else{let t=i.get(e)??i.get(x(e));t!==void 0&&(o.$dynamicRef=t.length>0?`#${t}`:`#`)}}for(let[e,n]of Object.entries(o)){if(Array.isArray(n)){n.forEach((n,r)=>{E(n,[...t,e,String(r)],s,i,a)});continue}E(n,[...t,e],s,i,a)}}function D(e){if(!(0,m.isSetObject)(e))return e;let t=(0,d.deepClone)(e),n=(0,r.isSetString)(t.$id)?w(t.$id,_):_,i=new Map,a=new Map;return T(t,[],n,i,a),E(t,[],n,i,a),t}function O(e){if(t.isUntypedSchema(e))return j(e);if((0,m.isSetObject)(e)){if(t.isUntypedInput(e))return M(e);let n=e;if(`$schema`in n&&t.isUntypedSchema(n.$schema))return j(n.$schema)}return e}function k(e){return Array.isArray(e)?e.map(e=>O(e)):e}function A(e){return(0,g.toJsonSchema)(e,{target:`draft-2020-12`})}function j(e){let t=e,n={};for(let[e,i]of Object.entries(t))if(!(e===`tsType`||e===`markdownType`||e===`tags`||e===`args`||e===`resolve`)){if(e===`id`&&(0,r.isSetString)(i)){n.$id=i;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!(0,m.isSetObject)(i)){n[e]=i;continue}n[e]=Object.fromEntries(Object.entries(i).map(([e,t])=>[e,O(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=O(i);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=k(i);continue}n[e]=i}return n}function M(e){let n=e,r=t.isUntypedSchema(n.$schema)?j(n.$schema):{},i={};for(let[e,r]of Object.entries(n)){if(e.startsWith(`$`)||!(0,m.isSetObject)(r))continue;if(t.isUntypedInput(r)){i[e]=M(r);continue}let n=r;if(`$schema`in n&&t.isUntypedSchema(n.$schema)){i[e]=j(n.$schema);continue}t.isUntypedSchema(r)&&(i[e]=j(r))}if(!t.isJsonSchemaObject(r))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let a={...(0,m.isSetObject)(r.properties)?r.properties:{},...i};return{...r,type:r.type??`object`,...Object.keys(a).length>0?{properties:a}:{}}}function N(e,n){let{input:i}=y(n);if(t.isSchemaWithSource(i)||t.isSchema(i))return(0,u.murmurhash)({variant:e,input:i.schema});if((0,r.isSetString)(i)||typeof i==`boolean`)return(0,u.murmurhash)({variant:e,input:i});if((0,m.isSetObject)(i)){if((0,h.isZod3Type)(i))return(0,u.murmurhash)({variant:e,input:i._def});if((0,f.isStandardJsonSchema)(i))return(0,u.murmurhash)({variant:e,input:i[`~standard`]});if(t.isJsonSchema(i))return(0,u.murmurhash)({variant:e,input:i});if(t.isValibotSchema(i))return(0,u.murmurhash)({variant:e,input:A(i)});if(t.isUntypedInput(i))return(0,u.murmurhash)({variant:e,input:M(i)});if(t.isUntypedSchema(i))return(0,u.murmurhash)({variant:e,input:j(i)})}throw Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`)}function P(e){if((0,m.isSetObject)(e)){if((0,h.isZod3Type)(e))return(0,h.extractJsonSchema)(e,{target:`draft-2020-12`});if(t.isUntypedInputStrict(e))return M(e);if(t.isUntypedSchemaStrict(e))return j(e);if((0,f.isStandardJsonSchema)(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(t.isValibotSchema(e))return A(e);if(t.isJsonSchema(e))return e}}function F(e){if((0,m.isSetObject)(e)){if((0,h.isZod3Type)(e))return`zod3`;if(t.isUntypedInputStrict(e)||t.isUntypedSchemaStrict(e))return`untyped`;if((0,f.isStandardJsonSchema)(e))return`standard-schema`;if(t.isJsonSchema(e))return`json-schema`;if(t.isValibotSchema(e))return`valibot`}throw Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`)}function I(e){let{input:n}=y(e);return t.isSchemaWithSource(n)||t.isSchema(n)?n.variant:(0,r.isSetString)(n)||t.isFileReference(n)?`file-reference`:F(n)}async function L(e,n){if(t.isSchemaWithSource(e))return e.schema;let r=n??F(e),i;if((r===`zod3`||r===`json-schema`||r===`standard-schema`||r===`untyped`||r===`valibot`)&&(i=P(e)),i)return D(i);throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`)}function R(e,t){if(e===`zod3`)return{hash:N(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:N(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:N(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:N(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:N(e,t),variant:`valibot`,schema:t};throw Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`)}async function z(r,o={}){let{input:s,meta:c}=y(r);if(t.isSchemaWithSource(s))return c===void 0?s:{...s,meta:c};if(t.isSchema(s))return{...s,...c===void 0?{}:{meta:c},source:{hash:N(`json-schema`,s.schema),variant:`json-schema`,schema:s.schema}};let l,u=I(s),d=N(u,s),f=c;if(u===`file-reference`){let r=(0,i.extractFileReference)(s);if(!r)throw Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(s)}". Please ensure that the input is correctly formatted as a file reference (e.g. "./schema.ts#MySchema") and that the file exists at the specified path.`);let c=(0,a.findFileExtensionSafe)(r.file);if(c&&!e.VALID_SOURCE_FILE_EXTENSIONS.includes(c))throw Error(`The provided schema file input "${r.file}" has an invalid file extension (.${c}). Please ensure that the file has one of the following extensions: ${(0,p.list)(e.VALID_SOURCE_FILE_EXTENSIONS,{conjunction:`or`})}.`);let u=await n.resolveSafe(s,o);u??=await n.resolveTSType(s,o);let{input:d,meta:m}=y(u);f===void 0&&m!==void 0&&(f=m),l=t.isSchemaWithSource(d)?d.source:t.isSchema(d)?{hash:N(`json-schema`,d.schema),variant:`json-schema`,schema:d.schema}:R(F(d),d)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(u))l=R(u,s);else throw Error(`Invalid schema definition input "${u}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);let m={variant:u,source:l,schema:await L(l.schema,l.variant),hash:d};return f!==void 0&&(m.meta=f),m}async function B(e,n={}){let{input:r,meta:i}=y(e);if(t.isSchemaWithSource(r)||t.isSchema(r))return i===void 0?r:{...r,meta:i};let a,u=I(r),d=N(u,r),f=n.cachePath??(0,l.getEnvPaths)().cache,p={cachePath:f},m=(0,c.joinPaths)(V(p),`${d}.json`);if(n.skipCache!==!0&&(0,s.existsSync)(m)){let e=await(0,o.readFile)(m,`utf8`);if(e){let t={variant:u,hash:d,schema:JSON.parse(e)};i!==void 0&&(t.meta=i),a=t}}if(a??=await z(e,{...n,cachePath:f}),i!==void 0&&a&&(a.meta=i),!a?.schema)throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);return n.skipCache!==!0&&await U(p,a),a}function V(e){return(0,c.joinPaths)(e.cachePath,`schemas`)}function H(e,t){let n=N(I(t),t);return(0,c.joinPaths)(V(e),`${n}.json`)}async function U(e,n){if(!t.isSchema(n))throw Error(`The provided input is not a valid schema. A valid schema must have a "variant" property indicating the type of the input and a "schema" property containing the parsed JSON Schema object.`);let r=V(e),i=e.fs?.mkdir??o.mkdir,a=e.fs?.write??o.writeFile;!(0,s.existsSync)(r)&&!e.fs?.mkdir?await(0,o.mkdir)(r,{recursive:!0}):e.fs?.mkdir&&await i(r,{recursive:!0}),await a(H(e,n),JSON.stringify(n.schema))}async function W(e,n){let r=H(e,n),i=e.fs?.exists??(async e=>Promise.resolve((0,s.existsSync)(e))),a=e.fs?.read??o.readFile;if(!await i(r))return;let c=await a(r);if(!c)return;let l=JSON.parse(typeof c==`string`?c:c.toString());if(t.isSchema(l))return l}async function G(e,t){let n=await W(e,t);if(!n){let e=I(t),n=N(e,t);throw Error(`The ${e} schema with hash "${n}" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`)}return n}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return F}});
|
package/dist/persistence.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("./type-checks.cjs");const e=require("./persistence-CLni2zCP.cjs");exports.getCacheDirectory=e.t,exports.getCacheFilePath=e.n,exports.readSchema=e.r,exports.readSchemaSafe=e.i,exports.writeSchema=e.a;
|