Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eidos.space/types

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eidos.space/types - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2118

index.d.ts
declare module "lib/const" {
export enum MsgType {
SetConfig = "SetConfig",
CallFunction = "CallFunction",
SwitchDatabase = "SwitchDatabase",
CreateSpace = "CreateSpace",
Syscall = "Syscall",
Error = "Error",
QueryResp = "QueryResp",
DataUpdateSignal = "DataUpdateSignal",
WebSocketConnected = "WebSocketConnected",
WebSocketDisconnected = "WebSocketDisconnected"
}
export enum MainServiceWorkerMsgType {
SetData = "SetData"
}
export enum EidosDataEventChannelMsgType {
DataUpdateSignalType = "DataUpdateSignalType"
}
export enum DataUpdateSignalType {
Update = "update",
Insert = "insert",
Delete = "delete"
}
export const EidosDataEventChannelName = "eidos-data-event";
export const EidosSharedEnvChannelName = "eidos-shared-env";
export enum MsgType {
SetConfig = "SetConfig",
CallFunction = "CallFunction",
SwitchDatabase = "SwitchDatabase",
CreateSpace = "CreateSpace",
Syscall = "Syscall",
Error = "Error",
QueryResp = "QueryResp",
DataUpdateSignal = "DataUpdateSignal",
WebSocketConnected = "WebSocketConnected",
WebSocketDisconnected = "WebSocketDisconnected",
}
export enum MainServiceWorkerMsgType {
SetData = "SetData",
}
export enum EidosDataEventChannelMsgType {
DataUpdateSignalType = "DataUpdateSignalType",
}
export enum DataUpdateSignalType {
Update = "update",
Insert = "insert",
Delete = "delete",
}
export const EidosDataEventChannelName = "eidos-data-event"
export const EidosSharedEnvChannelName = "eidos-shared-env"
}
declare module "lib/fields/const" {
export enum FieldType {
Number = "number",
Text = "text",
Title = "title",
Checkbox = "checkbox",
Date = "date",
File = "file",
MultiSelect = "multi-select",
Rating = "rating",
Select = "select",
URL = "url",
Formula = "formula",
Link = "link"
}
export enum GridCellKind {
Uri = "uri",
Text = "text",
Image = "image",
RowID = "row-id",
Number = "number",
Bubble = "bubble",
Boolean = "boolean",
Loading = "loading",
Markdown = "markdown",
Drilldown = "drilldown",
Protected = "protected",
Custom = "custom"
}
export enum FieldType {
Number = "number",
Text = "text",
Title = "title",
Checkbox = "checkbox",
Date = "date",
File = "file",
MultiSelect = "multi-select",
Rating = "rating",
Select = "select",
URL = "url",
Formula = "formula",
Link = "link",
}
export enum GridCellKind {
Uri = "uri",
Text = "text",
Image = "image",
RowID = "row-id",
Number = "number",
Bubble = "bubble",
Boolean = "boolean",
Loading = "loading",
Markdown = "markdown",
Drilldown = "drilldown",
Protected = "protected",
Custom = "custom",
}
}
declare module "types/IUIColumn" {
import { FieldType } from "lib/fields/const";
export type IUIColumn<T = any> = {
name: string;
type: FieldType;
table_column_name: string;
table_name: string;
property: T;
};
import { FieldType } from "lib/fields/const"
export type IUIColumn<T = any> = {
name: string
type: FieldType
table_column_name: string
table_name: string
property: T
}
}
declare module "lib/fields/base" {
import { IUIColumn } from "types/IUIColumn";
type UIColumn<P> = Omit<IUIColumn, "property"> & {
property: P;
};
interface IBaseField<T, P, R> {
column: UIColumn<P>;
getCellContent(rawData: any): T;
rawData2JSON(rawData: R): any;
cellData2RawData(cell: T): any;
import { IUIColumn } from "types/IUIColumn"
type UIColumn<P> = Omit<IUIColumn, "property"> & {
property: P
}
interface IBaseField<T, P, R> {
column: UIColumn<P>
getCellContent(rawData: any): T
rawData2JSON(rawData: R): any
cellData2RawData(cell: T): any
}
export abstract class BaseField<T, P, R = string>
implements IBaseField<T, P, R>
{
static type: string
static getDefaultProperty(): {}
/**
* each table column has a corresponding ui column, which stored in the `${ColumnTableName}` table
* we use the ui column to store the column's display name, type, and other ui related information
* different field will have different property
*/
column: UIColumn<P>
constructor(column: UIColumn<P>)
/**
* getCellContent will be called when the cell is rendered
* transform the raw data into the cell content for rendering
* @param rawData this is the raw data stored in the database
*/
abstract getCellContent(rawData: any): T
abstract rawData2JSON(rawData: R): any
abstract cellData2RawData(cell: T): {
rawData: any
shouldUpdateFieldProperty?: boolean
}
export abstract class BaseField<T, P, R = string> implements IBaseField<T, P, R> {
static type: string;
static getDefaultProperty(): {};
/**
* each table column has a corresponding ui column, which stored in the `${ColumnTableName}` table
* we use the ui column to store the column's display name, type, and other ui related information
* different field will have different property
*/
column: UIColumn<P>;
constructor(column: UIColumn<P>);
/**
* getCellContent will be called when the cell is rendered
* transform the raw data into the cell content for rendering
* @param rawData this is the raw data stored in the database
*/
abstract getCellContent(rawData: any): T;
abstract rawData2JSON(rawData: R): any;
abstract cellData2RawData(cell: T): {
rawData: any;
shouldUpdateFieldProperty?: boolean;
};
/**
* every field should have a property, when you create a new field, you should implement this method
* @returns
*/
getDefaultFieldProperty(): P;
text2RawData(text: string): string;
}
/**
* every field should have a property, when you create a new field, you should implement this method
* @returns
*/
getDefaultFieldProperty(): P
text2RawData(text: string): string
}
}
declare module "lib/fields/checkbox" {
import type { BooleanCell } from "@glideapps/glide-data-grid";
import { BaseField } from "lib/fields/base";
type CheckboxProperty = {};
type CheckboxCell = BooleanCell;
export class CheckboxField extends BaseField<CheckboxCell, CheckboxProperty, number> {
static type: string;
rawData2JSON(rawData: number): number;
getCellContent(rawData: number | undefined): CheckboxCell;
cellData2RawData(cell: CheckboxCell): {
rawData: number;
};
import type { BooleanCell } from "@glideapps/glide-data-grid"
import { BaseField } from "lib/fields/base"
type CheckboxProperty = {}
type CheckboxCell = BooleanCell
export class CheckboxField extends BaseField<
CheckboxCell,
CheckboxProperty,
number
> {
static type: string
rawData2JSON(rawData: number): number
getCellContent(rawData: number | undefined): CheckboxCell
cellData2RawData(cell: CheckboxCell): {
rawData: number
}
}
}
declare module "lib/fields/date" {
import type { DatePickerCell } from "@/components/grid/cells/date-picker-cell";
import { BaseField } from "lib/fields/base";
type DateProperty = {};
type DateCell = DatePickerCell;
export class DateField extends BaseField<DateCell, DateProperty, string> {
static type: string;
rawData2JSON(rawData: string): string;
getCellContent(rawData: string | undefined): DateCell;
cellData2RawData(cell: DateCell): {
rawData: any;
};
import type { DatePickerCell } from "@/components/grid/cells/date-picker-cell"
import { BaseField } from "lib/fields/base"
type DateProperty = {}
type DateCell = DatePickerCell
export class DateField extends BaseField<DateCell, DateProperty, string> {
static type: string
rawData2JSON(rawData: string): string
getCellContent(rawData: string | undefined): DateCell
cellData2RawData(cell: DateCell): {
rawData: any
}
}
}
declare module "lib/fields/file" {
import type { FileCell } from "@/components/grid/cells/file/file-cell";
import { BaseField } from "lib/fields/base";
export type FileProperty = {
proxyUrl?: string;
};
export class FileField extends BaseField<FileCell, FileProperty, string> {
static type: string;
rawData2JSON(rawData: string): string;
static getDefaultProperty(): {
proxyUrl: string;
};
/**
* we need to proxy the image to avoid CORS issue. if the image is a remote url, we will proxy it
*/
getProxyData: (data: string[]) => string[];
getCellContent(rawData: string): FileCell;
cellData2RawData(cell: FileCell): {
rawData: any;
};
import type { FileCell } from "@/components/grid/cells/file/file-cell"
import { BaseField } from "lib/fields/base"
export type FileProperty = {
proxyUrl?: string
}
export class FileField extends BaseField<FileCell, FileProperty, string> {
static type: string
rawData2JSON(rawData: string): string
static getDefaultProperty(): {
proxyUrl: string
}
/**
* we need to proxy the image to avoid CORS issue. if the image is a remote url, we will proxy it
*/
getProxyData: (data: string[]) => string[]
getCellContent(rawData: string): FileCell
cellData2RawData(cell: FileCell): {
rawData: any
}
}
}
declare module "lib/fields/formula" {
import type { TextCell } from "@glideapps/glide-data-grid";
import { BaseField } from "lib/fields/base";
export type FormulaProperty = {
formula: string;
};
export class FormulaField extends BaseField<TextCell, FormulaProperty> {
static type: string;
rawData2JSON(rawData: string): string;
getCellContent(rawData: string): TextCell;
cellData2RawData(cell: TextCell): {
rawData: string;
};
import type { TextCell } from "@glideapps/glide-data-grid"
import { BaseField } from "lib/fields/base"
export type FormulaProperty = {
formula: string
}
export class FormulaField extends BaseField<TextCell, FormulaProperty> {
static type: string
rawData2JSON(rawData: string): string
getCellContent(rawData: string): TextCell
cellData2RawData(cell: TextCell): {
rawData: string
}
}
}
declare module "lib/fields/link" {
import { LinkCell } from "@/components/grid/cells/link-cell";
import { BaseField } from "lib/fields/base";
type LinkProperty = {
linkTable: string;
};
export type LinkCellData = {
id: string;
title: string;
img?: string;
};
export class LinkField extends BaseField<LinkCell, LinkProperty> {
static type: string;
rawData2JSON(rawData: string): string;
getCellContent(rawData: LinkCellData[]): LinkCell;
cellData2RawData(cell: LinkCell): {
rawData: any;
};
import { LinkCell } from "@/components/grid/cells/link-cell"
import { BaseField } from "lib/fields/base"
type LinkProperty = {
linkTable: string
}
export type LinkCellData = {
id: string
title: string
img?: string
}
export class LinkField extends BaseField<LinkCell, LinkProperty> {
static type: string
rawData2JSON(rawData: string): string
getCellContent(rawData: LinkCellData[]): LinkCell
cellData2RawData(cell: LinkCell): {
rawData: any
}
}
}
declare module "lib/utils" {
import { type ClassValue } from "clsx";
export { v4 as uuidv4 } from "uuid";
export function cn(...inputs: ClassValue[]): string;
export const hashText: (text: string) => number;
export const checkIsInWorker: () => boolean;
/**
* pathname = /space1/5c5bf8539ee9434aa721560c89f34ed6
* databaseName = space1
* tableId = 5c5bf8539ee9434aa721560c89f34ed6
* tableName = user custom name
* rawTableName = tb_5c5bf8539ee9434aa721560c89f34ed6 (real table name in sqlite)
* @param id
* @returns
*/
export const getRawTableNameById: (id: string) => string;
export const getTableIdByRawTableName: (rawTableName: string) => string;
export const generateColumnName: () => string;
export const getRawDocNameById: (id: string) => string;
export const shortenId: (id: string) => string;
export const extractIdFromShortId: (shortId: string) => string;
export const getToday: () => string;
export const getUuid: () => string;
import { type ClassValue } from "clsx"
export { v4 as uuidv4 } from "uuid"
export function cn(...inputs: ClassValue[]): string
export const hashText: (text: string) => number
export const checkIsInWorker: () => boolean
/**
* pathname = /space1/5c5bf8539ee9434aa721560c89f34ed6
* databaseName = space1
* tableId = 5c5bf8539ee9434aa721560c89f34ed6
* tableName = user custom name
* rawTableName = tb_5c5bf8539ee9434aa721560c89f34ed6 (real table name in sqlite)
* @param id
* @returns
*/
export const getRawTableNameById: (id: string) => string
export const getTableIdByRawTableName: (rawTableName: string) => string
export const generateColumnName: () => string
export const getRawDocNameById: (id: string) => string
export const shortenId: (id: string) => string
export const extractIdFromShortId: (shortId: string) => string
export const getToday: () => string
export const getUuid: () => string
}
declare module "lib/fields/select" {
import type { SelectCell } from "@/components/grid/cells/select-cell";
import { BaseField } from "lib/fields/base";
export type SelectOption = {
id: string;
name: string;
color: string;
};
export type SelectProperty = {
options: SelectOption[];
defaultOption?: string;
};
export class SelectField extends BaseField<SelectCell, SelectProperty> {
static type: string;
static colors: {
name: string;
value: string;
}[];
static defaultColor: string;
static colorNameValueMap: Record<string, string>;
static getColorValue(colorName: string): string;
get options(): SelectOption[];
rawData2JSON(rawData: any): string;
getCellContent(rawData: string): SelectCell;
cellData2RawData(cell: SelectCell): {
rawData: any;
shouldUpdateColumnProperty?: undefined;
} | {
rawData: string;
shouldUpdateColumnProperty: boolean;
};
getDefaultFieldProperty(): {
options: never[];
};
changeOptionName(id: string, newName: string): void;
changeOptionColor(id: string, newColor: string): void;
addOption(name: string): SelectOption[];
deleteOption(id: string): void;
/**
* @param text tag1
* return tag1id
*/
text2RawData(text: string): string;
import type { SelectCell } from "@/components/grid/cells/select-cell"
import { BaseField } from "lib/fields/base"
export type SelectOption = {
id: string
name: string
color: string
}
export type SelectProperty = {
options: SelectOption[]
defaultOption?: string
}
export class SelectField extends BaseField<SelectCell, SelectProperty> {
static type: string
static colors: {
name: string
value: string
}[]
static defaultColor: string
static colorNameValueMap: Record<string, string>
static getColorValue(colorName: string): string
get options(): SelectOption[]
rawData2JSON(rawData: any): string
getCellContent(rawData: string): SelectCell
cellData2RawData(cell: SelectCell):
| {
rawData: any
shouldUpdateColumnProperty?: undefined
}
| {
rawData: string
shouldUpdateColumnProperty: boolean
}
getDefaultFieldProperty(): {
options: never[]
}
changeOptionName(id: string, newName: string): void
changeOptionColor(id: string, newColor: string): void
addOption(name: string): SelectOption[]
deleteOption(id: string): void
/**
* @param text tag1
* return tag1id
*/
text2RawData(text: string): string
}
}
declare module "lib/fields/multi-select" {
import { MultiSelectCell } from "@/components/grid/cells/multi-select-cell";
import { BaseField } from "lib/fields/base";
import { SelectProperty } from "lib/fields/select";
type MultiSelectProperty = SelectProperty;
export class MultiSelectField extends BaseField<MultiSelectCell, MultiSelectProperty, string> {
getDefaultFieldProperty(): MultiSelectProperty;
static type: string;
get type(): string;
get options(): import("@/lib/fields/select").SelectOption[];
addOption(name: string): import("@/lib/fields/select").SelectOption[];
rawData2JSON(rawData: string): string[];
/**
* in database we store the tags as a string, so we need to convert it to an array of strings
* e.g. "tag1,tag2,tag3" => ["tag1", "tag2", "tag3"]
* @param rawData
* @returns
*/
getCellContent(rawData: string): MultiSelectCell;
/**
* @param text tag1,tag2
* return tag1id,tag2id
*/
text2RawData(text: string): string;
cellData2RawData(cell: MultiSelectCell): {
rawData: string;
shouldUpdateColumnProperty: boolean;
};
createFieldProperty(): {
options: never[];
};
import { MultiSelectCell } from "@/components/grid/cells/multi-select-cell"
import { BaseField } from "lib/fields/base"
import { SelectProperty } from "lib/fields/select"
type MultiSelectProperty = SelectProperty
export class MultiSelectField extends BaseField<
MultiSelectCell,
MultiSelectProperty,
string
> {
getDefaultFieldProperty(): MultiSelectProperty
static type: string
get type(): string
get options(): import("@/lib/fields/select").SelectOption[]
addOption(name: string): import("@/lib/fields/select").SelectOption[]
rawData2JSON(rawData: string): string[]
/**
* in database we store the tags as a string, so we need to convert it to an array of strings
* e.g. "tag1,tag2,tag3" => ["tag1", "tag2", "tag3"]
* @param rawData
* @returns
*/
getCellContent(rawData: string): MultiSelectCell
/**
* @param text tag1,tag2
* return tag1id,tag2id
*/
text2RawData(text: string): string
cellData2RawData(cell: MultiSelectCell): {
rawData: string
shouldUpdateColumnProperty: boolean
}
createFieldProperty(): {
options: never[]
}
}
}
declare module "lib/fields/number" {
import type { NumberCell } from "@glideapps/glide-data-grid";
import { BaseField } from "lib/fields/base";
type NumberProperty = {};
export class NumberField extends BaseField<NumberCell, NumberProperty, number> {
static type: string;
rawData2JSON(rawData: number): number;
getCellContent(rawData: number | undefined): NumberCell;
cellData2RawData(cell: NumberCell): {
rawData: number | undefined;
};
import type { NumberCell } from "@glideapps/glide-data-grid"
import { BaseField } from "lib/fields/base"
type NumberProperty = {}
export class NumberField extends BaseField<
NumberCell,
NumberProperty,
number
> {
static type: string
rawData2JSON(rawData: number): number
getCellContent(rawData: number | undefined): NumberCell
cellData2RawData(cell: NumberCell): {
rawData: number | undefined
}
}
}
declare module "lib/fields/rating" {
import type { RatingCell } from "@/components/grid/cells/rating-cell";
import { BaseField } from "lib/fields/base";
type RatingProperty = {};
export class RatingField extends BaseField<RatingCell, RatingProperty, number> {
static type: string;
rawData2JSON(rawData: number): number;
getCellContent(rawData: number): RatingCell;
cellData2RawData(cell: RatingCell): {
rawData: any;
};
import type { RatingCell } from "@/components/grid/cells/rating-cell"
import { BaseField } from "lib/fields/base"
type RatingProperty = {}
export class RatingField extends BaseField<
RatingCell,
RatingProperty,
number
> {
static type: string
rawData2JSON(rawData: number): number
getCellContent(rawData: number): RatingCell
cellData2RawData(cell: RatingCell): {
rawData: any
}
}
}
declare module "lib/fields/text" {
import type { TextCell } from "@glideapps/glide-data-grid";
import { BaseField } from "lib/fields/base";
type TextProperty = {};
export class TextField extends BaseField<TextCell, TextProperty> {
static type: string;
rawData2JSON(rawData: string): string;
getCellContent(rawData: string): TextCell;
cellData2RawData(cell: TextCell): {
rawData: string;
};
import type { TextCell } from "@glideapps/glide-data-grid"
import { BaseField } from "lib/fields/base"
type TextProperty = {}
export class TextField extends BaseField<TextCell, TextProperty> {
static type: string
rawData2JSON(rawData: string): string
getCellContent(rawData: string): TextCell
cellData2RawData(cell: TextCell): {
rawData: string
}
}
}
declare module "lib/fields/title" {
import type { TextCell } from "@glideapps/glide-data-grid";
import { BaseField } from "lib/fields/base";
type TitleProperty = {};
export class TitleField extends BaseField<TextCell, TitleProperty> {
static type: string;
rawData2JSON(rawData: string): string;
getCellContent(rawData: string): TextCell;
cellData2RawData(cell: TextCell): {
rawData: string;
};
import type { TextCell } from "@glideapps/glide-data-grid"
import { BaseField } from "lib/fields/base"
type TitleProperty = {}
export class TitleField extends BaseField<TextCell, TitleProperty> {
static type: string
rawData2JSON(rawData: string): string
getCellContent(rawData: string): TextCell
cellData2RawData(cell: TextCell): {
rawData: string
}
}
}
declare module "lib/fields/url" {
import type { UriCell } from "@glideapps/glide-data-grid";
import { BaseField } from "lib/fields/base";
type URLProperty = {};
type URLCell = UriCell;
export class URLField extends BaseField<URLCell, URLProperty> {
static type: string;
rawData2JSON(rawData: string): string;
getCellContent(rawData: string): URLCell;
cellData2RawData(cell: URLCell): {
rawData: string;
};
import type { UriCell } from "@glideapps/glide-data-grid"
import { BaseField } from "lib/fields/base"
type URLProperty = {}
type URLCell = UriCell
export class URLField extends BaseField<URLCell, URLProperty> {
static type: string
rawData2JSON(rawData: string): string
getCellContent(rawData: string): URLCell
cellData2RawData(cell: URLCell): {
rawData: string
}
}
}
declare module "lib/fields/index" {
import { CheckboxField } from "lib/fields/checkbox";
import { DateField } from "lib/fields/date";
import { FileField } from "lib/fields/file";
import { FormulaField } from "lib/fields/formula";
import { LinkField } from "lib/fields/link";
import { MultiSelectField } from "lib/fields/multi-select";
import { NumberField } from "lib/fields/number";
import { RatingField } from "lib/fields/rating";
import { SelectField } from "lib/fields/select";
import { TextField } from "lib/fields/text";
import { TitleField } from "lib/fields/title";
import { URLField } from "lib/fields/url";
export const allFieldTypes: (typeof DateField | typeof LinkField | typeof MultiSelectField | typeof RatingField)[];
type FieldTypes = typeof CheckboxField | typeof DateField | typeof FileField | typeof MultiSelectField | typeof NumberField | typeof RatingField | typeof SelectField | typeof TextField | typeof TitleField | typeof URLField | typeof FormulaField | typeof LinkField;
export const allFieldTypesMap: Record<string, FieldTypes>;
import { CheckboxField } from "lib/fields/checkbox"
import { DateField } from "lib/fields/date"
import { FileField } from "lib/fields/file"
import { FormulaField } from "lib/fields/formula"
import { LinkField } from "lib/fields/link"
import { MultiSelectField } from "lib/fields/multi-select"
import { NumberField } from "lib/fields/number"
import { RatingField } from "lib/fields/rating"
import { SelectField } from "lib/fields/select"
import { TextField } from "lib/fields/text"
import { TitleField } from "lib/fields/title"
import { URLField } from "lib/fields/url"
export const allFieldTypes: (
| typeof DateField
| typeof LinkField
| typeof MultiSelectField
| typeof RatingField
)[]
type FieldTypes =
| typeof CheckboxField
| typeof DateField
| typeof FileField
| typeof MultiSelectField
| typeof NumberField
| typeof RatingField
| typeof SelectField
| typeof TextField
| typeof TitleField
| typeof URLField
| typeof FormulaField
| typeof LinkField
export const allFieldTypesMap: Record<string, FieldTypes>
}
declare module "lib/log" {
export const logger: Console;
export const EIDOS_VERSION = "0.4.0";
export const logger: Console
export const EIDOS_VERSION = "0.4.0"
}
declare module "lib/sqlite/const" {
/**
* define constance what we will use in sqlite
*/
export const TreeTableName = "eidos__tree";
export const ColumnTableName = "eidos__columns";
export const TodoTableName = "eidos__todo";
export const FileTableName = "eidos__files";
export const DocTableName = "eidos__docs";
export const ActionTableName = "eidos__actions";
export const ScriptTableName = "eidos__scripts";
export const ViewTableName = "eidos__views";
export const EmbeddingTableName = "eidos__embeddings";
/**
* define constance what we will use in sqlite
*/
export const TreeTableName = "eidos__tree"
export const ColumnTableName = "eidos__columns"
export const TodoTableName = "eidos__todo"
export const FileTableName = "eidos__files"
export const DocTableName = "eidos__docs"
export const ActionTableName = "eidos__actions"
export const ScriptTableName = "eidos__scripts"
export const ViewTableName = "eidos__views"
export const EmbeddingTableName = "eidos__embeddings"
}
declare module "lib/sqlite/helper" {
export function isReadOnlySql(sql: string): boolean;
/**
*
* example 1:
*
* const id = 42
* const fieldName = "id"
* buildSql`select ${Symbol(fieldName)} from table where id = ${id}` => { sql: "select id from table where id = ?", bind: [42]}
*
* example 2:
* const table = "books"
* buildSql`select * from ${Symbol(table)}` => { sql: "select * from books", bind: []}
*
* buildSql only return sql and bind, no execute.we need to escape table name, column name, etc.
*
* in example 1, we can use ? placeholder to avoid sql injection
* in example 2, we need to escape table name, column name, etc.
*
* if variable is a Symbol, we don't escape it.
* @param strings
* @param values
* @returns
*/
export function buildSql(strings: TemplateStringsArray, ...values: any[]): {
sql: string;
bind: any[];
};
export const checkSqlIsModifyTableSchema: (sql: string) => boolean;
export const checkSqlIsOnlyQuery: (sql: string) => boolean;
export const checkSqlIsModifyTableData: (sql: string) => boolean;
export function isAggregated(sql: string): boolean;
export const aggregateSql2columns: (sql: string, originFields: string[]) => any;
export const getSqlQueryColumns: (sql: string, originSchema: any) => any;
export const queryData2JSON: (sqlResult: any[][], fields: string[]) => any[];
export const stringify: (obj: any) => any;
export function isReadOnlySql(sql: string): boolean
/**
*
* example 1:
*
* const id = 42
* const fieldName = "id"
* buildSql`select ${Symbol(fieldName)} from table where id = ${id}` => { sql: "select id from table where id = ?", bind: [42]}
*
* example 2:
* const table = "books"
* buildSql`select * from ${Symbol(table)}` => { sql: "select * from books", bind: []}
*
* buildSql only return sql and bind, no execute.we need to escape table name, column name, etc.
*
* in example 1, we can use ? placeholder to avoid sql injection
* in example 2, we need to escape table name, column name, etc.
*
* if variable is a Symbol, we don't escape it.
* @param strings
* @param values
* @returns
*/
export function buildSql(
strings: TemplateStringsArray,
...values: any[]
): {
sql: string
bind: any[]
}
export const checkSqlIsModifyTableSchema: (sql: string) => boolean
export const checkSqlIsOnlyQuery: (sql: string) => boolean
export const checkSqlIsModifyTableData: (sql: string) => boolean
export function isAggregated(sql: string): boolean
export const aggregateSql2columns: (
sql: string,
originFields: string[]
) => any
export const getSqlQueryColumns: (sql: string, originSchema: any) => any
export const queryData2JSON: (sqlResult: any[][], fields: string[]) => any[]
export const stringify: (obj: any) => any
}
declare module "lib/opfs" {
export const getAllSpaceNames: () => Promise<string[]>;
export class OpfsSpaceManager {
list(): Promise<string[]>;
remove(spaceName: string): Promise<void>;
}
export const getSpaceDatabasePath: (spaceName: string) => Promise<string>;
export const getSpaceDatabaseFileHandle: (spaceName: string) => Promise<FileSystemFileHandle>;
export const saveFile: (file: File, space: string, name?: string) => Promise<FileSystemFileHandle>;
export const getAllDays: (spaceName: string) => Promise<any[]>;
export const getDirHandle: (_paths: string[], rootDirHandle?: FileSystemDirectoryHandle) => Promise<FileSystemDirectoryHandle>;
export class OpfsManager {
rootDirHandle: FileSystemDirectoryHandle | undefined;
constructor(rootDirHandle?: FileSystemDirectoryHandle);
getFileUrlByPath: (path: string) => string;
getFileByURL: (url: string) => Promise<File>;
getFileByPath: (path: string) => Promise<File>;
listDir: (_paths: string[]) => Promise<FileSystemFileHandle[]>;
updateDocFile: (_paths: string[], content: string) => Promise<void>;
getFile: (_paths: string[]) => Promise<File>;
getDocContent: (_paths: string[]) => Promise<string>;
addDir: (_paths: string[], dirName: string) => Promise<void>;
addFile: (_paths: string[], file: File, fileId?: string) => Promise<string[] | null>;
deleteEntry: (_paths: string[], isDir?: boolean) => Promise<void>;
renameFile: (_paths: string[], newName: string) => Promise<void>;
}
export const opfsManager: OpfsManager;
export const getAllSpaceNames: () => Promise<string[]>
export class OpfsSpaceManager {
list(): Promise<string[]>
remove(spaceName: string): Promise<void>
}
export const getSpaceDatabasePath: (spaceName: string) => Promise<string>
export const getSpaceDatabaseFileHandle: (
spaceName: string
) => Promise<FileSystemFileHandle>
export const saveFile: (
file: File,
space: string,
name?: string
) => Promise<FileSystemFileHandle>
export const getAllDays: (spaceName: string) => Promise<any[]>
export const getDirHandle: (
_paths: string[],
rootDirHandle?: FileSystemDirectoryHandle
) => Promise<FileSystemDirectoryHandle>
export class OpfsManager {
rootDirHandle: FileSystemDirectoryHandle | undefined
constructor(rootDirHandle?: FileSystemDirectoryHandle)
getFileUrlByPath: (path: string) => string
getFileByURL: (url: string) => Promise<File>
getFileByPath: (path: string) => Promise<File>
listDir: (_paths: string[]) => Promise<FileSystemFileHandle[]>
updateDocFile: (_paths: string[], content: string) => Promise<void>
getFile: (_paths: string[]) => Promise<File>
getDocContent: (_paths: string[]) => Promise<string>
addDir: (_paths: string[], dirName: string) => Promise<void>
addFile: (
_paths: string[],
file: File,
fileId?: string
) => Promise<string[] | null>
deleteEntry: (_paths: string[], isDir?: boolean) => Promise<void>
renameFile: (_paths: string[], newName: string) => Promise<void>
}
export const opfsManager: OpfsManager
}
declare module "worker/DbMigrator" {
import { DataSpace } from "worker/DataSpace";
/**
* auto migrate db schema when db schema changed
*/
export class DbMigrator {
private db;
private draftDb;
private allowDeletions;
constructor(db: DataSpace, draftDb: DataSpace, allowDeletions?: boolean);
private compareTables;
private compareColumns;
private migrateTables;
private migrateTable;
migrate(): void;
}
import { DataSpace } from "worker/DataSpace"
/**
* auto migrate db schema when db schema changed
*/
export class DbMigrator {
private db
private draftDb
private allowDeletions
constructor(db: DataSpace, draftDb: DataSpace, allowDeletions?: boolean)
private compareTables
private compareColumns
private migrateTables
private migrateTable
migrate(): void
}
}
declare module "worker/meta_table/base" {
import { DataSpace } from "worker/DataSpace";
export interface MetaTable<T> {
add(data: T): Promise<T>;
get(id: string): Promise<T | null>;
set(id: string, data: Partial<T>): Promise<boolean>;
del(id: string): Promise<boolean>;
}
export interface BaseTable<T> extends MetaTable<T> {
name: string;
createTableSql: string;
}
export class BaseTableImpl {
protected dataSpace: DataSpace;
constructor(dataSpace: DataSpace);
initTable(createTableSql: string): void;
}
import { DataSpace } from "worker/DataSpace"
export interface MetaTable<T> {
add(data: T): Promise<T>
get(id: string): Promise<T | null>
set(id: string, data: Partial<T>): Promise<boolean>
del(id: string): Promise<boolean>
}
export interface BaseTable<T> extends MetaTable<T> {
name: string
createTableSql: string
}
export class BaseTableImpl {
protected dataSpace: DataSpace
constructor(dataSpace: DataSpace)
initTable(createTableSql: string): void
}
}
declare module "worker/meta_table/action" {
import { BaseTable, BaseTableImpl } from "worker/meta_table/base";
type ParamType = "string" | "number" | "boolean";
interface IFunction {
name: string;
params: {
name: string;
value: any;
}[];
}
export interface IAction {
id: string;
name: string;
params: {
name: string;
type: ParamType;
}[];
nodes: IFunction[];
}
export class ActionTable extends BaseTableImpl implements BaseTable<IAction> {
name: string;
createTableSql: string;
add(data: IAction): Promise<IAction>;
set(id: string, data: IAction): Promise<boolean>;
del(id: string): Promise<boolean>;
get(id: string): Promise<{
id: any;
name: any;
params: any;
nodes: any;
} | null>;
list(): Promise<IAction[]>;
}
import { BaseTable, BaseTableImpl } from "worker/meta_table/base"
type ParamType = "string" | "number" | "boolean"
interface IFunction {
name: string
params: {
name: string
value: any
}[]
}
export interface IAction {
id: string
name: string
params: {
name: string
type: ParamType
}[]
nodes: IFunction[]
}
export class ActionTable extends BaseTableImpl implements BaseTable<IAction> {
name: string
createTableSql: string
add(data: IAction): Promise<IAction>
set(id: string, data: IAction): Promise<boolean>
del(id: string): Promise<boolean>
get(id: string): Promise<{
id: any
name: any
params: any
nodes: any
} | null>
list(): Promise<IAction[]>
}
}
declare module "worker/meta_table/column" {
import { IUIColumn } from "types/IUIColumn";
import { BaseTable, BaseTableImpl } from "worker/meta_table/base";
export class ColumnTable extends BaseTableImpl implements BaseTable<IUIColumn> {
name: string;
createTableSql: string;
add(data: IUIColumn): Promise<IUIColumn>;
get(id: string): Promise<IUIColumn | null>;
set(id: string, data: Partial<IUIColumn>): Promise<boolean>;
del(id: string): Promise<boolean>;
/**
* @param tableName tb_<uuid>
*/
deleteByRawTableName(tableName: string): Promise<void>;
updateProperty(data: {
tableName: string;
tableColumnName: string;
property: any;
isFormula?: boolean;
}): Promise<void>;
list(tableName: string): Promise<IUIColumn[]>;
}
import { IUIColumn } from "types/IUIColumn"
import { BaseTable, BaseTableImpl } from "worker/meta_table/base"
export class ColumnTable
extends BaseTableImpl
implements BaseTable<IUIColumn>
{
name: string
createTableSql: string
add(data: IUIColumn): Promise<IUIColumn>
get(id: string): Promise<IUIColumn | null>
set(id: string, data: Partial<IUIColumn>): Promise<boolean>
del(id: string): Promise<boolean>
/**
* @param tableName tb_<uuid>
*/
deleteByRawTableName(tableName: string): Promise<void>
updateProperty(data: {
tableName: string
tableColumnName: string
property: any
isFormula?: boolean
}): Promise<void>
list(tableName: string): Promise<IUIColumn[]>
}
}
declare module "lib/doc/markdown" {
import { DataSpace } from "worker/DataSpace";
import { CodeHighlightNode, CodeNode } from "@lexical/code";
import { LinkNode } from "@lexical/link";
import { ListItemNode, ListNode } from "@lexical/list";
import { HeadingNode, QuoteNode } from "@lexical/rich-text";
import { TableCellNode, TableNode, TableRowNode } from "@lexical/table";
export const allTransformers: import("@lexical/markdown").Transformer[];
export const AllNodes: (typeof HeadingNode | typeof ListNode | typeof ListItemNode | typeof QuoteNode | typeof CodeNode | typeof CodeHighlightNode | typeof TableNode | typeof TableCellNode | typeof TableRowNode | typeof LinkNode)[];
export const _getDocMarkdown: (sqlite: DataSpace | null, docId: string) => Promise<string>;
export const _convertMarkdown2State: (markdown: string) => Promise<string>;
import { DataSpace } from "worker/DataSpace"
import { CodeHighlightNode, CodeNode } from "@lexical/code"
import { LinkNode } from "@lexical/link"
import { ListItemNode, ListNode } from "@lexical/list"
import { HeadingNode, QuoteNode } from "@lexical/rich-text"
import { TableCellNode, TableNode, TableRowNode } from "@lexical/table"
export const allTransformers: import("@lexical/markdown").Transformer[]
export const AllNodes: (
| typeof HeadingNode
| typeof ListNode
| typeof ListItemNode
| typeof QuoteNode
| typeof CodeNode
| typeof CodeHighlightNode
| typeof TableNode
| typeof TableCellNode
| typeof TableRowNode
| typeof LinkNode
)[]
export const _getDocMarkdown: (
sqlite: DataSpace | null,
docId: string
) => Promise<string>
export const _convertMarkdown2State: (markdown: string) => Promise<string>
}
declare module "worker/meta_table/doc" {
import { BaseTable, BaseTableImpl } from "worker/meta_table/base";
interface IDoc {
id: string;
content: string;
markdown: string;
isDayPage?: boolean;
}
export class DocTable extends BaseTableImpl implements BaseTable<IDoc> {
name: string;
createTableSql: string;
rebuildIndex(refillNullMarkdown?: boolean): Promise<void>;
listAllDayPages(): Promise<{
id: any;
content: any;
}[]>;
listDayPage(page?: number): Promise<{
id: any;
}[]>;
add(data: IDoc): Promise<IDoc>;
get(id: string): Promise<{
id: string;
title: any;
content: any;
markdown: any;
} | null>;
set(id: string, data: IDoc): Promise<boolean>;
del(id: string): Promise<boolean>;
getMarkdown(id: string): Promise<string>;
search(query: string): Promise<{
id: string;
result: string;
}[]>;
createOrUpdateWithMarkdown(id: string, mdStr: string): Promise<{
id: string;
success: boolean;
msg?: undefined;
} | {
id: string;
success: boolean;
msg: string;
}>;
}
import { BaseTable, BaseTableImpl } from "worker/meta_table/base"
interface IDoc {
id: string
content: string
markdown: string
isDayPage?: boolean
}
export class DocTable extends BaseTableImpl implements BaseTable<IDoc> {
name: string
createTableSql: string
rebuildIndex(refillNullMarkdown?: boolean): Promise<void>
listAllDayPages(): Promise<
{
id: any
content: any
}[]
>
listDayPage(page?: number): Promise<
{
id: any
}[]
>
add(data: IDoc): Promise<IDoc>
get(id: string): Promise<{
id: string
title: any
content: any
markdown: any
} | null>
set(id: string, data: IDoc): Promise<boolean>
del(id: string): Promise<boolean>
getMarkdown(id: string): Promise<string>
search(query: string): Promise<
{
id: string
result: string
}[]
>
createOrUpdateWithMarkdown(
id: string,
mdStr: string
): Promise<
| {
id: string
success: boolean
msg?: undefined
}
| {
id: string
success: boolean
msg: string
}
>
}
}
declare module "worker/meta_table/embedding" {
import { BaseTable, BaseTableImpl } from "worker/meta_table/base";
export interface IEmbedding {
id: string;
embedding: string;
model: string;
rawContent: string;
sourceType: "doc" | "table" | "file";
source: string;
}
export class EmbeddingTable extends BaseTableImpl implements BaseTable<IEmbedding> {
name: string;
createTableSql: string;
add(data: IEmbedding): Promise<IEmbedding>;
get(id: string): Promise<IEmbedding | null>;
set(id: string, data: Partial<IEmbedding>): Promise<boolean>;
del(id: string): Promise<boolean>;
}
import { BaseTable, BaseTableImpl } from "worker/meta_table/base"
export interface IEmbedding {
id: string
embedding: string
model: string
rawContent: string
sourceType: "doc" | "table" | "file"
source: string
}
export class EmbeddingTable
extends BaseTableImpl
implements BaseTable<IEmbedding>
{
name: string
createTableSql: string
add(data: IEmbedding): Promise<IEmbedding>
get(id: string): Promise<IEmbedding | null>
set(id: string, data: Partial<IEmbedding>): Promise<boolean>
del(id: string): Promise<boolean>
}
}
declare module "worker/meta_table/file" {
import { BaseTable, BaseTableImpl } from "worker/meta_table/base";
export interface IFile {
id: string;
name: string;
path: string;
size: number;
mime: string;
isVectorized?: boolean;
}
export class FileTable extends BaseTableImpl implements BaseTable<IFile> {
name: string;
createTableSql: string;
saveFile2OPFS(url: string, _name?: string): Promise<IFile | null>;
add(data: IFile): Promise<IFile>;
getFileByPath(path: string): Promise<IFile | null>;
deleteFileByPathPrefix(prefix: string): Promise<boolean>;
updateVectorized(id: string, isVectorized: boolean): Promise<boolean>;
get(id: string): Promise<IFile | null>;
list(): Promise<IFile[]>;
set(id: string, data: Partial<IFile>): Promise<boolean>;
del(id: string): Promise<boolean>;
/**
* get blob url of file
* in script or extension environment we can't access opfs file directly, so we need to use blob url to access it.
* @param id file id
* @returns
*/
getBlobURL(id: string): Promise<string | null>;
}
import { BaseTable, BaseTableImpl } from "worker/meta_table/base"
export interface IFile {
id: string
name: string
path: string
size: number
mime: string
isVectorized?: boolean
}
export class FileTable extends BaseTableImpl implements BaseTable<IFile> {
name: string
createTableSql: string
saveFile2OPFS(url: string, _name?: string): Promise<IFile | null>
add(data: IFile): Promise<IFile>
getFileByPath(path: string): Promise<IFile | null>
deleteFileByPathPrefix(prefix: string): Promise<boolean>
updateVectorized(id: string, isVectorized: boolean): Promise<boolean>
get(id: string): Promise<IFile | null>
list(): Promise<IFile[]>
set(id: string, data: Partial<IFile>): Promise<boolean>
del(id: string): Promise<boolean>
/**
* get blob url of file
* in script or extension environment we can't access opfs file directly, so we need to use blob url to access it.
* @param id file id
* @returns
*/
getBlobURL(id: string): Promise<string | null>
}
}
declare module "worker/meta_table/script" {
import { JsonSchema7ObjectType } from "zod-to-json-schema/src/parsers/object";
import { BaseTable, BaseTableImpl } from "worker/meta_table/base";
export type ScriptStatus = "all" | "enabled" | "disabled";
export interface IScript {
id: string;
name: string;
description: string;
version: string;
code: string;
enabled?: boolean;
inputJSONSchema?: JsonSchema7ObjectType;
outputJSONSchema?: JsonSchema7ObjectType;
tables?: {
name: string;
fields: {
name: string;
type: string;
}[];
}[];
envs?: {
name: string;
type: string;
}[];
envMap?: {
[key: string]: string;
};
fieldsMap?: {
[tableName: string]: {
name: string;
fieldsMap: {
[fieldName: string]: string;
};
};
};
import { JsonSchema7ObjectType } from "zod-to-json-schema/src/parsers/object"
import { BaseTable, BaseTableImpl } from "worker/meta_table/base"
export type ScriptStatus = "all" | "enabled" | "disabled"
export interface IScript {
id: string
name: string
description: string
version: string
code: string
enabled?: boolean
inputJSONSchema?: JsonSchema7ObjectType
outputJSONSchema?: JsonSchema7ObjectType
tables?: {
name: string
fields: {
name: string
type: string
}[]
}[]
envs?: {
name: string
type: string
}[]
envMap?: {
[key: string]: string
}
export class ScriptTable extends BaseTableImpl implements BaseTable<IScript> {
name: string;
createTableSql: string;
add(data: IScript): Promise<IScript>;
set(id: string, data: IScript): Promise<boolean>;
del(id: string): Promise<boolean>;
get(id: string): Promise<IScript | null>;
list(status?: ScriptStatus): Promise<IScript[]>;
enable(id: string): Promise<boolean>;
disable(id: string): Promise<boolean>;
fieldsMap?: {
[tableName: string]: {
name: string
fieldsMap: {
[fieldName: string]: string
}
}
}
}
export class ScriptTable extends BaseTableImpl implements BaseTable<IScript> {
name: string
createTableSql: string
add(data: IScript): Promise<IScript>
set(id: string, data: IScript): Promise<boolean>
del(id: string): Promise<boolean>
get(id: string): Promise<IScript | null>
list(status?: ScriptStatus): Promise<IScript[]>
enable(id: string): Promise<boolean>
disable(id: string): Promise<boolean>
}
}
declare module "worker/meta_table/view" {
import { BaseTable, BaseTableImpl } from "worker/meta_table/base";
export enum ViewTypeEnum {
Grid = "grid",
Gallery = "gallery"
}
export interface IView {
id: string;
name: string;
type: ViewTypeEnum;
tableId: string;
query: string;
}
export class ViewTable extends BaseTableImpl implements BaseTable<IView> {
name: string;
createTableSql: string;
add(data: IView): Promise<IView>;
get(id: string): Promise<IView | null>;
set(id: string, data: Partial<IView>): Promise<boolean>;
del(id: string): Promise<boolean>;
deleteByTableId(tableId: string): Promise<void>;
updateQuery(id: string, query: string): Promise<void>;
list(tableId: string): Promise<IView[]>;
createDefaultView(tableId: string): Promise<IView>;
}
import { BaseTable, BaseTableImpl } from "worker/meta_table/base"
export enum ViewTypeEnum {
Grid = "grid",
Gallery = "gallery",
}
export interface IView {
id: string
name: string
type: ViewTypeEnum
tableId: string
query: string
}
export class ViewTable extends BaseTableImpl implements BaseTable<IView> {
name: string
createTableSql: string
add(data: IView): Promise<IView>
get(id: string): Promise<IView | null>
set(id: string, data: Partial<IView>): Promise<boolean>
del(id: string): Promise<boolean>
deleteByTableId(tableId: string): Promise<void>
updateQuery(id: string, query: string): Promise<void>
list(tableId: string): Promise<IView[]>
createDefaultView(tableId: string): Promise<IView>
}
}
declare module "worker/meta_table/table" {
import { DataSpace } from "worker/DataSpace";
import { MetaTable } from "worker/meta_table/base";
import { IView } from "worker/meta_table/view";
interface ITable {
id: string;
name: string;
views: IView[];
}
export class Table implements MetaTable<ITable> {
protected dataSpace: DataSpace;
constructor(dataSpace: DataSpace);
add(data: ITable): Promise<ITable>;
isExist(id: string): Promise<boolean>;
get(id: string): Promise<ITable | null>;
set(id: string, data: Partial<ITable>): Promise<boolean>;
del(id: string): Promise<boolean>;
}
import { DataSpace } from "worker/DataSpace"
import { MetaTable } from "worker/meta_table/base"
import { IView } from "worker/meta_table/view"
interface ITable {
id: string
name: string
views: IView[]
}
export class Table implements MetaTable<ITable> {
protected dataSpace: DataSpace
constructor(dataSpace: DataSpace)
add(data: ITable): Promise<ITable>
isExist(id: string): Promise<boolean>
get(id: string): Promise<ITable | null>
set(id: string, data: Partial<ITable>): Promise<boolean>
del(id: string): Promise<boolean>
}
}
declare module "worker/meta_table/tree" {
import { BaseTable, BaseTableImpl } from "worker/meta_table/base";
export interface ITreeNode {
id: string;
name: string;
type: "table" | "doc";
parentId?: string;
isPinned?: boolean;
}
export class TreeTable extends BaseTableImpl implements BaseTable<ITreeNode> {
name: string;
createTableSql: string;
add(data: ITreeNode): Promise<ITreeNode>;
get(id: string): Promise<ITreeNode | null>;
updateName(id: string, name: string): Promise<boolean>;
set(id: string, data: ITreeNode): Promise<boolean>;
pin(id: string, isPinned: boolean): Promise<boolean>;
del(id: string): Promise<boolean>;
makeProxyRow(row: any): ITreeNode;
list(query?: string, withSubNode?: boolean): Promise<ITreeNode[]>;
moveIntoTable(id: string, tableId: string): Promise<boolean>;
}
import { BaseTable, BaseTableImpl } from "worker/meta_table/base"
export interface ITreeNode {
id: string
name: string
type: "table" | "doc"
parentId?: string
isPinned?: boolean
}
export class TreeTable extends BaseTableImpl implements BaseTable<ITreeNode> {
name: string
createTableSql: string
add(data: ITreeNode): Promise<ITreeNode>
get(id: string): Promise<ITreeNode | null>
updateName(id: string, name: string): Promise<boolean>
set(id: string, data: ITreeNode): Promise<boolean>
pin(id: string, isPinned: boolean): Promise<boolean>
del(id: string): Promise<boolean>
makeProxyRow(row: any): ITreeNode
list(query?: string, withSubNode?: boolean): Promise<ITreeNode[]>
moveIntoTable(id: string, tableId: string): Promise<boolean>
}
}
declare module "worker/sdk/rows" {
import type { IUIColumn } from "types/IUIColumn";
import { DataSpace } from "worker/DataSpace";
import { TableManager } from "worker/sdk/table";
export class RowsManager {
private table;
dataSpace: DataSpace;
constructor(table: TableManager);
getFieldMap(): Promise<{
fieldRawColumnNameFieldMap: Record<string, IUIColumn>;
fieldNameRawColumnNameMap: Record<string, string>;
}>;
rawData2Json(row: Record<string, any>, fieldRawColumnNameFieldMap: Record<string, IUIColumn>): Record<string, any>;
transformData(data: Record<string, any>, context: {
fieldNameRawColumnNameMap: Record<string, string>;
fieldRawColumnNameFieldMap: Record<string, IUIColumn>;
}, options?: {
noGenerateId?: boolean;
}): {
notExistKeys: string[];
rawData: {
[k: string]: any;
};
};
query(filter?: Record<string, any>, options?: {
limit?: number;
offset?: number;
raw?: boolean;
}): Promise<any[]>;
create(data: Record<string, any>): Promise<{
[k: string]: any;
}>;
delete(id: string): Promise<boolean>;
update(id: string, data: Record<string, any>): Promise<{
_id: string;
}>;
import type { IUIColumn } from "types/IUIColumn"
import { DataSpace } from "worker/DataSpace"
import { TableManager } from "worker/sdk/table"
export class RowsManager {
private table
dataSpace: DataSpace
constructor(table: TableManager)
getFieldMap(): Promise<{
fieldRawColumnNameFieldMap: Record<string, IUIColumn>
fieldNameRawColumnNameMap: Record<string, string>
}>
rawData2Json(
row: Record<string, any>,
fieldRawColumnNameFieldMap: Record<string, IUIColumn>
): Record<string, any>
transformData(
data: Record<string, any>,
context: {
fieldNameRawColumnNameMap: Record<string, string>
fieldRawColumnNameFieldMap: Record<string, IUIColumn>
},
options?: {
noGenerateId?: boolean
}
): {
notExistKeys: string[]
rawData: {
[k: string]: any
}
}
query(
filter?: Record<string, any>,
options?: {
limit?: number
offset?: number
raw?: boolean
}
): Promise<any[]>
create(data: Record<string, any>): Promise<{
[k: string]: any
}>
delete(id: string): Promise<boolean>
update(
id: string,
data: Record<string, any>
): Promise<{
_id: string
}>
}
}
declare module "worker/sdk/table" {
import { DataSpace } from "worker/DataSpace";
import { RowsManager } from "worker/sdk/rows";
export class TableManager {
id: string;
dataSpace: DataSpace;
rawTableName: string;
constructor(id: string, dataSpace: DataSpace);
get rows(): RowsManager;
}
import { DataSpace } from "worker/DataSpace"
import { RowsManager } from "worker/sdk/rows"
export class TableManager {
id: string
dataSpace: DataSpace
rawTableName: string
constructor(id: string, dataSpace: DataSpace)
get rows(): RowsManager
}
}
declare module "worker/sql_undo_redo_v2" {
import { DataSpace } from "worker/DataSpace";
interface StackEntry {
begin: number;
end: number;
}
interface UndoRedoState {
active: boolean;
undostack: StackEntry[];
redostack: StackEntry[];
pending?: any;
firstlog: number;
freeze?: number;
startstate?: unknown;
}
export class SQLiteUndoRedo {
undo: UndoRedoState;
db: DataSpace;
constructor(db: DataSpace);
activate(tables: string[]): void;
deactivate(): void;
freeze(): void;
unfreeze(): void;
event(): void;
barrier(): Promise<void>;
callUndo(): void;
callRedo(): void;
refresh(): void;
reload_all(): void;
private _makeTriggersForTbl;
private createTriggers;
private _drop_triggers;
private _start_interval;
private _step;
}
import { DataSpace } from "worker/DataSpace"
interface StackEntry {
begin: number
end: number
}
interface UndoRedoState {
active: boolean
undostack: StackEntry[]
redostack: StackEntry[]
pending?: any
firstlog: number
freeze?: number
startstate?: unknown
}
export class SQLiteUndoRedo {
undo: UndoRedoState
db: DataSpace
constructor(db: DataSpace)
activate(tables: string[]): void
deactivate(): void
freeze(): void
unfreeze(): void
event(): void
barrier(): Promise<void>
callUndo(): void
callRedo(): void
refresh(): void
reload_all(): void
private _makeTriggersForTbl
private createTriggers
private _drop_triggers
private _start_interval
private _step
}
}
declare module "worker/trigger/data_change_trigger" {
import { DataSpace } from "worker/DataSpace";
type IRegisterTrigger = {
update: string;
insert: string;
delete: string;
};
export class DataChangeTrigger {
triggerMap: Map<string, IRegisterTrigger>;
constructor();
private getRowJSONObj;
registerTrigger(space: string, tableName: string, trigger: IRegisterTrigger): Promise<void>;
isTriggerChanged(space: string, tableName: string, trigger: IRegisterTrigger): boolean;
setTrigger(db: DataSpace, tableName: string, collist: any[], toDeleteColumns?: string[]): Promise<void>;
}
import { DataSpace } from "worker/DataSpace"
type IRegisterTrigger = {
update: string
insert: string
delete: string
}
export class DataChangeTrigger {
triggerMap: Map<string, IRegisterTrigger>
constructor()
private getRowJSONObj
registerTrigger(
space: string,
tableName: string,
trigger: IRegisterTrigger
): Promise<void>
isTriggerChanged(
space: string,
tableName: string,
trigger: IRegisterTrigger
): boolean
setTrigger(
db: DataSpace,
tableName: string,
collist: any[],
toDeleteColumns?: string[]
): Promise<void>
}
}
declare module "worker/udf/index" {
export const twice: {
name: string;
xFunc: (pCx: any, arg: any) => any;
opt: {
deterministic: boolean;
};
};
export const today: {
name: string;
xFunc: (pCx: any) => string;
opt: {
deterministic: boolean;
};
};
export const eidos_data_event_update: {
name: string;
xFunc: (pCx: any, table: any, _new: any, _old: any) => void;
};
export const eidos_data_event_insert: {
name: string;
xFunc: (pCx: any, table: any, _new: any) => void;
};
export const eidos_data_event_delete: {
name: string;
xFunc: (pCx: any, table: any, _old: any) => void;
};
export const ALL_UDF: {
name: string;
xFunc: (pCx: any, table: any, _new: any, _old: any) => void;
}[];
export const twice: {
name: string
xFunc: (pCx: any, arg: any) => any
opt: {
deterministic: boolean
}
}
export const today: {
name: string
xFunc: (pCx: any) => string
opt: {
deterministic: boolean
}
}
export const eidos_data_event_update: {
name: string
xFunc: (pCx: any, table: any, _new: any, _old: any) => void
}
export const eidos_data_event_insert: {
name: string
xFunc: (pCx: any, table: any, _new: any) => void
}
export const eidos_data_event_delete: {
name: string
xFunc: (pCx: any, table: any, _old: any) => void
}
export const ALL_UDF: {
name: string
xFunc: (pCx: any, table: any, _new: any, _old: any) => void
}[]
}
declare module "worker/DataSpace" {
import { Database } from "@sqlite.org/sqlite-wasm";
import { IUIColumn } from "types/IUIColumn";
import { ActionTable } from "worker/meta_table/action";
import { BaseTable } from "worker/meta_table/base";
import { ColumnTable } from "worker/meta_table/column";
import { DocTable } from "worker/meta_table/doc";
import { EmbeddingTable, IEmbedding } from "worker/meta_table/embedding";
import { FileTable, IFile } from "worker/meta_table/file";
import { IScript, ScriptStatus, ScriptTable } from "worker/meta_table/script";
import { Table } from "worker/meta_table/table";
import { ITreeNode, TreeTable } from "worker/meta_table/tree";
import { IView, ViewTable } from "worker/meta_table/view";
import { TableManager } from "worker/sdk/table";
import { SQLiteUndoRedo } from "worker/sql_undo_redo_v2";
import { DataChangeTrigger } from "worker/trigger/data_change_trigger";
export type EidosTable = DocTable | ActionTable | ScriptTable | TreeTable | ViewTable | ColumnTable | EmbeddingTable | FileTable;
export class DataSpace {
db: Database;
draftDb: DataSpace | undefined;
undoRedoManager: SQLiteUndoRedo;
activeUndoManager: boolean;
dbName: string;
doc: DocTable;
action: ActionTable;
script: ScriptTable;
tree: TreeTable;
view: ViewTable;
column: ColumnTable;
embedding: EmbeddingTable;
file: FileTable;
_table: Table;
dataChangeTrigger: DataChangeTrigger;
allTables: BaseTable<any>[];
hasMigrated: boolean;
constructor(db: Database, activeUndoManager: boolean, dbName: string, draftDb?: DataSpace);
private initUDF;
private initMetaTable;
onTableChange(space: string, tableName: string, toDeleteColumns?: string[]): Promise<void>;
addEmbedding(embedding: IEmbedding): Promise<IEmbedding>;
table(id: string): TableManager;
addFile(file: IFile): Promise<IFile>;
getFileById(id: string): Promise<IFile | null>;
getFileByPath(path: string): Promise<IFile | null>;
delFile(id: string): Promise<boolean>;
delFileByPath(path: string): Promise<boolean | undefined>;
deleteFileByPathPrefix(prefix: string): Promise<boolean>;
updateFileVectorized(id: string, isVectorized: boolean): Promise<boolean>;
saveFile2OPFS(url: string, name?: string): Promise<IFile | null>;
listViews(tableId: string): Promise<IView[]>;
addView(view: IView): Promise<IView>;
delView(viewId: string): Promise<boolean>;
updateView(viewId: string, view: Partial<IView>): Promise<boolean>;
createDefaultView(tableId: string): Promise<IView>;
addColumn(data: IUIColumn): Promise<IUIColumn>;
listRawColumns(tableName: string): Promise<{
[columnName: string]: import("@sqlite.org/sqlite-wasm").SqlValue;
}[]>;
updateColumnProperty(data: {
tableName: string;
tableColumnName: string;
property: any;
isFormula?: boolean;
}): Promise<void>;
addRow(tableName: string, data: any): Promise<any[]>;
addAction(data: any): Promise<void>;
listActions(): Promise<import("@/worker/meta_table/action").IAction[]>;
addScript(data: IScript): Promise<void>;
listScripts(status?: ScriptStatus): Promise<IScript[]>;
getScript(id: string): Promise<IScript | null>;
deleteScript(id: string): Promise<void>;
updateScript(data: IScript): Promise<void>;
enableScript(id: string): Promise<void>;
disableScript(id: string): Promise<void>;
rebuildIndex(refillNullMarkdown?: boolean): Promise<void>;
addDoc(docId: string, content: string, markdown: string, isDayPage?: boolean): Promise<void>;
updateDoc(docId: string, content: string, markdown: string, _isDayPage?: boolean): Promise<void>;
getDoc(docId: string): Promise<any>;
getDocMarkdown(docId: string): Promise<string>;
/**
* if you want to create or update a day page, you should pass a day page id. page id is like 2021-01-01
* @param docId
* @param mdStr
* @param parentId
* @returns
*/
createOrUpdateDocWithMarkdown(docId: string, mdStr: string, parentId?: string): Promise<any>;
deleteDoc(docId: string): Promise<void>;
fullTextSearch(query: string): Promise<{
id: string;
result: string;
}[]>;
createTable(id: string, name: string, tableSchema: string): Promise<void>;
isTableExist(id: string): Promise<boolean>;
deleteTable(id: string): Promise<void>;
listDays(page: number): Promise<{
id: any;
}[]>;
listAllDays(): Promise<{
id: any;
content: any;
}[]>;
syncExec2(sql: string, bind?: any[]): any[];
exec2(sql: string, bind?: any[]): Promise<any[]>;
listTreeNodes(q?: string, withSubNode?: boolean): Promise<ITreeNode[]>;
pinNode(id: string, isPinned: boolean): Promise<boolean>;
updateTreeNodeName(id: string, name: string): Promise<any>;
addTreeNode(data: ITreeNode): Promise<ITreeNode>;
getOrCreateTreeNode(data: ITreeNode): Promise<ITreeNode>;
getTreeNode(id: string): Promise<ITreeNode | null>;
moveDraftIntoTable(id: string, tableId: string): Promise<boolean>;
listUiColumns(tableName: string): Promise<IUIColumn[]>;
/**
* this will return all ui columns in this space
* @param tableName
* @returns
*/
listAllUiColumns(): Promise<any[]>;
undo(): void;
redo(): void;
private activeAllTablesUndoRedo;
execute(sql: string, bind?: any[]): {
fetchone: () => any;
fetchall: () => any[];
};
exec(sql: string, bind?: any[]): void;
private execSqlWithBind;
/**
* it's a template string function, to execute sql. safe from sql injection
* table name and column name need to be Symbol, like Symbol('table_name') or Symbol('column_name')
*
* example:
* const tableName = "books"
* const id = 42
* sql`select ${Symbol("title")} from ${Symbol('table_name')} where id = ${id}`.then(logger.info)
* @param strings
* @param values
* @returns
*/
sql(strings: TemplateStringsArray, ...values: any[]): Promise<any[]>;
sql2: (strings: TemplateStringsArray, ...values: any[]) => Promise<any[]>;
sqlQuery: (sql: string, bind?: any[], rowMode?: "object" | "array") => Promise<any[]>;
/**
* Symbol can't be transformed between main thread and worker thread.
* so we need to parse sql in main thread, then call this function. it will equal to call `sql` function in worker thread
* be careful, it just parse sql before, the next logic need to be same with `sql` function
* @param sql
* @param bind
* @returns
*/
sql4mainThread(sql: string, bind?: any[], rowMode?: "object" | "array"): Promise<any[]>;
sql4mainThread2(sql: string, bind?: any[]): Promise<any[]>;
onUpdate(): void;
withTransaction(fn: Function): Promise<any>;
import { Database } from "@sqlite.org/sqlite-wasm"
import { IUIColumn } from "types/IUIColumn"
import { ActionTable } from "worker/meta_table/action"
import { BaseTable } from "worker/meta_table/base"
import { ColumnTable } from "worker/meta_table/column"
import { DocTable } from "worker/meta_table/doc"
import { EmbeddingTable, IEmbedding } from "worker/meta_table/embedding"
import { FileTable, IFile } from "worker/meta_table/file"
import { IScript, ScriptStatus, ScriptTable } from "worker/meta_table/script"
import { Table } from "worker/meta_table/table"
import { ITreeNode, TreeTable } from "worker/meta_table/tree"
import { IView, ViewTable } from "worker/meta_table/view"
import { TableManager } from "worker/sdk/table"
import { SQLiteUndoRedo } from "worker/sql_undo_redo_v2"
import { DataChangeTrigger } from "worker/trigger/data_change_trigger"
export type EidosTable =
| DocTable
| ActionTable
| ScriptTable
| TreeTable
| ViewTable
| ColumnTable
| EmbeddingTable
| FileTable
export class DataSpace {
db: Database
draftDb: DataSpace | undefined
undoRedoManager: SQLiteUndoRedo
activeUndoManager: boolean
dbName: string
doc: DocTable
action: ActionTable
script: ScriptTable
tree: TreeTable
view: ViewTable
column: ColumnTable
embedding: EmbeddingTable
file: FileTable
_table: Table
dataChangeTrigger: DataChangeTrigger
allTables: BaseTable<any>[]
hasMigrated: boolean
constructor(
db: Database,
activeUndoManager: boolean,
dbName: string,
draftDb?: DataSpace
)
private initUDF
private initMetaTable
onTableChange(
space: string,
tableName: string,
toDeleteColumns?: string[]
): Promise<void>
addEmbedding(embedding: IEmbedding): Promise<IEmbedding>
table(id: string): TableManager
addFile(file: IFile): Promise<IFile>
getFileById(id: string): Promise<IFile | null>
getFileByPath(path: string): Promise<IFile | null>
delFile(id: string): Promise<boolean>
delFileByPath(path: string): Promise<boolean | undefined>
deleteFileByPathPrefix(prefix: string): Promise<boolean>
updateFileVectorized(id: string, isVectorized: boolean): Promise<boolean>
saveFile2OPFS(url: string, name?: string): Promise<IFile | null>
listViews(tableId: string): Promise<IView[]>
addView(view: IView): Promise<IView>
delView(viewId: string): Promise<boolean>
updateView(viewId: string, view: Partial<IView>): Promise<boolean>
createDefaultView(tableId: string): Promise<IView>
addColumn(data: IUIColumn): Promise<IUIColumn>
listRawColumns(tableName: string): Promise<
{
[columnName: string]: import("@sqlite.org/sqlite-wasm").SqlValue
}[]
>
updateColumnProperty(data: {
tableName: string
tableColumnName: string
property: any
isFormula?: boolean
}): Promise<void>
addRow(tableName: string, data: any): Promise<any[]>
addAction(data: any): Promise<void>
listActions(): Promise<import("@/worker/meta_table/action").IAction[]>
addScript(data: IScript): Promise<void>
listScripts(status?: ScriptStatus): Promise<IScript[]>
getScript(id: string): Promise<IScript | null>
deleteScript(id: string): Promise<void>
updateScript(data: IScript): Promise<void>
enableScript(id: string): Promise<void>
disableScript(id: string): Promise<void>
rebuildIndex(refillNullMarkdown?: boolean): Promise<void>
addDoc(
docId: string,
content: string,
markdown: string,
isDayPage?: boolean
): Promise<void>
updateDoc(
docId: string,
content: string,
markdown: string,
_isDayPage?: boolean
): Promise<void>
getDoc(docId: string): Promise<any>
getDocMarkdown(docId: string): Promise<string>
/**
* if you want to create or update a day page, you should pass a day page id. page id is like 2021-01-01
* @param docId
* @param mdStr
* @param parentId
* @returns
*/
createOrUpdateDocWithMarkdown(
docId: string,
mdStr: string,
parentId?: string
): Promise<any>
deleteDoc(docId: string): Promise<void>
fullTextSearch(query: string): Promise<
{
id: string
result: string
}[]
>
createTable(id: string, name: string, tableSchema: string): Promise<void>
isTableExist(id: string): Promise<boolean>
deleteTable(id: string): Promise<void>
listDays(page: number): Promise<
{
id: any
}[]
>
listAllDays(): Promise<
{
id: any
content: any
}[]
>
syncExec2(sql: string, bind?: any[]): any[]
exec2(sql: string, bind?: any[]): Promise<any[]>
listTreeNodes(q?: string, withSubNode?: boolean): Promise<ITreeNode[]>
pinNode(id: string, isPinned: boolean): Promise<boolean>
updateTreeNodeName(id: string, name: string): Promise<any>
addTreeNode(data: ITreeNode): Promise<ITreeNode>
getOrCreateTreeNode(data: ITreeNode): Promise<ITreeNode>
getTreeNode(id: string): Promise<ITreeNode | null>
moveDraftIntoTable(id: string, tableId: string): Promise<boolean>
listUiColumns(tableName: string): Promise<IUIColumn[]>
/**
* this will return all ui columns in this space
* @param tableName
* @returns
*/
listAllUiColumns(): Promise<any[]>
undo(): void
redo(): void
private activeAllTablesUndoRedo
execute(
sql: string,
bind?: any[]
): {
fetchone: () => any
fetchall: () => any[]
}
exec(sql: string, bind?: any[]): void
private execSqlWithBind
/**
* it's a template string function, to execute sql. safe from sql injection
* table name and column name need to be Symbol, like Symbol('table_name') or Symbol('column_name')
*
* example:
* const tableName = "books"
* const id = 42
* sql`select ${Symbol("title")} from ${Symbol('table_name')} where id = ${id}`.then(logger.info)
* @param strings
* @param values
* @returns
*/
sql(strings: TemplateStringsArray, ...values: any[]): Promise<any[]>
sql2: (strings: TemplateStringsArray, ...values: any[]) => Promise<any[]>
sqlQuery: (
sql: string,
bind?: any[],
rowMode?: "object" | "array"
) => Promise<any[]>
/**
* Symbol can't be transformed between main thread and worker thread.
* so we need to parse sql in main thread, then call this function. it will equal to call `sql` function in worker thread
* be careful, it just parse sql before, the next logic need to be same with `sql` function
* @param sql
* @param bind
* @returns
*/
sql4mainThread(
sql: string,
bind?: any[],
rowMode?: "object" | "array"
): Promise<any[]>
sql4mainThread2(sql: string, bind?: any[]): Promise<any[]>
onUpdate(): void
withTransaction(fn: Function): Promise<any>
}
}
declare module "worker/sdk/index" {
import { DataSpace as Space } from "worker/DataSpace";
export interface Eidos {
space(space: string): Space;
currentSpace: Space;
}
export interface EidosTable<T = Record<string, string>> {
id: string;
name: string;
fieldsMap: T;
}
import { DataSpace as Space } from "worker/DataSpace"
export interface Eidos {
space(space: string): Space
currentSpace: Space
}
export interface EidosTable<T = Record<string, string>> {
id: string
name: string
fieldsMap: T
}
}
export { Eidos } from "worker/sdk/index"
{
"name": "@eidos.space/types",
"version": "0.0.1",
"version": "0.0.2",
"description": "",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
"index.d.ts"
],

@@ -11,0 +9,0 @@ "keywords": [],

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc