@kronor/dtv 4.0.0 → 5.0.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 (35) hide show
  1. package/README.md +6 -0
  2. package/bin/dtv.js +24 -0
  3. package/dist/assets/{index-BktfNqU5.js → index-BCuRRUo9.js} +215 -128
  4. package/dist/cli/dtv.js +512 -0
  5. package/dist/cli/dtv.js.map +1 -0
  6. package/dist/cli/typegen/schemaToTs.js +163 -0
  7. package/dist/cli/typegen/schemaToTs.js.map +1 -0
  8. package/dist/index.es.js +7930 -7750
  9. package/dist/index.html +1 -1
  10. package/dist/types/App.d.ts.map +1 -1
  11. package/dist/types/cli/dtv.d.ts +2 -0
  12. package/dist/types/cli/dtv.d.ts.map +1 -0
  13. package/dist/types/cli/typegen/schemaToTs.d.ts +13 -0
  14. package/dist/types/cli/typegen/schemaToTs.d.ts.map +1 -0
  15. package/dist/types/components/ActionButtons.d.ts +2 -1
  16. package/dist/types/components/ActionButtons.d.ts.map +1 -1
  17. package/dist/types/dsl/columns.d.ts +50 -23
  18. package/dist/types/dsl/columns.d.ts.map +1 -1
  19. package/dist/types/dsl/internal/queryForRow.d.ts +42 -0
  20. package/dist/types/dsl/internal/queryForRow.d.ts.map +1 -0
  21. package/dist/types/framework/actions.d.ts +13 -0
  22. package/dist/types/framework/actions.d.ts.map +1 -1
  23. package/dist/types/framework/column-definition.d.ts +205 -24
  24. package/dist/types/framework/column-definition.d.ts.map +1 -1
  25. package/dist/types/framework/hasura.d.ts +2 -2
  26. package/dist/types/framework/hasura.d.ts.map +1 -1
  27. package/dist/types/framework/native-runtime/index.d.ts +2 -2
  28. package/dist/types/framework/typelevel.d.ts +6 -0
  29. package/dist/types/framework/typelevel.d.ts.map +1 -0
  30. package/dist/types/lib/index.d.ts +2 -0
  31. package/dist/types/lib/index.d.ts.map +1 -1
  32. package/dist/types/typegen/index.d.ts +27 -0
  33. package/dist/types/typegen/index.d.ts.map +1 -0
  34. package/docs/typegen.md +86 -0
  35. package/package.json +18 -5
@@ -12,8 +12,8 @@ export type NativeRuntime = Runtime & {
12
12
  };
13
13
  };
14
14
  export declare const cellRenderers: {
15
- text: ({ data, columnDefinition }: import("../column-definition").CellRendererProps) => string;
16
- json: ({ data }: import("../column-definition").CellRendererProps) => string;
15
+ text: ({ data, columnDefinition }: import("../column-definition").CellRendererProps<Record<string, any>>) => string;
16
+ json: ({ data }: import("../column-definition").CellRendererProps<Record<string, any>>) => string;
17
17
  };
18
18
  export declare const filterTransforms: {
19
19
  autocomplete: {
@@ -0,0 +1,6 @@
1
+ export type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
2
+ export type Simplify<T> = {
3
+ [K in keyof T]: T[K];
4
+ } & {};
5
+ export type EmptyObject = Record<never, never>;
6
+ //# sourceMappingURL=typelevel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typelevel.d.ts","sourceRoot":"","sources":["../../../src/framework/typelevel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CACjC,CAAC,SAAS,OAAO,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAC/C,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,IAAI,GAC1B,CAAC,GACD,KAAK,CAAC;AAEZ,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAC;AAExD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC"}
@@ -4,12 +4,14 @@ export type { AppProps, DTVAPI } from '../App';
4
4
  export type { View } from '../framework/view';
5
5
  export type { Runtime } from '../framework/runtime';
6
6
  export type { ColumnDefinition } from '../framework/column-definition';
7
+ export type { FieldQuery } from '../framework/column-definition';
7
8
  export type { FilterState } from '../framework/state';
8
9
  export type { FilterSchema, FilterField, SuggestionFetcher } from '../framework/filters';
9
10
  export { FilterExpr } from '../dsl/filterExpr';
10
11
  export { FilterControl } from '../dsl/filterControl';
11
12
  export { CellRenderer } from '../dsl/cellRenderer';
12
13
  export { FilterTransform } from '../dsl/filterTransform';
14
+ export { rowType } from '../dsl/columns';
13
15
  export type { UserDataJson } from '../framework/user-data';
14
16
  export type { UserDataLoadAPI, UserDataSaveAPI, UserDataLoadCallback, UserDataSaveCallback } from '../framework/user-data-manager';
15
17
  export type { ActionDefinition, ActionAPI } from '../framework/actions';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,QAAQ,CAAC;AACxC,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG/C,YAAY,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,YAAY,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EACR,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,gCAAgC,CAAC;AACx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AM,wBAAwB,CAAC;AAC3D,YAAY,EACR,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAE/D,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,27 @@
1
+ export type DtvTypegenConfig = {
2
+ schema: {
3
+ endpoint: string;
4
+ headers?: Record<string, string>;
5
+ };
6
+ scan: {
7
+ include: string[];
8
+ exclude?: string[];
9
+ dtvImport?: string;
10
+ };
11
+ output: {
12
+ /**
13
+ * Output file name pattern written next to each view source file.
14
+ *
15
+ * Supported placeholders:
16
+ * - `{viewId}`
17
+ * - `{collectionName}`
18
+ */
19
+ fileNamePattern: string;
20
+ };
21
+ scalars?: Record<string, string>;
22
+ debug?: {
23
+ /** Include original GraphQL type references as comments in generated output. */
24
+ includeGraphqlTypeComments?: boolean;
25
+ };
26
+ };
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/typegen/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG;IAC3B,MAAM,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACpC,CAAC;IAEF,IAAI,EAAE;QACF,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IAEF,MAAM,EAAE;QACJ;;;;;;WAMG;QACH,eAAe,EAAE,MAAM,CAAC;KAC3B,CAAC;IAEF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC,KAAK,CAAC,EAAE;QACJ,gFAAgF;QAChF,0BAA0B,CAAC,EAAE,OAAO,CAAC;KACxC,CAAC;CACL,CAAC"}
@@ -0,0 +1,86 @@
1
+ # DTV Type Generation (CLI)
2
+
3
+ DTV ships with a CLI command for generating TypeScript types from a Hasura GraphQL schema.
4
+
5
+ ## Install / Run
6
+
7
+ When `@kronor/dtv` is installed, it exposes a `dtv` executable:
8
+
9
+ - `dtv typegen -c dtv.config.ts`
10
+
11
+ (You can also run via `npx dtv typegen ...` depending on how you install it.)
12
+
13
+ To scaffold a config file:
14
+
15
+ - `dtv init`
16
+
17
+ ## Configuration
18
+
19
+ The CLI loads a TypeScript config file (recommended) by transpiling it to ESM and importing it.
20
+
21
+ Minimal `dtv.config.ts`:
22
+
23
+ ```ts
24
+ import type { DtvTypegenConfig } from '@kronor/dtv/typegen';
25
+
26
+ const config: DtvTypegenConfig = {
27
+ schema: {
28
+ endpoint: 'https://my-hasura.example.com/v1/graphql',
29
+ headers: {
30
+ // Example:
31
+ // Authorization: `Bearer ${process.env.HASURA_TOKEN}`,
32
+ // 'x-hasura-admin-secret': process.env.HASURA_ADMIN_SECRET ?? '',
33
+ }
34
+ },
35
+
36
+ scan: {
37
+ // Scan TS/TSX files for `DSL.view({ ... })` calls (supports aliased/namespaced imports too)
38
+ include: [
39
+ 'src/**/*.{ts,tsx}'
40
+ ],
41
+ exclude: [
42
+ '**/*.test.*',
43
+ '**/node_modules/**'
44
+ ],
45
+
46
+ // Optional override if you re-export DTV under a different specifier.
47
+ // dtvImport: '@kronor/dtv'
48
+ },
49
+
50
+ output: {
51
+ // File name written next to each view module that calls DSL.view(...)
52
+ // Supported placeholders: {viewId}, {collectionName}
53
+ fileNamePattern: 'dtv.generated.{viewId}.ts'
54
+ },
55
+
56
+ // Optional scalar overrides: GraphQL scalar name -> TS type
57
+ scalars: {
58
+ // DateTime: 'string'
59
+ // json: 'unknown'
60
+ // jsonb: 'unknown'
61
+ },
62
+
63
+ debug: {
64
+ // When true, include original GraphQL type refs as comments
65
+ includeGraphqlTypeComments: false
66
+ }
67
+ };
68
+
69
+ export default config;
70
+ ```
71
+
72
+ ## Output
73
+
74
+ For each discovered `DSL.view({ id, collectionName, ... })` call, the generator writes one file next to the view source file, named by `output.fileNamePattern`.
75
+
76
+ That file contains:
77
+
78
+ - TypeScript types for GraphQL output types reachable from the view’s `collectionName` row type (not exported)
79
+ - One exported alias:
80
+ - `<ViewIdPascal>Row` – the inferred row type for that view’s `collectionName`
81
+
82
+ ## Current limitations (v1)
83
+
84
+ - Only TS-authored views are considered. The scanner looks specifically for `DSL.view({ ... })` calls.
85
+ - `id` and `collectionName` must be string literals in the call argument.
86
+ - JSON views are not part of this flow yet.
package/package.json CHANGED
@@ -1,15 +1,21 @@
1
1
  {
2
2
  "name": "@kronor/dtv",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "type": "module",
5
+ "bin": {
6
+ "dtv": "./bin/dtv.js"
7
+ },
5
8
  "files": [
9
+ "bin",
6
10
  "dist",
7
11
  "docs"
8
12
  ],
9
13
  "scripts": {
10
14
  "dev": "vite",
11
15
  "build": "tsc -b && vite build",
12
- "build:lib": "tsc -p tsconfig.lib.json && vite build --config vite.lib.config.ts",
16
+ "build:cli": "tsc -p tsconfig.cli.json",
17
+ "build:lib": "npm run build:cli && tsc -p tsconfig.lib.json && vite build --config vite.lib.config.ts",
18
+ "prepack": "npm run build:lib",
13
19
  "dev:playground": "npm run build:lib -- --watch & vite --config vite.playground.config.ts",
14
20
  "clean": "rimraf dist",
15
21
  "lint": "eslint .",
@@ -25,6 +31,10 @@
25
31
  ".": {
26
32
  "types": "./dist/types/lib/index.d.ts",
27
33
  "import": "./dist/index.es.js"
34
+ },
35
+ "./typegen": {
36
+ "types": "./dist/types/typegen/index.d.ts",
37
+ "default": "./dist/index.es.js"
28
38
  }
29
39
  },
30
40
  "main": "./dist/index.es.js",
@@ -35,12 +45,17 @@
35
45
  "react-dom": "^19.0.0"
36
46
  },
37
47
  "dependencies": {
48
+ "commander": "^14.0.0",
49
+ "fast-glob": "^3.3.3",
50
+ "graphql": "^16.11.0",
38
51
  "graphql-request": "^7.1.2",
39
52
  "primeicons": "^7.0.0",
40
53
  "primereact": "^10.9.5",
41
54
  "react": "^19.0.0",
42
55
  "react-dom": "^19.0.0",
43
- "tailwindcss": "^4.1.1"
56
+ "tailwindcss": "^4.1.1",
57
+ "tsx": "^4.20.5",
58
+ "typescript": "~5.7.2"
44
59
  },
45
60
  "devDependencies": {
46
61
  "@eslint/js": "^9.21.0",
@@ -61,8 +76,6 @@
61
76
  "jest-environment-jsdom": "^30.0.4",
62
77
  "rimraf": "^5.0.5",
63
78
  "ts-jest": "^29.4.0",
64
- "tsx": "^4.20.5",
65
- "typescript": "~5.7.2",
66
79
  "typescript-eslint": "^8.24.1",
67
80
  "vite": "^6.2.0",
68
81
  "vite-plugin-css-injected-by-js": "^3.5.2"