Seed Protocol
@seedprotocol/sdk

Node entry point

What @seedprotocol/sdk/node exports: the Property builders, the schema import helpers, and the Node file manager and database.

@seedprotocol/sdk/node is a smaller entry point than the main one, with a few Node-only helpers. To run the client on Node or in Electron, see Using Seed in Node and Electron; for where filesDir puts data on disk, see Client and configuration. For a Next.js app, use withSeed from @seedprotocol/next.

import { client, Item, Model, Property } from '@seedprotocol/sdk/node'

What ./node exports

@seedprotocol/sdk/node shares its code with the main entry, so the client and classes you get from either are the same objects. It exports less than the main entry, though:

ExportWhat it is
clientThe client singleton. See Client and configuration
Model, Item, ItemProperty, ItemPropertySaveValidationErrorThe same classes as the main entry
ClientNotInitializedError, ResetLocalDataBrowserOnlyError, AmbiguousModelError, ItemCreateError, ItemCreateValidationError, UnknownModelError, ConflictError, OwnershipError, ClearNotSupportedError, EntityUnloadedError, TabLockTimeoutError, OutboxOpFailedError, OutboxSaveTimeoutError, RelationTargetError, StagedValueMissingError, PublishValidationFailedError, RelatedItemUnpublishedError, HtmlEmbeddedDataUriLimitError, HtmlSeedPropertyRefErrorError classes, the same as the main entry's. See Types
entityLoadErrorThe error an instance's last load failed with. See Item
exportArchive, ArchiveExportErrorExport a published item as a BagIt bag. See Export a published item
isItemOwned, assertItemOwnedOwnership checks. See Item
PropertyBuilders for property definitions. See Property builders
importJsonSchema, readJsonImportFile, syncSchemaFromSource, transformImportToSchemaFile, loadSchemaFromFileSchema import helpers. See Schema
NodeFileManagerThe Node file manager class (the main entry's FileManager is the platform-neutral facade instead)
NodeDb, resolveSdkDrizzleMigrationsDirLow-level database setup. client.init does this for you
eventEmitterThe SDK's event bus. See Events
seeds, versions, metadata, models, modelUids, appState, configDrizzle tables (config is only exported here)
getCorrectId, isPublishedSeedRef, normalizeRelationPropertyValue, resolveSeedIdsFromRefStringID and relation helpers
typesMost of the main entry's config, schema and property types and ItemData, plus IItem, IItemProperty, ConflictResult, ItemCreateProblem, ItemCreateErrorCode, PublishValidationError, the exportArchive option and result types, MultiTabMode, SyncFromEasOptions, HtmlEmbeddedDataUriPolicy, JsonImportSchema, SchemaFileFormat and SchemaNameMatch. See Types

importJsonSchema(input, version) uses version only when the JSON has none, and stores a changed minimal file (one without $schema) as the next version. At client.init the SDK applies config.schema and the complete schema files (<id>_<name>_v<n>.json with $schema) in filesDir; a minimal <name>-v<n>.json file there isn't imported.

./node doesn't export Schema, ModelProperty, getClient, BaseDb, ModelPropertyDataTypes, the Arweave link helpers, the publish helpers, or most of the main entry. Import those from @seedprotocol/sdk alongside ./node.

Importing ./node has side effects: it wires up the Node platform services straight away (before client.init) and enables Immer's Map/Set support.

Property builders

Property has one function per data type. Each returns a plain property definition you can pass to Model.create.

Property.Text(storageType?: 'ItemStorage' | 'PropertyStorage', localStorageDir?: string, filenameSuffix?: string)
Property.Number()
Property.Boolean()
Property.Date()
Property.Json()
Property.Image()
Property.File()
Property.Html(opts?: { htmlEmbeddedDataUriPolicy?: 'materialize' | 'preserve' })
Property.List(refValueType: PropertyDataType, ref?: string)
Property.Relation(ref?: string, refValueType?: PropertyDataType, required?: boolean)
import { Model, Property } from '@seedprotocol/sdk/node'
import { Schema } from '@seedprotocol/sdk'

const blog = await Schema.create('blog', { waitForReady: true })

await Model.create('Post', blog, {
  properties: {
    title: Property.Text(),
    body: Property.Html(),
    cover: Property.Image(),
    tags: Property.List('Text'),
    author: Property.Relation('Author'),
  },
})

The result is the same as writing { dataType: 'Text' } and so on by hand, which also works from the main entry. See Model.

The property decorators ./node once exported (Text, Number, Boolean and the rest) are gone; use Property.* with Model.create, or your schema file. See Migration.

On this page