@korajs/core 1.0.0-beta.13 → 1.0.0-beta.14

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.
@@ -1,5 +1,5 @@
1
- import { X as KoraEventEmitter } from '../events-BSU-0z5O.cjs';
2
- import { S as ScopeMap } from '../build-scope-map-ClIq_doj.cjs';
1
+ import { X as KoraEventEmitter } from '../events-Da29Dt_3.cjs';
2
+ import { S as ScopeMap } from '../build-scope-map-C9zBTJ1R.cjs';
3
3
 
4
4
  /** Sync status shape consumed by framework binding hooks (matches {@link SyncStatusInfo} in `@korajs/sync`). */
5
5
  interface KoraBindingSyncStatus {
@@ -1,5 +1,5 @@
1
- import { X as KoraEventEmitter } from '../events-BSU-0z5O.js';
2
- import { S as ScopeMap } from '../build-scope-map-CIFa58oA.js';
1
+ import { X as KoraEventEmitter } from '../events-Da29Dt_3.js';
2
+ import { S as ScopeMap } from '../build-scope-map-CZaMyZLV.js';
3
3
 
4
4
  /** Sync status shape consumed by framework binding hooks (matches {@link SyncStatusInfo} in `@korajs/sync`). */
5
5
  interface KoraBindingSyncStatus {
@@ -1,4 +1,4 @@
1
- import { S as SchemaDefinition } from './events-BSU-0z5O.cjs';
1
+ import { S as SchemaDefinition } from './events-Da29Dt_3.cjs';
2
2
 
3
3
  /**
4
4
  * Per-collection scope map: `{ collectionName: { field: value, ... } }`
@@ -1,4 +1,4 @@
1
- import { S as SchemaDefinition } from './events-BSU-0z5O.js';
1
+ import { S as SchemaDefinition } from './events-Da29Dt_3.js';
2
2
 
3
3
  /**
4
4
  * Per-collection scope map: `{ collectionName: { field: value, ... } }`
@@ -1315,8 +1315,8 @@ type KoraEvent = {
1315
1315
  } | {
1316
1316
  /**
1317
1317
  * A sync peer speaks an older, deprecated protocol version (protocol v2): a
1318
- * server emits it for a protocol-1 client (Kora <= beta.12), accepted in
1319
- * beta.13 only. `message` says what to upgrade.
1318
+ * server emits it for a protocol-1 client (Kora <= beta.12), accepted with this
1319
+ * deprecation in beta.13 and beta.14. `message` says what to upgrade.
1320
1320
  */
1321
1321
  type: 'sync:protocol-deprecated';
1322
1322
  nodeId: string;
@@ -1315,8 +1315,8 @@ type KoraEvent = {
1315
1315
  } | {
1316
1316
  /**
1317
1317
  * A sync peer speaks an older, deprecated protocol version (protocol v2): a
1318
- * server emits it for a protocol-1 client (Kora <= beta.12), accepted in
1319
- * beta.13 only. `message` says what to upgrade.
1318
+ * server emits it for a protocol-1 client (Kora <= beta.12), accepted with this
1319
+ * deprecation in beta.13 and beta.14. `message` says what to upgrade.
1320
1320
  */
1321
1321
  type: 'sync:protocol-deprecated';
1322
1322
  nodeId: string;
package/dist/index.cjs CHANGED
@@ -3594,6 +3594,22 @@ function validateConstraint(collection, constraint, fields) {
3594
3594
  );
3595
3595
  }
3596
3596
  }
3597
+ if (constraint.where !== void 0 && constraint.type !== "referential") {
3598
+ for (const [key, value] of Object.entries(constraint.where)) {
3599
+ if (key !== "id" && !(key in fields)) {
3600
+ throw new SchemaValidationError(
3601
+ `Constraint where references field "${key}" which does not exist in collection "${collection}". Available fields: ${Object.keys(fields).join(", ")}`,
3602
+ { collection, field: key }
3603
+ );
3604
+ }
3605
+ if (value !== null && typeof value === "object") {
3606
+ throw new SchemaValidationError(
3607
+ `Constraint where on "${collection}.${key}" uses ${Array.isArray(value) ? "an array" : `the operator object ${JSON.stringify(value)}`}, but constraint where matches by plain equality only, so the constraint would never apply. Use an equality value (for example { ${key}: 'published' }), or enforce the rule in validateOperation or a server route.`,
3608
+ { collection, field: key }
3609
+ );
3610
+ }
3611
+ }
3612
+ }
3597
3613
  if (constraint.onConflict === "priority-field" && !constraint.priorityField) {
3598
3614
  throw new SchemaValidationError(
3599
3615
  `Constraint with "priority-field" onConflict strategy in collection "${collection}" requires a priorityField`,
@@ -4689,10 +4705,13 @@ function isPlainObject3(value) {
4689
4705
  const proto = Object.getPrototypeOf(value);
4690
4706
  return proto === null || proto === Object.prototype;
4691
4707
  }
4692
- function findNonJsonSerializable(value, path, seen = /* @__PURE__ */ new WeakSet()) {
4708
+ function findNonJsonSerializable(value, path, seen = /* @__PURE__ */ new WeakSet(), nested = false) {
4693
4709
  if (value === null) {
4694
4710
  return null;
4695
4711
  }
4712
+ if (value === void 0 && nested) {
4713
+ return null;
4714
+ }
4696
4715
  const type = typeof value;
4697
4716
  if (type === "string" || type === "number" || type === "boolean") {
4698
4717
  if (type === "number" && !Number.isFinite(value)) {
@@ -4705,7 +4724,7 @@ function findNonJsonSerializable(value, path, seen = /* @__PURE__ */ new WeakSet
4705
4724
  }
4706
4725
  if (Array.isArray(value)) {
4707
4726
  for (let index = 0; index < value.length; index++) {
4708
- const invalid = findNonJsonSerializable(value[index], `${path}[${index}]`, seen);
4727
+ const invalid = findNonJsonSerializable(value[index], `${path}[${index}]`, seen, true);
4709
4728
  if (invalid) return invalid;
4710
4729
  }
4711
4730
  return null;
@@ -4717,7 +4736,7 @@ function findNonJsonSerializable(value, path, seen = /* @__PURE__ */ new WeakSet
4717
4736
  }
4718
4737
  seen.add(objectValue);
4719
4738
  for (const [key, nestedValue] of Object.entries(objectValue)) {
4720
- const invalid = findNonJsonSerializable(nestedValue, `${path}.${key}`, seen);
4739
+ const invalid = findNonJsonSerializable(nestedValue, `${path}.${key}`, seen, true);
4721
4740
  if (invalid) return invalid;
4722
4741
  }
4723
4742
  seen.delete(objectValue);