@vireocodedev/query 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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -0
  3. package/package.json +52 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vireocodedev
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,104 @@
1
+ # @vireocodedev/query
2
+
3
+ Framework-free query metadata, transport ports, filter compilation, and parameterized SQLite execution for Vireo Starter.
4
+
5
+ The package owns reusable query contracts. An application still owns its entity-key vocabulary, HTTP implementation, database schema, SQL expressions, authorization, cache lifecycle, and product UI.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @vireocodedev/query zod
11
+ ```
12
+
13
+ The package is published publicly on npm; installation requires no registry
14
+ authentication. TypeScript declarations are verified from the packed artifact
15
+ with TypeScript 6, `moduleResolution: "Bundler"`, and `skipLibCheck: false`.
16
+ Relative source maps with embedded source content are published intentionally
17
+ for debugging.
18
+
19
+ The sole peer dependency is `zod >=4.4 <5`. The root entry point is React-free,
20
+ browser-global-free, and worker-safe.
21
+
22
+ React Query integration lives in `@vireocodedev/ui/tanstack-query`:
23
+
24
+ ```bash
25
+ npm install @vireocodedev/ui @tanstack/react-query
26
+ ```
27
+
28
+ ## Public architecture
29
+
30
+ ```text
31
+ application transport
32
+ -> createQueryEngineApi
33
+ -> Zod-validated entity metadata
34
+ -> application cache or createVireoQueryEngineQueries
35
+ -> query-filter JSON
36
+ -> compileQueryFilterWhere / compileSearchTextWhere
37
+ -> createSqliteQueryExecutor
38
+ -> application-owned SQLite worker port
39
+ ```
40
+
41
+ There are no package-global signals or caches. Every API, executor, and config client is instance-scoped.
42
+
43
+ ## Entity metadata and API
44
+
45
+ `createQueryEngineEntitySchemas` builds recursive Zod schemas from an optional application-owned entity-key schema. The default accepts any non-empty string, keeping this package generic while rejecting unusable identifiers.
46
+
47
+ `createQueryEngineApi` accepts a minimal `get(path, options)` port. It validates all responses, encodes dynamic path segments, forwards abort signals, preserves transport and Zod failures, and can optionally retry an application-provided legacy entity key.
48
+
49
+ ```ts
50
+ import { createQueryEngineApi } from "@vireocodedev/query";
51
+ import z from "zod";
52
+
53
+ const api = createQueryEngineApi(fetchAdapter, {
54
+ entityKeySchema: z.enum(["CUSTOMER", "ORDER"]),
55
+ legacyEntityKey: key => (key === "CUSTOMER" ? "customer" : undefined),
56
+ });
57
+ ```
58
+
59
+ ## Filter compilation
60
+
61
+ `bindSqliteSearchColumns` creates one explicit registry for selectable columns, filter fields, and sort expressions. `compileQueryFilterWhere` compiles supported operators into SQL placeholders plus bound values. `compileSearchTextWhere` does the same for free-text search.
62
+
63
+ The compiler fails closed. Malformed JSON, a mismatched entity, unknown fields, duplicate bindings, and invalid typed values throw instead of silently removing restrictions.
64
+
65
+ Application-authored SQL expressions remain trusted configuration. Runtime filter/search values are always returned separately as parameters.
66
+
67
+ ## SQLite execution
68
+
69
+ `createSqliteQueryExecutor` provides paged searches, optional count probing, concurrent-request deduplication, matching-key lookup, timing hooks, and deterministic row mapping over injected execution ports.
70
+
71
+ `executeParameterizedSqliteQuery` and `executeParameterizedSqlitePagedQuery` are worker-side helpers. Pagination is normalized to whole rows before transport and validated again before interpolation into SQL.
72
+
73
+ ## Config persistence
74
+
75
+ `createQueryEngineConfigClient` owns instance-local in-memory fallback state and an injected request transport. `createQueryEngineConfigSqliteRequestHandlers`, `replaceQueryEngineConfig`, and `getQueryEngineConfig` provide the worker-side persistence boundary.
76
+
77
+ Table identifiers, singleton keys, request names, snapshot shape, and persisted JSON are validated. Corrupt storage is reported explicitly and never replaced with an empty configuration.
78
+
79
+ ## React Query integration
80
+
81
+ The optional React adapter belongs to Starter UI because it imports React Query:
82
+
83
+ ```ts
84
+ import { createVireoQueryEngineQueries } from "@vireocodedev/ui/tanstack-query";
85
+
86
+ export const QueryEngineQueries = createVireoQueryEngineQueries(api);
87
+ ```
88
+
89
+ The adapter creates stable query options without mutating global signals. Applications remain free to use another cache or the framework-free API directly.
90
+
91
+ ## Failure semantics
92
+
93
+ - Invalid API response data raises the original Zod error.
94
+ - Transport failures remain transport failures when no legacy retry applies.
95
+ - Aborted requests are never retried.
96
+ - Invalid filter contracts fail closed before SQL execution.
97
+ - Invalid pagination fails before a statement is prepared.
98
+ - Invalid SQLite config identifiers fail synchronously.
99
+ - Malformed or shape-incompatible persisted config raises an error.
100
+ - Duplicate request and filter registrations are rejected.
101
+
102
+ ## Verification and live documentation
103
+
104
+ Package tests cover public schemas, API paths and failures, filter compilation, pagination, config persistence, concurrency, and framework boundaries. The unified Vireo Storybook contains executable examples under **Query Engine**; every displayed source file is the same TypeScript module Storybook executes.
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@vireocodedev/query",
3
+ "version": "0.2.0",
4
+ "description": "Framework-free query schemas, transport ports, and parameterized SQLite execution for Vireo Starter.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/vireocodedev/starter.git",
11
+ "directory": "packages/queryengine"
12
+ },
13
+ "keywords": [
14
+ "queryengine",
15
+ "filters",
16
+ "zod",
17
+ "starter"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ },
25
+ "main": "./dist/index.js",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "scripts": {
32
+ "build": "vite build",
33
+ "dev": "vite build --watch --mode watch",
34
+ "typecheck": "tsc --noEmit -p tsconfig.json",
35
+ "test": "vitest run"
36
+ },
37
+ "peerDependencies": {
38
+ "zod": ">=4.4 <5"
39
+ },
40
+ "devDependencies": {
41
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
42
+ "vite": "^8.2.2",
43
+ "vite-plugin-dts": "^5.0.3",
44
+ "vitest": "^4.1.11",
45
+ "zod": "^4.4.3"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public",
49
+ "provenance": true,
50
+ "registry": "https://registry.npmjs.org"
51
+ }
52
+ }