@kubun/standalone 0.3.7 → 0.4.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/lib/standalone.d.ts +2 -0
- package/lib/standalone.d.ts.map +1 -1
- package/lib/standalone.js +19 -0
- package/package.json +8 -7
package/lib/standalone.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { KubunDB } from '@kubun/db';
|
|
2
|
+
import { type Logger } from '@kubun/logger';
|
|
2
3
|
import type { ClusterModel, DocumentModelsRecord, GraphModelJSON } from '@kubun/protocol';
|
|
3
4
|
import type { ExecutionResult, GraphQLSchema } from 'graphql';
|
|
4
5
|
export type StandaloneParams = {
|
|
5
6
|
db: KubunDB;
|
|
6
7
|
did: string;
|
|
8
|
+
logger?: Logger;
|
|
7
9
|
};
|
|
8
10
|
export type DeployParams = {
|
|
9
11
|
clusters: Array<ClusterModel>;
|
package/lib/standalone.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEzF,OAAO,KAAK,EAAiB,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAK5E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,OAAO,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,o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C5E,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;CAI1E;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,eAAe,CAEpE"}
|
package/lib/standalone.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createSchema } from '@kubun/graphql';
|
|
2
|
+
import { getKubunLogger } from '@kubun/logger';
|
|
2
3
|
import { GraphModel } from '@kubun/protocol';
|
|
3
4
|
import { execute, parse, subscribe } from 'graphql';
|
|
4
5
|
import { createContext } from './graphql.js';
|
|
@@ -6,6 +7,7 @@ export class KubunStandalone {
|
|
|
6
7
|
#context;
|
|
7
8
|
#db;
|
|
8
9
|
#graphModels = {};
|
|
10
|
+
#logger;
|
|
9
11
|
#schemas = {};
|
|
10
12
|
constructor(params){
|
|
11
13
|
this.#context = createContext({
|
|
@@ -14,13 +16,21 @@ export class KubunStandalone {
|
|
|
14
16
|
validators: {}
|
|
15
17
|
});
|
|
16
18
|
this.#db = params.db;
|
|
19
|
+
this.#logger = params.logger ?? getKubunLogger('standalone');
|
|
17
20
|
}
|
|
18
21
|
async getGraphModel(id) {
|
|
19
22
|
if (this.#graphModels[id] == null) {
|
|
20
23
|
this.#graphModels[id] = this.#db.getGraph(id).then((graph)=>{
|
|
21
24
|
if (graph == null) {
|
|
25
|
+
this.#logger.warn('graph {id} not found', {
|
|
26
|
+
id
|
|
27
|
+
});
|
|
28
|
+
delete this.#graphModels[id];
|
|
22
29
|
throw new Error(`Graph not found: ${id}`);
|
|
23
30
|
}
|
|
31
|
+
this.#logger.debug('cached model for graph {id}', {
|
|
32
|
+
id
|
|
33
|
+
});
|
|
24
34
|
return {
|
|
25
35
|
aliases: graph.aliases,
|
|
26
36
|
record: graph.record
|
|
@@ -33,8 +43,14 @@ export class KubunStandalone {
|
|
|
33
43
|
if (this.#schemas[id] == null) {
|
|
34
44
|
this.#schemas[id] = this.getGraphModel(id).then((model)=>{
|
|
35
45
|
const schema = createSchema(model.record, model.aliases);
|
|
46
|
+
this.#logger.debug('cached schema for graph {id}', {
|
|
47
|
+
id
|
|
48
|
+
});
|
|
36
49
|
// console.log(printSchema(schema))
|
|
37
50
|
return schema;
|
|
51
|
+
}).catch((err)=>{
|
|
52
|
+
delete this.#schemas[id];
|
|
53
|
+
throw err;
|
|
38
54
|
});
|
|
39
55
|
}
|
|
40
56
|
return await this.#schemas[id];
|
|
@@ -63,6 +79,9 @@ export class KubunStandalone {
|
|
|
63
79
|
});
|
|
64
80
|
this.#graphModels[id] = Promise.resolve(model.toJSON());
|
|
65
81
|
delete this.#schemas[id];
|
|
82
|
+
this.#logger.info('deployed graph {id}', {
|
|
83
|
+
id
|
|
84
|
+
});
|
|
66
85
|
return {
|
|
67
86
|
id,
|
|
68
87
|
models: model.record
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/standalone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"graphql": "^16.12.0",
|
|
19
|
-
"@kubun/
|
|
20
|
-
"@kubun/
|
|
21
|
-
"@kubun/
|
|
19
|
+
"@kubun/mutation": "^0.4.0",
|
|
20
|
+
"@kubun/protocol": "^0.4.0",
|
|
21
|
+
"@kubun/logger": "^0.4.0",
|
|
22
|
+
"@kubun/graphql": "^0.4.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"@kubun/test-utils": "^0.
|
|
25
|
-
"@kubun/db": "^0.
|
|
25
|
+
"@kubun/test-utils": "^0.4.0",
|
|
26
|
+
"@kubun/db": "^0.4.0"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
28
29
|
"build:clean": "del lib",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
32
33
|
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
33
34
|
"test:types": "tsc --noEmit",
|
|
34
|
-
"test:unit": "
|
|
35
|
+
"test:unit": "vitest run",
|
|
35
36
|
"test": "pnpm run test:types && pnpm run test:unit"
|
|
36
37
|
}
|
|
37
38
|
}
|