@palantir/pack.sdkgen.pack-template 0.0.1-beta.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.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2025 Palantir Technologies, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # @palantir/pack.sdkgen.pack-template
2
+
3
+ PACK SDK template for generating TypeScript types and Zod schemas from YAML schema definitions.
4
+
5
+ ## Overview
6
+
7
+ This template generates a TypeScript SDK with:
8
+
9
+ - TypeScript type definitions from YAML schemas
10
+ - Zod schema validators for runtime validation
11
+ - ESM-only module output
12
+ - Prettier and ESLint configuration
13
+ - Full TypeScript strict mode
14
+
15
+ ## Usage
16
+
17
+ ```bash
18
+ # Generate an SDK from YAML schema files
19
+ npx @palantir/pack.sdkgen create my-sdk \
20
+ --template @palantir/pack.sdkgen.pack-template \
21
+ --schema ./path/to/schema.yaml
22
+
23
+ # With a directory of YAML files
24
+ npx @palantir/pack.sdkgen create my-sdk \
25
+ --template @palantir/pack.sdkgen.pack-template \
26
+ --schema ./path/to/schemas/
27
+ ```
28
+
29
+ ## How It Works
30
+
31
+ 1. **Schema Processing**: When you provide a schema via `--schema`, the template copies it to the generated SDK
32
+ 2. **Type Generation**: The `afterGenerate` hook automatically runs `@palantir/pack.document-schema.type-gen` to generate:
33
+ - TypeScript types in `src/types.ts`
34
+ - Zod schemas in `src/schema.ts`
35
+ 3. **SDK Structure**: Creates a complete TypeScript package with build configuration
36
+
37
+ ## Template Architecture
38
+
39
+ ### Hook Execution
40
+
41
+ This template uses an `afterGenerate` hook that runs in the template's Node.js context with access to the template's dependencies. The hook:
42
+
43
+ - Runs as a child process with the template's `node_modules` available
44
+ - Uses `@palantir/pack.document-schema.type-gen` (a dependency of this template) to generate types
45
+ - Only generates types if a schema was provided via the `--schema` flag
46
+
47
+ ### Dependencies
48
+
49
+ The template package has its own dependencies:
50
+
51
+ - `@palantir/pack.document-schema.type-gen` - For generating types and Zod schemas
52
+ - `fs-extra` - For file system operations
53
+
54
+ The generated SDK has minimal runtime dependencies:
55
+
56
+ - `zod` - For runtime schema validation
57
+
58
+ ## Generated SDK Structure
59
+
60
+ ```
61
+ my-sdk/
62
+ ├── src/
63
+ │ ├── index.ts # Re-exports types and schemas
64
+ │ ├── types.ts # Generated TypeScript types
65
+ │ └── schema.ts # Generated Zod schemas
66
+ ├── build/ # Compiled output (after build)
67
+ ├── package.json # ESM-only configuration
68
+ ├── tsconfig.json # TypeScript configuration
69
+ ├── eslint.config.mjs # ESLint flat config
70
+ ├── .prettierrc.json # Prettier configuration
71
+ └── README.md # SDK documentation
72
+ ```
73
+
74
+ ## Schema Format
75
+
76
+ The template supports YAML schemas in the document-schema format:
77
+
78
+ ```yaml
79
+ - local-fragment:
80
+ position:
81
+ x: double
82
+ y: double
83
+
84
+ - add-records:
85
+ Point:
86
+ docs: "A point in 2D space"
87
+ extends: [position]
88
+ fields:
89
+ label: optional<string>
90
+ color: string
91
+
92
+ - add-union:
93
+ Shape:
94
+ circle: Circle
95
+ rectangle: Rectangle
96
+ point: Point
97
+ ```
98
+
99
+ Supported types:
100
+
101
+ - Primitives: `string`, `double`, `boolean`, `int32`, `int64`
102
+ - Collections: `array<T>`, `list<T>`, `map<K, V>`
103
+ - Modifiers: `optional<T>`, `nullable<T>`
104
+ - References: to other defined records
105
+
106
+ ## Development
107
+
108
+ ### Building the Template
109
+
110
+ ```bash
111
+ pnpm build
112
+ pnpm test
113
+ ```
114
+
115
+ ### Testing
116
+
117
+ The template includes tests that verify:
118
+
119
+ - Template configuration
120
+ - File structure
121
+ - Hook execution
122
+ - Type generation
123
+
124
+ ## Compatibility
125
+
126
+ This template requires:
127
+
128
+ - `@palantir/pack.sdkgen` CLI (any version that supports child process hooks)
129
+ - Node.js 18+ (for native ESM support)
130
+ - `@palantir/pack.document-schema.type-gen` for type generation
131
+
132
+ The template specifies its compatible sdkgen version in its `devDependencies`.