kodo-core 0.0.3 → 0.1.0
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/README.md +3 -0
- package/dist/index.js +1 -0
- package/package.json +35 -47
- package/dist/_enums.d.ts +0 -0
- package/dist/expressions/_defines.d.ts +0 -7
- package/dist/expressions/index.d.ts +0 -3
- package/dist/expressions/linkExpression.d.ts +0 -12
- package/dist/expressions/queryExpression.d.ts +0 -19
- package/dist/index.d.ts +0 -6
- package/dist/kodo-core.min.js +0 -972
- package/dist/kodo-core.min.js.map +0 -1
- package/dist/kodo.d.ts +0 -25
- package/dist/nodes/dataNode.d.ts +0 -15
- package/dist/nodes/index.d.ts +0 -4
- package/dist/nodes/linkNode.d.ts +0 -9
- package/dist/nodes/nodeBase.d.ts +0 -4
- package/dist/nodes/queryNode.d.ts +0 -9
- package/dist/providers/iDataProvider.d.ts +0 -4
- package/dist/providers/index.d.ts +0 -2
- package/dist/providers/memoryProvider.d.ts +0 -19
- package/dist/translators/iNodeTranslator.d.ts +0 -7
- package/dist/translators/index.d.ts +0 -2
- package/dist/translators/nodeTranslator.d.ts +0 -12
- package/dist/utils/hash.d.ts +0 -3
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/objectUtil.d.ts +0 -1
package/README.md
CHANGED
|
@@ -15,6 +15,9 @@ Then we need write `expression` to describe the data relationship & connect them
|
|
|
15
15
|
By doing the 2 preparations, we can then give a detailed data from any `kodo node` & start to query.
|
|
16
16
|
It then will select & load all the related data via your giving.
|
|
17
17
|
|
|
18
|
+
## Version Updates
|
|
19
|
+
* v0.0.4: Support query expression on `QueryNode<T>` when explore.
|
|
20
|
+
> i.e. `expression: p => p.orderid === "o3" && p.id === "p3-2"`
|
|
18
21
|
|
|
19
22
|
## Design
|
|
20
23
|
* Kodo-Overview:
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class z{$id;$ns}class X extends z{$fromQN;data}class Y{nodes;ns;constructor(){this.nodes=new Map,this.ns=new Map}tryAdd(T){let f=`${T.$ns}-${T.$id}`;if(this.nodes.get(f))return!1;this.nodes.set(f,T);let $=this.ns.get(T.$ns);if(!$)$=[],this.ns.set(T.$ns,$);return $.push(T),!0}getList(){return Array.from(this.nodes.values())}clear(){this.nodes.clear(),this.ns.clear()}existNS(T){return!!this.ns.get(T)}}class Z extends z{$fromDN;$fromLN;expression}class I extends z{$fromNS;$toNS;$type;expression;static revertExpression(T){if(typeof T==="function")return T;let f={$from:T.$to,$to:T.$from,$with:T.$with,$where:[]};if(T.$op==="==")f.$op=T.$op,T.$where?.forEach(($)=>{let F=this.revertExpression($);if(F)f.$where.push(F)});return f}static revert(T){let f=I.revertExpression(T.expression);if(!f)return null;let $=new I;return $.$id=`${T.$id}-r`,$.$type="R",$.$ns=T.$ns,$.$fromNS=T.$toNS,$.$toNS=T.$fromNS,$.expression=f,$}}function x(T){switch(T){case">":return"<";case">=":return"<=";case"<":return">";case"<=":return">=";case"->":return null;default:return T}}function B(T){switch(T){case"->":return"==";default:return T}}function w(T){return T==="$with"||T==="$where"}function K(T){return T==="$with"||T==="$where"}var O=Math.ceil(Math.random()*1e5);function m(T){let f="null";switch(typeof T){case"undefined":f="undefined";break;case"string":f=T;break;case"boolean":case"number":case"bigint":case"function":case"symbol":f=T;break;case"object":try{T=T||null,f=JSON.stringify(T||null)}catch(F){}break;default:break}return f}function G(T,f){let $=f?.seed||O,F=m(T),R=$;for(let r=0;r<F.length;r++)R=(R<<5)-R+F.charCodeAt(r),R|=0;return R=R&2147483647,R.toString()}function S(T){return T===null||T===void 0}class C{ns;val}class D{objs;constructor(){this.objs=[]}add(T,f){this.objs.push({ns:T,val:f})}copmareNull(T,f,$){switch(T){case"==":return S($);case"!=":return!S($);case"===":return $===f;case"!==":return $!==f;default:return!1}}isMatchData(T,f,$,F){let R=F[T];if(S($))return this.copmareNull(f,$,R);switch(f||="==",f){case"==":return R==$;case"===":return R===$;case"!=":return R!=$;case"!==":return R!==$;case">":return R>$;case">=":return R>=$;case"<":return R<$;case"<=":return R<=$;case"IN":if($ instanceof Array)return $.some((r)=>r==R);return!1;case"!IN":if($ instanceof Array)return!$.some((r)=>r==R);return!1;default:break}throw{key:"MemoryProvider.isMatchData",exp:"Not implemented yet."}}assumeMatchList(T,f){let $="defer";return T.every((F)=>{if(F==="defer")return!0;if(F===f)return $=f,!1;else $=!f;return!0}),$}isAllMatchWith(T,f){if(f.length<=0)return"defer";if(T==="&&")return this.assumeMatchList(f,!1);else if(T==="||")return this.assumeMatchList(f,!0);else throw{key:"MemoryProvider.isMatchWith",exp:`QueryCondition ${T} not allowed.`}}matchOnData(T,f){let $=T.$with||"&&",F=$==="&&",R=[];for(let r in T){if(K(r))continue;let _=T[r],A=!1;if(typeof _==="object"){let J=_;A=this.isMatchData(r,J.$op,J.$val,f)}else A=this.isMatchData(r,"==",_,f);if(R.push(A),!A&&F)return!1}return this.isAllMatchWith($,R)}match(T,f){let $=[];if(typeof T==="function")return T(f);let F=T.$with||"&&",R=F==="&&",r=this.matchOnData(T,f);if(!r&&R)return!1;if($.push(r),T.$where?.length>0)T.$where.every((A)=>{let J=this.match(A,f);if($.push(J),!r&&R)return!1;return!0});return this.isAllMatchWith(F,$)}lookup(T){return this.objs.filter((F)=>{if(T.$ns!==F.ns)return!1;let R=this.match(T.expression,F.val);if(R==="defer")return!1;else return R}).map((F)=>{let R=new X;return R.$fromQN=T,R.$ns=F.ns,R.data=F.val,R.$id=F.val?.id||G(F.val),R})}}class H{name;translators;providers;nodes;opt;getDefaultOption(T){return Object.assign({cache:!0,recursion:!0,tierLimit:0},T||{})}constructor(T,f){this.name=T;this.translators=[],this.providers=[],this.nodes=new Y,this.opt=this.getDefaultOption(f)}setOption(T){this.opt=Object.assign(this.opt,T)}linkExpression(T,f){}registerTranslator(T){this.translators.push(T)}registerProvider(T){this.providers.push(T)}loopExplore(T,f){if(!this.opt.recursion){if(this.nodes.existNS(T.$ns))return}if(this.opt.tierLimit){if(f.tierLimit>=this.opt.tierLimit)return}let $=[];if(this.providers.forEach((F)=>{F.lookup(T).forEach((r)=>{if(this.nodes.tryAdd(r))$.push(r)})}),$.length<=0)return;$.forEach((F)=>{this.translators.forEach((R)=>{if(!R.match(F))return;R.translate(F).forEach((_)=>{this.loopExplore(_,{tierLimit:f.tierLimit+1})})})})}explore(T){if(!this.opt.cache)this.nodes.clear();if(!T.$id){let f=G(T);T.$id=`qn-${T.$ns}-$startup-${f}`}return this.loopExplore(T,{tierLimit:0}),this.nodes.getList()}}class U{linkNodes;constructor(){this.linkNodes=[]}all(){return this.linkNodes}match(T){return!0}link(T){if(!T.$id){let $=G(T);T.$id=`ln-${T.$fromNS}-${T.$toNS}-${$}`}this.linkNodes.push(T);let f=I.revert(T);if(f)this.linkNodes.push(f);return!0}tryMapOnData(T,f,$){let F=$.data[f.$from];if(F===void 0)return!1;let R=x(f.$op);if(!R)return!1;T.$with=f.$with,T[f.$to]||={},T[f.$to].$op=B(R),T[f.$to].$val=F}tryMap(T,f,$){if(T.$with=f.$with,this.tryMapOnData(T,f,$),f.$where?.length>0)f.$where.forEach((F)=>{F=F;let R={};R.$with=F.$with,R.$where=[],this.tryMap(R,F,$),T.$where.push(R)})}translate(T){let f=[];return this.linkNodes.forEach(($)=>{if($.$fromNS!==T.$ns)return;let F=new Z;F.$id=`qn-${T.$ns}-${T.$id}-${$.$id}`,F.$ns=$.$toNS,F.$fromDN=T,F.$fromLN=$,F.expression={},F.expression.$where=[],this.tryMap(F.expression,$.expression,T),f.push(F)}),f}}export{x as revertLinkOperator,K as isQueryExpressionKey,S as isNullOrUndefined,w as isLinkExpressionKey,G as generateHashCode,B as convertLP2RO,Z as QueryNode,U as NodeTranslator,z as NodeBase,D as MemoryProvider,C as MemoryData,I as LinkNode,H as Kodo,Y as DataNodeMap,X as DataNode};
|
package/package.json
CHANGED
|
@@ -1,48 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"mocha": "^10.2.0",
|
|
38
|
-
"ts-loader": "^9.4.3",
|
|
39
|
-
"ts-node": "^10.9.1",
|
|
40
|
-
"source-map-loader": "^0.2.4",
|
|
41
|
-
"ts-mocha": "^10.0.0",
|
|
42
|
-
"tslint": "^6.1.3",
|
|
43
|
-
"typescript": "^4.7.4",
|
|
44
|
-
"webpack": "^5.73.0",
|
|
45
|
-
"webpack-cli": "^4.10.0",
|
|
46
|
-
"webpack-node-externals": "^3.0.0"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
2
|
+
"name": "kodo-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/kodo-core.min.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"repository": "git@github.com:ShadowLei/kodo-core.git",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"registry": "https://registry.npmjs.org"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"package.json",
|
|
13
|
+
"README.md",
|
|
14
|
+
"dist/"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build-dev": "bun build ./src/index.ts --outdir ./dist",
|
|
18
|
+
"build": "bun build --production ./src/index.ts --outdir ./dist",
|
|
19
|
+
"test": "bun test ./test/*.test.ts"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"kodo-core",
|
|
23
|
+
"nerual",
|
|
24
|
+
"net",
|
|
25
|
+
"connection"
|
|
26
|
+
],
|
|
27
|
+
"module": "index.ts",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/bun": "latest"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"typescript": "^6"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/_enums.d.ts
DELETED
|
File without changes
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare type LinkOperator = ">=" | ">" | "<" | "<=" | "==" | "!=" | "->";
|
|
2
|
-
export declare type ROperator_Atom = ">=" | ">" | "<" | "<=" | "==" | "===" | "!=" | "!==";
|
|
3
|
-
export declare type ROperator_Array = "IN" | "!IN";
|
|
4
|
-
export declare type ROperator = ROperator_Atom | ROperator_Array;
|
|
5
|
-
export declare type BOperator = "&&" | "||";
|
|
6
|
-
export declare function revertLinkOperator(op: LinkOperator): LinkOperator | null;
|
|
7
|
-
export declare function convertLP2RO(op: LinkOperator): ROperator | null;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BOperator, LinkOperator } from "./_defines";
|
|
2
|
-
export type LinkOn<TFrom, TTo> = {
|
|
3
|
-
$from?: keyof TFrom;
|
|
4
|
-
$op?: LinkOperator;
|
|
5
|
-
$to?: keyof TTo;
|
|
6
|
-
};
|
|
7
|
-
export type LinkExpressionWhere<TFrom, TTo> = {
|
|
8
|
-
$with?: BOperator;
|
|
9
|
-
$where?: Array<LinkExpression<TFrom, TTo>>;
|
|
10
|
-
};
|
|
11
|
-
export type LinkExpression<TFrom, TTo> = LinkExpressionWhere<TFrom, TTo> & LinkOn<TFrom, TTo>;
|
|
12
|
-
export declare function isLinkExpressionKey(key: string): boolean;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BOperator, ROperator_Atom, ROperator_Array } from "./_defines";
|
|
2
|
-
export type QueryOnAtomValue<T, P extends keyof T> = {
|
|
3
|
-
$op?: ROperator_Atom;
|
|
4
|
-
$val: T[P] | null | undefined;
|
|
5
|
-
};
|
|
6
|
-
export type QueryOnArrayValue<T, P extends keyof T> = {
|
|
7
|
-
$op?: ROperator_Array;
|
|
8
|
-
$val: T[P][];
|
|
9
|
-
};
|
|
10
|
-
export type QueryOnValue<T, P extends keyof T> = QueryOnAtomValue<T, P> | QueryOnArrayValue<T, P>;
|
|
11
|
-
export type QueryOn<T> = {
|
|
12
|
-
[P in keyof T]?: QueryOnValue<T, P> | T[P];
|
|
13
|
-
};
|
|
14
|
-
export type QueryExpressionWhere<T> = {
|
|
15
|
-
$with?: BOperator;
|
|
16
|
-
$where?: Array<QueryExpression<T>>;
|
|
17
|
-
};
|
|
18
|
-
export type QueryExpression<T> = QueryExpressionWhere<T> & QueryOn<T>;
|
|
19
|
-
export declare function isQueryExpressionKey(key: string): boolean;
|