pocketbase-zod-schema 0.1.2
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/cli/index.cjs +3383 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +30 -0
- package/dist/cli/index.d.ts +30 -0
- package/dist/cli/index.js +3331 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/migrate.cjs +3380 -0
- package/dist/cli/migrate.cjs.map +1 -0
- package/dist/cli/migrate.d.cts +1 -0
- package/dist/cli/migrate.d.ts +1 -0
- package/dist/cli/migrate.js +3353 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/cli/utils/index.cjs +540 -0
- package/dist/cli/utils/index.cjs.map +1 -0
- package/dist/cli/utils/index.d.cts +232 -0
- package/dist/cli/utils/index.d.ts +232 -0
- package/dist/cli/utils/index.js +487 -0
- package/dist/cli/utils/index.js.map +1 -0
- package/dist/enums.cjs +19 -0
- package/dist/enums.cjs.map +1 -0
- package/dist/enums.d.cts +6 -0
- package/dist/enums.d.ts +6 -0
- package/dist/enums.js +17 -0
- package/dist/enums.js.map +1 -0
- package/dist/index.cjs +4900 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +4726 -0
- package/dist/index.js.map +1 -0
- package/dist/migration/analyzer.cjs +1267 -0
- package/dist/migration/analyzer.cjs.map +1 -0
- package/dist/migration/analyzer.d.cts +186 -0
- package/dist/migration/analyzer.d.ts +186 -0
- package/dist/migration/analyzer.js +1232 -0
- package/dist/migration/analyzer.js.map +1 -0
- package/dist/migration/diff.cjs +557 -0
- package/dist/migration/diff.cjs.map +1 -0
- package/dist/migration/diff.d.cts +291 -0
- package/dist/migration/diff.d.ts +291 -0
- package/dist/migration/diff.js +534 -0
- package/dist/migration/diff.js.map +1 -0
- package/dist/migration/generator.cjs +778 -0
- package/dist/migration/generator.cjs.map +1 -0
- package/dist/migration/generator.d.cts +225 -0
- package/dist/migration/generator.d.ts +225 -0
- package/dist/migration/generator.js +737 -0
- package/dist/migration/generator.js.map +1 -0
- package/dist/migration/index.cjs +3390 -0
- package/dist/migration/index.cjs.map +1 -0
- package/dist/migration/index.d.cts +103 -0
- package/dist/migration/index.d.ts +103 -0
- package/dist/migration/index.js +3265 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/migration/snapshot.cjs +609 -0
- package/dist/migration/snapshot.cjs.map +1 -0
- package/dist/migration/snapshot.d.cts +167 -0
- package/dist/migration/snapshot.d.ts +167 -0
- package/dist/migration/snapshot.js +575 -0
- package/dist/migration/snapshot.js.map +1 -0
- package/dist/migration/utils/index.cjs +672 -0
- package/dist/migration/utils/index.cjs.map +1 -0
- package/dist/migration/utils/index.d.cts +207 -0
- package/dist/migration/utils/index.d.ts +207 -0
- package/dist/migration/utils/index.js +641 -0
- package/dist/migration/utils/index.js.map +1 -0
- package/dist/mutator.cjs +427 -0
- package/dist/mutator.cjs.map +1 -0
- package/dist/mutator.d.cts +190 -0
- package/dist/mutator.d.ts +190 -0
- package/dist/mutator.js +425 -0
- package/dist/mutator.js.map +1 -0
- package/dist/permissions-ZHafVSIx.d.cts +71 -0
- package/dist/permissions-ZHafVSIx.d.ts +71 -0
- package/dist/schema.cjs +430 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +316 -0
- package/dist/schema.d.ts +316 -0
- package/dist/schema.js +396 -0
- package/dist/schema.js.map +1 -0
- package/dist/types-BbTgmg6H.d.cts +91 -0
- package/dist/types-z1Dkjg8m.d.ts +91 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +14 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/user-jS1aYoeD.d.cts +123 -0
- package/dist/user-jS1aYoeD.d.ts +123 -0
- package/package.json +165 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.2](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.1.1...pocketbase-zod-schema-v0.1.2) (2025-12-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* Update Readme ([b1194fe](https://github.com/dastron/pocketbase-zod-schema/commit/b1194fe518b0c124730071e8f91c7aa4111ab8d2))
|
|
9
|
+
* Update README ([526f378](https://github.com/dastron/pocketbase-zod-schema/commit/526f37843ec4cdba0ddae06bf0156447671c1641))
|
|
10
|
+
|
|
11
|
+
## [0.1.1](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.1.0...pocketbase-zod-schema-v0.1.1) (2025-12-19)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* broken tests ([059ae92](https://github.com/dastron/pocketbase-zod-schema/commit/059ae92415c0705fa3c4372a27de98de047d150d))
|
|
17
|
+
* github actions ([2e29d48](https://github.com/dastron/pocketbase-zod-schema/commit/2e29d4894f4ecb70acf0c2a613268df461c64acd))
|
|
18
|
+
* Github Actions ([b0b6a54](https://github.com/dastron/pocketbase-zod-schema/commit/b0b6a54f9cae5e4fb6c573e5bddd9baba682b333))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 dastron
|
|
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,167 @@
|
|
|
1
|
+
# PocketBase Zod Migration Package
|
|
2
|
+
|
|
3
|
+
This is the **published NPM package**: `pocketbase-zod-schema`.
|
|
4
|
+
|
|
5
|
+
If you're here from NPM, you can ignore the monorepo details — everything you need to **install and use** the library/CLI is below.
|
|
6
|
+
|
|
7
|
+
## Structure
|
|
8
|
+
|
|
9
|
+
- `src/` - TypeScript source code
|
|
10
|
+
- `dist/` - Built output (generated by tsup)
|
|
11
|
+
- `package.json` - Package configuration and dependencies
|
|
12
|
+
- `tsconfig.json` - TypeScript configuration
|
|
13
|
+
- `tsup.config.ts` - Build configuration
|
|
14
|
+
- `vitest.config.ts` - Test configuration
|
|
15
|
+
- `.prettierrc` - Code formatting configuration
|
|
16
|
+
- `nodemon.json` - Development server configuration
|
|
17
|
+
- `.npmignore` - Files to exclude from npm package
|
|
18
|
+
|
|
19
|
+
## Installation (NPM)
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install pocketbase-zod-schema
|
|
23
|
+
# or
|
|
24
|
+
yarn add pocketbase-zod-schema
|
|
25
|
+
# or
|
|
26
|
+
pnpm add pocketbase-zod-schema
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### CLI (`pocketbase-migrate`)
|
|
32
|
+
|
|
33
|
+
The package ships a CLI named `pocketbase-migrate`.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# generate migrations from schema changes
|
|
37
|
+
npx pocketbase-migrate generate
|
|
38
|
+
|
|
39
|
+
# show migration status without writing files
|
|
40
|
+
npx pocketbase-migrate status
|
|
41
|
+
|
|
42
|
+
# force generation even if destructive changes are detected
|
|
43
|
+
npx pocketbase-migrate generate --force
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Configuration
|
|
47
|
+
|
|
48
|
+
Create a `pocketbase-migrate.config.js` at your project root:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
export default {
|
|
52
|
+
schema: {
|
|
53
|
+
directory: "./src/schema",
|
|
54
|
+
exclude: ["*.test.ts", "*.spec.ts"],
|
|
55
|
+
},
|
|
56
|
+
migrations: {
|
|
57
|
+
directory: "./pocketbase/pb_migrations",
|
|
58
|
+
format: "js",
|
|
59
|
+
},
|
|
60
|
+
diff: {
|
|
61
|
+
warnOnDelete: true,
|
|
62
|
+
requireForceForDestructive: true,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Defining schemas (Zod)
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { z } from "zod";
|
|
71
|
+
import { baseSchema, withPermissions } from "pocketbase-zod-schema/schema";
|
|
72
|
+
|
|
73
|
+
export const UserInputSchema = z.object({
|
|
74
|
+
name: z.string().min(1),
|
|
75
|
+
email: z.string().email(),
|
|
76
|
+
avatar: z.string().optional(),
|
|
77
|
+
role: z.enum(["user", "admin"]).default("user"),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export const UserSchema = withPermissions(
|
|
81
|
+
baseSchema.extend(UserInputSchema.shape),
|
|
82
|
+
{
|
|
83
|
+
listRule: '@request.auth.id != ""',
|
|
84
|
+
viewRule: '@request.auth.id != ""',
|
|
85
|
+
createRule: "",
|
|
86
|
+
updateRule: "@request.auth.id = id",
|
|
87
|
+
deleteRule: "@request.auth.id = id",
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Programmatic usage
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import {
|
|
96
|
+
parseSchemaFiles,
|
|
97
|
+
compare,
|
|
98
|
+
generate,
|
|
99
|
+
loadSnapshotIfExists,
|
|
100
|
+
} from "pocketbase-zod-schema/migration";
|
|
101
|
+
|
|
102
|
+
const migrationsDir = "./pocketbase/pb_migrations";
|
|
103
|
+
|
|
104
|
+
const currentSchema = await parseSchemaFiles("./src/schema");
|
|
105
|
+
const previousSnapshot = loadSnapshotIfExists({ migrationsPath: migrationsDir });
|
|
106
|
+
|
|
107
|
+
const diff = compare(currentSchema, previousSnapshot);
|
|
108
|
+
const migrationPath = generate(diff, migrationsDir);
|
|
109
|
+
console.log({ migrationPath });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Development (repo contributors)
|
|
113
|
+
|
|
114
|
+
From the root directory, you can run:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Build the package
|
|
118
|
+
yarn build
|
|
119
|
+
|
|
120
|
+
# Run tests
|
|
121
|
+
yarn test
|
|
122
|
+
|
|
123
|
+
# Start development mode
|
|
124
|
+
yarn dev
|
|
125
|
+
|
|
126
|
+
# Format code
|
|
127
|
+
yarn format
|
|
128
|
+
|
|
129
|
+
# Lint code
|
|
130
|
+
yarn lint
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
All commands are proxied through the root package.json to this workspace.
|
|
134
|
+
|
|
135
|
+
## Publishing
|
|
136
|
+
|
|
137
|
+
Publishing is handled by GitHub Actions (Release Please).
|
|
138
|
+
|
|
139
|
+
### Manual publish (maintainers)
|
|
140
|
+
|
|
141
|
+
If you need to publish manually, use the **same command as CI**. It only requires `NPM_TOKEN`.
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
export NPM_TOKEN="***"
|
|
145
|
+
yarn publish:npm
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
If you'd rather keep the token in a local `.env` file (gitignored), you can do:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
echo 'NPM_TOKEN="***"' > .env
|
|
152
|
+
yarn publish:npm:env
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
If your npm org/account requires publish-time 2FA, either:
|
|
156
|
+
|
|
157
|
+
- use an **automation / granular token** configured to bypass 2FA for publishing (recommended for CI), or
|
|
158
|
+
- set a one-time password for local publishing:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
export NPM_OTP="123456"
|
|
162
|
+
yarn publish:npm:env
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Authentication options:
|
|
166
|
+
|
|
167
|
+
- set `NPM_TOKEN` in your shell for the command
|