@cap-js/cds-types 0.6.3 → 0.6.4

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 CHANGED
@@ -2,8 +2,17 @@
2
2
 
3
3
  [![REUSE status](https://api.reuse.software/badge/github.com/cap-js/cds-types)](https://api.reuse.software/info/github.com/cap-js/cds-types)
4
4
  ![Unit Tests passing](https://github.com/cap-js/cds-types/actions/workflows/test.yml/badge.svg)
5
+ [![npmjscom](https://img.shields.io/npm/v/@cap-js/cds-types?color=green&label=npmjs.com)](https://www.npmjs.com/package/@cap-js/cds-types)
6
+ ![downloads](https://img.shields.io/npm/dw/@cap-js/cds-types)
7
+ [![deps](https://img.shields.io/librariesio/release/npm/@cap-js/cds-types?label=Dependencies)](https://www.npmjs.com/package/@cap-js/cds-types?activeTab=dependencies)
5
8
 
6
- ## About this project
9
+
10
+ [![main test](https://img.shields.io/github/actions/workflow/status/cap-js/cds-types/test.yml?label=main%20test)](https://github.com/cap-js/cds-types/actions/workflows/test.yml?query=branch%3Amain)
11
+ [![main integration test](https://img.shields.io/github/actions/workflow/status/cap-js/cds-types/integration-test.yml?label=main%20integration-test)](https://github.com/cap-js/cds-types/actions/workflows/integration-test.yml?query=branch%3Amain)
12
+ [![main lint](https://img.shields.io/github/actions/workflow/status/cap-js/cds-types/lint.yml?label=main%20lint)](https://github.com/cap-js/cds-types/actions/workflows/lint.yml?query=branch%3Amain)
13
+
14
+
15
+ ## About this Project
7
16
 
8
17
  Contains type definitions for the [Node.js SDK](https://cap.cloud.sap/docs/node.js/) of the SAP Cloud Application Programming Model (CAP).
9
18
 
@@ -13,6 +22,9 @@ Just install package `@sap/cds` into a Javascript or Typescript project, and the
13
22
 
14
23
  Find more information on the APIs in the [Node.js SDK documentation](https://cap.cloud.sap/docs/node.js/).
15
24
 
25
+ ## Note to Microsoft Windows Users
26
+ If you rename your project after you installed the type definitions on Windows, you have to rerun `npm install` to correctly recreate the symlink `node_modules/@types/sap__cds`.
27
+
16
28
  ## Support, Feedback, Contributing
17
29
 
18
30
  ### Local Setup
@@ -66,6 +66,7 @@ export type __Vector = classes.Vector
66
66
  class action extends any_<'action' | 'function'> {}
67
67
 
68
68
  export interface ActionEventHandler<P, R> {
69
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
69
70
  (req: Omit<Request_2, 'data'> & { data: P }, next: Function): Promise<R> | R
70
71
  }
71
72
 
@@ -200,6 +201,7 @@ export type CDL = string
200
201
 
201
202
  namespace cds {
202
203
  export {
204
+ default_2 as default,
203
205
  log,
204
206
  debug,
205
207
  test,
@@ -536,12 +538,27 @@ export const connect: {
536
538
 
537
539
  /**
538
540
  * Connects to a specific datasource.
541
+ * @example cds.connect.to ('service')
539
542
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
540
543
  */
541
544
  to(datasource: string, options?: cds_connect_options): Promise<Service>,
542
545
 
546
+ /**
547
+ * Shortcut for 'db' as the primary database returning `cds.DatabaseService`
548
+ * @example cds.connect.to ('db')
549
+ */
550
+ to(datasource: 'db', options?: cds_connect_options): Promise<cds.DatabaseService>,
551
+
552
+ /**
553
+ * Connects to a specific datasource via a Service subclass
554
+ * @example cds.connect.to (ServiceClass)
555
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
556
+ */
557
+ to<S extends Service>(datasource: {new(): S}, options?: cds_connect_options): Promise<S>,
558
+
543
559
  /**
544
560
  * Connects to a specific datasource via options.
561
+ * @example cds.connect.to ({ kind:..., impl:... })
545
562
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
546
563
  */
547
564
  to(options: cds_connect_options): Promise<Service>,
@@ -728,6 +745,168 @@ export function debug (name: string): undefined | Log
728
745
 
729
746
  class Decimal extends Float { }
730
747
 
748
+ export namespace default_2 {
749
+ export {
750
+ log,
751
+ debug,
752
+ test,
753
+ ql,
754
+ QLExtensions,
755
+ csn,
756
+ delete_ as delete,
757
+ version,
758
+ home,
759
+ root,
760
+ requires,
761
+ extend,
762
+ lazify,
763
+ lazified,
764
+ entity,
765
+ event,
766
+ type,
767
+ array,
768
+ struct,
769
+ Association,
770
+ Composition,
771
+ builtin,
772
+ on,
773
+ once,
774
+ exit,
775
+ _cds,
776
+ cds_services,
777
+ connect,
778
+ server,
779
+ serve,
780
+ services,
781
+ service,
782
+ cds_serve_fluent,
783
+ cds_connect_options,
784
+ Middleswares,
785
+ middlewares,
786
+ env,
787
+ _TODO,
788
+ get,
789
+ load,
790
+ resolve,
791
+ reflect,
792
+ _flavor,
793
+ _odata_options,
794
+ _options,
795
+ JSON_2 as JSON,
796
+ YAML,
797
+ CDL,
798
+ SQL,
799
+ XML,
800
+ EDM,
801
+ EDMX,
802
+ filename,
803
+ model,
804
+ parse,
805
+ linked,
806
+ __type,
807
+ __aspect,
808
+ __any_,
809
+ __scalar,
810
+ __Boolean,
811
+ __UUID,
812
+ __String,
813
+ __LargeString,
814
+ __Binary,
815
+ __LargeBinary,
816
+ __Vector,
817
+ __Integer,
818
+ __UInt8,
819
+ __Int16,
820
+ __Int32,
821
+ __Int64,
822
+ __Float,
823
+ __Double,
824
+ __Decimal,
825
+ __date,
826
+ __Date,
827
+ __Time,
828
+ __DateTime,
829
+ __TimeStamp,
830
+ __array,
831
+ __struct,
832
+ __context_,
833
+ __service,
834
+ __entity,
835
+ __Association,
836
+ __Composition,
837
+ compile,
838
+ spawn,
839
+ Key,
840
+ QueryAPI,
841
+ Service,
842
+ ApplicationService,
843
+ MessagingService,
844
+ RemoteService,
845
+ DatabaseService,
846
+ Transaction,
847
+ ResultSet,
848
+ ServiceImpl,
849
+ EventHandler,
850
+ OnEventHandler,
851
+ OnErrorHandler,
852
+ Partial_2 as Partial,
853
+ OneOrMany,
854
+ CdsFunction,
855
+ TypedRequest,
856
+ CRUDEventHandler,
857
+ ActionEventHandler,
858
+ ResultsHandler,
859
+ SpawnEvents,
860
+ SpawnEventEmitter,
861
+ types,
862
+ SpawnOptions,
863
+ context,
864
+ tx,
865
+ entities,
866
+ run,
867
+ foreach,
868
+ stream,
869
+ read,
870
+ create,
871
+ insert,
872
+ update,
873
+ transaction,
874
+ db,
875
+ outboxed,
876
+ unboxed,
877
+ EventContext,
878
+ Event_2 as Event,
879
+ Request_2 as Request,
880
+ User,
881
+ Privileged,
882
+ utils,
883
+ Query,
884
+ SELECT_2 as SELECT,
885
+ INSERT_2 as INSERT,
886
+ UPSERT_2 as UPSERT,
887
+ UPDATE_2 as UPDATE,
888
+ DELETE_2 as DELETE,
889
+ CREATE_2 as CREATE,
890
+ DROP_2 as DROP,
891
+ primitive,
892
+ data,
893
+ name,
894
+ source,
895
+ column_expr,
896
+ predicate,
897
+ ordering_term,
898
+ expr,
899
+ ref,
900
+ val,
901
+ xpr,
902
+ _xpr,
903
+ operator,
904
+ function_call,
905
+ enum_literal,
906
+ expr_literal
907
+ }
908
+ }
909
+
731
910
  /**
732
911
  * Definitions are the central elements of a CDS model.
733
912
  */
@@ -1412,7 +1591,7 @@ type LogFactory = {
1412
1591
  Logger: Logger,
1413
1592
 
1414
1593
  // FIXME
1415
- /* eslint-disable-next-line @typescript-eslint/ban-types */
1594
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
1416
1595
  winstonLogger (LoggerOptions?: { level?: string, levels?: any, format?: any, transports?: any, exitOnError?: boolean | Function, silent?: boolean }),
1417
1596
  }
1418
1597
 
@@ -1666,6 +1845,7 @@ export interface OnErrorHandler {
1666
1845
  }
1667
1846
 
1668
1847
  export interface OnEventHandler {
1848
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
1669
1849
  (req: Request_2, next: Function): Promise<any> | any | void
1670
1850
  }
1671
1851
 
@@ -2282,8 +2462,8 @@ export class Service extends QueryAPI {
2282
2462
  // Provider API
2283
2463
  prepend (fn: ServiceImpl): this
2284
2464
 
2285
- on<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<InstanceType<T>>): this
2286
- on<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<Array<InstanceType<T>>>): this
2465
+ on<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<Unwrap<T>>): this
2466
+ on<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<InstanceType<T>>): this
2287
2467
  on<F extends CdsFunction>(boundAction: F, service: string, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
2288
2468
  on<F extends CdsFunction>(unboundAction: F, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
2289
2469
  on (eve: types.event, entity: types.target, handler: OnEventHandler): this
@@ -2294,20 +2474,25 @@ export class Service extends QueryAPI {
2294
2474
  // onSucceeded (eve: types.Events, handler: types.EventHandler): this
2295
2475
  // onFailed (eve: types.Events, entity: types.Target, handler: types.EventHandler): this
2296
2476
  // onFailed (eve: types.Events, handler: types.EventHandler): this
2297
- before<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.Before<InstanceType<T>>): this
2298
- before<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.Before<Array<InstanceType<T>>>): this
2477
+ before<F extends CdsFunction>(boundAction: F, service: string, handler: CRUDEventHandler.Before<F['__parameters'], void | Error | F['__returns']>): this
2478
+ before<F extends CdsFunction>(unboundAction: F, handler: CRUDEventHandler.Before<F['__parameters'], void | Error | F['__returns']>): this
2479
+ before<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.Before<Unwrap<T>>): this
2480
+ before<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.Before<InstanceType<T>>): this
2299
2481
  before (eve: types.event, entity: types.target, handler: EventHandler): this
2300
2482
  before (eve: types.event, handler: EventHandler): this
2301
2483
 
2302
2484
  // order relevant:
2303
- // (2) check if T is arrayable -> use T directly
2304
- // (3) check if T is scalar -> wrap into array
2305
- // this streamlines that in _most_ cases, handlers will receive an array.
2485
+ // (2) check if T is arrayable -> unwrap array type
2486
+ // (3) check if T is scalar -> use T directly
2487
+ // this streamlines that in _most_ cases, handlers will receive a single object.
2306
2488
  // _Except_ for after.read handlers (1), which will change its inflection based on T.
2307
- after<T extends ArrayConstructable>(event: 'READ' | 'EACH', entity: T, handler: CRUDEventHandler.After<Unwrap<T>>): this
2308
- after<T extends Constructable>(event: 'READ' | 'EACH', entity: T, handler: CRUDEventHandler.After<InstanceType<T>>): this
2309
- after<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.After<InstanceType<T>>): this
2310
- after<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.After<Array<InstanceType<T>>>): this
2489
+ after<T extends ArrayConstructable>(event: 'READ', entity: T, handler: CRUDEventHandler.After<InstanceType<T>>): this
2490
+ after<T extends ArrayConstructable>(event: 'each', entity: T, handler: CRUDEventHandler.After<Unwrap<T>>): this
2491
+ after<T extends Constructable>(event: 'READ' | 'each', entity: T, handler: CRUDEventHandler.After<InstanceType<T>>): this
2492
+ after<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.After<Unwrap<T>>): this
2493
+ after<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.After<InstanceType<T>>): this
2494
+ after<F extends CdsFunction>(boundAction: F, service: string, handler: CRUDEventHandler.After<F['__parameters'], void | Error | F['__returns']>): this
2495
+ after<F extends CdsFunction>(unboundAction: F, handler: CRUDEventHandler.After<F['__parameters'], void | Error | F['__returns']>): this
2311
2496
  after (eve: types.event, entity: types.target, handler: ResultsHandler): this
2312
2497
  after (eve: types.event, handler: ResultsHandler): this
2313
2498
 
@@ -2597,7 +2782,7 @@ export type TypedRequest<T> = Omit<Request_2, 'data'> & { data: T }
2597
2782
 
2598
2783
  export namespace types {
2599
2784
  export type event = eventName | eventName[]
2600
- export type eventName = string
2785
+ export type eventName = { name: string } | string
2601
2786
  | 'CREATE' | 'READ' | 'UPDATE' | 'DELETE'
2602
2787
  | 'NEW' | 'EDIT' | 'PATCH' | 'SAVE'
2603
2788
  | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/cds-types",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Type definitions for main packages of CAP, like `@sap/cds`",
5
5
  "repository": "github:cap-js/cds-types",
6
6
  "homepage": "https://cap.cloud.sap/",
@@ -20,6 +20,7 @@
20
20
  ],
21
21
  "scripts": {
22
22
  "test": "jest --silent",
23
+ "test:integration": "jest --silent --testMatch \"**/test/**/*.integrationtest.js\"",
23
24
  "test:rollup": "npm run rollup; npm run rollup:on; npm run test; npm run rollup:off",
24
25
  "rollup": "rm -rf dist/ && mkdir -p etc/ && npx -y @microsoft/api-extractor run --local --verbose && .github/rollup-patch.js",
25
26
  "rollup:on": "npm pkg set typings=dist/cds-types.d.ts && [ -d 'apis' ] && mv -- apis -apis || true",
@@ -38,7 +39,7 @@
38
39
  },
39
40
  "devDependencies": {
40
41
  "@eslint/js": "^9.2.0",
41
- "@sap/cds": ">=7.5.0",
42
+ "@sap/cds": ">=8.0.0",
42
43
  "@stylistic/eslint-plugin-js": "^2.1.0",
43
44
  "@stylistic/eslint-plugin-ts": "^2.1.0",
44
45
  "@types/jest": "^29.5.11",
@@ -49,7 +50,7 @@
49
50
  "jest": "^29.7.0",
50
51
  "ts-jest": "^29.1.1",
51
52
  "typescript": "^5.4.5",
52
- "typescript-eslint": "^8.0.0-alpha.10",
53
+ "typescript-eslint": "^8.0.0-alpha.51",
53
54
  "winston": "^3.13.0"
54
55
  },
55
56
  "jest": {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- /* eslint-disable @typescript-eslint/no-var-requires*/
4
3
  /* eslint-disable no-undef */
4
+ /* eslint-disable @typescript-eslint/no-require-imports */
5
5
  const fs = require('node:fs')
6
6
  const { join, relative, dirname } = require('node:path')
7
7