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:
| Export | What it is |
|---|---|
client | The client singleton. See Client and configuration |
Model, Item, ItemProperty, ItemPropertySaveValidationError | The same classes as the main entry |
ClientNotInitializedError, ResetLocalDataBrowserOnlyError, AmbiguousModelError, ItemCreateError, ItemCreateValidationError, UnknownModelError, ConflictError, OwnershipError, ClearNotSupportedError, EntityUnloadedError, TabLockTimeoutError, OutboxOpFailedError, OutboxSaveTimeoutError, RelationTargetError, StagedValueMissingError, PublishValidationFailedError, RelatedItemUnpublishedError, HtmlEmbeddedDataUriLimitError, HtmlSeedPropertyRefError | Error classes, the same as the main entry's. See Types |
entityLoadError | The error an instance's last load failed with. See Item |
exportArchive, ArchiveExportError | Export a published item as a BagIt bag. See Export a published item |
isItemOwned, assertItemOwned | Ownership checks. See Item |
Property | Builders for property definitions. See Property builders |
importJsonSchema, readJsonImportFile, syncSchemaFromSource, transformImportToSchemaFile, loadSchemaFromFile | Schema import helpers. See Schema |
NodeFileManager | The Node file manager class (the main entry's FileManager is the platform-neutral facade instead) |
NodeDb, resolveSdkDrizzleMigrationsDir | Low-level database setup. client.init does this for you |
eventEmitter | The SDK's event bus. See Events |
seeds, versions, metadata, models, modelUids, appState, config | Drizzle tables (config is only exported here) |
getCorrectId, isPublishedSeedRef, normalizeRelationPropertyValue, resolveSeedIdsFromRefString | ID and relation helpers |
| types | Most 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.
Related
- Using Seed in Node and Electron: install, the working directory, the loader hook, CommonJS and Electron
- Client and configuration: every
SeedConfigoption, and wherefilesDirresolves on Node - Querying:
BaseDb.liveQuery, which polls on Node - Overview and install: all six entry points
Events
The SDK's event bus: how to listen for saves, conflicts, EAS syncs, address changes and file changes, every event name with its payload, and which events reach other tabs.
Types
The TypeScript types and error classes from @seedprotocol/sdk that app code uses, grouped by area, with their gaps and the page that covers each.