@blitznocode/blitz-orm 0.0.41 → 0.0.43
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/LICENSE +661 -661
- package/dist/index.d.ts +243 -243
- package/dist/index.js +22 -75
- package/package.json +4 -5
- package/readme.md +50 -44
package/dist/index.js
CHANGED
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
8
|
var __export = (target, all) => {
|
|
12
9
|
for (var name in all)
|
|
13
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -26,44 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
23
|
));
|
|
27
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
25
|
|
|
29
|
-
// ../essentials/dist/index.js
|
|
30
|
-
var require_dist = __commonJS({
|
|
31
|
-
"../essentials/dist/index.js"(exports, module2) {
|
|
32
|
-
"use strict";
|
|
33
|
-
var __defProp2 = Object.defineProperty;
|
|
34
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
35
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
36
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
37
|
-
var __export2 = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps2 = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames2(from))
|
|
44
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
45
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
50
|
-
var essentials_exports = {};
|
|
51
|
-
__export2(essentials_exports, {
|
|
52
|
-
oFilter: () => oFilter4,
|
|
53
|
-
oFind: () => oFind2,
|
|
54
|
-
oMap: () => oMap,
|
|
55
|
-
objectFilter: () => objectFilter
|
|
56
|
-
});
|
|
57
|
-
module2.exports = __toCommonJS2(essentials_exports);
|
|
58
|
-
var oFilter4 = (obj, fn) => Object.fromEntries(Object.entries(obj).filter(fn));
|
|
59
|
-
function objectFilter(obj, fn) {
|
|
60
|
-
return Object.fromEntries(Object.entries(obj).filter(([k, v]) => fn(k, v)));
|
|
61
|
-
}
|
|
62
|
-
var oMap = (obj, fn) => Object.entries(obj).map(([key, value]) => fn(key, value));
|
|
63
|
-
var oFind2 = (obj, fn) => Object.values(Object.fromEntries(Object.entries(obj).filter(fn)))[0];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
26
|
// src/index.ts
|
|
68
27
|
var src_exports = {};
|
|
69
28
|
__export(src_exports, {
|
|
@@ -82,10 +41,13 @@ var defaultConfig = {
|
|
|
82
41
|
};
|
|
83
42
|
|
|
84
43
|
// src/helpers.ts
|
|
85
|
-
var import_essentials = __toESM(require_dist());
|
|
86
44
|
var import_immer = __toESM(require("immer"));
|
|
87
45
|
var import_object_traversal = require("object-traversal");
|
|
88
46
|
var import_radash = require("radash");
|
|
47
|
+
var oFind = (obj, fn) => Object.values(
|
|
48
|
+
Object.fromEntries(Object.entries(obj).filter(([k, v]) => fn(k, v)))
|
|
49
|
+
)[0];
|
|
50
|
+
var oFilter = (obj, fn) => Object.fromEntries(Object.entries(obj).filter(([k, v]) => fn(k, v)));
|
|
89
51
|
var enrichSchema = (schema) => {
|
|
90
52
|
const allLinkedFields = [];
|
|
91
53
|
const withExtensionsSchema = (0, import_immer.default)(
|
|
@@ -294,14 +256,8 @@ var getCurrentFields = (currentSchema, node) => {
|
|
|
294
256
|
const unidentifiedFields = [...usedFields, ...localFilterFields].filter(
|
|
295
257
|
(x) => !allowedFields.includes(x)
|
|
296
258
|
);
|
|
297
|
-
const localFilters = !node.$filter ? {} : (
|
|
298
|
-
|
|
299
|
-
([k, _v]) => localFilterFields.includes(k)
|
|
300
|
-
);
|
|
301
|
-
const nestedFilters = !node.$filter ? {} : (0, import_essentials.oFilter)(
|
|
302
|
-
node.$filter,
|
|
303
|
-
([k, _v]) => nestedFilterFields.includes(k)
|
|
304
|
-
);
|
|
259
|
+
const localFilters = !node.$filter ? {} : oFilter(node.$filter, (k, _v) => localFilterFields.includes(k));
|
|
260
|
+
const nestedFilters = !node.$filter ? {} : oFilter(node.$filter, (k, _v) => nestedFilterFields.includes(k));
|
|
305
261
|
return {
|
|
306
262
|
fields: availableFields,
|
|
307
263
|
dataFields: availableDataFields,
|
|
@@ -545,7 +501,6 @@ var parseTQLRes = async (req, res) => {
|
|
|
545
501
|
var import_radash3 = require("radash");
|
|
546
502
|
|
|
547
503
|
// src/pipeline/postprocess/buildBQLTree.ts
|
|
548
|
-
var import_essentials2 = __toESM(require_dist());
|
|
549
504
|
var import_immer2 = __toESM(require("immer"));
|
|
550
505
|
var import_object_traversal2 = require("object-traversal");
|
|
551
506
|
var import_radash4 = require("radash");
|
|
@@ -591,7 +546,7 @@ var filterChildrenEntities = (things, ids, node, path) => things.map(([id, entit
|
|
|
591
546
|
);
|
|
592
547
|
if (currentFieldConf) {
|
|
593
548
|
const onlyMetadataEntity = {
|
|
594
|
-
...
|
|
549
|
+
...oFilter(entity, (k, _v) => k.startsWith("$"))
|
|
595
550
|
};
|
|
596
551
|
const withFieldsEntity = currentFieldConf.$fields ? {
|
|
597
552
|
...onlyMetadataEntity,
|
|
@@ -1208,7 +1163,6 @@ var buildTQLMutation = async (req) => {
|
|
|
1208
1163
|
};
|
|
1209
1164
|
|
|
1210
1165
|
// src/pipeline/preprocess/parseBQLMutation.ts
|
|
1211
|
-
var import_essentials3 = __toESM(require_dist());
|
|
1212
1166
|
var import_immer3 = __toESM(require("immer"));
|
|
1213
1167
|
var import_object_traversal3 = require("object-traversal");
|
|
1214
1168
|
var import_radash8 = require("radash");
|
|
@@ -1245,9 +1199,9 @@ var parseBQLMutation = async (req) => {
|
|
|
1245
1199
|
const currentValue = value[currentField.path];
|
|
1246
1200
|
if (currentValue === void 0)
|
|
1247
1201
|
return;
|
|
1248
|
-
const currentRoleFieldSchema = "roles" in currentSchema ?
|
|
1202
|
+
const currentRoleFieldSchema = "roles" in currentSchema ? oFind(
|
|
1249
1203
|
currentSchema.roles,
|
|
1250
|
-
(
|
|
1204
|
+
(k) => k === currentField.path
|
|
1251
1205
|
) : null;
|
|
1252
1206
|
const currentFieldSchema = currentLinkFieldSchema || currentRoleFieldSchema;
|
|
1253
1207
|
if (currentRoleFieldSchema && [...new Set(currentRoleFieldSchema.playedBy?.map((x) => x.thing))].length !== 1) {
|
|
@@ -1269,11 +1223,11 @@ var parseBQLMutation = async (req) => {
|
|
|
1269
1223
|
};
|
|
1270
1224
|
const relation = getCurrentRelation();
|
|
1271
1225
|
const relationSchema = relation === "$self" ? currentSchema : schema.relations[relation];
|
|
1272
|
-
const currentFieldRole =
|
|
1226
|
+
const currentFieldRole = oFind(
|
|
1273
1227
|
relationSchema.roles,
|
|
1274
|
-
(
|
|
1228
|
+
(k, _v) => k === currentField.path
|
|
1275
1229
|
);
|
|
1276
|
-
if (currentFieldRole?.playedBy
|
|
1230
|
+
if (currentFieldRole?.playedBy?.length === 0)
|
|
1277
1231
|
throw new Error(
|
|
1278
1232
|
`unused role: ${currentPath}.${currentField.path}`
|
|
1279
1233
|
);
|
|
@@ -1438,10 +1392,7 @@ var parseBQLMutation = async (req) => {
|
|
|
1438
1392
|
(x) => x.path === fieldPath
|
|
1439
1393
|
);
|
|
1440
1394
|
const currentLinkedDef = currentLinkDef?.oppositeLinkFieldsPlayedBy[0];
|
|
1441
|
-
const currentRoleDef = "roles" in currentSchema ? (
|
|
1442
|
-
currentSchema.roles,
|
|
1443
|
-
([k, _v]) => k === fieldPath
|
|
1444
|
-
) : void 0;
|
|
1395
|
+
const currentRoleDef = "roles" in currentSchema ? oFind(currentSchema.roles, (k, _v) => k === fieldPath) : void 0;
|
|
1445
1396
|
const currentDef = currentFieldDef || currentLinkedDef || currentRoleDef;
|
|
1446
1397
|
if (!currentDef) {
|
|
1447
1398
|
throw new Error(`no field Def for ${fieldPath}`);
|
|
@@ -1551,14 +1502,14 @@ var parseBQLMutation = async (req) => {
|
|
|
1551
1502
|
"An id must be specified either in the mutation or has tu have a default value in the schema"
|
|
1552
1503
|
);
|
|
1553
1504
|
}
|
|
1554
|
-
const rolesObjFiltered =
|
|
1505
|
+
const rolesObjFiltered = oFilter(
|
|
1555
1506
|
val,
|
|
1556
|
-
(
|
|
1507
|
+
(k, _v) => roleFieldPaths.includes(k)
|
|
1557
1508
|
);
|
|
1558
1509
|
const rolesObjOnlyIds = (0, import_radash8.mapEntries)(rolesObjFiltered, (k, v) => {
|
|
1559
1510
|
return [k, v.$id || v];
|
|
1560
1511
|
});
|
|
1561
|
-
const objWithMetaDataOnly =
|
|
1512
|
+
const objWithMetaDataOnly = oFilter(val, (k, _v) => {
|
|
1562
1513
|
return k.startsWith("$") || k.startsWith("Symbol");
|
|
1563
1514
|
});
|
|
1564
1515
|
if (Object.keys(rolesObjFiltered).filter((x) => !x.startsWith("$")).length > 0) {
|
|
@@ -1581,9 +1532,9 @@ var parseBQLMutation = async (req) => {
|
|
|
1581
1532
|
return;
|
|
1582
1533
|
}
|
|
1583
1534
|
if (val.$op === "noop") {
|
|
1584
|
-
const rolesWithLinks =
|
|
1535
|
+
const rolesWithLinks = oFilter(
|
|
1585
1536
|
rolesObjOnlyIds,
|
|
1586
|
-
(
|
|
1537
|
+
(_k, v) => v.some(
|
|
1587
1538
|
(x) => x.$op === "link" || x.$op === "create"
|
|
1588
1539
|
)
|
|
1589
1540
|
);
|
|
@@ -1591,14 +1542,12 @@ var parseBQLMutation = async (req) => {
|
|
|
1591
1542
|
rolesWithLinks,
|
|
1592
1543
|
(k, v) => [
|
|
1593
1544
|
k,
|
|
1594
|
-
v.filter(
|
|
1595
|
-
(x) => x.$op === "link" || x.$op === "create"
|
|
1596
|
-
).map((y) => y.$id)
|
|
1545
|
+
v.filter((x) => x.$op === "link" || x.$op === "create").map((y) => y.$id)
|
|
1597
1546
|
]
|
|
1598
1547
|
);
|
|
1599
|
-
const rolesWithUnlinks =
|
|
1548
|
+
const rolesWithUnlinks = oFilter(
|
|
1600
1549
|
rolesObjOnlyIds,
|
|
1601
|
-
(
|
|
1550
|
+
(_k, v) => v.some(
|
|
1602
1551
|
(x) => x.$op === "unlink" || x.$op === "delete"
|
|
1603
1552
|
)
|
|
1604
1553
|
);
|
|
@@ -1606,9 +1555,7 @@ var parseBQLMutation = async (req) => {
|
|
|
1606
1555
|
rolesWithUnlinks,
|
|
1607
1556
|
(k, v) => [
|
|
1608
1557
|
k,
|
|
1609
|
-
v.filter(
|
|
1610
|
-
(x) => x.$op === "unlink" || x.$op === "delete"
|
|
1611
|
-
).map((y) => y.$id)
|
|
1558
|
+
v.filter((x) => x.$op === "unlink" || x.$op === "delete").map((y) => y.$id)
|
|
1612
1559
|
]
|
|
1613
1560
|
);
|
|
1614
1561
|
const rolesWithReplaces = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blitznocode/blitz-orm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.43",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
"license": "AGPL-3.0-only",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "
|
|
21
|
-
"directory": "packages/blitz-orm"
|
|
20
|
+
"url": "https://github.com/Blitzapps/blitz-orm"
|
|
22
21
|
},
|
|
23
22
|
"files": [
|
|
24
23
|
"README.md",
|
|
@@ -62,9 +61,9 @@
|
|
|
62
61
|
},
|
|
63
62
|
"description": "Blitz-orm is a public package that can be open-sourced",
|
|
64
63
|
"bugs": {
|
|
65
|
-
"url": "https://github.com/
|
|
64
|
+
"url": "https://github.com/Blitzapps/blitz-orm/issues"
|
|
66
65
|
},
|
|
67
|
-
"homepage": "https://github.com/
|
|
66
|
+
"homepage": "https://github.com/Blitzapps/blitz-orm#readme",
|
|
68
67
|
"directories": {
|
|
69
68
|
"test": "tests"
|
|
70
69
|
},
|
package/readme.md
CHANGED
|
@@ -1,44 +1,50 @@
|
|
|
1
|
-
Blitz-orm
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
##
|
|
38
|
-
You can
|
|
39
|
-
|
|
40
|
-
## Warning
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
## Working
|
|
44
|
-
|
|
1
|
+
# Blitz-orm
|
|
2
|
+
Blitz-orm is an Object Relational Mapper (ORM) for graph databases that uses a JSON query language called Blitz Query Language (BQL). BQL is similar to GraphQL but uses JSON instead of strings.
|
|
3
|
+
|
|
4
|
+
Blitz-orm is similar to other ORM packages such as Prisma. You define a BQL schema and it gets translated to different databases (currently only compatible with TypeDB).
|
|
5
|
+
|
|
6
|
+
## Compatibility
|
|
7
|
+
Currently, the only database that is compatible with Blitz-orm is TypeDB. The goal is to build adapters for other graph databases such as Dgraph and Neo4j, as well as classic databases like PostgreSQL and MongoDB in the future.
|
|
8
|
+
|
|
9
|
+
## How to Use
|
|
10
|
+
1. Install the package using your package manager, for example:
|
|
11
|
+
`yarn add @blitznocode/blitz-orm`
|
|
12
|
+
2. Create a Borm schema. You can find an example in the test folder.
|
|
13
|
+
3. The borm.define() function is currently not working, so you will need to manually translate your BQL schema into a TypeQL schema (an example can be found in the test folder).
|
|
14
|
+
4. Create a configuration file with the database name that you have created in TypeDB.
|
|
15
|
+
5. Initialize Blitz-orm in a file like this:
|
|
16
|
+
```
|
|
17
|
+
import BormClient from '@blitznocode/blitz-orm';
|
|
18
|
+
|
|
19
|
+
import { bormConfig } from './borm.config';
|
|
20
|
+
import { schema } from './schema';
|
|
21
|
+
|
|
22
|
+
const bormClient = new BormClient({
|
|
23
|
+
schema,
|
|
24
|
+
config: bormConfig,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export default bormClient;
|
|
28
|
+
```
|
|
29
|
+
6. You can then run queries and mutations like this:
|
|
30
|
+
```
|
|
31
|
+
const res = await bormClient.mutate({$entity: 'User', name: 'Ann'}, { noMetadata: true });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## How to Run TypeDB Locally
|
|
35
|
+
To run TypeDB locally, follow the official instructions at https://docs.vaticle.com/docs/running-typedb/install-and-run. It is recommended to run TypeDB Studio, define the schema there, and test with pure TypeQL before using Blitz-orm.
|
|
36
|
+
|
|
37
|
+
## Collaboration & Contact
|
|
38
|
+
You can contribute to the project by adding adapters for other databases, developing a BQL-to-GraphQL mapper, enhancing performance, or contributing to the public roadmap for this package (not yet published). To get in touch, please send an email to loic@blitznocode.com.
|
|
39
|
+
|
|
40
|
+
## Warning
|
|
41
|
+
Blitz-orm is currently in alpha version and not ready for production use. Some key queries and mutations do work, but there is still much that needs to be done and performance improvements are needed. One of the biggest performance issues is with nested queries, as they currently require a call to TypeDB for each level of depth.
|
|
42
|
+
|
|
43
|
+
## What is Currently Working
|
|
44
|
+
To see what is currently working and find examples, please check the test folder, where you will find a variety of queries and mutations.
|
|
45
|
+
|
|
46
|
+
## The future of this package
|
|
47
|
+
- Achieve 100% compatibility with typeDB functions
|
|
48
|
+
- Enhance functionality with new features such as, cardinality management, ordered attributes, Vectors (ordered relations)...
|
|
49
|
+
- Expand compatibility to other graph databases and traditional databases such as PostgreSQL or MongoDB
|
|
50
|
+
- Enable the ability to split queries and mutations across multiple databases (for example, some data stored in PostgreSQL and other data in typeQL, all queried from a single point)
|