Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"surrealdb",
"tailwindcss",
"tanstack",
"treeshake",
"tryit",
"tsup",
"typedb",
Expand Down
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

📝 following beta format X.Y.Z where Y = breaking change and Z = feature and fix. Later => FAIL.FEATURE.FIX

## 0.10.16(2024-06-09)

- Fix: EnrichSchema issues
- Fix: Esm config issues


## 0.10.15(2024-06-09)

- Fix: Replaced surrealdb.node => surrealdb.js


## 0.10.14(2024-06-08)

- Feat:
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"name": "@blitznocode/blitz-orm",
"version": "0.10.15",
"version": "0.10.16",
"author": "blitznocode.com",
"main": "dist/index.cjs",
"module": "./dist/index.mjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"type": "commonjs",
"exports": {
".": {
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"module": "./dist/index.mjs"
}
},
"scripts": {
"bench:surrealdb": "./tests/bench.sh surrealdb/bench",
"bench:typedb": "vitest bench typedb/bench",
"build": "tsup src/index.ts --format cjs,esm --clean --dts --treeshake --minify",
"dev": "tsup --dts --watch --sourcemap",
"build": "tsup",
"dev": "tsup --watch --sourcemap",
"knip": "knip",
"husky:prepare": "husky init",
"lint:check": "eslint src --quiet --ext .ts,.tsx",
Expand Down Expand Up @@ -96,6 +97,5 @@
"ORM",
"database",
"graph-database"
],
"author": "blitznocode.com"
]
}
30 changes: 24 additions & 6 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const enrichSchema = (schema: BormSchema, dbHandles: DBHandles): Enriched
if (!value.defaultDBConnector.as) {
//todo: Check if we can add the "as" as default. When the path of the parent === name of the parent then it's fine. As would be used for those cases where they are not equal (same as path, which is needed only if different names)
throw new Error(
`[Schema] ${key} is extending a thing but missing the "as" property in its defaultDBConnector`,
`[Schema] ${key} is extending a thing but missing the "as" property in its defaultDBConnector. Path:${meta.nodePath}`,
);
}

Expand Down Expand Up @@ -277,15 +277,27 @@ export const enrichSchema = (schema: BormSchema, dbHandles: DBHandles): Enriched
linkField.fieldType = 'linkField';
const linkFieldRelation = withExtensionsSchema.relations[linkField.relation];

if (linkFieldRelation.roles?.[linkField.plays] === undefined) {
throw new Error(
`The role ${linkField.plays} is not defined in the relation ${linkField.relation} (linkField: ${linkField.path})`,
);
if (!linkField.isVirtual) {
//its ok for virtual linkFields to don't have a relation
if (!linkFieldRelation) {
throw new Error(`The relation ${linkField.relation} does not exist in the schema`);
}

if (linkFieldRelation.roles?.[linkField.plays] === undefined) {
throw new Error(
`The role ${linkField.plays} is not defined in the relation ${linkField.relation} (linkField: ${linkField.path})`,
);
}
}

//#region SHARED METADATA

if (linkField.target === 'relation') {
if (linkField.isVirtual) {
throw new Error(
`[Schema] Virtual linkFields can't target a relation. Thing: "${val.name}" LinkField: "${linkField.path}. Path:${meta.nodePath}."`,
);
}
linkField.$things = [linkField.relation];
linkField.oppositeLinkFieldsPlayedBy = [
{
Expand All @@ -308,6 +320,12 @@ export const enrichSchema = (schema: BormSchema, dbHandles: DBHandles): Enriched
(x) => x.target === 'role',
);

if (linkField.oppositeLinkFieldsPlayedBy.length === 0) {
throw new Error(
`[Schema] LinkFields require to have at least one opposite linkField playing an opposite role. Thing: "${val.name}" LinkField: "${linkField.path}. Path:${meta.nodePath}."`,
);
}

linkField.$things = linkField.oppositeLinkFieldsPlayedBy.map((x) => x.thing);

// #region FILTERING OPPOSITE LINKFIELDS
Expand All @@ -330,7 +348,7 @@ export const enrichSchema = (schema: BormSchema, dbHandles: DBHandles): Enriched
// We take the original relation as its the one that holds the name of the relation in surrealDB
const originalRelation =
// @ts-expect-error - This is fine, extensions schema is a middle state
linkFieldRelation.roles?.[linkField.plays][SharedMetadata]?.inheritanceOrigin ?? linkField.relation;
linkFieldRelation?.roles?.[linkField.plays][SharedMetadata]?.inheritanceOrigin ?? linkField.relation;
const queryPath = getSurrealLinkFieldQueryPath({ linkField, originalRelation, withExtensionsSchema });

linkField[SuqlMetadata] = {
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"module": "ESNext",
"moduleResolution": "Bundler",
"isolatedModules": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"rootDir": ".",
"sourceMap": true,
"outDir": "dist"
},
"include": ["src", "tests"],
Expand Down
8 changes: 6 additions & 2 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
format: ['esm', 'cjs'], // Output both ES modules and CommonJS modules
dts: true,
target: 'esnext',
clean: true,
treeshake: true,
minify: true,
sourcemap: true,
});