@antelopejs/interface-database 0.1.7 → 0.1.8

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/README.md CHANGED
@@ -1,5 +1,3 @@
1
- ![Database](.github/social-card.png)
2
-
3
1
  # Interface Database
4
2
 
5
3
  <div align="center">
@@ -11,7 +11,7 @@ exports.default = (0, config_1.defineConfig)({
11
11
  source: {
12
12
  type: "package",
13
13
  package: "@antelopejs/mongodb",
14
- version: "1.3.0",
14
+ version: "1.3.1",
15
15
  },
16
16
  },
17
17
  },
@@ -13,6 +13,17 @@ export interface IndexDefinition {
13
13
  * Whether or not this is a multi index
14
14
  */
15
15
  multi?: boolean;
16
+ /**
17
+ * Whether this index must also serve queries that run across all instances
18
+ * ({@link CROSS_INSTANCE})
19
+ *
20
+ * When `true`, the driver also maintains an index usable by cross-instance
21
+ * queries. Defaults to `false`: the index is optimized for queries scoped to
22
+ * one instance, and cross-instance queries using it may be slow.
23
+ *
24
+ * This flag never changes query results, only performance.
25
+ */
26
+ crossInstance?: boolean;
16
27
  }
17
28
  export type StringFieldType = string | Array<StringFieldType> | {
18
29
  [subfield: string]: StringFieldType;
@@ -48,6 +59,10 @@ export interface SchemaDefinition {
48
59
  }
49
60
  /**
50
61
  * Sentinel instance id meaning "operate across all instances of the schema".
62
+ *
63
+ * Secondary indexes are optimized for queries scoped to one instance; set
64
+ * {@link IndexDefinition.crossInstance} on the indexes that cross-instance
65
+ * queries rely on.
51
66
  */
52
67
  export declare const CROSS_INSTANCE: unique symbol;
53
68
  /**
@@ -6,6 +6,10 @@ const selection_1 = require("./selection");
6
6
  const common_1 = require("./common");
7
7
  /**
8
8
  * Sentinel instance id meaning "operate across all instances of the schema".
9
+ *
10
+ * Secondary indexes are optimized for queries scoped to one instance; set
11
+ * {@link IndexDefinition.crossInstance} on the indexes that cross-instance
12
+ * queries rely on.
9
13
  */
10
14
  exports.CROSS_INSTANCE = Symbol("antelopejs:cross-instance");
11
15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;IACI,cAAc,CAAC,EAAW;QAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA,aAAa,CAAA,EAAE,gBAAgB,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,EAAW;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA,aAAW,CAAA,EAAE,iBAAiB,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;;OAMG;IACI,aAAa;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA,aAAe,CAAA,EAAE,eAAe,CAAC,CAAC;IACtD,CAAC;;AAtEH,wBAuEC;AAED;;GAEG;AACH,MAAa,cAAkB,SAAQ,qBAAY;IACjD;;;;;OAKG;IACI,KAAK,CAAqB,EAAM;QACrC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA,iBAAY,CAAA,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACnD,CAAC;CACF;AAVD,wCAUC"}
@@ -27,6 +27,7 @@ const schema = new Schema("myapp", {
27
27
  interface IndexDefinition {
28
28
  fields?: string[]; // Fields for compound indexes (omit for single-field)
29
29
  multi?: boolean; // Whether this is a multi-valued index
30
+ crossInstance?: boolean; // Also serve CROSS_INSTANCE queries efficiently
30
31
  }
31
32
  ```
32
33
 
@@ -102,6 +103,29 @@ const schema = new Schema("content", {
102
103
  });
103
104
  ```
104
105
 
106
+ ## Cross-Instance Indexes
107
+
108
+ Indexes are optimized for queries scoped to one instance (`schema.instance(id)`). Queries run with `schema.instance(CROSS_INSTANCE)` can still use them, but may be slow. Set `crossInstance: true` on the indexes that cross-instance queries rely on, and the driver also maintains an index usable by those queries:
109
+
110
+ ```typescript
111
+ const schema = new Schema("billing", {
112
+ invoices: {
113
+ fields: { status: "string" },
114
+ indexes: {
115
+ status: { crossInstance: true },
116
+ },
117
+ },
118
+ });
119
+
120
+ // Efficient on every instance at once
121
+ await schema
122
+ .instance(CROSS_INSTANCE)
123
+ .table("invoices")
124
+ .getAll("unpaid", "status");
125
+ ```
126
+
127
+ The flag defaults to `false`. It never changes query results, only performance. Each flagged index costs extra storage and write overhead, so only set it where cross-instance queries use the index.
128
+
105
129
  ## Index Design Guidelines
106
130
 
107
131
  - **Index fields used in `getAll()` and `between()` calls** for best performance.
@@ -8,6 +8,7 @@ In AQL, indexes are defined as part of the schema definition rather than created
8
8
  interface IndexDefinition {
9
9
  fields?: string[]; // Fields for compound indexes
10
10
  multi?: boolean; // Multi-valued index
11
+ crossInstance?: boolean; // Also serve CROSS_INSTANCE queries efficiently
11
12
  }
12
13
  ```
13
14
 
@@ -60,6 +61,16 @@ indexes: {
60
61
  }
61
62
  ```
62
63
 
64
+ ### Cross-Instance Indexes
65
+
66
+ Set `crossInstance: true` when queries run with `CROSS_INSTANCE` use the index. The driver then also maintains an index usable across all instances. Without it, the index is optimized for queries scoped to one instance and cross-instance queries using it may be slow. Results are never affected:
67
+
68
+ ```typescript
69
+ indexes: {
70
+ status: { crossInstance: true },
71
+ }
72
+ ```
73
+
63
74
  ## Use Indexes in Queries
64
75
 
65
76
  Once defined, indexes are available for `getAll()` and `between()` operations:
@@ -34,6 +34,8 @@ type InstanceId = string | typeof CROSS_INSTANCE;
34
34
 
35
35
  `schema.instance(CROSS_INSTANCE)` returns a query stage that operates across every instance of the schema. Adapters skip the per-instance filter on read/update/delete and reject inserts.
36
36
 
37
+ Secondary indexes are optimized for queries scoped to one instance. Set `crossInstance: true` in the `IndexDefinition` of the indexes that cross-instance queries rely on (see [Index Management](../2.operations/5.indexes.md)).
38
+
37
39
  ## Create and Manage Instances
38
40
 
39
41
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/interface-database",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "AntelopeJS interface for database-agnostic query operations",
5
5
  "keywords": [
6
6
  "antelopejs",
@@ -110,8 +110,9 @@
110
110
  "knip": "knip"
111
111
  },
112
112
  "devDependencies": {
113
- "@antelopejs/interface-core": ">=0.0.3 <1.0.0",
114
- "@antelopejs/tooling-configs": "^0.0.4",
113
+ "@antelopejs/core": "^1.9.1",
114
+ "@antelopejs/interface-core": ">=0.1.1 <1.0.0",
115
+ "@antelopejs/tooling-configs": "^0.0.6",
115
116
  "@types/chai": "^4.3.20",
116
117
  "@types/mocha": "^10.0.10",
117
118
  "@types/node": "^22.19.15",
@@ -131,7 +132,7 @@
131
132
  "typescript": "^5.9.3"
132
133
  },
133
134
  "peerDependencies": {
134
- "@antelopejs/interface-core": ">=0.0.3 <1.0.0"
135
+ "@antelopejs/interface-core": ">=0.1.1 <1.0.0"
135
136
  },
136
137
  "packageManager": "pnpm@10.6.5",
137
138
  "antelopeJs": {
@@ -89,7 +89,7 @@ for await (const change of novels.changes()) {
89
89
  - **Callbacks receive `ValueProxy`, not values.** Functions passed to `filter`, `map`, `do`, `update(fn)`, `join`, `group` are recorded, then replayed by the backend. Only `ValueProxy` methods (`key`, `eq`, `ne`, `gt/ge/lt/le`, `and/or/not`, `add/sub/mul/div`, string/date/array/object helpers, `ValueProxy.constant`) become part of the query — plain JS (`if`, `===`, `Math.*`, template strings) does not travel. Exception: `group`'s mapper receives a staged `Stream` (the group's documents) as its first parameter and a `ValueProxy` (the index value) second — staged `Stream` methods also travel.
90
90
  - **Staged objects are immutable.** Each chained call returns a new object; a prefix like `novels.getAll(true, "available")` can be safely reused for several derived queries.
91
91
  - A provider module must be loaded in the project or startup fails with unresolved interface dependencies; queries themselves need no defensive "is the DB ready" checks (calls queue until the provider attaches).
92
- - `Schema` ids are persistent: changing an id leaves previous data inaccessible. `Schema.get(id)` retrieves a previously constructed schema. `instance()` with no argument is the default instance; pass `CROSS_INSTANCE` to query across all instances.
92
+ - `Schema` ids are persistent: changing an id leaves previous data inaccessible. `Schema.get(id)` retrieves a previously constructed schema. `instance()` with no argument is the default instance; pass `CROSS_INSTANCE` to query across all instances. Indexes are optimized for per-instance queries; set `crossInstance: true` on the indexes that `CROSS_INSTANCE` queries use (performance only, results are unchanged).
93
93
  - Field types are string tokens (`"string"`, `"number"`, `"boolean"`, `"date"`, `"string[]"`, nested object literals) or a single io-ts codec at the field root — codecs are not mixed inside string-tree records.
94
94
  - Range semantics: `Table.between(index, low, high)` and `ValueProxy.during(left, right)` exclude the upper bound.
95
95
  - `insert` accepts one document or an array, with `{ conflict: "update" | "replace" }` as options; it resolves to the inserted ids.