
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
typed-pocketbase
Advanced tools
Add types to the PocketBase JavaScript SDK.
# npm
npm i typed-pocketbase
# pnpm
pnpm i typed-pocketbase
# yarn
yarn add typed-pocketbase
Generate the types:
npx typed-pocketbase --email admin@mail.com --password supersecretpassword -o Database.d.ts
The codegen tool will look for POCKETBASE_EMAIL
and POCKETBASE_PASSWORD
environment variables if the email or password are not passed using cli options.
Create a PocketBase client:
import PocketBase from 'pocketbase';
import { TypedPocketBase } from 'typed-pocketbase';
import { Schema } from './Database';
const db = new TypedPocketBase<Schema>('http://localhost:8090');
Enjoy full type-safety:
import { neq } from 'typed-pocketbase';
db.from('posts').getFullList({
select: {
id: true,
title: true,
content: true,
expand: {
owner: {
username: true
}
}
}
sort: '-date',
filter: neq('content', '')
});
const showId = Math.random() < 0.5;
db.from('posts').getFullList({
select: {
id: showId,
title: true,
content: true
}
});
Use the and
, or
and other utility functions to filter rows:
import { and, or, eq, gte, lt } from 'typed-pocketbase';
// get all posts created in 2022
db.from('posts').getFullList({
// a "manual" filter is a tuple of length 3
filter: and(['date', '<', '2023-01-01'], ['data', '>=', '2022-01-01'])
});
// get all posts expect for those created in 2022
db.from('posts').getFullList({
filter: or(['date', '>=', '2023-01-01'], ['data', '<', '2022-01-01'])
});
// get all posts that were create at '2023-01-01'
db.from('posts').getFullList({ filter: eq('date', '2023-01-01') });
// combine or/and with helpers and manual filters
db.from('posts').getFullList({
filter: or(
//
['date', '>=', '2023-01-01'],
lt('date', '2022-01-01')
)
});
// conditionally filter rows
// falsy values are excluded
db.from('posts').getFullList({
filter: and(
//
gte('date', '2022-01-01'),
!untilNow && lt('date', '2023-01-01')
)
});
// filter for columns in relations
// works up to 6 levels deep, including the top level
db.from('posts').getFullList({
filter: eq('owner.name', 'me')
});
Most filter operators are available as short hand function.
Visit the pocketbase documentation to find out about all filters in the List/Search records
section.
db.from('posts').getFullList({
// sort by descending 'date'
sort: '-date'
});
db.from('posts').getFullList({
// sort by descending 'date' and ascending 'title'
sort: ['-date', '+title']
});
// conditionally sort rows
// falsy values are excluded
db.from('posts').getFullList({
sort: ['-date', sortTitle && '+title']
});
In typed-pocketbase
expanding happens automatically when using select.
db.from('posts').getFullList({
select: {
expand: {
user: true
}
}
});
// select nested columns
db.from('posts').getFullList({
select: {
expand: {
user: {
name: true
avatar: true
}
}
}
});
// nested expand
db.from('posts').getFullList({
select:{
expand: {
user: {
expand: {
profile: true
}
}
}
}
});
Back relation expanding is support aswell:
db.from('user').getFullList({
select: {
expand: {
'posts(user)': {
title: true,
created: true
}
}
}
});
const select = db.from('posts').createSelect({
id: true,
content: true,
owner: true,
collectionName: true,
asd: true,
expand: {
owner: {
username: true,
email: true
}
}
});
const filter = db
.from('posts')
.createFilter(or(eq('content', 'bla'), eq('published', true)));
const sort = db.from('posts').createSort('+id', '-date');
0.1.1
FAQs
Add types to the PocketBase JavaScript SDK
The npm package typed-pocketbase receives a total of 18 weekly downloads. As such, typed-pocketbase popularity was classified as not popular.
We found that typed-pocketbase demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.