@queryweave/standard-schema 0.1.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 QueryWeave contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # `@queryweave/standard-schema`
2
+
3
+ Standard Schema interoperability for QueryWeave parameters and models.
4
+
5
+ ```ts
6
+ import { fromStandardSchema } from "@queryweave/standard-schema";
7
+
8
+ param.text().refine(fromStandardSchema(schema)).optional();
9
+ defineQueryModel(definitions, { refine: [fromStandardSchema(crossFieldSchema)] });
10
+ ```
11
+
12
+ The package depends on `@standard-schema/spec` and nothing else. Zod, Valibot, and ArkType are
13
+ development-only dependencies of the test suite, and one shared compatibility contract runs against
14
+ all three. Vendor errors are normalized into QueryWeave `validation_failed` issues.
15
+
16
+ Asynchronous schemas resolve through `model.decodeAsync`.
@@ -0,0 +1,27 @@
1
+ import { QueryRefinement } from "@queryweave/core";
2
+ import { StandardSchemaV1 } from "@standard-schema/spec";
3
+ //#region src/index.d.ts
4
+ /**
5
+ * Standard Schema interoperability.
6
+ *
7
+ * The validator stays a development-time choice: this package depends on the specification alone,
8
+ * never on Zod, Valibot, ArkType, or any other runtime. Vendor errors are normalized so consumers
9
+ * only ever see QueryWeave issues.
10
+ */
11
+ /** Options accepted by {@link fromStandardSchema}. */
12
+ interface StandardSchemaRefinementOptions {
13
+ /** Label used for diagnostics. Defaults to the schema's own vendor name. */
14
+ readonly name?: string | undefined;
15
+ }
16
+ /** The refinement produced from a Standard Schema. */
17
+ type StandardSchemaRefinement<TSchema extends StandardSchemaV1> = QueryRefinement<StandardSchemaV1.InferInput<TSchema>, StandardSchemaV1.InferOutput<TSchema>>;
18
+ /**
19
+ * Adapt any Standard Schema into a QueryWeave refinement.
20
+ *
21
+ * Synchronous schemas keep synchronous decoding available. Asynchronous schemas resolve through
22
+ * `model.decodeAsync`, and transformed outputs flow through to the parameter's value type.
23
+ */
24
+ declare function fromStandardSchema<TSchema extends StandardSchemaV1>(schema: TSchema, options?: StandardSchemaRefinementOptions): StandardSchemaRefinement<TSchema>;
25
+ //#endregion
26
+ export { StandardSchemaRefinement, StandardSchemaRefinementOptions, fromStandardSchema };
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;UAgBiB;;WAEN;;;KAIC,yBAAyB,gBAAgB,oBAAoB,gBACvE,iBAAiB,WAAW,UAC5B,iBAAiB,YAAY;;;;;;;iBAqCf,mBAAmB,gBAAgB,kBACjD,QAAQ,SACR,UAAS,kCACR,yBAAyB"}
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ //#region src/index.ts
2
+ function toPath(segments) {
3
+ if (segments === void 0) return;
4
+ const path = [];
5
+ for (const segment of segments) if (typeof segment === "object") path.push(segment.key);
6
+ else path.push(segment);
7
+ return path;
8
+ }
9
+ function toRefinementResult(result) {
10
+ if (result.issues === void 0) return {
11
+ ok: true,
12
+ value: result.value
13
+ };
14
+ return {
15
+ ok: false,
16
+ issues: result.issues.map((issue) => ({
17
+ message: issue.message,
18
+ path: toPath(issue.path)
19
+ }))
20
+ };
21
+ }
22
+ /**
23
+ * Adapt any Standard Schema into a QueryWeave refinement.
24
+ *
25
+ * Synchronous schemas keep synchronous decoding available. Asynchronous schemas resolve through
26
+ * `model.decodeAsync`, and transformed outputs flow through to the parameter's value type.
27
+ */
28
+ function fromStandardSchema(schema, options = {}) {
29
+ const standard = schema["~standard"];
30
+ return {
31
+ name: options.name ?? standard.vendor,
32
+ refine: (value) => {
33
+ const outcome = standard.validate(value);
34
+ if (outcome instanceof Promise) return outcome.then((resolved) => toRefinementResult(resolved));
35
+ return toRefinementResult(outcome);
36
+ }
37
+ };
38
+ }
39
+
40
+ //#endregion
41
+ export { fromStandardSchema };
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n QueryRefinement,\n QueryRefinementIssue,\n QueryRefinementResult,\n} from \"@queryweave/core\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Standard Schema interoperability.\n *\n * The validator stays a development-time choice: this package depends on the specification alone,\n * never on Zod, Valibot, ArkType, or any other runtime. Vendor errors are normalized so consumers\n * only ever see QueryWeave issues.\n */\n\n/** Options accepted by {@link fromStandardSchema}. */\nexport interface StandardSchemaRefinementOptions {\n /** Label used for diagnostics. Defaults to the schema's own vendor name. */\n readonly name?: string | undefined;\n}\n\n/** The refinement produced from a Standard Schema. */\nexport type StandardSchemaRefinement<TSchema extends StandardSchemaV1> = QueryRefinement<\n StandardSchemaV1.InferInput<TSchema>,\n StandardSchemaV1.InferOutput<TSchema>\n>;\n\nfunction toPath(segments: StandardSchemaV1.Issue[\"path\"]): readonly PropertyKey[] | undefined {\n if (segments === undefined) {\n return undefined;\n }\n const path: PropertyKey[] = [];\n for (const segment of segments) {\n if (typeof segment === \"object\") {\n path.push(segment.key);\n } else {\n path.push(segment);\n }\n }\n return path;\n}\n\nfunction toRefinementResult<TOutput>(\n result: StandardSchemaV1.Result<TOutput>,\n): QueryRefinementResult<TOutput> {\n if (result.issues === undefined) {\n return { ok: true, value: result.value };\n }\n const issues: QueryRefinementIssue[] = result.issues.map((issue) => ({\n message: issue.message,\n path: toPath(issue.path),\n }));\n return { ok: false, issues };\n}\n\n/**\n * Adapt any Standard Schema into a QueryWeave refinement.\n *\n * Synchronous schemas keep synchronous decoding available. Asynchronous schemas resolve through\n * `model.decodeAsync`, and transformed outputs flow through to the parameter's value type.\n */\nexport function fromStandardSchema<TSchema extends StandardSchemaV1>(\n schema: TSchema,\n options: StandardSchemaRefinementOptions = {},\n): StandardSchemaRefinement<TSchema> {\n const standard = schema[\"~standard\"];\n\n return {\n name: options.name ?? standard.vendor,\n refine: (value) => {\n const outcome = standard.validate(value);\n if (outcome instanceof Promise) {\n return outcome.then((resolved) =>\n toRefinementResult(\n resolved as StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>,\n ),\n );\n }\n return toRefinementResult(\n outcome as StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>,\n );\n },\n };\n}\n"],"mappings":";AA2BA,SAAS,OAAO,UAA8E;CAC5F,IAAI,aAAa,QACf;CAEF,MAAM,OAAsB,CAAC;CAC7B,KAAK,MAAM,WAAW,UACpB,IAAI,OAAO,YAAY,UACrB,KAAK,KAAK,QAAQ,GAAG;MAErB,KAAK,KAAK,OAAO;CAGrB,OAAO;AACT;AAEA,SAAS,mBACP,QACgC;CAChC,IAAI,OAAO,WAAW,QACpB,OAAO;EAAE,IAAI;EAAM,OAAO,OAAO;CAAM;CAMzC,OAAO;EAAE,IAAI;EAAO,QAJmB,OAAO,OAAO,KAAK,WAAW;GACnE,SAAS,MAAM;GACf,MAAM,OAAO,MAAM,IAAI;EACzB,EACyB;CAAE;AAC7B;;;;;;;AAQA,SAAgB,mBACd,QACA,UAA2C,CAAC,GACT;CACnC,MAAM,WAAW,OAAO;CAExB,OAAO;EACL,MAAM,QAAQ,QAAQ,SAAS;EAC/B,SAAS,UAAU;GACjB,MAAM,UAAU,SAAS,SAAS,KAAK;GACvC,IAAI,mBAAmB,SACrB,OAAO,QAAQ,MAAM,aACnB,mBACE,QACF,CACF;GAEF,OAAO,mBACL,OACF;EACF;CACF;AACF"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@queryweave/standard-schema",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Standard Schema interoperability contracts for QueryWeave.",
5
+ "keywords": [
6
+ "query",
7
+ "standard-schema",
8
+ "state",
9
+ "url",
10
+ "validation"
11
+ ],
12
+ "homepage": "https://github.com/boussadjra/queryweave#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/boussadjra/queryweave/issues"
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/boussadjra/queryweave.git",
20
+ "directory": "packages/standard-schema"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "provenance": true
39
+ },
40
+ "dependencies": {
41
+ "@standard-schema/spec": "1.1.0",
42
+ "@queryweave/core": "0.1.0-alpha.1"
43
+ },
44
+ "devDependencies": {
45
+ "@queryweave/typescript-config": "0.0.0"
46
+ },
47
+ "engines": {
48
+ "node": ">=24.18.0"
49
+ },
50
+ "scripts": {
51
+ "build": "tsdown",
52
+ "dev": "tsdown --watch",
53
+ "typecheck": "tsc -p tsconfig.json",
54
+ "test:types": "tsc -p tsconfig.json",
55
+ "package:check": "publint --strict && attw --pack . --profile esm-only",
56
+ "clean": "node ../../scripts/clean-package.mjs"
57
+ }
58
+ }