@open-rap/runtime 0.0.0-stage → 0.1.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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -2
  3. package/dist/abap/background.d.ts +14 -0
  4. package/dist/abap/background.js +130 -0
  5. package/dist/abap/background.js.map +1 -0
  6. package/dist/abap/bridge.d.ts +62 -0
  7. package/dist/abap/bridge.js +402 -0
  8. package/dist/abap/bridge.js.map +1 -0
  9. package/dist/abap/convert.d.ts +26 -0
  10. package/dist/abap/convert.js +197 -0
  11. package/dist/abap/convert.js.map +1 -0
  12. package/dist/abap/http.d.ts +34 -0
  13. package/dist/abap/http.js +133 -0
  14. package/dist/abap/http.js.map +1 -0
  15. package/dist/abap/mail.d.ts +10 -0
  16. package/dist/abap/mail.js +83 -0
  17. package/dist/abap/mail.js.map +1 -0
  18. package/dist/abap/odata-client.d.ts +33 -0
  19. package/dist/abap/odata-client.js +576 -0
  20. package/dist/abap/odata-client.js.map +1 -0
  21. package/dist/abap/sql.d.ts +92 -0
  22. package/dist/abap/sql.js +261 -0
  23. package/dist/abap/sql.js.map +1 -0
  24. package/dist/abap/utils.d.ts +41 -0
  25. package/dist/abap/utils.js +976 -0
  26. package/dist/abap/utils.js.map +1 -0
  27. package/dist/app.d.ts +53 -0
  28. package/dist/app.js +169 -0
  29. package/dist/app.js.map +1 -0
  30. package/dist/auth/auth.d.ts +68 -0
  31. package/dist/auth/auth.js +140 -0
  32. package/dist/auth/auth.js.map +1 -0
  33. package/dist/auth/authorizations.d.ts +39 -0
  34. package/dist/auth/authorizations.js +103 -0
  35. package/dist/auth/authorizations.js.map +1 -0
  36. package/dist/auth/business-users.d.ts +15 -0
  37. package/dist/auth/business-users.js +36 -0
  38. package/dist/auth/business-users.js.map +1 -0
  39. package/dist/auth/dev-oauth.d.ts +38 -0
  40. package/dist/auth/dev-oauth.js +156 -0
  41. package/dist/auth/dev-oauth.js.map +1 -0
  42. package/dist/auth/environment.d.ts +7 -0
  43. package/dist/auth/environment.js +57 -0
  44. package/dist/auth/environment.js.map +1 -0
  45. package/dist/auth/session.d.ts +45 -0
  46. package/dist/auth/session.js +257 -0
  47. package/dist/auth/session.js.map +1 -0
  48. package/dist/auth/user.d.ts +21 -0
  49. package/dist/auth/user.js +12 -0
  50. package/dist/auth/user.js.map +1 -0
  51. package/dist/db/database.d.ts +30 -0
  52. package/dist/db/database.js +131 -0
  53. package/dist/db/database.js.map +1 -0
  54. package/dist/db/seed.d.ts +9 -0
  55. package/dist/db/seed.js +63 -0
  56. package/dist/db/seed.js.map +1 -0
  57. package/dist/index.d.ts +20 -0
  58. package/dist/index.js +21 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/launchpad/dev.d.ts +14 -0
  61. package/dist/launchpad/dev.js +48 -0
  62. package/dist/launchpad/dev.js.map +1 -0
  63. package/dist/launchpad/proxy.d.ts +30 -0
  64. package/dist/launchpad/proxy.js +98 -0
  65. package/dist/launchpad/proxy.js.map +1 -0
  66. package/dist/launchpad/server.d.ts +77 -0
  67. package/dist/launchpad/server.js +177 -0
  68. package/dist/launchpad/server.js.map +1 -0
  69. package/dist/mcp/server.d.ts +22 -0
  70. package/dist/mcp/server.js +222 -0
  71. package/dist/mcp/server.js.map +1 -0
  72. package/dist/odata/access.d.ts +31 -0
  73. package/dist/odata/access.js +142 -0
  74. package/dist/odata/access.js.map +1 -0
  75. package/dist/odata/batch.d.ts +36 -0
  76. package/dist/odata/batch.js +147 -0
  77. package/dist/odata/batch.js.map +1 -0
  78. package/dist/odata/csrf.d.ts +13 -0
  79. package/dist/odata/csrf.js +27 -0
  80. package/dist/odata/csrf.js.map +1 -0
  81. package/dist/odata/custom.d.ts +90 -0
  82. package/dist/odata/custom.js +373 -0
  83. package/dist/odata/custom.js.map +1 -0
  84. package/dist/odata/draft.d.ts +78 -0
  85. package/dist/odata/draft.js +590 -0
  86. package/dist/odata/draft.js.map +1 -0
  87. package/dist/odata/errors.d.ts +27 -0
  88. package/dist/odata/errors.js +41 -0
  89. package/dist/odata/errors.js.map +1 -0
  90. package/dist/odata/handler.d.ts +90 -0
  91. package/dist/odata/handler.js +312 -0
  92. package/dist/odata/handler.js.map +1 -0
  93. package/dist/odata/json.d.ts +23 -0
  94. package/dist/odata/json.js +85 -0
  95. package/dist/odata/json.js.map +1 -0
  96. package/dist/odata/read.d.ts +90 -0
  97. package/dist/odata/read.js +686 -0
  98. package/dist/odata/read.js.map +1 -0
  99. package/dist/odata/service.d.ts +45 -0
  100. package/dist/odata/service.js +145 -0
  101. package/dist/odata/service.js.map +1 -0
  102. package/dist/odata/uri/ast.d.ts +103 -0
  103. package/dist/odata/uri/ast.js +3 -0
  104. package/dist/odata/uri/ast.js.map +1 -0
  105. package/dist/odata/uri/parser.d.ts +26 -0
  106. package/dist/odata/uri/parser.js +697 -0
  107. package/dist/odata/uri/parser.js.map +1 -0
  108. package/dist/odata/write.d.ts +127 -0
  109. package/dist/odata/write.js +799 -0
  110. package/dist/odata/write.js.map +1 -0
  111. package/dist/platform.d.ts +14 -0
  112. package/dist/platform.js +66 -0
  113. package/dist/platform.js.map +1 -0
  114. package/dist/rap/bo.d.ts +76 -0
  115. package/dist/rap/bo.js +184 -0
  116. package/dist/rap/bo.js.map +1 -0
  117. package/dist/rap/kernel.d.ts +7 -0
  118. package/dist/rap/kernel.js +287 -0
  119. package/dist/rap/kernel.js.map +1 -0
  120. package/dist/rap/runtime.d.ts +84 -0
  121. package/dist/rap/runtime.js +128 -0
  122. package/dist/rap/runtime.js.map +1 -0
  123. package/dist/rap/transaction.d.ts +227 -0
  124. package/dist/rap/transaction.js +1385 -0
  125. package/dist/rap/transaction.js.map +1 -0
  126. package/dist/rap/types.d.ts +74 -0
  127. package/dist/rap/types.js +25 -0
  128. package/dist/rap/types.js.map +1 -0
  129. package/dist/server.d.ts +34 -0
  130. package/dist/server.js +114 -0
  131. package/dist/server.js.map +1 -0
  132. package/dist/ui/plugin.d.ts +14 -0
  133. package/dist/ui/plugin.js +47 -0
  134. package/dist/ui/plugin.js.map +1 -0
  135. package/dist/ui/resources.d.ts +22 -0
  136. package/dist/ui/resources.js +88 -0
  137. package/dist/ui/resources.js.map +1 -0
  138. package/dist/ui/variants.d.ts +25 -0
  139. package/dist/ui/variants.js +68 -0
  140. package/dist/ui/variants.js.map +1 -0
  141. package/dist/values.d.ts +43 -0
  142. package/dist/values.js +367 -0
  143. package/dist/values.js.map +1 -0
  144. package/package.json +60 -3
@@ -0,0 +1,227 @@
1
+ /**
2
+ * The managed RAP transaction (LUW): transactional buffer over the persistent tables, the
3
+ * operations of the business objects with their checks (authorization, feature control, locks,
4
+ * numbering, administrative fields), the determinations on modify (decision D21) and the save
5
+ * sequence (determinations on save, validations, write).
6
+ */
7
+ import { type Kysely } from "kysely";
8
+ import { type ActionModel, type EntityModel } from "@open-rap/model";
9
+ import type { AbapBridge } from "../abap/bridge.js";
10
+ import type { User } from "../auth/user.js";
11
+ import { type CanonicalValue } from "../values.js";
12
+ import { type BoAssociation, type BoEntity, type BoModel } from "./bo.js";
13
+ import { Responses, type AccessMode, type FailedOperation, type Row } from "./types.js";
14
+ export interface CreateRequest {
15
+ cid?: string;
16
+ values: Row;
17
+ /** Fields given by the consumer (`%control`). */
18
+ fields: Set<string>;
19
+ }
20
+ export interface UpdateRequest {
21
+ key: Row;
22
+ cidRef?: string;
23
+ values: Row;
24
+ fields: Set<string>;
25
+ }
26
+ export interface DeleteRequest {
27
+ key: Row;
28
+ cidRef?: string;
29
+ }
30
+ export interface CreateByAssociationRequest {
31
+ key: Row;
32
+ cidRef?: string;
33
+ targets: CreateRequest[];
34
+ }
35
+ export interface ActionRequest {
36
+ /** Instance actions: the instance. */
37
+ key?: Row;
38
+ cidRef?: string;
39
+ /** Static and factory actions: the content ID of the call. */
40
+ cid?: string;
41
+ param: Row;
42
+ }
43
+ export interface ActionResult {
44
+ key?: Row;
45
+ cidRef?: string;
46
+ cid?: string;
47
+ /** The result: a row of the result entity (or of the abstract entity), when the action has one. */
48
+ value?: Row;
49
+ }
50
+ export interface TransactionServices {
51
+ bo: BoModel;
52
+ bridge: AbapBridge;
53
+ /** Reads the instances of a custom entity through its query class (D43): rows by element. */
54
+ customRead?: (entity: EntityModel, equalities: Array<{
55
+ name: string;
56
+ value: CanonicalValue;
57
+ }>) => Promise<Row[]>;
58
+ /** Time stamps of the administrative fields: ISO UTC with microseconds, strictly increasing. */
59
+ now(): string;
60
+ }
61
+ export declare class Transaction {
62
+ private readonly services;
63
+ readonly db: Kysely<unknown>;
64
+ readonly user: User;
65
+ private readonly instances;
66
+ private readonly cids;
67
+ private readonly events;
68
+ private seq;
69
+ private readonly seen;
70
+ private readonly locked;
71
+ private source;
72
+ private saved;
73
+ /** ETag masters whose ETag field changes with their `etag dependent` instances (D32). */
74
+ private readonly etagTouched;
75
+ /** The saver runs (save_modified, cleanup): the only place where ABAP SQL may write. */
76
+ inSaver: boolean;
77
+ constructor(services: TransactionServices, db: Kysely<unknown>, user: User);
78
+ private get bo();
79
+ private get bridge();
80
+ private id;
81
+ /** The instances of a custom entity meeting equalities, read by its query class (D43). */
82
+ private readCustom;
83
+ private load;
84
+ /**
85
+ * The calculated elements (D67) of instances read from the persistent table, read from the CDS
86
+ * view: their values as of the last save.
87
+ */
88
+ private withCalculated;
89
+ private fromRecord;
90
+ /** The instance with this key, from the buffer or the database; undefined if it does not exist. */
91
+ private instance;
92
+ /** Key of a request row: its key, or the instance created with its `%cid_ref`. */
93
+ private resolveKey;
94
+ private record;
95
+ /** Instances of the buffer and the database reached by an association. */
96
+ private associated;
97
+ private failure;
98
+ /** Locks the lock master of an existing instance (`SELECT … FOR UPDATE NOWAIT`). */
99
+ private lock;
100
+ /** Global authorization of operations: the result of the authorization master's handler. */
101
+ private globalAuthorization;
102
+ /** Instance authorization: denied operations per instance key (of `bo`). */
103
+ private instanceAuthorization;
104
+ /** Key of the instance of `master` (an ancestor) that `key` of `bo` belongs to. */
105
+ private masterKey;
106
+ /** Instance feature control: operations disabled per instance, and read-only fields. */
107
+ private instanceFeatures;
108
+ /** Global feature control: disabled operations. */
109
+ private globalFeatures;
110
+ private operationFlag;
111
+ /** Calls a handler with the parameter names of its definition. */
112
+ private call;
113
+ private precheck;
114
+ private setAdminFields;
115
+ /** Fields a consumer may not write: read-only, managed numbering, admin fields (outside local mode). */
116
+ private writable;
117
+ create(bo: BoEntity, requests: CreateRequest[], mode: AccessMode, parent?: {
118
+ association: BoAssociation;
119
+ key: Row;
120
+ numbered?: Map<string, Row>;
121
+ }): Promise<Responses>;
122
+ private createTable;
123
+ /** Early numbering by the FOR NUMBERING handler: %cid → key. */
124
+ private number;
125
+ /**
126
+ * Early numbering of a creation by association (`FOR NUMBERING … FOR CREATE Travel\_Booking`):
127
+ * the handler gets the parent instances with their %target, and maps the %cid of the children.
128
+ */
129
+ private numberByAssociation;
130
+ update(bo: BoEntity, requests: UpdateRequest[], mode: AccessMode): Promise<Responses>;
131
+ delete(bo: BoEntity, requests: DeleteRequest[], mode: AccessMode): Promise<Responses>;
132
+ /** Deletes an instance and its composition children. */
133
+ private cascade;
134
+ createByAssociation(bo: BoEntity, association: BoAssociation, requests: CreateByAssociationRequest[], mode: AccessMode): Promise<Responses>;
135
+ read(bo: BoEntity, keys: Array<{
136
+ key: Row;
137
+ cidRef?: string;
138
+ }>): Promise<{
139
+ rows: Array<Row | undefined>;
140
+ responses: Responses;
141
+ }>;
142
+ readByAssociation(bo: BoEntity, association: BoAssociation, keys: Row[]): Promise<{
143
+ results: Array<{
144
+ source: Row;
145
+ target: Row;
146
+ }>;
147
+ responses: Responses;
148
+ }>;
149
+ execute(bo: BoEntity, action: ActionModel, requests: ActionRequest[], mode: AccessMode): Promise<{
150
+ results: ActionResult[];
151
+ responses: Responses;
152
+ }>;
153
+ private matches;
154
+ /** Keys of the instances whose triggers were touched since `since`, not by `id` itself. */
155
+ private triggered;
156
+ /** Keys of the instances changed in the LUW in a way that matches the triggers. */
157
+ private triggeredInLuw;
158
+ private runDetermination;
159
+ /** Determinations on modify, by rounds (D21). Called at the end of each modify request. */
160
+ determineOnModify(): Promise<Responses>;
161
+ private determine;
162
+ /** The save sequence: determinations on save, validations; the write when nothing failed. */
163
+ save(): Promise<Responses>;
164
+ /**
165
+ * Enhanced mode (D45): `field ( mandatory )` is checked when saving, as a validation on save
166
+ * would (on SAP, the mandatory characteristic is only a hint for the consumer, D20): each
167
+ * created or changed instance with an initial mandatory field fails, with a message per field.
168
+ */
169
+ private checkMandatory;
170
+ /** The changes of the LUW for save_modified: created, updated and deleted instances. */
171
+ private changes;
172
+ /**
173
+ * `INSERT|UPDATE|MODIFY|DELETE dbtab FROM [TABLE] @source [INDICATORS SET STRUCTURE %control]
174
+ * MAPPING FROM ENTITY` in save_modified: the rows of the entity are written to the table of its
175
+ * BDEF mapping. sy-subrc 4 when a row is not found (UPDATE, DELETE) or already there (INSERT of
176
+ * a work area); an INSERT FROM TABLE with a duplicate key is a runtime error, as in ABAP.
177
+ */
178
+ writeMapped(bo: BoEntity, operation: string, rows: Array<{
179
+ values: Row;
180
+ control: Set<string> | undefined;
181
+ }>, single: boolean, indicators: boolean): Promise<{
182
+ subrc: number;
183
+ dbcnt: number;
184
+ }>;
185
+ /** save_modified (and cleanup) of the BDEFs with additional or unmanaged save. */
186
+ private saveModified;
187
+ private write;
188
+ /** Keys of the instances created in the LUW, by content ID. */
189
+ createdByCid(cid: string): {
190
+ bo: BoEntity;
191
+ key: Row;
192
+ } | undefined;
193
+ /**
194
+ * The instance whose ETag field covers an instance (of `bo`, with the values `row`): itself
195
+ * for an `etag master`, the master reached by the `etag dependent by` associations otherwise.
196
+ */
197
+ private etagMasterInstance;
198
+ /**
199
+ * The ETag value an If-Match is compared with: the ETag field of the instance or of its ETag
200
+ * master, as it was when the LUW began (the state the client has read: the requests of a change
201
+ * set carry the ETags read before it, and the changes of the LUW, a determination that updates
202
+ * the master for example, do not make them stale); undefined when the instance is not found.
203
+ */
204
+ etagValue(bo: BoEntity, key: Row): Promise<{
205
+ value: unknown;
206
+ } | undefined>;
207
+ /**
208
+ * `etag dependent by` (D32): the ETag field of a master changes with its dependent instances.
209
+ * The runtime sets it when it is an administrative time stamp it manages
210
+ * (`localInstanceLastChangedAt`, `lastChangedAt`) and writes the master; at save time, so that
211
+ * the requests of a change set check the ETag the client has read.
212
+ */
213
+ private refreshEtagMasters;
214
+ /**
215
+ * Instance and global feature control of rows about to be read (GET): __EntityControl… The
216
+ * global and instance authorizations of the user disable the operations they refuse, as RAP
217
+ * presents both to its consumers (D36).
218
+ */
219
+ features(bo: BoEntity, keys: Row[], operations: FailedOperation[], fields: string[]): Promise<{
220
+ disabled: Set<string>;
221
+ readonly: Map<string, Set<string>>;
222
+ global: Set<string>;
223
+ }>;
224
+ /** The operations of an entity the user may perform: global authorization and global features (D36). */
225
+ allowed(bo: BoEntity, operations: FailedOperation[]): Promise<Set<string>>;
226
+ }
227
+ export declare function operationId(op: FailedOperation): string;