@cap-js/cds-types 0.2.0 → 0.3.0-beta.1
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/dist/cds-types.d.ts +2778 -0
- package/package.json +22 -15
- package/apis/cds.d.ts +0 -44
- package/apis/core.d.ts +0 -108
- package/apis/cqn.d.ts +0 -98
- package/apis/csn.d.ts +0 -126
- package/apis/env.d.ts +0 -22
- package/apis/events.d.ts +0 -149
- package/apis/internal/inference.d.ts +0 -66
- package/apis/linked.d.ts +0 -104
- package/apis/log.d.ts +0 -173
- package/apis/models.d.ts +0 -173
- package/apis/ql.d.ts +0 -395
- package/apis/server.d.ts +0 -145
- package/apis/services.d.ts +0 -449
- package/apis/test.d.ts +0 -112
- package/apis/utils.d.ts +0 -90
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/cds-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta.1",
|
|
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/",
|
|
@@ -11,36 +11,43 @@
|
|
|
11
11
|
],
|
|
12
12
|
"author": "SAP SE (https://www.sap.com)",
|
|
13
13
|
"license": "SEE LICENSE IN LICENSE",
|
|
14
|
-
"typings": "
|
|
14
|
+
"typings": "dist/cds-types.d.ts",
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
16
|
+
"dist/",
|
|
17
17
|
"LICENSE",
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "jest --silent",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
22
|
+
"rollup": "rm -rf dist/ && mkdir -p etc/ && npx -y @microsoft/api-extractor run --local --verbose && .github/rollup-patch.js",
|
|
23
|
+
"rollup:on": "npm pkg set typings=dist/cds-types.d.ts && [ -d 'apis' ] && mv -- apis -apis || true",
|
|
24
|
+
"rollup:off": "npm pkg set typings=apis/cds.d.ts && [ -d '-apis' ] && mv -- -apis apis || true",
|
|
25
|
+
"lint": "npx eslint .",
|
|
26
|
+
"lint:fix": "npx eslint . --fix",
|
|
27
|
+
"setup": "npm i && npm i file:. --no-save --force",
|
|
28
|
+
"prerelease:ci-fix": ".github/prerelease-fix.js"
|
|
26
29
|
},
|
|
27
30
|
"peerDependencies": {
|
|
28
|
-
"@sap/cds": ">=7"
|
|
31
|
+
"@sap/cds": ">=7 || ^8.0.0-beta"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@types/express": "^4.17.21"
|
|
29
35
|
},
|
|
30
36
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
37
|
+
"@eslint/js": "^9.2.0",
|
|
38
|
+
"@sap/cds": ">=7.5.0",
|
|
39
|
+
"@stylistic/eslint-plugin-js": "^2.1.0",
|
|
40
|
+
"@stylistic/eslint-plugin-ts": "^2.1.0",
|
|
33
41
|
"@types/jest": "^29.5.11",
|
|
34
42
|
"@types/node": "^20",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
36
|
-
"@typescript-eslint/parser": "^6.18.1",
|
|
37
43
|
"axios": "^1.6.2",
|
|
38
44
|
"chai": "^4.3.10",
|
|
39
|
-
"eslint": "^
|
|
45
|
+
"eslint": "^9.2.0",
|
|
40
46
|
"jest": "^29.7.0",
|
|
41
47
|
"ts-jest": "^29.1.1",
|
|
42
|
-
"typescript": "^5.
|
|
43
|
-
"
|
|
48
|
+
"typescript": "^5.4.5",
|
|
49
|
+
"typescript-eslint": "^8.0.0-alpha.10",
|
|
50
|
+
"winston": "^3.13.0"
|
|
44
51
|
},
|
|
45
52
|
"jest": {
|
|
46
53
|
"transform": {
|
package/apis/cds.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export * from './core'
|
|
2
|
-
export * from './server'
|
|
3
|
-
export * from './env'
|
|
4
|
-
export * from './models'
|
|
5
|
-
export * from './services'
|
|
6
|
-
export * from './events'
|
|
7
|
-
export * from './utils'
|
|
8
|
-
export { log, debug } from './log'
|
|
9
|
-
export { test } from './test'
|
|
10
|
-
export * from './cqn'
|
|
11
|
-
|
|
12
|
-
// FIXME: sort out what needs to be exported from csn/linked and under which namespace
|
|
13
|
-
// export { Association, CSN, Definition, Extension, Element, EntityElements, FQN, kinds } from './csn'
|
|
14
|
-
// export { Definitions, LinkedCSN, LinkedDefinition, LinkedAssociation, LinkedEntity, Filter, Visitor } from './linked'
|
|
15
|
-
|
|
16
|
-
// API extractor cannot handle export * as ql from './ql', so split it into an import and an export statement
|
|
17
|
-
import * as ql from './ql'
|
|
18
|
-
export { ql }
|
|
19
|
-
export { QLExtensions } from './ql' // cds-ql.ts test tries to import this from top level? Correct? Or ql.QLExtensions?
|
|
20
|
-
|
|
21
|
-
// trick to work around "delete" as reserved identifier
|
|
22
|
-
import { Service } from './services'
|
|
23
|
-
declare const delete_: Service['delete']
|
|
24
|
-
export { delete_ as delete }
|
|
25
|
-
|
|
26
|
-
declare global {
|
|
27
|
-
// these provide the functionality from SELECT, INSERT, etc in the global facade
|
|
28
|
-
const SELECT: ql.QL<any>['SELECT']
|
|
29
|
-
const INSERT: ql.QL<any>['INSERT']
|
|
30
|
-
const UPSERT: ql.QL<any>['UPSERT']
|
|
31
|
-
const UPDATE: ql.QL<any>['UPDATE']
|
|
32
|
-
const DELETE: ql.QL<any>['DELETE']
|
|
33
|
-
const CREATE: ql.QL<any>['CREATE']
|
|
34
|
-
const DROP: ql.QL<any>['DROP']
|
|
35
|
-
|
|
36
|
-
// and these allow us to use them as type too, i.e. `const q: SELECT<Book> = ...`
|
|
37
|
-
type SELECT<T> = ql.SELECT<T>
|
|
38
|
-
type INSERT<T> = ql.INSERT<T>
|
|
39
|
-
type UPSERT<T> = ql.UPSERT<T>
|
|
40
|
-
type UPDATE<T> = ql.UPDATE<T>
|
|
41
|
-
type DELETE<T> = ql.DELETE<T>
|
|
42
|
-
type CREATE<T> = ql.CREATE<T>
|
|
43
|
-
type DROP<T> = ql.DROP<T>
|
|
44
|
-
}
|
package/apis/core.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { LinkedAssociation, LinkedEntity, linked } from './linked'
|
|
2
|
-
import * as csn from './csn'
|
|
3
|
-
import { service } from './server'
|
|
4
|
-
|
|
5
|
-
type Intersect<T extends readonly unknown[]> = T extends [infer Head, ...infer Tail]
|
|
6
|
-
? Head & Intersect<Tail>
|
|
7
|
-
: unknown
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Base class for linked Associations from reflected models.
|
|
11
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-Association)
|
|
12
|
-
*/
|
|
13
|
-
export interface Association extends LinkedAssociation {}
|
|
14
|
-
export declare class Association { constructor (_?: object) }
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Base class for linked Compositions from reflected models.
|
|
18
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-composition)
|
|
19
|
-
*/
|
|
20
|
-
export interface Composition extends Association {}
|
|
21
|
-
export declare class Composition { constructor (_?: object) }
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Base class for linked entities from reflected models.
|
|
25
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-entity)
|
|
26
|
-
*/
|
|
27
|
-
export interface entity extends LinkedEntity {}
|
|
28
|
-
export declare class entity { constructor (_?: object) }
|
|
29
|
-
|
|
30
|
-
export interface event extends linked, csn.struct {}
|
|
31
|
-
export class event { constructor (_?: object) }
|
|
32
|
-
|
|
33
|
-
export interface type extends linked, csn.type {}
|
|
34
|
-
export class type { constructor (_?: object) }
|
|
35
|
-
|
|
36
|
-
export interface array extends linked, csn.type {}
|
|
37
|
-
export class array { constructor (_?: object) }
|
|
38
|
-
|
|
39
|
-
export interface struct extends linked, csn.struct {}
|
|
40
|
-
export class struct { constructor (_?: object) }
|
|
41
|
-
|
|
42
|
-
// infer (query : cqn, model : csn) : LinkedDefinition
|
|
43
|
-
export const builtin: {
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Base classes of linked definitions from reflected models.
|
|
47
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-builtin-classes)
|
|
48
|
-
*/
|
|
49
|
-
classes: {
|
|
50
|
-
Association: typeof Association,
|
|
51
|
-
Composition: typeof Composition,
|
|
52
|
-
entity: typeof entity,
|
|
53
|
-
event: typeof event,
|
|
54
|
-
type: typeof type,
|
|
55
|
-
array: typeof array,
|
|
56
|
-
struct: typeof struct,
|
|
57
|
-
service: service,
|
|
58
|
-
},
|
|
59
|
-
types: Record<string, object>,
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Add aspects to a given object, for example:
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```js
|
|
67
|
-
* extend (Object.prototype) .with (class {
|
|
68
|
-
* get foo() { return ... }
|
|
69
|
-
* bar() {...}
|
|
70
|
-
* }.prototype)
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export function extend<T> (target: T): {
|
|
74
|
-
with<E extends readonly any[]>(...ext: E): T & Intersect<E>,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Equip a given facade object with getters for lazy-loading modules instead
|
|
79
|
-
* of static requires. Example:
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```js
|
|
83
|
-
* const facade = lazify ({
|
|
84
|
-
* sub: lazy => require ('./sub-module')
|
|
85
|
-
* })
|
|
86
|
-
* ```
|
|
87
|
-
*
|
|
88
|
-
* The first usage of `facade.sub` will load the sub module
|
|
89
|
-
* using standard Node.js's `module.require` functions.
|
|
90
|
-
*/
|
|
91
|
-
export function lazify<T> (target: T): T
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Prepare a node module for lazy-loading submodules instead
|
|
95
|
-
* of static requires. Example:
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```js
|
|
99
|
-
* require = lazify (module) //> turns require into a lazy one
|
|
100
|
-
* const facade = module.exports = {
|
|
101
|
-
* sub: require ('./sub-module')
|
|
102
|
-
* })
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* The first usage of `facade.sub` will load the sub module
|
|
106
|
-
* using standard Node.js's `module.require` functions.
|
|
107
|
-
*/
|
|
108
|
-
export function lazified<T> (target: T): T
|
package/apis/cqn.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { entity } from './csn' // cyclic dependency
|
|
2
|
-
import { UnionToIntersection, UnionsToIntersections } from './internal/inference'
|
|
3
|
-
|
|
4
|
-
// FIXME: a union type would be more appropriate here
|
|
5
|
-
export type Query = Partial<SELECT & INSERT & UPDATE & DELETE & CREATE & DROP & UPSERT>
|
|
6
|
-
|
|
7
|
-
export type SELECT = { SELECT: {
|
|
8
|
-
distinct?: true,
|
|
9
|
-
one?: boolean,
|
|
10
|
-
from: source,
|
|
11
|
-
mixin?: { [key: string]: expr },
|
|
12
|
-
columns?: column_expr[],
|
|
13
|
-
excluding?: string[],
|
|
14
|
-
where?: predicate,
|
|
15
|
-
having?: predicate,
|
|
16
|
-
groupBy?: expr[],
|
|
17
|
-
orderBy?: ordering_term[],
|
|
18
|
-
limit?: { rows: val, offset: val },
|
|
19
|
-
}, }
|
|
20
|
-
|
|
21
|
-
export type INSERT = { INSERT: {
|
|
22
|
-
into: ref | name,
|
|
23
|
-
entries: data[],
|
|
24
|
-
columns: string[],
|
|
25
|
-
values: scalar[],
|
|
26
|
-
rows: scalar[][],
|
|
27
|
-
as: SELECT,
|
|
28
|
-
}, }
|
|
29
|
-
|
|
30
|
-
export type UPSERT = { UPSERT: {
|
|
31
|
-
into: ref | name,
|
|
32
|
-
columns: string[],
|
|
33
|
-
entries: data[],
|
|
34
|
-
values: scalar[],
|
|
35
|
-
rows: scalar[][],
|
|
36
|
-
}, }
|
|
37
|
-
|
|
38
|
-
export type UPDATE = { UPDATE: {
|
|
39
|
-
entity: ref | name,
|
|
40
|
-
data: { [key: string]: expr },
|
|
41
|
-
where?: predicate,
|
|
42
|
-
}, }
|
|
43
|
-
|
|
44
|
-
export type DELETE = { DELETE: {
|
|
45
|
-
from: ref | name,
|
|
46
|
-
where?: predicate,
|
|
47
|
-
}, }
|
|
48
|
-
|
|
49
|
-
export type CREATE = { CREATE: {
|
|
50
|
-
entity: entity | name,
|
|
51
|
-
as: SELECT,
|
|
52
|
-
}, }
|
|
53
|
-
|
|
54
|
-
export type DROP = { DROP: {
|
|
55
|
-
entity: name,
|
|
56
|
-
table: ref,
|
|
57
|
-
view: ref,
|
|
58
|
-
}, }
|
|
59
|
-
|
|
60
|
-
/** @private */
|
|
61
|
-
type scalar = number | string | boolean | null
|
|
62
|
-
|
|
63
|
-
/** @private */
|
|
64
|
-
type data = Record<string, any>
|
|
65
|
-
|
|
66
|
-
/** @private */
|
|
67
|
-
type name = string
|
|
68
|
-
|
|
69
|
-
/** @private */
|
|
70
|
-
type source = UnionToIntersection<ref | SELECT> & { as?: name, join?: name, on?: xpr }
|
|
71
|
-
export type column_expr = UnionToIntersection<expr> & { as?: name, cast?: any, expand?: column_expr[], inline?: column_expr[] }
|
|
72
|
-
export type predicate = UnionsToIntersections<_xpr>
|
|
73
|
-
|
|
74
|
-
/** @private */
|
|
75
|
-
type ordering_term = expr & { sort?: 'asc' | 'desc', nulls?: 'first' | 'last' }
|
|
76
|
-
|
|
77
|
-
export type expr = ref | val | xpr | function_call | SELECT
|
|
78
|
-
|
|
79
|
-
/** @private */
|
|
80
|
-
type ref = { ref: (name & { id?: string, where?: expr, args?: expr[] })[] }
|
|
81
|
-
|
|
82
|
-
/** @private */
|
|
83
|
-
type val = { val: any }
|
|
84
|
-
|
|
85
|
-
/** @private */
|
|
86
|
-
type xpr = { xpr: _xpr }
|
|
87
|
-
|
|
88
|
-
/** @private */
|
|
89
|
-
type _xpr = (expr | operator) []
|
|
90
|
-
|
|
91
|
-
/** @private */
|
|
92
|
-
type operator = string
|
|
93
|
-
|
|
94
|
-
/** @private */
|
|
95
|
-
type function_call = { func: string, args: { [key: string]: any }[] }
|
|
96
|
-
|
|
97
|
-
export type enum_literal = { '#': string }
|
|
98
|
-
export type expr_literal = { '=': string }
|
package/apis/csn.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { SELECT, ref, predicate } from './cqn'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A parsed CDS model in CSN object notation.
|
|
5
|
-
*/
|
|
6
|
-
export interface CSN {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The assigned namespace. If parsed from multiple sources,
|
|
10
|
-
* this is the topmost model's namespace, if any, not the
|
|
11
|
-
* ones of imported models.
|
|
12
|
-
*/
|
|
13
|
-
namespace?: string
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The list of usings in this parsed model. Not available after
|
|
17
|
-
* imports have been resolved into a merged model.
|
|
18
|
-
*/
|
|
19
|
-
requires?: string[]
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* All definitions in the model including those from imported models.
|
|
23
|
-
*/
|
|
24
|
-
definitions?: Record<FQN, Definition>
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* All extensions in the model including those from imported models.
|
|
28
|
-
* Not available after extensions have been applied.
|
|
29
|
-
*/
|
|
30
|
-
extensions?: Extension[]
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The names of the files from which this model has been loaded.
|
|
34
|
-
*/
|
|
35
|
-
$sources?: string[]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The fully-quality name of a definition.
|
|
40
|
-
*/
|
|
41
|
-
export type FQN = string
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Definitions are the central elements of a CDS model.
|
|
45
|
-
*/
|
|
46
|
-
export type Definition = context & service & type & struct & entity & Association
|
|
47
|
-
// NOTE: If we use & instead of | CSN.definitions values would be reduced to <never>
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Extensions capture `extend Foo with { ... }` directives.
|
|
51
|
-
*/
|
|
52
|
-
export type Extension = {
|
|
53
|
-
extend: FQN,
|
|
54
|
-
elements?: { [name: string]: Element },
|
|
55
|
-
includes?: FQN[],
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type Element = type & struct & Association
|
|
59
|
-
|
|
60
|
-
export type kinds = 'type' | 'entity' | 'event' | 'service' | 'context' | 'struct'
|
|
61
|
-
|
|
62
|
-
export interface any_ {
|
|
63
|
-
kind?: kinds
|
|
64
|
-
}
|
|
65
|
-
export interface context extends any_ { }
|
|
66
|
-
export interface service extends any_ { }
|
|
67
|
-
|
|
68
|
-
export interface type extends any_ {
|
|
69
|
-
type?: FQN
|
|
70
|
-
items?: type
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface struct extends type {
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* References to definitions to be included.
|
|
77
|
-
* Not available after extensions have been applied.
|
|
78
|
-
*/
|
|
79
|
-
includes?: FQN[]
|
|
80
|
-
elements: { [name: string]: Element }
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface entity extends Omit<struct, 'elements'> {
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Entities with a query signify a view
|
|
87
|
-
*/
|
|
88
|
-
query?: SELECT
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Elements of entities may have additional qualifiers
|
|
92
|
-
*/
|
|
93
|
-
elements: EntityElements
|
|
94
|
-
// REVISIT: following should move to LinkedCSN
|
|
95
|
-
keys: { [name: string]: Definition }
|
|
96
|
-
drafts?: entity
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export type EntityElements = {
|
|
100
|
-
[name: string]: Element & {
|
|
101
|
-
key?: boolean,
|
|
102
|
-
virtual?: boolean,
|
|
103
|
-
unique?: boolean,
|
|
104
|
-
notNull?: boolean,
|
|
105
|
-
},
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export interface Association extends type {
|
|
109
|
-
type: 'cds.Association' | 'cds.Composition'
|
|
110
|
-
target: FQN
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The specified cardinality. to-one = `{max:1}`, to-many = `{max:'*'}`
|
|
114
|
-
*/
|
|
115
|
-
cardinality?: { src?: 1, min?: 1 | 0, max?: 1 | '*' }
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The parsed on condition in case of unmanaged Associations
|
|
119
|
-
*/
|
|
120
|
-
on?: predicate
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* The optionally specified keys in case of managed Associations
|
|
124
|
-
*/
|
|
125
|
-
keys?: (ref & { as: string })[]
|
|
126
|
-
}
|
package/apis/env.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Access to the configuration for Node.js runtime and tools.
|
|
3
|
-
* The object is the effective result of configuration merged from various sources,
|
|
4
|
-
* filtered through the currently active profiles, thus highly dependent on the current working
|
|
5
|
-
* directory and process environment.
|
|
6
|
-
*/
|
|
7
|
-
export const env: {
|
|
8
|
-
build: any,
|
|
9
|
-
hana: any,
|
|
10
|
-
i18n: any,
|
|
11
|
-
mtx: any,
|
|
12
|
-
requires: any,
|
|
13
|
-
folders: any,
|
|
14
|
-
odata: any,
|
|
15
|
-
query: any,
|
|
16
|
-
sql: any,
|
|
17
|
-
} & { [key: string]: any } // to allow additional values we have not yet captured
|
|
18
|
-
|
|
19
|
-
export const requires: any
|
|
20
|
-
export const version: string
|
|
21
|
-
export const home: string
|
|
22
|
-
export const root: string
|
package/apis/events.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { LinkedDefinition } from './linked'
|
|
2
|
-
import { Query } from './cqn'
|
|
3
|
-
import { ref } from './cqn'
|
|
4
|
-
import * as express from 'express'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Represents the invocation context of incoming request and event messages.
|
|
9
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
|
|
10
|
-
*/
|
|
11
|
-
export class EventContext {
|
|
12
|
-
|
|
13
|
-
constructor (properties: { event: string, data?: object, query?: object, headers?: object })
|
|
14
|
-
http?: { req: express.Request, res: express.Response }
|
|
15
|
-
|
|
16
|
-
tenant: string
|
|
17
|
-
|
|
18
|
-
user: User
|
|
19
|
-
|
|
20
|
-
id: string
|
|
21
|
-
|
|
22
|
-
locale: `${string}_${string}`
|
|
23
|
-
|
|
24
|
-
timestamp: Date
|
|
25
|
-
|
|
26
|
-
features?: { [key: string]: boolean }
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
|
|
32
|
-
*/
|
|
33
|
-
export class Event extends EventContext {
|
|
34
|
-
|
|
35
|
-
event: string
|
|
36
|
-
|
|
37
|
-
data: any
|
|
38
|
-
|
|
39
|
-
headers: any
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
|
|
45
|
-
*/
|
|
46
|
-
export class Request extends Event {
|
|
47
|
-
|
|
48
|
-
params: (string | object)[]
|
|
49
|
-
|
|
50
|
-
method: string
|
|
51
|
-
|
|
52
|
-
path: string
|
|
53
|
-
|
|
54
|
-
target: LinkedDefinition
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Shortcut to {@link Request.target | target (entity) name}
|
|
58
|
-
* @see https://cap.cloud.sap/docs/node.js/events#req-entity
|
|
59
|
-
*/
|
|
60
|
-
entity: string
|
|
61
|
-
|
|
62
|
-
query: Query
|
|
63
|
-
|
|
64
|
-
subject: ref
|
|
65
|
-
|
|
66
|
-
reply (results: any): void
|
|
67
|
-
|
|
68
|
-
notify (code: number, message: string, target?: string, args?: any[]): Error
|
|
69
|
-
|
|
70
|
-
info (code: number, message: string, target?: string, args?: any[]): Error
|
|
71
|
-
|
|
72
|
-
warn (code: number, message: string, target?: string, args?: any[]): Error
|
|
73
|
-
|
|
74
|
-
error (code: number, message: string, target?: string, args?: any[]): Error
|
|
75
|
-
|
|
76
|
-
reject (code: number, message: string, target?: string, args?: any[]): Error
|
|
77
|
-
|
|
78
|
-
notify (code: number, message: string, args?: any[]): Error
|
|
79
|
-
|
|
80
|
-
info (code: number, message: string, args?: any[]): Error
|
|
81
|
-
|
|
82
|
-
warn (code: number, message: string, args?: any[]): Error
|
|
83
|
-
|
|
84
|
-
error (code: number, message: string, args?: any[]): Error
|
|
85
|
-
|
|
86
|
-
reject (code: number, message: string, args?: any[]): Error
|
|
87
|
-
|
|
88
|
-
notify (message: string, target?: string, args?: any[]): Error
|
|
89
|
-
|
|
90
|
-
info (message: string, target?: string, args?: any[]): Error
|
|
91
|
-
|
|
92
|
-
warn (message: string, target?: string, args?: any[]): Error
|
|
93
|
-
|
|
94
|
-
error (message: string, target?: string, args?: any[]): Error
|
|
95
|
-
|
|
96
|
-
reject (message: string, target?: string, args?: any[]): Error
|
|
97
|
-
|
|
98
|
-
notify (message: { code?: number | string, message: string, target?: string, args?: any[] }): Error
|
|
99
|
-
|
|
100
|
-
info (message: { code?: number | string, message: string, target?: string, args?: any[] }): Error
|
|
101
|
-
|
|
102
|
-
warn (message: { code?: number | string, message: string, target?: string, args?: any[] }): Error
|
|
103
|
-
|
|
104
|
-
error (message: { code?: number | string, message: string, target?: string, args?: any[], status?: number }): Error
|
|
105
|
-
|
|
106
|
-
reject (message: { code?: number | string, message: string, target?: string, args?: any[], status?: number }): Error
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Represents the user in a given context.
|
|
113
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/authentication#cds-user)
|
|
114
|
-
*/
|
|
115
|
-
export class User {
|
|
116
|
-
|
|
117
|
-
constructor (obj?: string | { id: string, attr: Record<string, string>, roles: Array<string> | Record<string, string> } | User)
|
|
118
|
-
id: string
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @deprecated Use https://cap.cloud.sap/docs/node.js/events#locale instead
|
|
122
|
-
*/
|
|
123
|
-
locale: string
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @deprecated Use https://cap.cloud.sap/docs/node.js/events#tenant instead
|
|
127
|
-
*/
|
|
128
|
-
tenant: string | undefined
|
|
129
|
-
|
|
130
|
-
attr: Record<string, string>
|
|
131
|
-
|
|
132
|
-
roles: Array<string> | Record<string, string>
|
|
133
|
-
|
|
134
|
-
static Privileged: typeof Privileged
|
|
135
|
-
|
|
136
|
-
is (role: string): boolean
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Subclass for executing code with superuser privileges.
|
|
142
|
-
*/
|
|
143
|
-
declare class Privileged extends User {
|
|
144
|
-
|
|
145
|
-
constructor ()
|
|
146
|
-
|
|
147
|
-
is (): boolean
|
|
148
|
-
|
|
149
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Types in this file are not part of the API.
|
|
2
|
-
// They are merely meant as definitions that are used
|
|
3
|
-
// in several places within the API.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export interface Constructable<T = any> {
|
|
7
|
-
new(...args: any[]): T
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// any class (not value) of array to represent plural types used in cds-typer.
|
|
11
|
-
// Mainly used as pattern match for SingularType
|
|
12
|
-
// type ArrayConstructable = Constructable<Array<any>>
|
|
13
|
-
export interface ArrayConstructable<T = any> {
|
|
14
|
-
new(...args: any[]): T[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// concrete singular type.
|
|
18
|
-
// `SingularType<typeof Books>` == `Book`.
|
|
19
|
-
export type SingularType<T extends ArrayConstructable<T>> = InstanceType<T>[number]
|
|
20
|
-
|
|
21
|
-
// Convenient way of unwrapping the inner type from array-typed values, as well as the value type itself
|
|
22
|
-
// `class MyArray<T> extends Array<T>``
|
|
23
|
-
// The latter is used heavily in the CDS typer, but its behaviour depends based on how the types are imported:
|
|
24
|
-
// If they are imported on a value based (`require('path/to/type')`) they will be considered `ArrayConstructable`.
|
|
25
|
-
// But if they are being used on type level (JSDOC: `/* @type {import('path/to/type')} */`) they are considered an `Array` .
|
|
26
|
-
// This type introduces an indirection that streamlines their behaviour for both cases.
|
|
27
|
-
// For any scalar type `Unwrap` behaves idempotent.
|
|
28
|
-
export type Unwrap<T> = T extends ArrayConstructable
|
|
29
|
-
? SingularType<T>
|
|
30
|
-
: T extends Array<infer U>
|
|
31
|
-
? U
|
|
32
|
-
: T
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/*
|
|
36
|
-
* the following three types are used to convert union types to intersection types.
|
|
37
|
-
* We need these as our types currently lack generics in places where we would need them to clearly decide
|
|
38
|
-
* on a subtype in the case of a union type. This leads to the following problem:
|
|
39
|
-
*
|
|
40
|
-
* ```ts
|
|
41
|
-
* type A = { a: number }
|
|
42
|
-
* type B = { b: string }
|
|
43
|
-
* type Foo = A | B
|
|
44
|
-
* function f(): Foo { ... }
|
|
45
|
-
* const x = f()
|
|
46
|
-
* x.a // error, could also be B
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* While we should have:
|
|
50
|
-
*
|
|
51
|
-
* ```ts
|
|
52
|
-
* function f<T extends Foo>(): T { ... }
|
|
53
|
-
* const x = f<A>()
|
|
54
|
-
* x.a
|
|
55
|
-
* ```ts
|
|
56
|
-
*
|
|
57
|
-
* Since we don't do that yet, we opt for intersection types instead.
|
|
58
|
-
* By also wrapping it in Partial, we at least force the user to check for the presence of any
|
|
59
|
-
* attribute they try to access.
|
|
60
|
-
*
|
|
61
|
-
* Places where these types are used are subject to a rework!
|
|
62
|
-
* the idea behind the conversion can be found in this excellent writeup: https://fettblog.eu/typescript-union-to-intersection/
|
|
63
|
-
*/
|
|
64
|
-
export type Scalarise<A> = A extends Array<infer N> ? N : A
|
|
65
|
-
export type UnionToIntersection<U> = Partial<(U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never>
|
|
66
|
-
export type UnionsToIntersections<U> = Array<UnionToIntersection<Scalarise<U>>>
|