@supersurkhet/sdk
v0.0.1
Published
## Developer experience (today)
Readme
@supersurkhet/sdk
Developer experience (today)
This is the current flow (without auth/project selection yet):
- Scaffold a project:
supersurkhet new my-plugin
cd my-pluginDefine schema docs in
supersurkhet.config.mjs.Generate local TS types from schema docs:
supersurkhet types --config supersurkhet.config.mjs --out supersurkhet/schema.types.ts- Link your local directory to a remote project:
supersurkhet link --project <project-id> --endpoint <api-url> --token <api-token>- Push local schema snapshot to remote project:
supersurkhet sync-up --config supersurkhet.config.mjs- Pull latest snapshot back down:
supersurkhet sync-down --config supersurkhet.config.mjs --out supersurkhet/schema.synced.jsonSDK authoring APIs
Define actions + plugin
import { createActionRegistry, definePlugin, defineSchemaDoc } from '@supersurkhet/sdk';
const actions = createActionRegistry().defineAction({
id: 'product.create',
handler: async (input: { name: string }) => ({ ok: true, input }),
});
const productSchema = defineSchemaDoc({
schemaId: 'product',
fields: [
{
key: 'name',
type: 'string',
dataType: 'string',
fieldType: 'string',
},
{
key: 'price',
type: 'number',
dataType: 'number',
fieldType: 'currency',
},
],
});
export default definePlugin({
pluginId: 'my.plugin',
version: '0.0.1',
actions,
schemaDocs: [productSchema],
});Zod schema conversion (SDK-patched Zod)
import { defineZodSchemaDoc } from '@supersurkhet/sdk';
const schema = defineZodSchemaDoc({
schemaId: 'product',
schema: ({ z }) =>
z
.object({
name: z.string(),
price: z.number().min(0),
})
.withDerivation('isPremium', z.boolean()),
});Realtime-ready schema sync store
import { createSchemaSyncStore } from '@supersurkhet/sdk';
const store = createSchemaSyncStore();
store.subscribe((envelope) => {
console.log(envelope.source, envelope.operations);
});
store.upsert(mySchema, 'cli');