The Collect.so SDK for JavaScript and TypeScript
- Automatic Type Inference: Enjoy seamless type safety with automatic TypeScript inference.
- Isomorphic Architecture: Fully compatible with both server and browser environments.
- Zero Dependencies: Lightweight and efficient with no external dependencies.
- No Configuration Needed: Plug-and-play design requires no setup or configuration.
NPM:
npm install @collect.so/javascript-sdk
YARN:
yarn add @collect.so/javascript-sdk
PNPM:
pnmp add @collect.so/javascript-sdk
- Obtain Collect API Token: Grab your API token from the Dashboard.
- Setup Collect Instance: Initialize your Collect instance with obtained token.
- (Optional) Define Data Models: Tailor your data models to fit your needs.
- Manage Your Data: Push, link, fetch, and manage your data effortlessly.
/* ./your-app/src/collect.ts */
import CollectSDK, { CollectModel } from '@collect.so/sdk'
// Setup Collect instance
const Collect = new CollectSDK("API_TOKEN")
// Optionaly define Model
export const UserRepo = new CollectModel(
'USER',
{
name: { type: 'string' },
email: { type: 'string', uniq: true },
verified: { type: 'boolean', default: false },
hobbies: { type: 'string', multiple: true, requiered: false },
rating: { type: 'number', default: 1 },
created: { type: 'datetime', default: () => new Date().toISOString() },
password: { type: 'string' }
},
Collect
)
// Create new Record
const newUser = await UserRepo.create({
name: "John Galt",
email: 'john.g@example.com',
hobbies: ['Programming', 'Hiking'],
password: '********'
})
// Find Records by specific criteria
const matchedUsers = await UserRepo.find({
where: {
email: { $ne: 'john.g@example.com' },
hobbies: { $in: ['Hiking'] },
rating: { $gte: 1.5 }
}
})
You're Awesome! 🚀
Check the Docs and Examples Repository to learn more 🤓
See CONTRIBUTING.md.