js-bao 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.cjs +382 -143
- package/dist/browser.d.cts +127 -5
- package/dist/browser.d.ts +127 -5
- package/dist/browser.js +380 -141
- package/dist/client.cjs +16 -11
- package/dist/client.d.cts +3 -1
- package/dist/client.d.ts +3 -1
- package/dist/client.js +16 -11
- package/dist/cloudflare-do.cjs +937 -286
- package/dist/cloudflare-do.d.cts +517 -15
- package/dist/cloudflare-do.d.ts +517 -15
- package/dist/cloudflare-do.js +928 -286
- package/dist/cloudflare.cjs +573 -18
- package/dist/cloudflare.d.cts +147 -2
- package/dist/cloudflare.d.ts +147 -2
- package/dist/cloudflare.js +573 -18
- package/dist/codegen.cjs +7 -15
- package/dist/index.cjs +32 -154
- package/dist/index.d.cts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +32 -152
- package/dist/node.cjs +404 -151
- package/dist/node.d.cts +132 -5
- package/dist/node.d.ts +132 -5
- package/dist/node.js +390 -145
- package/package.json +6 -6
package/dist/browser.d.cts
CHANGED
|
@@ -663,9 +663,6 @@ declare class ModelRegistry {
|
|
|
663
663
|
private validateSessionModels;
|
|
664
664
|
}
|
|
665
665
|
|
|
666
|
-
declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
|
|
667
|
-
declare function Model(options: ModelOptions): (targetClass: Function) => void;
|
|
668
|
-
|
|
669
666
|
interface SQLJSEngineOptions {
|
|
670
667
|
wasmURL?: string;
|
|
671
668
|
locateFile?: (file: string) => string;
|
|
@@ -751,7 +748,7 @@ interface InitJsBaoOptions {
|
|
|
751
748
|
/**
|
|
752
749
|
* Optional array of model classes to initialize.
|
|
753
750
|
* If not provided, the ORM will rely on models being registered
|
|
754
|
-
* via
|
|
751
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
755
752
|
*/
|
|
756
753
|
models?: (typeof BaseModel)[];
|
|
757
754
|
}
|
|
@@ -875,4 +872,129 @@ type HasManyThroughMethod<T> = (options?: PaginationOptions) => Promise<Paginate
|
|
|
875
872
|
type AddRelationMethod<T> = (target: T | string) => Promise<void>;
|
|
876
873
|
type RemoveRelationMethod<T> = (target: T | string) => Promise<void>;
|
|
877
874
|
|
|
878
|
-
|
|
875
|
+
/**
|
|
876
|
+
* YDoc Schema Discovery
|
|
877
|
+
*
|
|
878
|
+
* Reads _meta_* YMaps from a YDoc and returns a plain JSON description
|
|
879
|
+
* of the schema. Works with any YDoc — no BaseModel or database needed.
|
|
880
|
+
*
|
|
881
|
+
* Usage:
|
|
882
|
+
* import { discoverSchema } from "js-bao";
|
|
883
|
+
* const schema = discoverSchema(yDoc);
|
|
884
|
+
*/
|
|
885
|
+
|
|
886
|
+
interface DiscoveredField {
|
|
887
|
+
type: string;
|
|
888
|
+
indexed?: boolean;
|
|
889
|
+
unique?: boolean;
|
|
890
|
+
required?: boolean;
|
|
891
|
+
default?: string | number | boolean;
|
|
892
|
+
autoAssign?: boolean;
|
|
893
|
+
maxLength?: number;
|
|
894
|
+
maxCount?: number;
|
|
895
|
+
}
|
|
896
|
+
interface DiscoveredConstraint {
|
|
897
|
+
type: string;
|
|
898
|
+
fields: string[];
|
|
899
|
+
}
|
|
900
|
+
interface DiscoveredRelationship {
|
|
901
|
+
type: string;
|
|
902
|
+
model: string;
|
|
903
|
+
[key: string]: any;
|
|
904
|
+
}
|
|
905
|
+
interface DiscoveredModel {
|
|
906
|
+
fields: Record<string, DiscoveredField>;
|
|
907
|
+
constraints?: Record<string, DiscoveredConstraint>;
|
|
908
|
+
relationships?: Record<string, DiscoveredRelationship>;
|
|
909
|
+
}
|
|
910
|
+
interface DiscoveredSchema {
|
|
911
|
+
models: Record<string, DiscoveredModel>;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Discover the schema embedded in a YDoc by reading its `_meta_*` maps.
|
|
915
|
+
*
|
|
916
|
+
* Returns a plain JSON object describing every model that has metadata.
|
|
917
|
+
* Does not require BaseModel, a database, or any schema registration —
|
|
918
|
+
* just a Y.Doc.
|
|
919
|
+
*/
|
|
920
|
+
declare function discoverSchema(yDoc: Y.Doc): DiscoveredSchema;
|
|
921
|
+
/**
|
|
922
|
+
* List model names that have data in the YDoc (non-`_` prefixed top-level maps).
|
|
923
|
+
*/
|
|
924
|
+
declare function discoverModelNames(yDoc: Y.Doc): string[];
|
|
925
|
+
/**
|
|
926
|
+
* Convert a DiscoveredSchema to a TOML string matching the js-bao
|
|
927
|
+
* schema format.
|
|
928
|
+
*
|
|
929
|
+
* Usage:
|
|
930
|
+
* const schema = discoverSchema(yDoc);
|
|
931
|
+
* const toml = schemaToToml(schema);
|
|
932
|
+
*/
|
|
933
|
+
declare function schemaToToml(schema: DiscoveredSchema): string;
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* TOML Schema Loader
|
|
937
|
+
*
|
|
938
|
+
* Parses a TOML schema file and returns an array of DefinedModelSchema
|
|
939
|
+
* objects. Can be used in place of manual `defineModelSchema()` calls.
|
|
940
|
+
*
|
|
941
|
+
* TOML conventions:
|
|
942
|
+
* - Property names are snake_case (auto_assign, max_count, …)
|
|
943
|
+
* - Model names and field names are as-is (user-chosen)
|
|
944
|
+
* - Relationships live under [models.*.relationships.*]
|
|
945
|
+
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
946
|
+
*/
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* Parse a TOML string and return an array of DefinedModelSchema objects.
|
|
950
|
+
*/
|
|
951
|
+
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
|
955
|
+
*
|
|
956
|
+
* Each model with data in a YDoc gets a `_meta_{modelName}` YMap that
|
|
957
|
+
* describes the model's fields, constraints, and relationships. This
|
|
958
|
+
* lets any language that can read a YDoc discover the schema without
|
|
959
|
+
* external configuration.
|
|
960
|
+
*
|
|
961
|
+
* Two modes:
|
|
962
|
+
* 1. **Schema-aware** — full schema known (from defineModelSchema / TOML).
|
|
963
|
+
* Writes field metadata, constraints, and relationships.
|
|
964
|
+
* 2. **Infer-on-write** — no schema. Infers types from record values.
|
|
965
|
+
*/
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Infer a _meta_ type string from a JS runtime value.
|
|
969
|
+
*/
|
|
970
|
+
declare function inferFieldType(value: unknown): "string" | "number" | "boolean" | "stringset" | null;
|
|
971
|
+
/**
|
|
972
|
+
* Register a named function default so metaSync can encode it.
|
|
973
|
+
* Called once per known default generator.
|
|
974
|
+
*/
|
|
975
|
+
declare function registerFunctionDefault(fn: Function, name: string): void;
|
|
976
|
+
/**
|
|
977
|
+
* Clear the sync cache for a specific doc (or all docs).
|
|
978
|
+
* Useful for testing or when schema changes at runtime.
|
|
979
|
+
*/
|
|
980
|
+
declare function clearMetaSyncCache(yDoc?: Y.Doc): void;
|
|
981
|
+
/**
|
|
982
|
+
* Sync full schema metadata into `_meta_{modelName}` inside a YDoc.
|
|
983
|
+
*
|
|
984
|
+
* Call this inside an existing `yDoc.transact()`. Y.Map `.set()` on
|
|
985
|
+
* identical values is a CRDT no-op so there is no overhead after the
|
|
986
|
+
* first write.
|
|
987
|
+
*
|
|
988
|
+
* Skips the sync if this (yDoc, modelName) pair has already been synced
|
|
989
|
+
* in the current session.
|
|
990
|
+
*/
|
|
991
|
+
declare function syncModelMeta(yDoc: Y.Doc, modelName: string, schema: ModelSchemaRuntimeShape): void;
|
|
992
|
+
/**
|
|
993
|
+
* Infer-on-write: when no schema is available, infer field types from
|
|
994
|
+
* the record data and write minimal _meta_.
|
|
995
|
+
*
|
|
996
|
+
* Call inside an existing `yDoc.transact()`.
|
|
997
|
+
*/
|
|
998
|
+
declare function syncInferredMeta(yDoc: Y.Doc, modelName: string, recordData: Record<string, any>): void;
|
|
999
|
+
|
|
1000
|
+
export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineType, BrowserDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type FieldOptions, type FieldType, type GroupByField, type HasManyMethod, type HasManyThroughMethod, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type PaginatedResult, type PaginationOptions, RecordNotFoundError, type RefersToMethod, type RegisteredModelInfo, type RemoveRelationMethod, type SQLJSEngineOptions, type Schema, SqljsEngine, type SqljsEngineOptions, StringSet, type StringSetMembership, type UniqueConstraintConfig, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, createModelClass, defineModelSchema, detectEnvironment, discoverModelNames, discoverSchema, features, generateULID, inferFieldType, initJsBao, isBrowser, isNode, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, syncInferredMeta, syncModelMeta };
|
package/dist/browser.d.ts
CHANGED
|
@@ -663,9 +663,6 @@ declare class ModelRegistry {
|
|
|
663
663
|
private validateSessionModels;
|
|
664
664
|
}
|
|
665
665
|
|
|
666
|
-
declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
|
|
667
|
-
declare function Model(options: ModelOptions): (targetClass: Function) => void;
|
|
668
|
-
|
|
669
666
|
interface SQLJSEngineOptions {
|
|
670
667
|
wasmURL?: string;
|
|
671
668
|
locateFile?: (file: string) => string;
|
|
@@ -751,7 +748,7 @@ interface InitJsBaoOptions {
|
|
|
751
748
|
/**
|
|
752
749
|
* Optional array of model classes to initialize.
|
|
753
750
|
* If not provided, the ORM will rely on models being registered
|
|
754
|
-
* via
|
|
751
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
755
752
|
*/
|
|
756
753
|
models?: (typeof BaseModel)[];
|
|
757
754
|
}
|
|
@@ -875,4 +872,129 @@ type HasManyThroughMethod<T> = (options?: PaginationOptions) => Promise<Paginate
|
|
|
875
872
|
type AddRelationMethod<T> = (target: T | string) => Promise<void>;
|
|
876
873
|
type RemoveRelationMethod<T> = (target: T | string) => Promise<void>;
|
|
877
874
|
|
|
878
|
-
|
|
875
|
+
/**
|
|
876
|
+
* YDoc Schema Discovery
|
|
877
|
+
*
|
|
878
|
+
* Reads _meta_* YMaps from a YDoc and returns a plain JSON description
|
|
879
|
+
* of the schema. Works with any YDoc — no BaseModel or database needed.
|
|
880
|
+
*
|
|
881
|
+
* Usage:
|
|
882
|
+
* import { discoverSchema } from "js-bao";
|
|
883
|
+
* const schema = discoverSchema(yDoc);
|
|
884
|
+
*/
|
|
885
|
+
|
|
886
|
+
interface DiscoveredField {
|
|
887
|
+
type: string;
|
|
888
|
+
indexed?: boolean;
|
|
889
|
+
unique?: boolean;
|
|
890
|
+
required?: boolean;
|
|
891
|
+
default?: string | number | boolean;
|
|
892
|
+
autoAssign?: boolean;
|
|
893
|
+
maxLength?: number;
|
|
894
|
+
maxCount?: number;
|
|
895
|
+
}
|
|
896
|
+
interface DiscoveredConstraint {
|
|
897
|
+
type: string;
|
|
898
|
+
fields: string[];
|
|
899
|
+
}
|
|
900
|
+
interface DiscoveredRelationship {
|
|
901
|
+
type: string;
|
|
902
|
+
model: string;
|
|
903
|
+
[key: string]: any;
|
|
904
|
+
}
|
|
905
|
+
interface DiscoveredModel {
|
|
906
|
+
fields: Record<string, DiscoveredField>;
|
|
907
|
+
constraints?: Record<string, DiscoveredConstraint>;
|
|
908
|
+
relationships?: Record<string, DiscoveredRelationship>;
|
|
909
|
+
}
|
|
910
|
+
interface DiscoveredSchema {
|
|
911
|
+
models: Record<string, DiscoveredModel>;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Discover the schema embedded in a YDoc by reading its `_meta_*` maps.
|
|
915
|
+
*
|
|
916
|
+
* Returns a plain JSON object describing every model that has metadata.
|
|
917
|
+
* Does not require BaseModel, a database, or any schema registration —
|
|
918
|
+
* just a Y.Doc.
|
|
919
|
+
*/
|
|
920
|
+
declare function discoverSchema(yDoc: Y.Doc): DiscoveredSchema;
|
|
921
|
+
/**
|
|
922
|
+
* List model names that have data in the YDoc (non-`_` prefixed top-level maps).
|
|
923
|
+
*/
|
|
924
|
+
declare function discoverModelNames(yDoc: Y.Doc): string[];
|
|
925
|
+
/**
|
|
926
|
+
* Convert a DiscoveredSchema to a TOML string matching the js-bao
|
|
927
|
+
* schema format.
|
|
928
|
+
*
|
|
929
|
+
* Usage:
|
|
930
|
+
* const schema = discoverSchema(yDoc);
|
|
931
|
+
* const toml = schemaToToml(schema);
|
|
932
|
+
*/
|
|
933
|
+
declare function schemaToToml(schema: DiscoveredSchema): string;
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* TOML Schema Loader
|
|
937
|
+
*
|
|
938
|
+
* Parses a TOML schema file and returns an array of DefinedModelSchema
|
|
939
|
+
* objects. Can be used in place of manual `defineModelSchema()` calls.
|
|
940
|
+
*
|
|
941
|
+
* TOML conventions:
|
|
942
|
+
* - Property names are snake_case (auto_assign, max_count, …)
|
|
943
|
+
* - Model names and field names are as-is (user-chosen)
|
|
944
|
+
* - Relationships live under [models.*.relationships.*]
|
|
945
|
+
* - Compound unique constraints are [[models.*.unique_constraints]]
|
|
946
|
+
*/
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* Parse a TOML string and return an array of DefinedModelSchema objects.
|
|
950
|
+
*/
|
|
951
|
+
declare function loadSchemaFromTomlString(tomlString: string): DefinedModelSchema[];
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* Meta Sync — writes _meta_* YMaps into a YDoc.
|
|
955
|
+
*
|
|
956
|
+
* Each model with data in a YDoc gets a `_meta_{modelName}` YMap that
|
|
957
|
+
* describes the model's fields, constraints, and relationships. This
|
|
958
|
+
* lets any language that can read a YDoc discover the schema without
|
|
959
|
+
* external configuration.
|
|
960
|
+
*
|
|
961
|
+
* Two modes:
|
|
962
|
+
* 1. **Schema-aware** — full schema known (from defineModelSchema / TOML).
|
|
963
|
+
* Writes field metadata, constraints, and relationships.
|
|
964
|
+
* 2. **Infer-on-write** — no schema. Infers types from record values.
|
|
965
|
+
*/
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Infer a _meta_ type string from a JS runtime value.
|
|
969
|
+
*/
|
|
970
|
+
declare function inferFieldType(value: unknown): "string" | "number" | "boolean" | "stringset" | null;
|
|
971
|
+
/**
|
|
972
|
+
* Register a named function default so metaSync can encode it.
|
|
973
|
+
* Called once per known default generator.
|
|
974
|
+
*/
|
|
975
|
+
declare function registerFunctionDefault(fn: Function, name: string): void;
|
|
976
|
+
/**
|
|
977
|
+
* Clear the sync cache for a specific doc (or all docs).
|
|
978
|
+
* Useful for testing or when schema changes at runtime.
|
|
979
|
+
*/
|
|
980
|
+
declare function clearMetaSyncCache(yDoc?: Y.Doc): void;
|
|
981
|
+
/**
|
|
982
|
+
* Sync full schema metadata into `_meta_{modelName}` inside a YDoc.
|
|
983
|
+
*
|
|
984
|
+
* Call this inside an existing `yDoc.transact()`. Y.Map `.set()` on
|
|
985
|
+
* identical values is a CRDT no-op so there is no overhead after the
|
|
986
|
+
* first write.
|
|
987
|
+
*
|
|
988
|
+
* Skips the sync if this (yDoc, modelName) pair has already been synced
|
|
989
|
+
* in the current session.
|
|
990
|
+
*/
|
|
991
|
+
declare function syncModelMeta(yDoc: Y.Doc, modelName: string, schema: ModelSchemaRuntimeShape): void;
|
|
992
|
+
/**
|
|
993
|
+
* Infer-on-write: when no schema is available, infer field types from
|
|
994
|
+
* the record data and write minimal _meta_.
|
|
995
|
+
*
|
|
996
|
+
* Call inside an existing `yDoc.transact()`.
|
|
997
|
+
*/
|
|
998
|
+
declare function syncInferredMeta(yDoc: Y.Doc, modelName: string, recordData: Record<string, any>): void;
|
|
999
|
+
|
|
1000
|
+
export { type AddRelationMethod, type AggregationAliasDebugInfo, type AggregationOperation, type AggregationOptions, type AggregationResult, BaseModel, type DatabaseConfig, DatabaseEngine, type DatabaseEngineType, BrowserDatabaseFactory as DatabaseFactory, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type FieldOptions, type FieldType, type GroupByField, type HasManyMethod, type HasManyThroughMethod, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type PaginatedResult, type PaginationOptions, RecordNotFoundError, type RefersToMethod, type RegisteredModelInfo, type RemoveRelationMethod, type SQLJSEngineOptions, type Schema, SqljsEngine, type SqljsEngineOptions, StringSet, type StringSetMembership, type UniqueConstraintConfig, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, createModelClass, defineModelSchema, detectEnvironment, discoverModelNames, discoverSchema, features, generateULID, inferFieldType, initJsBao, isBrowser, isNode, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, syncInferredMeta, syncModelMeta };
|