@dxos/echo-query 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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,387 +1,367 @@
1
- // ../../../common/invariant/dist/lib/browser/index.mjs
1
+ //#region ../../../common/invariant/dist/lib/browser/index.mjs
2
2
  var assertArgument = (condition, argumentName, message) => {
3
- if (!condition) {
4
- const error = new TypeError(`Invalid argument \`${argumentName}\`` + (message ? `: ${message}` : ""));
5
- Error.captureStackTrace(error, assertArgument);
6
- throw error;
7
- }
3
+ if (!condition) {
4
+ const error = /* @__PURE__ */ new TypeError(`Invalid argument \`${argumentName}\`` + (message ? `: ${message}` : ""));
5
+ Error.captureStackTrace(error, assertArgument);
6
+ throw error;
7
+ }
8
8
  };
9
9
 
10
- // src/query-lite/query-lite.ts
11
- var OrderClass = class _OrderClass {
12
- constructor(ast) {
13
- this.ast = ast;
14
- }
15
- static variance = {};
16
- static is(value) {
17
- return typeof value === "object" && value !== null && "~Order" in value;
18
- }
19
- "~Order" = _OrderClass.variance;
10
+ //#endregion
11
+ //#region src/query-lite/query-lite.ts
12
+ var OrderClass = class OrderClass {
13
+ static variance = {};
14
+ static is(value) {
15
+ return typeof value === "object" && value !== null && "~Order" in value;
16
+ }
17
+ constructor(ast) {
18
+ this.ast = ast;
19
+ }
20
+ "~Order" = OrderClass.variance;
20
21
  };
21
- var Order1;
22
- ((Order12) => {
23
- Order12.natural = new OrderClass({ kind: "natural" });
24
- Order12.property = (property2, direction) => new OrderClass({
25
- kind: "property",
26
- property: property2,
27
- direction
28
- });
22
+ let Order1;
23
+ (function(_Order) {
24
+ _Order.natural = new OrderClass({ kind: "natural" });
25
+ _Order.property = (property, direction) => new OrderClass({
26
+ kind: "property",
27
+ property,
28
+ direction
29
+ });
30
+ _Order.rank = (direction = "desc") => new OrderClass({
31
+ kind: "rank",
32
+ direction
33
+ });
29
34
  })(Order1 || (Order1 = {}));
30
- var Order2 = Order1;
31
- var FilterClass = class _FilterClass {
32
- constructor(ast) {
33
- this.ast = ast;
34
- }
35
- static variance = {};
36
- static is(value) {
37
- return typeof value === "object" && value !== null && "~Filter" in value;
38
- }
39
- static fromAst(ast) {
40
- return new _FilterClass(ast);
41
- }
42
- static everything() {
43
- return new _FilterClass({
44
- type: "object",
45
- typename: null,
46
- props: {}
47
- });
48
- }
49
- static nothing() {
50
- return new _FilterClass({
51
- type: "not",
52
- filter: {
53
- type: "object",
54
- typename: null,
55
- props: {}
56
- }
57
- });
58
- }
59
- static relation() {
60
- return new _FilterClass({
61
- type: "object",
62
- typename: null,
63
- props: {}
64
- });
65
- }
66
- static ids(...ids) {
67
- if (ids.length === 0) {
68
- return _FilterClass.nothing();
69
- }
70
- return new _FilterClass({
71
- type: "object",
72
- typename: null,
73
- id: ids,
74
- props: {}
75
- });
76
- }
77
- static type(schema, props) {
78
- if (typeof schema !== "string") {
79
- throw new TypeError("expected typename as the first paramter");
80
- }
81
- return new _FilterClass({
82
- type: "object",
83
- typename: makeTypeDxn(schema),
84
- ...propsFilterToAst(props ?? {})
85
- });
86
- }
87
- static typename(typename) {
88
- return new _FilterClass({
89
- type: "object",
90
- typename: makeTypeDxn(typename),
91
- props: {}
92
- });
93
- }
94
- static typeDXN(dxn) {
95
- return new _FilterClass({
96
- type: "object",
97
- typename: dxn.toString(),
98
- props: {}
99
- });
100
- }
101
- static tag(tag) {
102
- return new _FilterClass({
103
- type: "tag",
104
- tag
105
- });
106
- }
107
- static props(props) {
108
- return new _FilterClass({
109
- type: "object",
110
- typename: null,
111
- ...propsFilterToAst(props)
112
- });
113
- }
114
- static text(text, options) {
115
- return new _FilterClass({
116
- type: "text-search",
117
- text,
118
- searchKind: options?.type
119
- });
120
- }
121
- static foreignKeys(schema, keys) {
122
- assertArgument(typeof schema === "string", "schema");
123
- assertArgument(!schema.startsWith("dxn:"), "schema");
124
- return new _FilterClass({
125
- type: "object",
126
- typename: `dxn:type:${schema}`,
127
- props: {},
128
- foreignKeys: keys
129
- });
130
- }
131
- static eq(value) {
132
- if (!isRef(value) && typeof value === "object" && value !== null) {
133
- throw new TypeError("Cannot use object as a value for eq filter");
134
- }
135
- return new _FilterClass({
136
- type: "compare",
137
- operator: "eq",
138
- value: isRef(value) ? value.noInline().encode() : value
139
- });
140
- }
141
- static neq(value) {
142
- return new _FilterClass({
143
- type: "compare",
144
- operator: "neq",
145
- value
146
- });
147
- }
148
- static gt(value) {
149
- return new _FilterClass({
150
- type: "compare",
151
- operator: "gt",
152
- value
153
- });
154
- }
155
- static gte(value) {
156
- return new _FilterClass({
157
- type: "compare",
158
- operator: "gte",
159
- value
160
- });
161
- }
162
- static lt(value) {
163
- return new _FilterClass({
164
- type: "compare",
165
- operator: "lt",
166
- value
167
- });
168
- }
169
- static lte(value) {
170
- return new _FilterClass({
171
- type: "compare",
172
- operator: "lte",
173
- value
174
- });
175
- }
176
- static in(...values) {
177
- return new _FilterClass({
178
- type: "in",
179
- values
180
- });
181
- }
182
- static contains(value) {
183
- return new _FilterClass({
184
- type: "contains",
185
- value
186
- });
187
- }
188
- static between(from, to) {
189
- return new _FilterClass({
190
- type: "range",
191
- from,
192
- to
193
- });
194
- }
195
- static not(filter) {
196
- return new _FilterClass({
197
- type: "not",
198
- filter: filter.ast
199
- });
200
- }
201
- static and(...filters) {
202
- return new _FilterClass({
203
- type: "and",
204
- filters: filters.map((f) => f.ast)
205
- });
206
- }
207
- static or(...filters) {
208
- return new _FilterClass({
209
- type: "or",
210
- filters: filters.map((f) => f.ast)
211
- });
212
- }
213
- "~Filter" = _FilterClass.variance;
35
+ const Order2 = Order1;
36
+ var FilterClass = class FilterClass {
37
+ static variance = {};
38
+ static is(value) {
39
+ return typeof value === "object" && value !== null && "~Filter" in value;
40
+ }
41
+ static fromAst(ast) {
42
+ return new FilterClass(ast);
43
+ }
44
+ static everything() {
45
+ return new FilterClass({
46
+ type: "object",
47
+ typename: null,
48
+ props: {}
49
+ });
50
+ }
51
+ static nothing() {
52
+ return new FilterClass({
53
+ type: "not",
54
+ filter: {
55
+ type: "object",
56
+ typename: null,
57
+ props: {}
58
+ }
59
+ });
60
+ }
61
+ static relation() {
62
+ return new FilterClass({
63
+ type: "object",
64
+ typename: null,
65
+ props: {}
66
+ });
67
+ }
68
+ static id(...ids) {
69
+ if (ids.length === 0) return FilterClass.nothing();
70
+ return new FilterClass({
71
+ type: "object",
72
+ typename: null,
73
+ id: ids,
74
+ props: {}
75
+ });
76
+ }
77
+ static type(schema, props) {
78
+ if (typeof schema !== "string") throw new TypeError("expected typename as the first paramter");
79
+ return new FilterClass({
80
+ type: "object",
81
+ typename: makeTypeDxn(schema),
82
+ ...propsFilterToAst(props ?? {})
83
+ });
84
+ }
85
+ static typename(typename) {
86
+ return new FilterClass({
87
+ type: "object",
88
+ typename: makeTypeDxn(typename),
89
+ props: {}
90
+ });
91
+ }
92
+ static typeDXN(dxn) {
93
+ return new FilterClass({
94
+ type: "object",
95
+ typename: dxn.toString(),
96
+ props: {}
97
+ });
98
+ }
99
+ static tag(tag) {
100
+ return new FilterClass({
101
+ type: "tag",
102
+ tag
103
+ });
104
+ }
105
+ static props(props) {
106
+ return new FilterClass({
107
+ type: "object",
108
+ typename: null,
109
+ ...propsFilterToAst(props)
110
+ });
111
+ }
112
+ static text(text, options) {
113
+ return new FilterClass({
114
+ type: "text-search",
115
+ text,
116
+ searchKind: options?.type
117
+ });
118
+ }
119
+ static foreignKeys(schema, keys) {
120
+ assertArgument(typeof schema === "string", "schema");
121
+ assertArgument(!schema.startsWith("dxn:"), "schema");
122
+ return new FilterClass({
123
+ type: "object",
124
+ typename: `dxn:type:${schema}`,
125
+ props: {},
126
+ foreignKeys: keys
127
+ });
128
+ }
129
+ static eq(value) {
130
+ if (!isRef(value) && typeof value === "object" && value !== null) throw new TypeError("Cannot use object as a value for eq filter");
131
+ return new FilterClass({
132
+ type: "compare",
133
+ operator: "eq",
134
+ value: isRef(value) ? value.noInline().encode() : value
135
+ });
136
+ }
137
+ static neq(value) {
138
+ return new FilterClass({
139
+ type: "compare",
140
+ operator: "neq",
141
+ value
142
+ });
143
+ }
144
+ static gt(value) {
145
+ return new FilterClass({
146
+ type: "compare",
147
+ operator: "gt",
148
+ value
149
+ });
150
+ }
151
+ static gte(value) {
152
+ return new FilterClass({
153
+ type: "compare",
154
+ operator: "gte",
155
+ value
156
+ });
157
+ }
158
+ static lt(value) {
159
+ return new FilterClass({
160
+ type: "compare",
161
+ operator: "lt",
162
+ value
163
+ });
164
+ }
165
+ static lte(value) {
166
+ return new FilterClass({
167
+ type: "compare",
168
+ operator: "lte",
169
+ value
170
+ });
171
+ }
172
+ static in(...values) {
173
+ return new FilterClass({
174
+ type: "in",
175
+ values
176
+ });
177
+ }
178
+ static contains(value) {
179
+ return new FilterClass({
180
+ type: "contains",
181
+ value
182
+ });
183
+ }
184
+ static between(from, to) {
185
+ return new FilterClass({
186
+ type: "range",
187
+ from,
188
+ to
189
+ });
190
+ }
191
+ static not(filter) {
192
+ return new FilterClass({
193
+ type: "not",
194
+ filter: filter.ast
195
+ });
196
+ }
197
+ static and(...filters) {
198
+ return new FilterClass({
199
+ type: "and",
200
+ filters: filters.map((f) => f.ast)
201
+ });
202
+ }
203
+ static or(...filters) {
204
+ return new FilterClass({
205
+ type: "or",
206
+ filters: filters.map((f) => f.ast)
207
+ });
208
+ }
209
+ constructor(ast) {
210
+ this.ast = ast;
211
+ }
212
+ "~Filter" = FilterClass.variance;
214
213
  };
215
- var Filter1 = FilterClass;
216
- var propsFilterToAst = (predicates) => {
217
- let idFilter;
218
- if ("id" in predicates) {
219
- assertArgument(
220
- typeof predicates.id === "string" || Array.isArray(predicates.id),
221
- "predicates.id",
222
- "invalid id filter"
223
- );
224
- idFilter = typeof predicates.id === "string" ? [predicates.id] : predicates.id;
225
- }
226
- return {
227
- id: idFilter,
228
- props: Object.fromEntries(
229
- Object.entries(predicates).filter(([prop, _value]) => prop !== "id").map(([prop, predicate]) => [prop, processPredicate(predicate)])
230
- )
231
- };
214
+ const Filter1 = FilterClass;
215
+ const propsFilterToAst = (predicates) => {
216
+ let idFilter;
217
+ if ("id" in predicates) {
218
+ assertArgument(typeof predicates.id === "string" || Array.isArray(predicates.id), "predicates.id", "invalid id filter");
219
+ idFilter = typeof predicates.id === "string" ? [predicates.id] : predicates.id;
220
+ }
221
+ return {
222
+ id: idFilter,
223
+ props: Object.fromEntries(Object.entries(predicates).filter(([prop, _value]) => prop !== "id").map(([prop, predicate]) => [prop, processPredicate(predicate)]))
224
+ };
232
225
  };
233
- var processPredicate = (predicate) => {
234
- if (FilterClass.is(predicate)) {
235
- return predicate.ast;
236
- }
237
- if (Array.isArray(predicate)) {
238
- throw new Error("Array predicates are not yet supported.");
239
- }
240
- if (!isRef(predicate) && typeof predicate === "object" && predicate !== null) {
241
- const nestedProps = Object.fromEntries(
242
- Object.entries(predicate).map(([key, value]) => [key, processPredicate(value)])
243
- );
244
- return {
245
- type: "object",
246
- typename: null,
247
- props: nestedProps
248
- };
249
- }
250
- return FilterClass.eq(predicate).ast;
226
+ const processPredicate = (predicate) => {
227
+ if (FilterClass.is(predicate)) return predicate.ast;
228
+ if (Array.isArray(predicate)) throw new Error("Array predicates are not yet supported.");
229
+ if (!isRef(predicate) && typeof predicate === "object" && predicate !== null) return {
230
+ type: "object",
231
+ typename: null,
232
+ props: Object.fromEntries(Object.entries(predicate).map(([key, value]) => [key, processPredicate(value)]))
233
+ };
234
+ return FilterClass.eq(predicate).ast;
251
235
  };
252
- var QueryClass = class _QueryClass {
253
- constructor(ast) {
254
- this.ast = ast;
255
- }
256
- static variance = {};
257
- static is(value) {
258
- return typeof value === "object" && value !== null && "~Query" in value;
259
- }
260
- static fromAst(ast) {
261
- return new _QueryClass(ast);
262
- }
263
- static select(filter) {
264
- return new _QueryClass({
265
- type: "select",
266
- filter: filter.ast
267
- });
268
- }
269
- static type(schema, predicates) {
270
- return new _QueryClass({
271
- type: "select",
272
- filter: FilterClass.type(schema, predicates).ast
273
- });
274
- }
275
- static all(...queries) {
276
- if (queries.length === 0) {
277
- throw new TypeError(
278
- "Query.all combines results of multiple queries, to query all objects use Query.select(Filter.everything())"
279
- );
280
- }
281
- return new _QueryClass({
282
- type: "union",
283
- queries: queries.map((q) => q.ast)
284
- });
285
- }
286
- static without(source, exclude) {
287
- return new _QueryClass({
288
- type: "set-difference",
289
- source: source.ast,
290
- exclude: exclude.ast
291
- });
292
- }
293
- "~Query" = _QueryClass.variance;
294
- select(filter) {
295
- if (FilterClass.is(filter)) {
296
- return new _QueryClass({
297
- type: "filter",
298
- selection: this.ast,
299
- filter: filter.ast
300
- });
301
- } else {
302
- return new _QueryClass({
303
- type: "filter",
304
- selection: this.ast,
305
- filter: FilterClass.props(filter).ast
306
- });
307
- }
308
- }
309
- reference(key) {
310
- return new _QueryClass({
311
- type: "reference-traversal",
312
- anchor: this.ast,
313
- property: key
314
- });
315
- }
316
- referencedBy(target, key) {
317
- assertArgument(typeof target === "string", "target");
318
- assertArgument(!target.startsWith("dxn:"), "target");
319
- return new _QueryClass({
320
- type: "incoming-references",
321
- anchor: this.ast,
322
- property: key,
323
- typename: target
324
- });
325
- }
326
- sourceOf(relation, predicates) {
327
- return new _QueryClass({
328
- type: "relation",
329
- anchor: this.ast,
330
- direction: "outgoing",
331
- filter: FilterClass.type(relation, predicates).ast
332
- });
333
- }
334
- targetOf(relation, predicates) {
335
- return new _QueryClass({
336
- type: "relation",
337
- anchor: this.ast,
338
- direction: "incoming",
339
- filter: FilterClass.type(relation, predicates).ast
340
- });
341
- }
342
- source() {
343
- return new _QueryClass({
344
- type: "relation-traversal",
345
- anchor: this.ast,
346
- direction: "source"
347
- });
348
- }
349
- target() {
350
- return new _QueryClass({
351
- type: "relation-traversal",
352
- anchor: this.ast,
353
- direction: "target"
354
- });
355
- }
356
- orderBy(...order) {
357
- return new _QueryClass({
358
- type: "order",
359
- query: this.ast,
360
- order: order.map((o) => o.ast)
361
- });
362
- }
363
- options(options) {
364
- return new _QueryClass({
365
- type: "options",
366
- query: this.ast,
367
- options
368
- });
369
- }
236
+ var QueryClass = class QueryClass {
237
+ static variance = {};
238
+ static is(value) {
239
+ return typeof value === "object" && value !== null && "~Query" in value;
240
+ }
241
+ static fromAst(ast) {
242
+ return new QueryClass(ast);
243
+ }
244
+ static select(filter) {
245
+ return new QueryClass({
246
+ type: "select",
247
+ filter: filter.ast
248
+ });
249
+ }
250
+ static type(schema, predicates) {
251
+ return new QueryClass({
252
+ type: "select",
253
+ filter: FilterClass.type(schema, predicates).ast
254
+ });
255
+ }
256
+ static all(...queries) {
257
+ if (queries.length === 0) throw new TypeError("Query.all combines results of multiple queries, to query all objects use Query.select(Filter.everything())");
258
+ return new QueryClass({
259
+ type: "union",
260
+ queries: queries.map((q) => q.ast)
261
+ });
262
+ }
263
+ static without(source, exclude) {
264
+ return new QueryClass({
265
+ type: "set-difference",
266
+ source: source.ast,
267
+ exclude: exclude.ast
268
+ });
269
+ }
270
+ constructor(ast) {
271
+ this.ast = ast;
272
+ }
273
+ "~Query" = QueryClass.variance;
274
+ select(filter) {
275
+ if (FilterClass.is(filter)) return new QueryClass({
276
+ type: "filter",
277
+ selection: this.ast,
278
+ filter: filter.ast
279
+ });
280
+ else return new QueryClass({
281
+ type: "filter",
282
+ selection: this.ast,
283
+ filter: FilterClass.props(filter).ast
284
+ });
285
+ }
286
+ reference(key) {
287
+ return new QueryClass({
288
+ type: "reference-traversal",
289
+ anchor: this.ast,
290
+ property: key
291
+ });
292
+ }
293
+ referencedBy(target, key) {
294
+ const typename = target !== void 0 ? (assertArgument(typeof target === "string", "target"), assertArgument(!target.startsWith("dxn:"), "target"), target) : null;
295
+ return new QueryClass({
296
+ type: "incoming-references",
297
+ anchor: this.ast,
298
+ property: key ?? null,
299
+ typename
300
+ });
301
+ }
302
+ sourceOf(relation, predicates) {
303
+ return new QueryClass({
304
+ type: "relation",
305
+ anchor: this.ast,
306
+ direction: "outgoing",
307
+ filter: FilterClass.type(relation, predicates).ast
308
+ });
309
+ }
310
+ targetOf(relation, predicates) {
311
+ return new QueryClass({
312
+ type: "relation",
313
+ anchor: this.ast,
314
+ direction: "incoming",
315
+ filter: FilterClass.type(relation, predicates).ast
316
+ });
317
+ }
318
+ source() {
319
+ return new QueryClass({
320
+ type: "relation-traversal",
321
+ anchor: this.ast,
322
+ direction: "source"
323
+ });
324
+ }
325
+ target() {
326
+ return new QueryClass({
327
+ type: "relation-traversal",
328
+ anchor: this.ast,
329
+ direction: "target"
330
+ });
331
+ }
332
+ orderBy(...order) {
333
+ return new QueryClass({
334
+ type: "order",
335
+ query: this.ast,
336
+ order: order.map((o) => o.ast)
337
+ });
338
+ }
339
+ limit(limit) {
340
+ return new QueryClass({
341
+ type: "limit",
342
+ query: this.ast,
343
+ limit
344
+ });
345
+ }
346
+ options(options) {
347
+ return new QueryClass({
348
+ type: "options",
349
+ query: this.ast,
350
+ options
351
+ });
352
+ }
370
353
  };
371
- var Query1 = QueryClass;
372
- var RefTypeId = Symbol("@dxos/echo-query/Ref");
373
- var isRef = (obj) => {
374
- return obj && typeof obj === "object" && RefTypeId in obj;
354
+ const Query1 = QueryClass;
355
+ const RefTypeId = Symbol("@dxos/echo-query/Ref");
356
+ const isRef = (obj) => {
357
+ return obj && typeof obj === "object" && RefTypeId in obj;
375
358
  };
376
- var makeTypeDxn = (typename) => {
377
- assertArgument(typeof typename === "string", "typename");
378
- assertArgument(!typename.startsWith("dxn:"), "typename");
379
- return `dxn:type:${typename}`;
380
- };
381
- export {
382
- Filter1 as Filter,
383
- Filter1,
384
- Order2 as Order,
385
- Query1 as Query,
386
- Query1
359
+ const makeTypeDxn = (typename) => {
360
+ assertArgument(typeof typename === "string", "typename");
361
+ assertArgument(!typename.startsWith("dxn:"), "typename");
362
+ return `dxn:type:${typename}`;
387
363
  };
364
+
365
+ //#endregion
366
+ export { Filter1 as Filter, Filter1, Order2 as Order, Query1 as Query, Query1 };
367
+ //# sourceMappingURL=index.js.map