@cero-base/cero 0.8.8 → 0.8.9
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/package.json +2 -2
- package/src/build/index.js +19 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cero-base/cero",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"description": "The ideal p2p API — everything is a handle, handles contain refs, refs contain rows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"test": "ls test/*.test.js | xargs -P1 -n1 brittle-node"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@cero-base/core": "^0.8.
|
|
81
|
+
"@cero-base/core": "^0.8.9",
|
|
82
82
|
"b4a": "^1.8.1",
|
|
83
83
|
"bare-abort-controller": "^1.1.2",
|
|
84
84
|
"bare-crypto": "^1.14.1",
|
package/src/build/index.js
CHANGED
|
@@ -120,7 +120,14 @@ function isPlainHandle(v) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
function compile(root, ns, scope = 'main') {
|
|
123
|
-
const ctx = {
|
|
123
|
+
const ctx = {
|
|
124
|
+
types: [],
|
|
125
|
+
collections: [],
|
|
126
|
+
dispatches: [],
|
|
127
|
+
indexes: [],
|
|
128
|
+
meta: { ns, refs: {} },
|
|
129
|
+
ns
|
|
130
|
+
}
|
|
124
131
|
|
|
125
132
|
Object.assign(ctx.meta.refs, builtinRefs(ns, scope))
|
|
126
133
|
|
|
@@ -136,6 +143,7 @@ function compile(root, ns, scope = 'main') {
|
|
|
136
143
|
types: ctx.types,
|
|
137
144
|
collections: ctx.collections,
|
|
138
145
|
dispatches: ctx.dispatches,
|
|
146
|
+
indexes: ctx.indexes,
|
|
139
147
|
meta: ctx.meta
|
|
140
148
|
}
|
|
141
149
|
}
|
|
@@ -173,6 +181,12 @@ function register(name, node, ctx) {
|
|
|
173
181
|
ctx.dispatches.push({ name: `set-${name}`, requestType: fqn })
|
|
174
182
|
ctx.dispatches.push({ name: `del-${name}`, requestType: `@${ctx.ns}/del-by-id` })
|
|
175
183
|
ctx.meta.refs[name] = { kind: 'collection', path: [name], schema: fqn }
|
|
184
|
+
if (node.indexes) {
|
|
185
|
+
for (const [idx, fields] of Object.entries(node.indexes)) {
|
|
186
|
+
ctx.indexes.push({ name: `${name}-${idx}`, collection: fqn, key: fields })
|
|
187
|
+
}
|
|
188
|
+
ctx.meta.refs[name].indexes = node.indexes
|
|
189
|
+
}
|
|
176
190
|
}
|
|
177
191
|
}
|
|
178
192
|
|
|
@@ -184,7 +198,7 @@ function fieldsFor(fields) {
|
|
|
184
198
|
}))
|
|
185
199
|
}
|
|
186
200
|
|
|
187
|
-
function emitMain(dir, ns, { types, collections, dispatches }, { rpc, extend = {} }) {
|
|
201
|
+
function emitMain(dir, ns, { types, collections, dispatches, indexes = [] }, { rpc, extend = {} }) {
|
|
188
202
|
const schemaDir = join(dir, 'schema')
|
|
189
203
|
const dbDir = join(dir, 'db')
|
|
190
204
|
const dispatchDir = join(dir, 'dispatch')
|
|
@@ -201,6 +215,7 @@ function emitMain(dir, ns, { types, collections, dispatches }, { rpc, extend = {
|
|
|
201
215
|
const dns = db.namespace(ns)
|
|
202
216
|
for (const desc of builtinCollections(ns, 'main')) dns.collections.register(desc)
|
|
203
217
|
for (const desc of collections) dns.collections.register(desc)
|
|
218
|
+
for (const desc of indexes) dns.indexes.register(desc)
|
|
204
219
|
HyperdbBuilder.toDisk(db, dbDir, { esm: true })
|
|
205
220
|
|
|
206
221
|
const d = Hyperdispatch.from(schemaDir, dispatchDir)
|
|
@@ -217,7 +232,7 @@ function emitMain(dir, ns, { types, collections, dispatches }, { rpc, extend = {
|
|
|
217
232
|
}
|
|
218
233
|
}
|
|
219
234
|
|
|
220
|
-
function emitLocal(dir, ns, { types, collections }) {
|
|
235
|
+
function emitLocal(dir, ns, { types, collections, indexes = [] }) {
|
|
221
236
|
const schemaDir = join(dir, 'schema')
|
|
222
237
|
const dbDir = join(dir, 'db')
|
|
223
238
|
|
|
@@ -231,6 +246,7 @@ function emitLocal(dir, ns, { types, collections }) {
|
|
|
231
246
|
const dns = db.namespace(ns)
|
|
232
247
|
for (const desc of builtinCollections(ns, 'local')) dns.collections.register(desc)
|
|
233
248
|
for (const desc of collections) dns.collections.register(desc)
|
|
249
|
+
for (const desc of indexes) dns.indexes.register(desc)
|
|
234
250
|
HyperdbBuilder.toDisk(db, dbDir, { esm: true })
|
|
235
251
|
}
|
|
236
252
|
|