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/codegen.cjs
CHANGED
|
@@ -312,7 +312,7 @@ var ModelAnalyzer = class {
|
|
|
312
312
|
return {};
|
|
313
313
|
}
|
|
314
314
|
/**
|
|
315
|
-
* Parse relationships object from
|
|
315
|
+
* Parse relationships object from a model schema definition
|
|
316
316
|
*/
|
|
317
317
|
parseRelationships(obj) {
|
|
318
318
|
const relationships = {};
|
|
@@ -461,14 +461,6 @@ var ModelAnalyzer = class {
|
|
|
461
461
|
type: this.getTypeString(member.type),
|
|
462
462
|
isOptional: !!member.questionToken
|
|
463
463
|
};
|
|
464
|
-
const memberDecorators = ts.getDecorators?.(member) || member.decorators;
|
|
465
|
-
if (memberDecorators) {
|
|
466
|
-
for (const decorator of memberDecorators) {
|
|
467
|
-
if (ts.isCallExpression(decorator.expression) && ts.isIdentifier(decorator.expression.expression) && decorator.expression.expression.text === "Field") {
|
|
468
|
-
field.decoratorOptions = {};
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
464
|
fields[fieldName] = field;
|
|
473
465
|
}
|
|
474
466
|
}
|
|
@@ -1189,7 +1181,7 @@ var SchemaExtractor = class {
|
|
|
1189
1181
|
// package.json
|
|
1190
1182
|
var package_default = {
|
|
1191
1183
|
name: "js-bao",
|
|
1192
|
-
version: "0.
|
|
1184
|
+
version: "0.4.0",
|
|
1193
1185
|
description: "A library providing data modeling capabilities which support live updates and queries.",
|
|
1194
1186
|
types: "dist/index.d.ts",
|
|
1195
1187
|
type: "module",
|
|
@@ -1245,17 +1237,17 @@ var package_default = {
|
|
|
1245
1237
|
scripts: {
|
|
1246
1238
|
build: "pnpm build:cli && pnpm codegen && rm -f dist/index.* dist/node.* dist/browser.* dist/cloudflare.* dist/cloudflare-do.* dist/client.* && pnpm build:main",
|
|
1247
1239
|
"build:main": "pnpm build:browser && pnpm build:node && pnpm build:universal && pnpm build:cloudflare && pnpm build:cloudflare-do && pnpm build:client",
|
|
1248
|
-
"build:browser": "tsup src/browser.ts --format esm,cjs --dts --platform browser --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --no-splitting",
|
|
1240
|
+
"build:browser": "tsup src/browser.ts --format esm,cjs --dts --platform browser --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --external fs --no-splitting",
|
|
1249
1241
|
"build:node": "tsup src/node.ts --format esm,cjs --dts --platform node --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --no-splitting",
|
|
1250
1242
|
"build:universal": "tsup src/index.ts --format esm,cjs --dts --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --no-splitting",
|
|
1251
|
-
"build:cloudflare": "tsup src/cloudflare.ts --format esm,cjs --dts --platform browser --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --no-splitting",
|
|
1252
|
-
"build:cloudflare-do": "tsup src/cloudflare-do.ts --format esm,cjs --dts --platform neutral --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --no-splitting",
|
|
1253
|
-
"build:client": "tsup src/client.ts --format esm,cjs --dts --platform browser --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --no-splitting",
|
|
1243
|
+
"build:cloudflare": "tsup src/cloudflare.ts --format esm,cjs --dts --platform browser --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --external fs --no-splitting",
|
|
1244
|
+
"build:cloudflare-do": "tsup src/cloudflare-do.ts --format esm,cjs --dts --platform neutral --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --external fs --no-splitting",
|
|
1245
|
+
"build:client": "tsup src/client.ts --format esm,cjs --dts --platform browser --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --external fs --no-splitting",
|
|
1254
1246
|
"build:cli": "tsup src/cli/codegen.ts --format cjs --dts --platform node --target node18 --external commander --external typescript --external fs --external path --external util --no-splitting",
|
|
1255
1247
|
dev: 'pnpm build:cli && concurrently "pnpm codegen:watch" "pnpm dev:main"',
|
|
1256
1248
|
"dev:main": 'concurrently "pnpm build:browser:dev --watch" "pnpm build:node:dev --watch" "pnpm build:universal:dev --watch"',
|
|
1257
1249
|
"dev:simple": "pnpm build:cli && pnpm codegen && pnpm build:main --watch",
|
|
1258
|
-
"build:browser:dev": "tsup src/browser.ts --format esm,cjs --dts --sourcemap --platform browser --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs",
|
|
1250
|
+
"build:browser:dev": "tsup src/browser.ts --format esm,cjs --dts --sourcemap --platform browser --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs --external fs",
|
|
1259
1251
|
"build:node:dev": "tsup src/node.ts --format esm,cjs --dts --sourcemap --platform node --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs",
|
|
1260
1252
|
"build:universal:dev": "tsup src/index.ts --format esm,cjs --dts --sourcemap --external better-sqlite3 --external sql.js --external async-mutex --external ulid --external yjs",
|
|
1261
1253
|
codegen: "./dist/codegen.cjs --config js-bao.config.cjs || echo 'Codegen skipped (likely in consumer project)'",
|
package/dist/index.cjs
CHANGED
|
@@ -1877,7 +1877,7 @@ var init_BaseModel = __esm({
|
|
|
1877
1877
|
getDocumentId() {
|
|
1878
1878
|
return this._metaDocId;
|
|
1879
1879
|
}
|
|
1880
|
-
// id is
|
|
1880
|
+
// id is a plain property. Subclasses define it via defineModelSchema.
|
|
1881
1881
|
id;
|
|
1882
1882
|
type;
|
|
1883
1883
|
// This should be the modelName from ModelOptions
|
|
@@ -2424,7 +2424,7 @@ var init_BaseModel = __esm({
|
|
|
2424
2424
|
const verboseEnabled = Logger.getLogLevel() >= 5 /* VERBOSE */;
|
|
2425
2425
|
if (!schema || !schema.options || !schema.options.name || !schema.resolvedUniqueConstraints) {
|
|
2426
2426
|
throw new Error(
|
|
2427
|
-
`[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to
|
|
2427
|
+
`[${this.name}] Model schema is not registered, missing options, or missing resolvedUniqueConstraints. Did you forget to call attachAndRegisterModel (or autoRegisterModel) for this model?`
|
|
2428
2428
|
);
|
|
2429
2429
|
}
|
|
2430
2430
|
const modelName = schema.options.name;
|
|
@@ -5132,11 +5132,11 @@ var init_ModelRegistry = __esm({
|
|
|
5132
5132
|
init_relationshipManager();
|
|
5133
5133
|
ModelRegistry = class _ModelRegistry {
|
|
5134
5134
|
static instance;
|
|
5135
|
-
// Stores globally registered model classes by their name
|
|
5135
|
+
// Stores globally registered model classes by their name
|
|
5136
5136
|
models = /* @__PURE__ */ new Map();
|
|
5137
|
-
// Stores options for globally registered models
|
|
5137
|
+
// Stores options for globally registered models
|
|
5138
5138
|
modelOptions = /* @__PURE__ */ new Map();
|
|
5139
|
-
// Stores fields for globally registered models (
|
|
5139
|
+
// Stores fields for globally registered models (or a static getter on class)
|
|
5140
5140
|
// For simplicity, let's assume fields can be derived or are less critical for this registry part
|
|
5141
5141
|
// private modelFields: Map<string, Map<string, FieldOptions>> = new Map();
|
|
5142
5142
|
// Holds the subset of models explicitly set for the current initialization session
|
|
@@ -5154,7 +5154,7 @@ var init_ModelRegistry = __esm({
|
|
|
5154
5154
|
registerModel(modelClass, options, fields) {
|
|
5155
5155
|
if (!options.name) {
|
|
5156
5156
|
throw new Error(
|
|
5157
|
-
`[ModelRegistry] Model class is missing a name in its
|
|
5157
|
+
`[ModelRegistry] Model class is missing a name in its options. Ensure the schema passed to defineModelSchema/createModelClass/attachAndRegisterModel includes a 'name' property.`
|
|
5158
5158
|
);
|
|
5159
5159
|
}
|
|
5160
5160
|
if (this.models.has(options.name)) {
|
|
@@ -5198,7 +5198,7 @@ var init_ModelRegistry = __esm({
|
|
|
5198
5198
|
}
|
|
5199
5199
|
return infos;
|
|
5200
5200
|
}
|
|
5201
|
-
// Helper to get model name from class (
|
|
5201
|
+
// Helper to get model name from class (set by attachAndRegisterModel/createModelClass)
|
|
5202
5202
|
getModelNameFromClass(modelClass) {
|
|
5203
5203
|
return modelClass.modelName;
|
|
5204
5204
|
}
|
|
@@ -5209,13 +5209,13 @@ var init_ModelRegistry = __esm({
|
|
|
5209
5209
|
const modelName = this.getModelNameFromClass(modelClass);
|
|
5210
5210
|
if (!modelName) {
|
|
5211
5211
|
console.warn(
|
|
5212
|
-
`[ModelRegistry] A model class provided to setExplicitModelsForSession does not have a static 'modelName' property or it's undefined. It will be ignored. Ensure
|
|
5212
|
+
`[ModelRegistry] A model class provided to setExplicitModelsForSession does not have a static 'modelName' property or it's undefined. It will be ignored. Ensure attachAndRegisterModel (or createModelClass) was called for this model.`
|
|
5213
5213
|
);
|
|
5214
5214
|
return;
|
|
5215
5215
|
}
|
|
5216
5216
|
if (!this.models.has(modelName) || this.models.get(modelName) !== modelClass) {
|
|
5217
5217
|
console.warn(
|
|
5218
|
-
`[ModelRegistry] Model class with name ${modelName} provided to setExplicitModelsForSession was not found in the global
|
|
5218
|
+
`[ModelRegistry] Model class with name ${modelName} provided to setExplicitModelsForSession was not found in the global registry or does not match. It will be ignored. Ensure the model file is imported and attachAndRegisterModel (or createModelClass) has run.`
|
|
5219
5219
|
);
|
|
5220
5220
|
return;
|
|
5221
5221
|
}
|
|
@@ -5245,7 +5245,7 @@ var init_ModelRegistry = __esm({
|
|
|
5245
5245
|
} else {
|
|
5246
5246
|
this.activeSessionModels = null;
|
|
5247
5247
|
console.log(
|
|
5248
|
-
"[ModelRegistry] No explicit models specified for session (undefined), will use all
|
|
5248
|
+
"[ModelRegistry] No explicit models specified for session (undefined), will use all globally registered models."
|
|
5249
5249
|
);
|
|
5250
5250
|
}
|
|
5251
5251
|
this.validateSessionModels();
|
|
@@ -5256,7 +5256,7 @@ var init_ModelRegistry = __esm({
|
|
|
5256
5256
|
const modelsToInitialize = this.activeSessionModels || this.models;
|
|
5257
5257
|
if (modelsToInitialize.size === 0) {
|
|
5258
5258
|
console.warn(
|
|
5259
|
-
"[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via
|
|
5259
|
+
"[ModelRegistry] No models to initialize (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5260
5260
|
);
|
|
5261
5261
|
return;
|
|
5262
5262
|
}
|
|
@@ -5287,7 +5287,7 @@ var init_ModelRegistry = __esm({
|
|
|
5287
5287
|
const modelsToInitialize = this.activeSessionModels || this.models;
|
|
5288
5288
|
if (modelsToInitialize.size === 0) {
|
|
5289
5289
|
Logger.warn(
|
|
5290
|
-
"[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via
|
|
5290
|
+
"[ModelRegistry] No models to initialize for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5291
5291
|
);
|
|
5292
5292
|
return;
|
|
5293
5293
|
}
|
|
@@ -5325,7 +5325,7 @@ var init_ModelRegistry = __esm({
|
|
|
5325
5325
|
const modelsToCleanup = this.activeSessionModels || this.models;
|
|
5326
5326
|
if (modelsToCleanup.size === 0) {
|
|
5327
5327
|
console.warn(
|
|
5328
|
-
"[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via
|
|
5328
|
+
"[ModelRegistry] No models to cleanup for document (either no explicit models set for session or no models globally registered via attachAndRegisterModel)."
|
|
5329
5329
|
);
|
|
5330
5330
|
return;
|
|
5331
5331
|
}
|
|
@@ -6649,10 +6649,8 @@ __export(index_exports, {
|
|
|
6649
6649
|
DatabaseEngine: () => DatabaseEngine,
|
|
6650
6650
|
DocumentClosedError: () => DocumentClosedError,
|
|
6651
6651
|
DocumentResolutionError: () => DocumentResolutionError,
|
|
6652
|
-
Field: () => Field,
|
|
6653
6652
|
LogLevel: () => LogLevel,
|
|
6654
6653
|
Logger: () => Logger,
|
|
6655
|
-
Model: () => Model,
|
|
6656
6654
|
ModelRegistry: () => ModelRegistry,
|
|
6657
6655
|
RecordNotFoundError: () => RecordNotFoundError,
|
|
6658
6656
|
StringSet: () => StringSet,
|
|
@@ -6894,133 +6892,6 @@ async function resetJsBao() {
|
|
|
6894
6892
|
// src/index.ts
|
|
6895
6893
|
init_documentTypes();
|
|
6896
6894
|
init_BaseModel();
|
|
6897
|
-
|
|
6898
|
-
// src/models/decorators.ts
|
|
6899
|
-
init_ModelRegistry();
|
|
6900
|
-
init_BaseModel();
|
|
6901
|
-
init_sql();
|
|
6902
|
-
var SCHEMA_FIELDS_PROPERTY = "_jsbaoSchemaFields";
|
|
6903
|
-
function Field(options) {
|
|
6904
|
-
return function(target, propertyKey) {
|
|
6905
|
-
const fieldName = String(propertyKey);
|
|
6906
|
-
const modelConstructor = target.constructor || target;
|
|
6907
|
-
assertValidIdentifier(
|
|
6908
|
-
fieldName,
|
|
6909
|
-
`[Field Decorator] Invalid field name on ${modelConstructor?.name || "unknown"}`
|
|
6910
|
-
);
|
|
6911
|
-
if (!modelConstructor) {
|
|
6912
|
-
console.error(
|
|
6913
|
-
"[Field Decorator] Could not determine model constructor for field:",
|
|
6914
|
-
fieldName,
|
|
6915
|
-
"Target:",
|
|
6916
|
-
target
|
|
6917
|
-
);
|
|
6918
|
-
throw new Error(
|
|
6919
|
-
`Failed to resolve model constructor for field '${fieldName}'.`
|
|
6920
|
-
);
|
|
6921
|
-
}
|
|
6922
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
6923
|
-
modelConstructor,
|
|
6924
|
-
SCHEMA_FIELDS_PROPERTY
|
|
6925
|
-
)) {
|
|
6926
|
-
modelConstructor[SCHEMA_FIELDS_PROPERTY] = /* @__PURE__ */ new Map();
|
|
6927
|
-
}
|
|
6928
|
-
modelConstructor[SCHEMA_FIELDS_PROPERTY].set(
|
|
6929
|
-
fieldName,
|
|
6930
|
-
options
|
|
6931
|
-
);
|
|
6932
|
-
Logger.debug(
|
|
6933
|
-
`[Field Decorator] Staged field "${fieldName}" for class ${modelConstructor.name}:`,
|
|
6934
|
-
options
|
|
6935
|
-
);
|
|
6936
|
-
};
|
|
6937
|
-
}
|
|
6938
|
-
function Model(options) {
|
|
6939
|
-
return function(targetClass) {
|
|
6940
|
-
Logger.debug(
|
|
6941
|
-
`[Model Decorator] Registering model:`,
|
|
6942
|
-
targetClass.name,
|
|
6943
|
-
options
|
|
6944
|
-
);
|
|
6945
|
-
assertValidIdentifier(
|
|
6946
|
-
options.name,
|
|
6947
|
-
`[Model Decorator] Invalid model name for ${targetClass.name}`
|
|
6948
|
-
);
|
|
6949
|
-
const registry = ModelRegistry.getInstance();
|
|
6950
|
-
targetClass.modelName = options.name;
|
|
6951
|
-
targetClass.getSchema = () => {
|
|
6952
|
-
const combinedFields = /* @__PURE__ */ new Map();
|
|
6953
|
-
const hierarchyStack = [];
|
|
6954
|
-
let currentEvalClass = targetClass;
|
|
6955
|
-
while (currentEvalClass && currentEvalClass.prototype) {
|
|
6956
|
-
hierarchyStack.push(currentEvalClass);
|
|
6957
|
-
const parentPrototype = Object.getPrototypeOf(
|
|
6958
|
-
currentEvalClass.prototype
|
|
6959
|
-
);
|
|
6960
|
-
currentEvalClass = parentPrototype ? parentPrototype.constructor : null;
|
|
6961
|
-
if (currentEvalClass === Object) break;
|
|
6962
|
-
}
|
|
6963
|
-
for (let i = hierarchyStack.length - 1; i >= 0; i--) {
|
|
6964
|
-
const cls = hierarchyStack[i];
|
|
6965
|
-
if (Object.prototype.hasOwnProperty.call(cls, SCHEMA_FIELDS_PROPERTY)) {
|
|
6966
|
-
const fieldsForClass = cls[SCHEMA_FIELDS_PROPERTY];
|
|
6967
|
-
fieldsForClass.forEach((fieldOpts, fieldName) => {
|
|
6968
|
-
combinedFields.set(fieldName, fieldOpts);
|
|
6969
|
-
});
|
|
6970
|
-
}
|
|
6971
|
-
}
|
|
6972
|
-
const resolvedUniqueConstraints = [];
|
|
6973
|
-
combinedFields.forEach((fieldOpts, fieldName) => {
|
|
6974
|
-
if (fieldOpts.unique) {
|
|
6975
|
-
const constraintName = `${options.name}_${fieldName}_unique`;
|
|
6976
|
-
resolvedUniqueConstraints.push({
|
|
6977
|
-
name: constraintName,
|
|
6978
|
-
fields: [fieldName]
|
|
6979
|
-
});
|
|
6980
|
-
}
|
|
6981
|
-
});
|
|
6982
|
-
if (options.uniqueConstraints) {
|
|
6983
|
-
options.uniqueConstraints.forEach(
|
|
6984
|
-
(constraintConfig) => {
|
|
6985
|
-
const allFieldsExist = constraintConfig.fields.every(
|
|
6986
|
-
(f) => combinedFields.has(f)
|
|
6987
|
-
);
|
|
6988
|
-
if (!allFieldsExist) {
|
|
6989
|
-
console.warn(
|
|
6990
|
-
`[Model Decorator] Unique constraint "${constraintConfig.name}" for model "${options.name}" specifies non-existent fields. Skipping.`
|
|
6991
|
-
);
|
|
6992
|
-
return;
|
|
6993
|
-
}
|
|
6994
|
-
if (resolvedUniqueConstraints.some(
|
|
6995
|
-
(rc) => rc.name === constraintConfig.name
|
|
6996
|
-
)) {
|
|
6997
|
-
console.warn(
|
|
6998
|
-
`[Model Decorator] Duplicate unique constraint name "${constraintConfig.name}" in model "${options.name}".`
|
|
6999
|
-
);
|
|
7000
|
-
}
|
|
7001
|
-
resolvedUniqueConstraints.push({
|
|
7002
|
-
name: constraintConfig.name,
|
|
7003
|
-
fields: constraintConfig.fields
|
|
7004
|
-
});
|
|
7005
|
-
}
|
|
7006
|
-
);
|
|
7007
|
-
}
|
|
7008
|
-
return {
|
|
7009
|
-
class: targetClass,
|
|
7010
|
-
options,
|
|
7011
|
-
fields: combinedFields,
|
|
7012
|
-
resolvedUniqueConstraints
|
|
7013
|
-
};
|
|
7014
|
-
};
|
|
7015
|
-
const directFieldsForThisClass = Object.prototype.hasOwnProperty.call(
|
|
7016
|
-
targetClass,
|
|
7017
|
-
SCHEMA_FIELDS_PROPERTY
|
|
7018
|
-
) ? targetClass[SCHEMA_FIELDS_PROPERTY] : /* @__PURE__ */ new Map();
|
|
7019
|
-
registry.registerModel(targetClass, options, directFieldsForThisClass);
|
|
7020
|
-
};
|
|
7021
|
-
}
|
|
7022
|
-
|
|
7023
|
-
// src/index.ts
|
|
7024
6895
|
init_StringSet();
|
|
7025
6896
|
|
|
7026
6897
|
// src/models/schema.ts
|
|
@@ -7338,32 +7209,41 @@ var Y3 = __toESM(require("yjs"), 1);
|
|
|
7338
7209
|
function discoverSchema(yDoc) {
|
|
7339
7210
|
const models = {};
|
|
7340
7211
|
const metaNames = /* @__PURE__ */ new Set();
|
|
7341
|
-
for (const
|
|
7212
|
+
for (const key of yDoc.share.keys()) {
|
|
7342
7213
|
if (!key.startsWith("_meta_")) continue;
|
|
7343
|
-
|
|
7214
|
+
const map = materializeMap(yDoc, key);
|
|
7215
|
+
if (!map) continue;
|
|
7344
7216
|
const modelName = key.slice("_meta_".length);
|
|
7345
7217
|
metaNames.add(modelName);
|
|
7346
|
-
models[modelName] = readModelMeta(
|
|
7218
|
+
models[modelName] = readModelMeta(map);
|
|
7347
7219
|
}
|
|
7348
|
-
for (const
|
|
7220
|
+
for (const key of yDoc.share.keys()) {
|
|
7349
7221
|
if (key.startsWith("_")) continue;
|
|
7350
|
-
if (!(type instanceof Y3.Map)) continue;
|
|
7351
7222
|
if (metaNames.has(key)) continue;
|
|
7352
|
-
const
|
|
7353
|
-
if (
|
|
7354
|
-
const inferred = inferModelFromData(
|
|
7223
|
+
const map = materializeMap(yDoc, key);
|
|
7224
|
+
if (!map || map.size === 0) continue;
|
|
7225
|
+
const inferred = inferModelFromData(map);
|
|
7355
7226
|
if (inferred) models[key] = inferred;
|
|
7356
7227
|
}
|
|
7357
7228
|
return { models };
|
|
7358
7229
|
}
|
|
7359
7230
|
function discoverModelNames(yDoc) {
|
|
7360
7231
|
const names = [];
|
|
7361
|
-
for (const
|
|
7232
|
+
for (const key of yDoc.share.keys()) {
|
|
7362
7233
|
if (key.startsWith("_")) continue;
|
|
7363
|
-
|
|
7234
|
+
const map = materializeMap(yDoc, key);
|
|
7235
|
+
if (map) names.push(key);
|
|
7364
7236
|
}
|
|
7365
7237
|
return names.sort();
|
|
7366
7238
|
}
|
|
7239
|
+
function materializeMap(yDoc, key) {
|
|
7240
|
+
try {
|
|
7241
|
+
const map = yDoc.getMap(key);
|
|
7242
|
+
return map instanceof Y3.Map ? map : null;
|
|
7243
|
+
} catch {
|
|
7244
|
+
return null;
|
|
7245
|
+
}
|
|
7246
|
+
}
|
|
7367
7247
|
function readModelMeta(metaMap) {
|
|
7368
7248
|
const fields = {};
|
|
7369
7249
|
let constraints;
|
|
@@ -7584,10 +7464,8 @@ function summarizePlainYDoc(dump) {
|
|
|
7584
7464
|
DatabaseEngine,
|
|
7585
7465
|
DocumentClosedError,
|
|
7586
7466
|
DocumentResolutionError,
|
|
7587
|
-
Field,
|
|
7588
7467
|
LogLevel,
|
|
7589
7468
|
Logger,
|
|
7590
|
-
Model,
|
|
7591
7469
|
ModelRegistry,
|
|
7592
7470
|
RecordNotFoundError,
|
|
7593
7471
|
StringSet,
|
package/dist/index.d.cts
CHANGED
|
@@ -702,7 +702,7 @@ interface InitJsBaoOptions {
|
|
|
702
702
|
/**
|
|
703
703
|
* Optional array of model classes to initialize.
|
|
704
704
|
* If not provided, the ORM will rely on models being registered
|
|
705
|
-
* via
|
|
705
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
706
706
|
*/
|
|
707
707
|
models?: (typeof BaseModel)[];
|
|
708
708
|
}
|
|
@@ -742,9 +742,6 @@ declare function initJsBao(options: InitJsBaoOptions): Promise<InitJsBaoResult>;
|
|
|
742
742
|
*/
|
|
743
743
|
declare function resetJsBao(): Promise<void>;
|
|
744
744
|
|
|
745
|
-
declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
|
|
746
|
-
declare function Model(options: ModelOptions): (targetClass: Function) => void;
|
|
747
|
-
|
|
748
745
|
interface ResolvedUniqueConstraint {
|
|
749
746
|
name: string;
|
|
750
747
|
fields: string[];
|
|
@@ -956,4 +953,4 @@ declare function dumpYDocToPlain(yDoc: Y.Doc, options?: DumpOptions): PlainYDoc;
|
|
|
956
953
|
*/
|
|
957
954
|
declare function summarizePlainYDoc(dump: PlainYDoc): DumpSummary;
|
|
958
955
|
|
|
959
|
-
export { BaseModel, type ConnectedDocument, type DatabaseConfig, DatabaseEngine, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, DocumentClosedError, type DocumentConnectionCallback, type DocumentConnectionEvent, type DocumentFilter, type DocumentManager, type DocumentPermissionHint, DocumentResolutionError, type DumpOptions, type DumpSummary, type DumpSummaryEntry,
|
|
956
|
+
export { BaseModel, type ConnectedDocument, type DatabaseConfig, DatabaseEngine, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, DocumentClosedError, type DocumentConnectionCallback, type DocumentConnectionEvent, type DocumentFilter, type DocumentManager, type DocumentPermissionHint, DocumentResolutionError, type DumpOptions, type DumpSummary, type DumpSummaryEntry, type FieldOptions, type IncludeSpec, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type PaginatedResult, type PaginationOptions, type PlainYDoc, type ProjectionSpec, type QueryOptions, type QueryResult, RecordNotFoundError, type SaveOptions, StringSet, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, createModelClass, defineModelSchema, discoverModelNames, discoverSchema, dumpYDocToPlain, generateULID, inferFieldType, initJsBao, loadSchemaFromToml, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, summarizePlainYDoc, syncInferredMeta, syncModelMeta };
|
package/dist/index.d.ts
CHANGED
|
@@ -702,7 +702,7 @@ interface InitJsBaoOptions {
|
|
|
702
702
|
/**
|
|
703
703
|
* Optional array of model classes to initialize.
|
|
704
704
|
* If not provided, the ORM will rely on models being registered
|
|
705
|
-
* via
|
|
705
|
+
* via attachAndRegisterModel (assuming they have been imported by the application).
|
|
706
706
|
*/
|
|
707
707
|
models?: (typeof BaseModel)[];
|
|
708
708
|
}
|
|
@@ -742,9 +742,6 @@ declare function initJsBao(options: InitJsBaoOptions): Promise<InitJsBaoResult>;
|
|
|
742
742
|
*/
|
|
743
743
|
declare function resetJsBao(): Promise<void>;
|
|
744
744
|
|
|
745
|
-
declare function Field(options: FieldOptions): (target: any, propertyKey: string | symbol) => void;
|
|
746
|
-
declare function Model(options: ModelOptions): (targetClass: Function) => void;
|
|
747
|
-
|
|
748
745
|
interface ResolvedUniqueConstraint {
|
|
749
746
|
name: string;
|
|
750
747
|
fields: string[];
|
|
@@ -956,4 +953,4 @@ declare function dumpYDocToPlain(yDoc: Y.Doc, options?: DumpOptions): PlainYDoc;
|
|
|
956
953
|
*/
|
|
957
954
|
declare function summarizePlainYDoc(dump: PlainYDoc): DumpSummary;
|
|
958
955
|
|
|
959
|
-
export { BaseModel, type ConnectedDocument, type DatabaseConfig, DatabaseEngine, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, DocumentClosedError, type DocumentConnectionCallback, type DocumentConnectionEvent, type DocumentFilter, type DocumentManager, type DocumentPermissionHint, DocumentResolutionError, type DumpOptions, type DumpSummary, type DumpSummaryEntry,
|
|
956
|
+
export { BaseModel, type ConnectedDocument, type DatabaseConfig, DatabaseEngine, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, DocumentClosedError, type DocumentConnectionCallback, type DocumentConnectionEvent, type DocumentFilter, type DocumentManager, type DocumentPermissionHint, DocumentResolutionError, type DumpOptions, type DumpSummary, type DumpSummaryEntry, type FieldOptions, type IncludeSpec, type InferAttrs, type InitJsBaoOptions, type InitJsBaoResult, LogLevel, Logger, type ModelConstructor, type ModelOptions, ModelRegistry, type PaginatedResult, type PaginationOptions, type PlainYDoc, type ProjectionSpec, type QueryOptions, type QueryResult, RecordNotFoundError, type SaveOptions, StringSet, UniqueConstraintViolationError, attachAndRegisterModel, attachSchemaToClass, autoRegisterModel, clearMetaSyncCache, createModelClass, defineModelSchema, discoverModelNames, discoverSchema, dumpYDocToPlain, generateULID, inferFieldType, initJsBao, loadSchemaFromToml, loadSchemaFromTomlString, registerFunctionDefault, resetJsBao, schemaToToml, summarizePlainYDoc, syncInferredMeta, syncModelMeta };
|