@blitznocode/blitz-orm 0.0.40 → 0.0.42

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/changelog.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## 0.0.41(2023-02-03)
4
+ - readme, changelog
5
+
6
+ ## 0.0.40(2023-02-03)
7
+
8
+ ### Features
9
+ - cleaned tests
10
+
11
+ ### Bug fixes
12
+ - All current test working again
13
+
14
+ ## 0.0.39(2023-02-03)
15
+
16
+ ### Features
17
+ - Created as new repo and published
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blitznocode/blitz-orm",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
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": "git+https://github.com/blitz/blitz.git",
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/blitz/blitz/issues"
64
+ "url": "https://github.com/Blitzapps/blitz-orm/issues"
66
65
  },
67
- "homepage": "https://github.com/blitz/blitz#readme",
66
+ "homepage": "https://github.com/Blitzapps/blitz-orm#readme",
68
67
  "directories": {
69
68
  "test": "tests"
70
69
  },
package/readme.md CHANGED
@@ -1,15 +1,50 @@
1
- Blitz-orm is a public package that can be open-sourced
2
-
3
- Similar to Prisma, it's used to interpret a BQL schema and provide the client and the server with tools to ensure they are "speaking the same language"
4
-
5
- ## How to use
6
- - Install the package with your packages manager, like this:
7
- `yarn add @blitznocode/blitz-orm`
8
-
9
- - Create a
10
-
11
- ## Definitions
12
-
13
-
14
- ## How does it work
15
- The client can get
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)
package/dist/index.d.ts DELETED
@@ -1,250 +0,0 @@
1
- import { TypeDBClient, TypeDBSession } from 'typedb-client';
2
-
3
- type BormConfig = {
4
- server: {
5
- provider: 'blitz-orm-js';
6
- };
7
- query?: {
8
- noMetadata?: boolean;
9
- simplifiedLinks?: boolean;
10
- };
11
- mutation?: {
12
- noMetadata?: boolean;
13
- };
14
- dbConnectors: [ProviderObject, ...ProviderObject[]];
15
- };
16
- type ProviderObject = {
17
- id: string;
18
- provider: 'typeDB';
19
- dbName: string;
20
- url: string;
21
- };
22
- type DBConnector = {
23
- id: string;
24
- subs?: string;
25
- path?: string;
26
- as?: string;
27
- };
28
- type TypeDBHandles = Map<string, {
29
- client: TypeDBClient;
30
- session: TypeDBSession;
31
- }>;
32
- type DBHandles = {
33
- typeDB: TypeDBHandles;
34
- };
35
- type BormSchema = {
36
- entities: {
37
- [s: string]: BormEntity;
38
- };
39
- relations: {
40
- [s: string]: BormRelation;
41
- };
42
- };
43
- type EnrichedBormSchema = {
44
- entities: {
45
- [s: string]: EnrichedBormEntity;
46
- };
47
- relations: {
48
- [s: string]: EnrichedBormRelation;
49
- };
50
- };
51
- type BormEntity = {
52
- extends: string;
53
- idFields?: string[];
54
- defaultDBConnector: DBConnector;
55
- dataFields?: DataField[];
56
- linkFields?: LinkField[];
57
- } | {
58
- extends?: string;
59
- idFields: string[];
60
- defaultDBConnector: DBConnector;
61
- dataFields?: DataField[];
62
- linkFields?: LinkField[];
63
- };
64
- type BormRelation = BormEntity & {
65
- roles?: {
66
- [key: string]: RoleField;
67
- };
68
- };
69
- type EnrichedBormEntity = Omit<BormEntity, 'linkFields' | 'idFields'> & {
70
- extends?: string;
71
- idFields: string[];
72
- thingType: 'entity';
73
- name: string;
74
- computedFields: string[];
75
- linkFields?: EnrichedLinkField[];
76
- };
77
- type EnrichedBormRelation = Omit<BormRelation, 'linkFields'> & {
78
- thingType: 'relation';
79
- name: string;
80
- computedFields: string[];
81
- linkFields?: EnrichedLinkField[];
82
- roles: {
83
- [key: string]: EnrichedRoleField;
84
- };
85
- };
86
- type LinkField = BormField & {
87
- relation: string;
88
- plays: string;
89
- } & ({
90
- target: 'role';
91
- filter?: Filter | Filter[];
92
- } | {
93
- target: 'relation';
94
- });
95
- type LinkedFieldWithThing = LinkField & {
96
- thing: string;
97
- thingType: ThingType;
98
- };
99
- type RequireAtLeastOne<T> = {
100
- [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>;
101
- }[keyof T];
102
- type LinkFilter = {
103
- $thing?: string;
104
- $thingType?: string;
105
- $role?: string;
106
- [key: string]: string | number | Filter | undefined;
107
- };
108
- type Filter = DataFilter | LinkFilter | MiddleFilter;
109
- type MiddleFilter = {
110
- $and?: Filter[];
111
- $or?: Filter[];
112
- };
113
- type DataFilter = RequireAtLeastOne<{
114
- $eq?: any;
115
- $ge?: number | string;
116
- }>;
117
- type EnrichedLinkField = BormField & {
118
- name: string;
119
- relation: string;
120
- plays: string;
121
- } & ({
122
- target: 'role';
123
- filter?: Filter | Filter[];
124
- oppositeLinkFieldsPlayedBy: LinkedFieldWithThing[];
125
- } | {
126
- target: 'relation';
127
- oppositeLinkFieldsPlayedBy: Pick<LinkedFieldWithThing, 'thing' | 'thingType' | 'plays'>[];
128
- });
129
- type BormField = {
130
- path: string;
131
- cardinality: CardinalityType;
132
- ordered?: boolean;
133
- embedded?: boolean;
134
- rights?: RightType[];
135
- };
136
- type RoleField = {
137
- cardinality: CardinalityType;
138
- dbConnector?: DBConnector;
139
- };
140
- type EnrichedRoleField = RoleField & {
141
- playedBy?: LinkedFieldWithThing[];
142
- };
143
- type DataField = BormField & {
144
- shared?: boolean;
145
- default?: any;
146
- contentType: ContentType;
147
- validations?: any;
148
- dbConnectors?: [DBConnector, ...DBConnector[]];
149
- };
150
- type ThingType = 'entity' | 'relation' | 'attribute';
151
- type RightType = 'CREATE' | 'DELETE' | 'UPDATE' | 'LINK' | 'UNLINK';
152
- type ContentType = 'ID' | 'JSON' | 'COLOR' | 'BOOLEAN' | 'POINT' | 'FILE' | 'EMAIL' | 'PHONE' | 'WEEK_DAY' | 'DURATION' | 'HOUR' | 'TIME' | 'DATE' | 'RATING' | 'CURRENCY' | 'PERCENTAGE' | 'NUMBER_DECIMAL' | 'NUMBER' | 'URL' | 'PASSWORD' | 'LANGUAGE_TEXT' | 'RICH_TEXT' | 'TEXT';
153
- type CardinalityType = 'ONE' | 'MANY' | 'INTERVAL';
154
- type RelationClassType = 'SYMMETRICAL' | 'OWNED';
155
- type RequiredKey<T, K extends keyof T> = T & {
156
- [P in K]-?: T[P];
157
- };
158
- type WithRequired<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> & RequiredKey<T, K>;
159
- type BQLMutationBlock = {
160
- [key: string]: any;
161
- $id?: string | string[];
162
- $filter?: Filter | Filter[];
163
- $tempId?: string;
164
- $op?: string;
165
- } & ({
166
- $entity: string;
167
- } | {
168
- $relation: string;
169
- });
170
- type FilledBQLMutationBlock = WithRequired<BQLMutationBlock, '$tempId' | '$op'>;
171
- type BQLFieldObj = {
172
- $path: string;
173
- } & Omit<RawBQLQuery, '$entity' | '$relation'>;
174
- type BQLField = string | BQLFieldObj;
175
- type RawBQLQuery = {
176
- $id?: string | string[];
177
- $filter?: Record<string, any>;
178
- $fields?: BQLField[];
179
- } & ({
180
- $entity: string;
181
- } | {
182
- $relation: string;
183
- });
184
- type RawBQLMutation = ({
185
- $entity: string;
186
- } | {
187
- $relation: string;
188
- }) & Record<string, any>;
189
- type ParsedBQLQuery = Omit<RawBQLQuery, '$entity' | '$relation'> & {
190
- $localFilters?: Record<string, any>;
191
- $nestedFilters?: Record<string, any>;
192
- } & ({
193
- $entity: EnrichedBormEntity;
194
- } | {
195
- $relation: EnrichedBormRelation;
196
- });
197
- type ParsedBQLMutation = {
198
- things: BQLMutationBlock[];
199
- edges: BQLMutationBlock[];
200
- };
201
- type TQLRequest = {
202
- entity?: string;
203
- roles?: {
204
- path: string;
205
- request: string;
206
- owner: string;
207
- }[];
208
- relations?: {
209
- relation: string;
210
- entity: string;
211
- request: string;
212
- }[];
213
- insertionMatches?: string;
214
- deletionMatches?: string;
215
- insertions?: string;
216
- deletions?: string;
217
- };
218
- type TQLEntityMutation = {
219
- entity: string;
220
- relations?: {
221
- relation: string;
222
- entity: string;
223
- request: string;
224
- }[];
225
- };
226
- type BQLResponseSingle = (({
227
- $entity: string;
228
- $id: string;
229
- } | undefined) & Record<string, any>) | string | null;
230
- type BQLResponseMulti = BQLResponseSingle[];
231
- type BQLResponse = BQLResponseSingle | BQLResponseMulti;
232
-
233
- type BormProps = {
234
- schema: BormSchema;
235
- config: BormConfig;
236
- };
237
- declare class BormClient {
238
- #private;
239
- private schema;
240
- private config;
241
- private dbHandles?;
242
- constructor({ schema, config }: BormProps);
243
- init: () => Promise<void>;
244
- introspect: () => Promise<BormSchema>;
245
- query: (query: RawBQLQuery, queryConfig?: any) => Promise<void | BQLResponse>;
246
- mutate: (mutation: RawBQLMutation | RawBQLMutation[], mutationConfig?: any) => Promise<void | BQLResponse>;
247
- close: () => Promise<void>;
248
- }
249
-
250
- export { BQLField, BQLFieldObj, BQLMutationBlock, BQLResponse, BQLResponseMulti, BQLResponseSingle, BormConfig, BormEntity, BormField, BormRelation, BormSchema, CardinalityType, ContentType, DBConnector, DBHandles, DataField, DataFilter, EnrichedBormEntity, EnrichedBormRelation, EnrichedBormSchema, EnrichedLinkField, EnrichedRoleField, FilledBQLMutationBlock, Filter, LinkField, LinkFilter, LinkedFieldWithThing, MiddleFilter, ParsedBQLMutation, ParsedBQLQuery, ProviderObject, RawBQLMutation, RawBQLQuery, RelationClassType, RightType, RoleField, TQLEntityMutation, TQLRequest, ThingType, BormClient as default };