-
-
Notifications
You must be signed in to change notification settings - Fork 0
243 lines (208 loc) · 7.73 KB
/
Copy pathpublish-sdk.yml
File metadata and controls
243 lines (208 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
name: Publish SDK
on:
push:
branches:
- main
paths:
- "src/api/**"
- "tsconfig.api.json"
- ".github/workflows/publish-sdk.yml"
workflow_dispatch:
jobs:
publish-sdk:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout ts-mapped
uses: actions/checkout@v4
with:
path: ts-mapped
- name: Checkout ts-mapped-sdk
uses: actions/checkout@v4
with:
repository: commonknowledge/ts-mapped-sdk
token: ${{ secrets.SDK_REPO_TOKEN }}
path: ts-mapped-sdk
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
working-directory: ts-mapped
run: npm ci
- name: Build API types
working-directory: ts-mapped
run: npm run build:api
- name: Prepare SDK package
run: |
# Clear existing directories in SDK repo
rm -rf ts-mapped-sdk/src
rm -rf ts-mapped-sdk/dist
# Copy built types
mkdir -p ts-mapped-sdk/dist
cp -r ts-mapped/dist/api/* ts-mapped-sdk/dist/
# Copy source types (for reference/debugging)
mkdir -p ts-mapped-sdk/src
cp -r ts-mapped/src/api/* ts-mapped-sdk/src/
# Generate package.json for SDK
cat > ts-mapped-sdk/package.json << 'EOF'
{
"name": "@commonknowledge/ts-mapped-sdk",
"version": "0.0.0",
"description": "TypeScript SDK for the ts-mapped REST API",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist",
"src"
],
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@types/geojson": "^7946.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/commonknowledge/ts-mapped-sdk.git"
},
"homepage": "https://github.com/commonknowledge/ts-mapped",
"license": "MIT",
"keywords": [
"typescript",
"types",
"geojson",
"api",
"sdk",
"mapped"
]
}
EOF
# Generate README
cat > ts-mapped-sdk/README.md << 'EOF'
# ts-mapped SDK
TypeScript SDK for consuming the [ts-mapped](https://github.com/commonknowledge/ts-mapped) REST API.
> **Note:** This package is automatically generated from the ts-mapped repository. Do not edit directly.
## Installation
```bash
npm install github:commonknowledge/ts-mapped-sdk
# or if published to npm:
npm install @commonknowledge/ts-mapped-sdk
```
## Usage
```typescript
import {
type GeoJSONAPIResponse,
type GeoJSONAPIFeature,
type GeoJSONFeatureProperties,
type APIRecordFilter,
type APIRecordSort,
APIFilterOperator,
APIFilterType,
} from '@commonknowledge/ts-mapped-sdk';
// Fetch data with proper typing
async function fetchGeoJSON(dataSourceId: string): Promise<GeoJSONAPIResponse> {
const response = await fetch(
`https://your-instance.com/api/rest/data-sources/${dataSourceId}/geojson`,
{
headers: {
'Authorization': `Basic ${btoa('email:password')}`,
},
}
);
return response.json();
}
// Use enums for filter operators
const filter: APIRecordFilter = {
type: APIFilterType.TEXT,
column: 'name',
search: 'example',
operator: APIFilterOperator.AND,
};
```
## Available Types
- `GeoJSONAPIResponse` - Main response type from the GeoJSON endpoint
- `GeoJSONAPIFeature` - Individual feature in the response
- `GeoJSONFeatureProperties` - Properties object for each feature
- `APIRecordFilter` - Filter configuration for querying
- `APIRecordSort` - Sort configuration
- `APIFilterOperator` - `AND` / `OR` operators (enum)
- `APIFilterType` - `GEO` / `MULTI` / `TEXT` filter types (enum)
- `APIPoint` - Geographic coordinates (lat/lng)
- `APIGeocodeResult` - Geocoding metadata
- `GeoJSONAPIErrorResponse` - Error response structure
## Documentation
For detailed usage examples, see the [API documentation](https://github.com/commonknowledge/ts-mapped/blob/main/src/api/README.md).
## License
MIT
EOF
# Generate tsconfig.json for SDK
cat > ts-mapped-sdk/tsconfig.json << 'EOF'
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
EOF
- name: Get commit info
id: commit-info
working-directory: ts-mapped
run: |
echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "message=$(git log -1 --pretty=%B | head -1)" >> $GITHUB_OUTPUT
- name: Update SDK version
working-directory: ts-mapped-sdk
run: |
# Read current version from the committed SDK package.json (HEAD),
# falling back to the working copy or 0.0.0 if necessary.
if git show HEAD:package.json >/tmp/original_package.json 2>/dev/null; then
CURRENT_VERSION=$(node -p "require('/tmp/original_package.json').version || '0.0.0'")
elif [ -f package.json ]; then
CURRENT_VERSION=$(node -p "require('./package.json').version || '0.0.0'")
else
CURRENT_VERSION="0.0.0"
fi
# Bump patch version
NEW_VERSION=$(echo "$CURRENT_VERSION" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
# Update package.json with new version
node -e "
const pkg = require('./package.json');
pkg.version = '$NEW_VERSION';
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
echo "Updated version from $CURRENT_VERSION to $NEW_VERSION"
- name: Commit and push to SDK repo
working-directory: ts-mapped-sdk
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "chore: sync types from ts-mapped@${{ steps.commit-info.outputs.sha }}" \
-m "Source commit: ${{ steps.commit-info.outputs.message }}" \
-m "Generated from: https://github.com/commonknowledge/ts-mapped/commit/${{ github.sha }}"
git push