@kubun/server 0.3.12 → 0.3.13

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.
@@ -1,8 +1,5 @@
1
1
  import type { ProcedureHandlers } from '@enkaku/server';
2
- import type { KubunDB } from '@kubun/db';
3
2
  import type { DocumentProtocol } from '@kubun/protocol';
4
- export type CreateHandlersParams = {
5
- db: KubunDB;
6
- };
3
+ import type { CreateHandlersParams } from './types.js';
7
4
  export declare function createHandlers(handlersParams: CreateHandlersParams): ProcedureHandlers<DocumentProtocol>;
8
5
  //# sourceMappingURL=document.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/handlers/document.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,OAAO,CAAA;CACZ,CAAA;AAED,wBAAgB,cAAc,CAC5B,cAAc,EAAE,oBAAoB,GACnC,iBAAiB,CAAC,gBAAgB,CAAC,CA8BrC"}
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/handlers/document.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,wBAAgB,cAAc,CAC5B,cAAc,EAAE,oBAAoB,GACnC,iBAAiB,CAAC,gBAAgB,CAAC,CA8BrC"}
@@ -1,8 +1,5 @@
1
1
  import type { ProcedureHandlers } from '@enkaku/server';
2
- import type { KubunDB } from '@kubun/db';
3
2
  import type { GraphProtocol } from '@kubun/protocol';
4
- export type CreateHandlersParams = {
5
- db: KubunDB;
6
- };
3
+ import type { CreateHandlersParams } from './types.js';
7
4
  export declare function createHandlers(handlersParams: CreateHandlersParams): ProcedureHandlers<GraphProtocol>;
8
5
  //# sourceMappingURL=graph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/handlers/graph.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAA4B,OAAO,EAAE,MAAM,WAAW,CAAA;AAGlE,OAAO,KAAK,EAKV,aAAa,EACd,MAAM,iBAAiB,CAAA;AAsBxB,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,OAAO,CAAA;CACZ,CAAA;AAED,wBAAgB,cAAc,CAC5B,cAAc,EAAE,oBAAoB,GACnC,iBAAiB,CAAC,aAAa,CAAC,CA4IlC"}
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/handlers/graph.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAKvD,OAAO,KAAK,EAKV,aAAa,EACd,MAAM,iBAAiB,CAAA;AAcxB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAUtD,wBAAgB,cAAc,CAC5B,cAAc,EAAE,oBAAoB,GACnC,iBAAiB,CAAC,aAAa,CAAC,CAsJlC"}
@@ -15,14 +15,21 @@ function toGraphResult(result) {
15
15
  };
16
16
  }
17
17
  export function createHandlers(handlersParams) {
18
- const { db } = handlersParams;
18
+ const { db, logger } = handlersParams;
19
19
  const graphModels = {};
20
20
  async function getGraphModels(id) {
21
21
  if (graphModels[id] == null) {
22
22
  graphModels[id] = db.getGraph(id).then((graph)=>{
23
23
  if (graph == null) {
24
+ logger.warn('graph {id} not found', {
25
+ id
26
+ });
27
+ delete graphModels[id];
24
28
  throw new Error(`Graph not found: ${id}`);
25
29
  }
30
+ logger.debug('cached model for graph {id}', {
31
+ id
32
+ });
26
33
  return graph.record;
27
34
  });
28
35
  }
@@ -33,8 +40,14 @@ export function createHandlers(handlersParams) {
33
40
  if (schemas[id] == null) {
34
41
  schemas[id] = getGraphModels(id).then((record)=>{
35
42
  const schema = createSchema(record);
43
+ logger.debug('cached schema for graph {id}', {
44
+ id
45
+ });
36
46
  // console.log(printSchema(schema))
37
47
  return schema;
48
+ }).catch((err)=>{
49
+ delete schemas[id];
50
+ throw err;
38
51
  });
39
52
  }
40
53
  return await schemas[id];
@@ -53,6 +66,9 @@ export function createHandlers(handlersParams) {
53
66
  name: ctx.param.name,
54
67
  record: model.record
55
68
  });
69
+ logger.info('deployed graph {id}', {
70
+ id
71
+ });
56
72
  return {
57
73
  id,
58
74
  models: model.record
@@ -1,9 +1,6 @@
1
1
  import type { ProcedureHandlers } from '@enkaku/server';
2
- import type { KubunDB } from '@kubun/db';
3
2
  import type { Protocol } from '@kubun/protocol';
4
- export type CreateHandlersParams = {
5
- db: KubunDB;
6
- };
3
+ import type { CreateHandlersParams } from './types.js';
7
4
  export type Handlers = ProcedureHandlers<Protocol>;
8
5
  export declare function createHandlers(params: CreateHandlersParams): Handlers;
9
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAK/C,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,OAAO,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;AAElD,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,QAAQ,CAKrE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAI/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,MAAM,MAAM,QAAQ,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;AAElD,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,QAAQ,CAKrE"}
@@ -0,0 +1,7 @@
1
+ import type { KubunDB } from '@kubun/db';
2
+ import type { Logger } from '@kubun/logger';
3
+ export type CreateHandlersParams = {
4
+ db: KubunDB;
5
+ logger: Logger;
6
+ };
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,OAAO,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;CACf,CAAA"}
@@ -0,0 +1 @@
1
+ export { };
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createContext, type ExecutionContext } from './data/graphql.js';
2
- export { type CreateHandlersParams, createHandlers } from './handlers/index.js';
2
+ export { createHandlers } from './handlers/index.js';
3
+ export type { CreateHandlersParams } from './handlers/types.js';
3
4
  export { type CreateClientParams, KubunServer, type ServerParams } from './server.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,KAAK,oBAAoB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC/E,OAAO,EAAE,KAAK,kBAAkB,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EAAE,KAAK,kBAAkB,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAA"}
package/lib/server.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { type Server } from '@enkaku/server';
2
2
  import { type ClientParams, KubunClient } from '@kubun/client';
3
3
  import { type DBParams, KubunDB } from '@kubun/db';
4
+ import { type Logger } from '@kubun/logger';
4
5
  import type { Protocol, ServerTransport } from '@kubun/protocol';
5
6
  export type ServerParams = {
6
7
  access?: Record<string, boolean | Array<string>>;
7
8
  db: KubunDB | DBParams;
8
9
  id: string;
10
+ logger?: Logger;
9
11
  };
10
12
  export type CreateClientParams = Omit<ClientParams, 'serverID' | 'transport'> & {
11
13
  signal?: AbortSignal;
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAS,MAAM,gBAAgB,CAAA;AAEnD,OAAO,EAAE,KAAK,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC9D,OAAO,EAAE,KAAK,QAAQ,EAAE,OAAO,EAAE,MAAM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tB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,WAAW,CAAC,GAAG;IAC9E,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,CAAA;AAED,qBAAa,WAAW;;gBAOV,MAAM,EAAE,YAAY;IAUhC,IAAI,EAAE,IAAI,OAAO,CAEhB;IAED,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW;IAkBrD,KAAK,CAAC,SAAS,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC;CAU1E"}
package/lib/server.js CHANGED
@@ -2,20 +2,27 @@ import { serve } from '@enkaku/server';
2
2
  import { DirectTransports } from '@enkaku/transport';
3
3
  import { KubunClient } from '@kubun/client';
4
4
  import { KubunDB } from '@kubun/db';
5
+ import { getKubunLogger } from '@kubun/logger';
5
6
  import { createHandlers } from './handlers/index.js';
6
7
  export class KubunServer {
7
8
  #access;
8
9
  #db;
9
10
  #handlers;
10
11
  #id;
12
+ #logger;
11
13
  constructor(params){
12
14
  const { access, db, id } = params;
15
+ const logger = params.logger ?? getKubunLogger('server', {
16
+ serverID: id
17
+ });
13
18
  this.#access = access ?? {};
14
19
  this.#db = db instanceof KubunDB ? db : new KubunDB(db);
15
20
  this.#handlers = createHandlers({
16
- db: this.#db
21
+ db: this.#db,
22
+ logger
17
23
  });
18
24
  this.#id = id;
25
+ this.#logger = logger;
19
26
  }
20
27
  get db() {
21
28
  return this.#db;
@@ -26,7 +33,11 @@ export class KubunServer {
26
33
  signal
27
34
  });
28
35
  this.serve(transports.server, signal);
36
+ const logger = params.logger ?? this.#logger.getChild('client').with({
37
+ clientID: params.getRandomID?.() ?? crypto.randomUUID()
38
+ });
29
39
  return new KubunClient({
40
+ logger,
30
41
  serverID: this.#id,
31
42
  transport: transports.client,
32
43
  ...clientParams
@@ -37,6 +48,7 @@ export class KubunServer {
37
48
  access: this.#access,
38
49
  handlers: this.#handlers,
39
50
  id: this.#id,
51
+ logger: this.#logger,
40
52
  signal,
41
53
  transport
42
54
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/server",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -19,22 +19,23 @@
19
19
  "@enkaku/codec": "^0.12.0",
20
20
  "@enkaku/generator": "^0.12.1",
21
21
  "@enkaku/schema": "^0.12.1",
22
- "@enkaku/server": "^0.12.1",
22
+ "@enkaku/server": "^0.12.2",
23
23
  "@enkaku/token": "0.12.3",
24
24
  "@enkaku/transport": "0.12.0",
25
25
  "graphql": "^16.12.0",
26
- "@kubun/client": "^0.3.7",
27
- "@kubun/protocol": "^0.3.9",
28
- "@kubun/db": "^0.3.6",
26
+ "@kubun/client": "^0.3.8",
27
+ "@kubun/logger": "^0.3.0",
28
+ "@kubun/graphql": "^0.3.14",
29
+ "@kubun/db": "^0.3.7",
30
+ "@kubun/protocol": "^0.3.10",
29
31
  "@kubun/id": "^0.3.1",
30
- "@kubun/mutation": "^0.3.3",
31
- "@kubun/graphql": "^0.3.14"
32
+ "@kubun/mutation": "^0.3.3"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@databases/pg-test": "^3.1.2",
35
36
  "@enkaku/stream": "^0.12.1",
36
- "@kubun/test-utils": "^0.3.0",
37
- "@kubun/db-postgres": "^0.3.2"
37
+ "@kubun/db-postgres": "^0.3.2",
38
+ "@kubun/test-utils": "^0.3.0"
38
39
  },
39
40
  "scripts": {
40
41
  "build:clean": "del lib",