@cap-js/cds-types 0.10.0 → 0.12.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.
Files changed (2) hide show
  1. package/dist/cds-types.d.ts +241 -204
  2. package/package.json +5 -3
@@ -1,5 +1,6 @@
1
1
  declare module '@sap/cds' {
2
-
2
+ export * from "@sap/cds-dk";
3
+
3
4
 
4
5
  export type __any_ = classes.any_
5
6
 
@@ -102,6 +103,11 @@ class any_<K extends kinds = kinds> {
102
103
 
103
104
  interface any__2 {
104
105
  kind?: kinds
106
+ /**
107
+ * only available when compiled with docs:true
108
+ * @see [capire docs](https://cap.cloud.sap/docs/cds/cdl#comments)
109
+ */
110
+ doc?: string
105
111
  }
106
112
 
107
113
  /**
@@ -111,7 +117,15 @@ interface any__2 {
111
117
  */
112
118
  export const app: import('express').Application;
113
119
 
114
- export class ApplicationService extends Service {}
120
+ export class ApplicationService extends Service {
121
+ new<T extends Constructable>(draft: T, data: {[K in keyof InstanceType<T>]?: InstanceType<T>[K]}): Promise<unknown>
122
+ new<T extends Constructable>(draft: T): {
123
+ for(keys: Key[]): Promise<unknown>,
124
+ }
125
+ discard(draft: Constructable, keys: Key[]): Promise<unknown>
126
+ edit(draft: Constructable, keys: Key[]): Promise<unknown>
127
+ save(draft: Constructable, keys: Key[]): Promise<unknown>
128
+ }
115
129
 
116
130
  export class array extends type<'type' | 'elements'> { }
117
131
 
@@ -214,7 +228,6 @@ export type CDL = string
214
228
 
215
229
  namespace cds {
216
230
  export {
217
- default_2 as default,
218
231
  log,
219
232
  debug,
220
233
  test,
@@ -309,6 +322,7 @@ namespace cds {
309
322
  spawn,
310
323
  Key,
311
324
  QueryAPI,
325
+ PropertiesOf,
312
326
  Service,
313
327
  ApplicationService,
314
328
  MessagingService,
@@ -387,10 +401,188 @@ namespace cds {
387
401
  i18n
388
402
  }
389
403
  }
404
+ export default cds;
390
405
 
391
- export type _cds = typeof cds
406
+ export type _cds = typeof cds_2
392
407
 
393
- type _cds_2 = typeof cds
408
+ namespace cds_2 {
409
+ export {
410
+ cds as default,
411
+ log,
412
+ debug,
413
+ test,
414
+ ql,
415
+ QLExtensions,
416
+ csn,
417
+ delete_ as delete,
418
+ version,
419
+ home,
420
+ root,
421
+ cli,
422
+ requires,
423
+ extend,
424
+ lazify,
425
+ lazified,
426
+ entity,
427
+ event,
428
+ type,
429
+ array,
430
+ struct,
431
+ Association,
432
+ Composition,
433
+ builtin,
434
+ on,
435
+ once,
436
+ exit,
437
+ _cds,
438
+ cds_services,
439
+ connect,
440
+ server,
441
+ serve,
442
+ services,
443
+ service,
444
+ cds_serve_fluent,
445
+ cds_connect_options,
446
+ Middlewares,
447
+ middlewares,
448
+ app,
449
+ env,
450
+ _TODO,
451
+ get,
452
+ load,
453
+ resolve,
454
+ minify,
455
+ reflect,
456
+ _flavor,
457
+ _odata_options,
458
+ _options,
459
+ JSON_2 as JSON,
460
+ YAML,
461
+ CDL,
462
+ SQL,
463
+ XML,
464
+ EDM,
465
+ EDMX,
466
+ filename,
467
+ model,
468
+ parse,
469
+ linked,
470
+ __type,
471
+ __aspect,
472
+ __any_,
473
+ __scalar,
474
+ __Boolean,
475
+ __UUID,
476
+ __String,
477
+ __LargeString,
478
+ __Binary,
479
+ __LargeBinary,
480
+ __Vector,
481
+ __Integer,
482
+ __UInt8,
483
+ __Int16,
484
+ __Int32,
485
+ __Int64,
486
+ __Float,
487
+ __Double,
488
+ __Decimal,
489
+ __date,
490
+ __Date,
491
+ __Time,
492
+ __DateTime,
493
+ __TimeStamp,
494
+ __array,
495
+ __struct,
496
+ __context_,
497
+ __service,
498
+ __entity,
499
+ __Association,
500
+ __Composition,
501
+ compile,
502
+ spawn,
503
+ Key,
504
+ QueryAPI,
505
+ PropertiesOf,
506
+ Service,
507
+ ApplicationService,
508
+ MessagingService,
509
+ RemoteService,
510
+ DatabaseService,
511
+ Transaction,
512
+ ResultSet,
513
+ ServiceImpl,
514
+ EventHandler,
515
+ OnEventHandler,
516
+ OnErrorHandler,
517
+ Partial_2 as Partial,
518
+ OneOrMany,
519
+ CdsFunction,
520
+ CdsFunctions,
521
+ HandlerFunction,
522
+ CRUDEventHandler,
523
+ ActionEventHandler,
524
+ ResultsHandler,
525
+ SpawnEvents,
526
+ SpawnEventEmitter,
527
+ types,
528
+ SpawnOptions,
529
+ context,
530
+ tx,
531
+ entities,
532
+ run,
533
+ foreach,
534
+ stream,
535
+ read,
536
+ create,
537
+ insert,
538
+ update,
539
+ transaction,
540
+ db,
541
+ outboxed,
542
+ unboxed,
543
+ EventContext,
544
+ Event_2 as Event,
545
+ Request_2 as Request,
546
+ User,
547
+ Anonymous,
548
+ Privileged,
549
+ utils,
550
+ Query,
551
+ SELECT_2 as SELECT,
552
+ INSERT_2 as INSERT,
553
+ UPSERT_2 as UPSERT,
554
+ UPDATE_2 as UPDATE,
555
+ DELETE_2 as DELETE,
556
+ CREATE_2 as CREATE,
557
+ DROP_2 as DROP,
558
+ primitive,
559
+ data,
560
+ name,
561
+ source,
562
+ column_expr,
563
+ predicate,
564
+ ordering_term,
565
+ expr,
566
+ ref,
567
+ _segment,
568
+ _named,
569
+ val,
570
+ xpr,
571
+ _xpr,
572
+ operator,
573
+ function_call,
574
+ enum_literal,
575
+ expr_literal,
576
+ Texts,
577
+ I18nBundle,
578
+ I18nFacade,
579
+ I18nFilesOptions,
580
+ I18nFiles,
581
+ i18n
582
+ }
583
+ }
584
+
585
+ type _cds_2 = typeof cds_2
394
586
 
395
587
  export interface cds_connect_options {
396
588
  impl?: string
@@ -609,7 +801,7 @@ export const connect: {
609
801
  * Shortcut for 'db' as the primary database returning `cds.DatabaseService`
610
802
  * @example await cds.connect.to ('db')
611
803
  */
612
- to(datasource: 'db', options?: cds_connect_options): Promise<cds.DatabaseService>,
804
+ to(datasource: 'db', options?: cds_connect_options): Promise<cds_2.DatabaseService>,
613
805
 
614
806
  /**
615
807
  * Connects to a specific datasource via a Service subclass
@@ -625,7 +817,7 @@ export const connect: {
625
817
  * await cds.connect.to (ServiceClass)
626
818
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
627
819
  */
628
- to<S>(datasource: S, options?: cds_connect_options): Promise<cds.CdsFunctions<S> & Service>,
820
+ to<S>(datasource: S, options?: cds_connect_options): Promise<cds_2.CdsFunctions<S> & Service>,
629
821
 
630
822
  /**
631
823
  * Connects to a specific datasource via options.
@@ -825,181 +1017,6 @@ class Decimal extends Float {
825
1017
  scale?: number
826
1018
  }
827
1019
 
828
- export namespace default_2 {
829
- export {
830
- log,
831
- debug,
832
- test,
833
- ql,
834
- QLExtensions,
835
- csn,
836
- delete_ as delete,
837
- version,
838
- home,
839
- root,
840
- cli,
841
- requires,
842
- extend,
843
- lazify,
844
- lazified,
845
- entity,
846
- event,
847
- type,
848
- array,
849
- struct,
850
- Association,
851
- Composition,
852
- builtin,
853
- on,
854
- once,
855
- exit,
856
- _cds,
857
- cds_services,
858
- connect,
859
- server,
860
- serve,
861
- services,
862
- service,
863
- cds_serve_fluent,
864
- cds_connect_options,
865
- Middlewares,
866
- middlewares,
867
- app,
868
- env,
869
- _TODO,
870
- get,
871
- load,
872
- resolve,
873
- minify,
874
- reflect,
875
- _flavor,
876
- _odata_options,
877
- _options,
878
- JSON_2 as JSON,
879
- YAML,
880
- CDL,
881
- SQL,
882
- XML,
883
- EDM,
884
- EDMX,
885
- filename,
886
- model,
887
- parse,
888
- linked,
889
- __type,
890
- __aspect,
891
- __any_,
892
- __scalar,
893
- __Boolean,
894
- __UUID,
895
- __String,
896
- __LargeString,
897
- __Binary,
898
- __LargeBinary,
899
- __Vector,
900
- __Integer,
901
- __UInt8,
902
- __Int16,
903
- __Int32,
904
- __Int64,
905
- __Float,
906
- __Double,
907
- __Decimal,
908
- __date,
909
- __Date,
910
- __Time,
911
- __DateTime,
912
- __TimeStamp,
913
- __array,
914
- __struct,
915
- __context_,
916
- __service,
917
- __entity,
918
- __Association,
919
- __Composition,
920
- compile,
921
- spawn,
922
- Key,
923
- QueryAPI,
924
- Service,
925
- ApplicationService,
926
- MessagingService,
927
- RemoteService,
928
- DatabaseService,
929
- Transaction,
930
- ResultSet,
931
- ServiceImpl,
932
- EventHandler,
933
- OnEventHandler,
934
- OnErrorHandler,
935
- Partial_2 as Partial,
936
- OneOrMany,
937
- CdsFunction,
938
- CdsFunctions,
939
- HandlerFunction,
940
- CRUDEventHandler,
941
- ActionEventHandler,
942
- ResultsHandler,
943
- SpawnEvents,
944
- SpawnEventEmitter,
945
- types,
946
- SpawnOptions,
947
- context,
948
- tx,
949
- entities,
950
- run,
951
- foreach,
952
- stream,
953
- read,
954
- create,
955
- insert,
956
- update,
957
- transaction,
958
- db,
959
- outboxed,
960
- unboxed,
961
- EventContext,
962
- Event_2 as Event,
963
- Request_2 as Request,
964
- User,
965
- Anonymous,
966
- Privileged,
967
- utils,
968
- Query,
969
- SELECT_2 as SELECT,
970
- INSERT_2 as INSERT,
971
- UPSERT_2 as UPSERT,
972
- UPDATE_2 as UPDATE,
973
- DELETE_2 as DELETE,
974
- CREATE_2 as CREATE,
975
- DROP_2 as DROP,
976
- primitive,
977
- data,
978
- name,
979
- source,
980
- column_expr,
981
- predicate,
982
- ordering_term,
983
- expr,
984
- ref,
985
- _segment,
986
- _named,
987
- val,
988
- xpr,
989
- _xpr,
990
- operator,
991
- function_call,
992
- enum_literal,
993
- expr_literal,
994
- Texts,
995
- I18nBundle,
996
- I18nFacade,
997
- I18nFilesOptions,
998
- I18nFiles,
999
- i18n
1000
- }
1001
- }
1002
-
1003
1020
  /**
1004
1021
  * Definitions are the central elements of a CDS model.
1005
1022
  */
@@ -1169,7 +1186,6 @@ export namespace env {
1169
1186
  [key: string]: MockUser | undefined
1170
1187
  }
1171
1188
 
1172
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
1173
1189
  export type Requires = {
1174
1190
  auth: {
1175
1191
  kind: 'dummy' | 'mocked' | 'basic' | 'xsuaa' | 'ias' | string,
@@ -1503,7 +1519,7 @@ type INSERT_2 = { INSERT: {
1503
1519
  columns: string[],
1504
1520
  values: primitive[],
1505
1521
  rows: primitive[][],
1506
- as: SELECT_2,
1522
+ from: SELECT_2,
1507
1523
  }, }
1508
1524
  export { INSERT_2 as INSERT }
1509
1525
 
@@ -1520,10 +1536,6 @@ class INSERT_3<T> extends ConstructedQuery<T> {
1520
1536
  & (<T> (entity: Constructable<T>, ...entries: T[]) => INSERT_3<T>)
1521
1537
  & (<T> (entity: Constructable<T>, entries?: T[]) => INSERT_3<T>)
1522
1538
 
1523
- /**
1524
- * @deprected
1525
- */
1526
- as (select: SELECT_3<T>): this
1527
1539
  from (select: SELECT_3<T>): this
1528
1540
  INSERT: CQN.INSERT['INSERT']
1529
1541
 
@@ -1648,6 +1660,9 @@ export const linked: {
1648
1660
  export namespace linked {
1649
1661
  export type LinkedDefinitions = IterableMap<linked_2.classes.any_>
1650
1662
  export type LinkedCSN = linked_2.LinkedCSN
1663
+ // synthetic class that is prominently featured in capire,
1664
+ // but described as "accessible through cds.linked.classes.any"
1665
+ export type LinkedDefinition = linked_2.classes.any_
1651
1666
 
1652
1667
  export namespace classes {
1653
1668
  export type type = __type
@@ -2201,6 +2216,10 @@ export class Privileged extends User {
2201
2216
 
2202
2217
  type Projection<T> = (e: QLExtensions<T extends ArrayConstructable ? SingularInstanceType<T> : T>) => void
2203
2218
 
2219
+ export type PropertiesOf<T> = {
2220
+ [K in keyof T]?: T[K];
2221
+ };
2222
+
2204
2223
  /**
2205
2224
  * @alpha
2206
2225
  * related to .protocols getters
@@ -2391,7 +2410,7 @@ export class RemoteService extends Service {}
2391
2410
  */
2392
2411
  class Request_2<T = any> extends Event_2<T> {
2393
2412
 
2394
- params: (string | object)[]
2413
+ params: Record<string, any>[]
2395
2414
 
2396
2415
  method: string
2397
2416
 
@@ -2410,6 +2429,8 @@ class Request_2<T = any> extends Event_2<T> {
2410
2429
  subject: ref
2411
2430
 
2412
2431
  reply (results: any): void
2432
+ /** @beta */
2433
+ reply (results: any, options: { mimetype?: string, filename?: string, [key: string]: any }): void
2413
2434
 
2414
2435
  notify (code: number, message: string, target?: string, args?: any[]): Error
2415
2436
 
@@ -2419,7 +2440,7 @@ class Request_2<T = any> extends Event_2<T> {
2419
2440
 
2420
2441
  error (code: number, message: string, target?: string, args?: any[]): Error
2421
2442
 
2422
- reject (code: number, message: string, target?: string, args?: any[]): Error
2443
+ reject (code: number, message: string, target?: string, args?: any[]): never
2423
2444
 
2424
2445
  notify (code: number, message: string, args?: any[]): Error
2425
2446
 
@@ -2429,7 +2450,7 @@ class Request_2<T = any> extends Event_2<T> {
2429
2450
 
2430
2451
  error (code: number, message: string, args?: any[]): Error
2431
2452
 
2432
- reject (code: number, message: string, args?: any[]): Error
2453
+ reject (code: number, message: string, args?: any[]): never
2433
2454
 
2434
2455
  notify (message: string, target?: string, args?: any[]): Error
2435
2456
 
@@ -2439,7 +2460,7 @@ class Request_2<T = any> extends Event_2<T> {
2439
2460
 
2440
2461
  error (message: string, target?: string, args?: any[]): Error
2441
2462
 
2442
- reject (message: string, target?: string, args?: any[]): Error
2463
+ reject (message: string, target?: string, args?: any[]): never
2443
2464
 
2444
2465
  notify (message: { code?: number | string, message: string, target?: string, args?: any[] }): Error
2445
2466
 
@@ -2449,7 +2470,7 @@ class Request_2<T = any> extends Event_2<T> {
2449
2470
 
2450
2471
  error (message: { code?: number | string, message: string, target?: string, args?: any[], status?: number }): Error
2451
2472
 
2452
- reject (message: { code?: number | string, message: string, target?: string, args?: any[], status?: number }): Error
2473
+ reject (message: { code?: number | string, message: string, target?: string, args?: any[], status?: number }): never
2453
2474
 
2454
2475
  }
2455
2476
  export { Request_2 as Request }
@@ -2538,17 +2559,6 @@ class SELECT_3<T, Q = SELECT_from> extends ConstructedQuery<T> {
2538
2559
  alias (as: string): this
2539
2560
  elements: EntityElements
2540
2561
 
2541
-
2542
- // Not yet public
2543
- // fullJoin (other: string, as: string) : this
2544
- // leftJoin (other: string, as: string) : this
2545
- // rightJoin (other: string, as: string) : this
2546
- // innerJoin (other: string, as: string) : this
2547
- // join (other: string, as: string, kind?: string) : this
2548
- // on : TaggedTemplateQueryPart<this>
2549
- // & ((...expr : string[]) => this)
2550
- // & ((predicate:object) => this)
2551
-
2552
2562
  SELECT: CQN.SELECT['SELECT'] & {
2553
2563
  forUpdate?: { wait: number },
2554
2564
  forShareLock?: { wait: number },
@@ -2698,6 +2708,14 @@ export class Service extends QueryAPI {
2698
2708
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#srv-emit-event)
2699
2709
  */
2700
2710
  emit: {
2711
+ // we can only give very little guidance as to code completion here.
2712
+ // Users will receive suggestions/ code completion for the property names of P.
2713
+ // But they will see no complaints for when they pass a non-existing property or use the wrong type for it.
2714
+ // That is because classes still fulfill {name:string}, so they can be used for the overload where event of type types.event,
2715
+ // which allows for any object as data.
2716
+ <P extends Constructable, R>(event: P, data: PropertiesOf<InstanceType<P>>, headers?: object): Promise<R>,
2717
+ <P extends ArrayConstructable, R>(event: P, data: PropertiesOf<SingularInstanceType<P>>, headers?: object): Promise<R>,
2718
+ <T = any>(event: types.event, data?: object, headers?: object): Promise<T>,
2701
2719
  <T = any>(details: { event: types.event, data?: object, headers?: object }): Promise<T>,
2702
2720
  <T = any>(event: types.event, data?: object, headers?: object): Promise<T>,
2703
2721
  }
@@ -2952,6 +2970,8 @@ type Subqueryable<T> = T extends Primitive ? unknown
2952
2970
  * Note that you do not need to return anything from these subqueries.
2953
2971
  */
2954
2972
  (fn: ((a: QLExtensions<T[number]>) => any) | '*'): T[number],
2973
+ // infix filters, like b.author`[city='Paris']`('*')
2974
+ (predicate: TemplateStringsArray): Subqueryable<T>,
2955
2975
  }
2956
2976
  // composition of one/ association to one
2957
2977
  : {
@@ -2972,6 +2992,8 @@ type Subqueryable<T> = T extends Primitive ? unknown
2972
2992
  * Note that you do not need to return anything from these subqueries.
2973
2993
  */
2974
2994
  (fn: ((a: QLExtensions<T>) => any) | '*'): T,
2995
+ // infix filters, like b.author`[city='Paris']`('*')
2996
+ (predicate: TemplateStringsArray): Subqueryable<T>,
2975
2997
  }
2976
2998
 
2977
2999
  type TaggedTemplateQueryPart<T> = (strings: TemplateStringsArray, ...params: unknown[]) => T
@@ -3302,6 +3324,21 @@ export const utils: {
3302
3324
  */
3303
3325
  rm: (...path: string[]) => Promise<ReturnType<typeof import('node:fs').promises.rm>>,
3304
3326
 
3327
+ /**
3328
+ * Shortcut for require("fs")
3329
+ */
3330
+ fs: typeof import('node:fs'),
3331
+
3332
+ /**
3333
+ * Shortcut for require("path")
3334
+ */
3335
+ path: typeof import('node:path'),
3336
+
3337
+ /**
3338
+ * Shortcut for require("util").inspect
3339
+ */
3340
+ inspect: typeof import('node:util').inspect,
3341
+
3305
3342
  /**
3306
3343
  * @since 8.3.0
3307
3344
  * @see https://cap.cloud.sap/docs/node.js/cds-utils#colors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/cds-types",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
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/",
@@ -29,7 +29,7 @@
29
29
  "test": "npm run test:setup && npm run test:rollup-on",
30
30
  "test:rollup-on": "npm run rollup && npm run rollup:on && npm run test:all --silent",
31
31
  "test:rollup-off": "npm run rollup:off && npm run test:all --silent",
32
- "rollup": "rm -rf dist/ && mkdir -p etc/ && npx -y @microsoft/api-extractor run --local --verbose && .github/rollup-patch.js",
32
+ "rollup": "rm -rf dist/ && mkdir -p etc/ && .github/api-extractor/run-api-extractor.js",
33
33
  "rollup:on": "npm pkg set typings=dist/cds-types.d.ts && [ -d 'apis' ] && mv -- apis -apis || true",
34
34
  "rollup:off": "npm pkg set typings=apis/cds.d.ts && [ -d '-apis' ] && mv -- -apis apis || true",
35
35
  "lint": "npx eslint .",
@@ -40,11 +40,13 @@
40
40
  "dependencies": "node ./scripts/postinstall.js"
41
41
  },
42
42
  "peerDependencies": {
43
- "@sap/cds": ">=8.0.0",
43
+ "@sap/cds": ">=9.0.0",
44
+ "@sap/cds-dk": "^9",
44
45
  "@types/express": ">=4"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@cap-js/cds-test": "^0",
49
+ "@microsoft/api-extractor": "^7.52.8",
48
50
  "@stylistic/eslint-plugin-js": "^4.0.1",
49
51
  "@stylistic/eslint-plugin-ts": "^4.0.1",
50
52
  "axios": "^1.6.2",